# frozen_string_literal: true
require 'spec_helper'
RSpec.describe TabHelper do
include ApplicationHelper
describe 'gl_tabs_nav' do
it 'creates a tabs navigation' do
expect(gl_tabs_nav).to match(%r{
<\/ul>})
end
it 'captures block output' do
expect(gl_tabs_nav { "block content" }).to match(/block content/)
end
it 'adds styles classes' do
expect(gl_tabs_nav).to match(/class="nav gl-tabs-nav"/)
end
it 'adds custom class' do
expect(gl_tabs_nav(class: 'my-class' )).to match(/class=".*my-class.*"/)
end
end
describe 'gl_tab_link_to' do
before do
allow(self).to receive(:current_page?).and_return(false)
end
it 'creates a tab' do
expect(gl_tab_link_to('Link', '/url')).to eq('- Link
')
end
it 'creates a tab with block output' do
expect(gl_tab_link_to('/url') { 'block content' }).to match(/block content/)
end
it 'creates a tab with custom classes' do
expect(gl_tab_link_to('Link', '/url', { class: 'my-class' })).to match(//)
expect(nav_link(html_options: { class: 'active' })).to match(/- /)
end
where(:controller_param, :action_param, :path_param, :active) do
nil | nil | nil | false
:foo | nil | nil | true
:bar | nil | nil | false
:bar | :foo | nil | false
:foo | :bar | nil | false
:foo | :foo | nil | true
:bar | nil | 'foo#foo' | true
:bar | nil | ['foo#foo', 'bar#bar'] | true
:bar | :bar | ['foo#foo', 'bar#bar'] | true
:foo | nil | 'bar#foo' | true
:bar | nil | 'bar#foo' | false
:foo | [:foo, :bar] | 'bar#foo' | true
:bar | :bar | 'foo#foo' | true
:foo | :foo | 'bar#foo' | true
:bar | :foo | 'bar#foo' | false
:foo | :bar | 'bar#foo' | false
[:foo, :bar] | nil | nil | true
[:foo, :bar] | nil | 'bar#foo' | true
[:foo, :bar] | :foo | 'bar#foo' | true
nil | :foo | nil | true
nil | :bar | nil | false
nil | nil | 'foo#bar' | false
nil | nil | 'foo#foo' | true
nil | :bar | ['foo#foo', 'bar#bar'] | true
nil | :bar | 'foo#foo' | true
nil | :foo | 'bar#foo' | true
nil | [:foo, :bar] | nil | true
nil | [:foo, :bar] | 'bar#foo' | true
nil | :bar | 'bar#foo' | false
end
with_them do
specify do
result = nav_link(controller: controller_param, action: action_param, path: path_param)
if active
expect(result).to match(/active/)
else
expect(result).not_to match(/active/)
end
end
end
context 'with namespace in path notation' do
before do
allow(controller).to receive(:controller_path).and_return('bar/foo')
end
where(:controller_param, :action_param, :path_param, :active) do
'foo/foo' | nil | nil | false
'bar/foo' | nil | nil | true
'foo/foo' | :foo | nil | false
'bar/foo' | :bar | nil | false
'bar/foo' | :foo | nil | true
nil | nil | 'foo/foo#foo' | false
nil | nil | 'bar/foo#foo' | true
end
with_them do
specify do
result = nav_link(controller: controller_param, action: action_param, path: path_param)
if active
expect(result).to match(/active/)
else
expect(result).not_to match(/active/)
end
end
end
end
end
end