From bd5995ef65bef3dd2eecfbfd7812f0b197685cb8 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Fri, 13 Aug 2021 00:53:11 +0200 Subject: [PATCH] Add specs for `nav_entry` helper --- app/helpers/application_helper.rb | 2 +- spec/helpers/application_helper_spec.rb | 34 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1405f6af..75360767 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -26,7 +26,7 @@ module ApplicationHelper badge_class = "badge" badge_class << " badge-#{options[:badge_color]}" unless options[:badge_color].nil? badge_class << " badge-pill" if options[:badge_pill] - body << " #{content_tag(:span, options[:badge], class: badge_class)}" + body += " #{content_tag(:span, options[:badge], class: badge_class)}" end content_tag(:li, link_to(body.html_safe, path, class: "nav-link"), class: classes) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 6bdc4702..fa6f8b4e 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -3,6 +3,40 @@ require "rails_helper" describe ApplicationHelper, :type => :helper do + describe '#nav_entry' do + it 'should return a HTML navigation item which links to a given address' do + allow(self).to receive(:current_page?).and_return(false) + expect(nav_entry('Example', '/example')).to( + eq('') + ) + end + + it 'should return with an active attribute if the link matches the current URL' do + allow(self).to receive(:current_page?).and_return(true) + expect(nav_entry('Example', '/example')).to( + eq('') + ) + end + + it 'should include an icon if given' do + allow(self).to receive(:current_page?).and_return(false) + expect(nav_entry('Example', '/example', icon: 'beaker')).to( + eq('') + ) + end + + it 'should include a badge if given' do + allow(self).to receive(:current_page?).and_return(false) + expect(nav_entry('Example', '/example', badge: 3)).to( + eq('') + ) + + expect(nav_entry('Example', '/example', badge: 3, badge_color: 'primary', badge_pill: true)).to( + eq('') + ) + end + end + describe "#bootstrap_color" do it 'should map error and alert to danger' do expect(bootstrap_color("error")).to eq("danger")