debian-mirror-gitlab/spec/helpers/tab_helper_spec.rb

100 lines
3.9 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe TabHelper do
2014-09-02 18:07:02 +05:30
include ApplicationHelper
describe 'nav_link' do
2021-04-29 21:17:54 +05:30
using RSpec::Parameterized::TableSyntax
2014-09-02 18:07:02 +05:30
before do
2015-04-26 12:48:37 +05:30
allow(controller).to receive(:controller_name).and_return('foo')
2014-09-02 18:07:02 +05:30
allow(self).to receive(:action_name).and_return('foo')
end
2018-12-05 23:21:45 +05:30
context 'with the content of the li' do
2021-04-29 21:17:54 +05:30
it 'captures block output' do
2018-12-05 23:21:45 +05:30
expect(nav_link { "Testing Blocks" }).to match(/Testing Blocks/)
end
2014-09-02 18:07:02 +05:30
end
2021-04-29 21:17:54 +05:30
it 'passes extra html options to the list element' do
expect(nav_link(action: :foo, html_options: { class: 'home' })).to match(/<li class="home active">/)
expect(nav_link(html_options: { class: 'active' })).to match(/<li class="active">/)
end
2018-12-05 23:21:45 +05:30
2021-04-29 21:17:54 +05:30
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
2018-12-05 23:21:45 +05:30
2021-04-29 21:17:54 +05:30
with_them do
specify do
result = nav_link(controller: controller_param, action: action_param, path: path_param)
2014-09-02 18:07:02 +05:30
2021-04-29 21:17:54 +05:30
if active
expect(result).to match(/active/)
else
expect(result).not_to match(/active/)
2018-12-05 23:21:45 +05:30
end
end
2014-09-02 18:07:02 +05:30
end
2021-04-29 21:17:54 +05:30
context 'with namespace in path notation' do
before do
allow(controller).to receive(:controller_path).and_return('bar/foo')
2018-12-05 23:21:45 +05:30
end
2014-09-02 18:07:02 +05:30
2021-04-29 21:17:54 +05:30
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
2018-12-05 23:21:45 +05:30
end
2021-04-29 21:17:54 +05:30
with_them do
specify do
result = nav_link(controller: controller_param, action: action_param, path: path_param)
2018-12-05 23:21:45 +05:30
2021-04-29 21:17:54 +05:30
if active
expect(result).to match(/active/)
else
expect(result).not_to match(/active/)
end
2018-12-05 23:21:45 +05:30
end
end
2014-09-02 18:07:02 +05:30
end
end
end