123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- require 'rails_helper'
- describe ApplicationHelper do
- describe '#icon_tag' do
- it 'returns a Glyphicon icon element' do
- icon = icon_tag('glyphicon-help')
- expect(icon).to be_html_safe
- expect(Nokogiri(icon).at('span.glyphicon.glyphicon-help')).to be_a Nokogiri::XML::Element
- end
- it 'returns a Glyphicon icon element with an addidional class' do
- icon = icon_tag('glyphicon-help', class: 'text-info')
- expect(icon).to be_html_safe
- expect(Nokogiri(icon).at('span.glyphicon.glyphicon-help.text-info')).to be_a Nokogiri::XML::Element
- end
- it 'returns a FontAwesome icon element' do
- icon = icon_tag('fa-copy')
- expect(icon).to be_html_safe
- expect(Nokogiri(icon).at('i.fa-solid.fa-copy')).to be_a Nokogiri::XML::Element
- end
- it 'returns a FontAwesome icon element with an additional class' do
- icon = icon_tag('fa-copy', class: 'text-info')
- expect(icon).to be_html_safe
- expect(Nokogiri(icon).at('i.fa-solid.fa-copy.text-info')).to be_a Nokogiri::XML::Element
- end
- it 'returns a FontAwesome brand icon element' do
- icon = icon_tag('fa-github', class: 'fa-brands')
- expect(icon).to be_html_safe
- expect(Nokogiri(icon).at('i.fa-brands.fa-github')).to be_a Nokogiri::XML::Element
- end
- end
- describe '#nav_link' do
- it 'returns a nav link' do
- allow(self).to receive(:current_page?).with('/things') { false }
- nav = nav_link('Things', '/things')
- a = Nokogiri(nav).at('li:not(.active) > a[href="/things"]')
- expect(a.text.strip).to eq('Things')
- end
- it 'returns an active nav link' do
- allow(self).to receive(:current_page?).with('/things') { true }
- nav = nav_link('Things', '/things')
- expect(nav).to be_html_safe
- a = Nokogiri(nav).at('li.active > a[href="/things"]')
- expect(a).to be_a Nokogiri::XML::Element
- expect(a.text.strip).to eq('Things')
- end
- describe 'with block' do
- it 'returns a nav link with menu' do
- allow(self).to receive(:current_page?).with('/things') { false }
- allow(self).to receive(:current_page?).with('/things/stuff') { false }
- nav = nav_link('Things', '/things') { nav_link('Stuff', '/things/stuff') }
- expect(nav).to be_html_safe
- a0 = Nokogiri(nav).at('li.dropdown.dropdown-hover:not(.active) > a[href="/things"]')
- expect(a0).to be_a Nokogiri::XML::Element
- expect(a0.text.strip).to eq('Things')
- a1 = Nokogiri(nav).at('li.dropdown.dropdown-hover:not(.active) > li:not(.active) > a[href="/things/stuff"]')
- expect(a1).to be_a Nokogiri::XML::Element
- expect(a1.text.strip).to eq('Stuff')
- end
- it 'returns an active nav link with menu' do
- allow(self).to receive(:current_page?).with('/things') { true }
- allow(self).to receive(:current_page?).with('/things/stuff') { false }
- nav = nav_link('Things', '/things') { nav_link('Stuff', '/things/stuff') }
- expect(nav).to be_html_safe
- a0 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > a[href="/things"]')
- expect(a0).to be_a Nokogiri::XML::Element
- expect(a0.text.strip).to eq('Things')
- a1 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > li:not(.active) > a[href="/things/stuff"]')
- expect(a1).to be_a Nokogiri::XML::Element
- expect(a1.text.strip).to eq('Stuff')
- end
- it 'returns an active nav link with menu when on a child page' do
- allow(self).to receive(:current_page?).with('/things') { false }
- allow(self).to receive(:current_page?).with('/things/stuff') { true }
- nav = nav_link('Things', '/things') { nav_link('Stuff', '/things/stuff') }
- expect(nav).to be_html_safe
- a0 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > a[href="/things"]')
- expect(a0).to be_a Nokogiri::XML::Element
- expect(a0.text.strip).to eq('Things')
- a1 = Nokogiri(nav).at('li.dropdown.dropdown-hover.active > li:not(.active) > a[href="/things/stuff"]')
- expect(a1).to be_a Nokogiri::XML::Element
- expect(a1.text.strip).to eq('Stuff')
- end
- end
- end
- describe '#yes_no' do
- it 'returns a label "Yes" if any truthy value is given' do
- [true, Object.new].each { |value|
- label = yes_no(value)
- expect(label).to be_html_safe
- expect(Nokogiri(label).text).to eq 'Yes'
- }
- end
- it 'returns a label "No" if any falsy value is given' do
- [false, nil].each { |value|
- label = yes_no(value)
- expect(label).to be_html_safe
- expect(Nokogiri(label).text).to eq 'No'
- }
- end
- end
- describe '#working' do
- before do
- @agent = agents(:jane_website_agent)
- end
- it 'returns a label "Disabled" if a given agent is disabled' do
- allow(@agent).to receive(:disabled?) { true }
- label = working(@agent)
- expect(label).to be_html_safe
- expect(Nokogiri(label).text).to eq 'Disabled'
- end
- it 'returns a label "Missing Gems" if a given agent has dependencies missing' do
- allow(@agent).to receive(:dependencies_missing?) { true }
- label = working(@agent)
- expect(label).to be_html_safe
- expect(Nokogiri(label).text).to eq 'Missing Gems'
- end
- it 'returns a label "Yes" if a given agent is working' do
- allow(@agent).to receive(:working?) { true }
- label = working(@agent)
- expect(label).to be_html_safe
- expect(Nokogiri(label).text).to eq 'Yes'
- end
- it 'returns a label "No" if a given agent is not working' do
- allow(@agent).to receive(:working?) { false }
- label = working(@agent)
- expect(label).to be_html_safe
- expect(Nokogiri(label).text).to eq 'No'
- end
- end
- describe '#omniauth_provider_icon' do
- it 'returns a correct icon tag for Twitter' do
- icon = omniauth_provider_icon(:twitter)
- expect(icon).to be_html_safe
- elem = Nokogiri(icon).at('i.fa-brands.fa-twitter')
- expect(elem).to be_a Nokogiri::XML::Element
- end
- it 'returns a correct icon tag for GitHub' do
- icon = omniauth_provider_icon(:github)
- expect(icon).to be_html_safe
- elem = Nokogiri(icon).at('i.fa-brands.fa-github')
- expect(elem).to be_a Nokogiri::XML::Element
- end
- it 'returns a correct icon tag for other services' do
- icon = omniauth_provider_icon(:evernote)
- expect(icon).to be_html_safe
- elem = Nokogiri(icon).at('i.fa-solid.fa-lock')
- expect(elem).to be_a Nokogiri::XML::Element
- end
- end
- describe '#highlighted?' do
- it 'understands hl=6-8' do
- allow(params).to receive(:[]).with(:hl) { '6-8' }
- expect((1..10).select { |i| highlighted?(i) }).to eq [6, 7, 8]
- end
- it 'understands hl=1,3-4,9' do
- allow(params).to receive(:[]).with(:hl) { '1,3-4,9' }
- expect((1..10).select { |i| highlighted?(i) }).to eq [1, 3, 4, 9]
- end
- it 'understands hl=8-' do
- allow(params).to receive(:[]).with(:hl) { '8-' }
- expect((1..10).select { |i| highlighted?(i) }).to eq [8, 9, 10]
- end
- it 'understands hl=-2' do
- allow(params).to receive(:[]).with(:hl) { '-2' }
- expect((1..10).select { |i| highlighted?(i) }).to eq [1, 2]
- end
- it 'understands hl=-' do
- allow(params).to receive(:[]).with(:hl) { '-' }
- expect((1..10).select { |i| highlighted?(i) }).to eq [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- end
- it 'is OK with no hl' do
- allow(params).to receive(:[]).with(:hl) { nil }
- expect((1..10).select { |i| highlighted?(i) }).to be_empty
- end
- end
- end
|