diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2019-04-23 19:58:20 +0000 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-04-23 19:58:20 +0000 |
commit | 8ce4b6093a2e64f21928dded6c58950f180d8c2a (patch) | |
tree | e3478cf58d2119fd2f84572d34acf0c507e75a5b /spec/helpers/labels_helper_spec.rb | |
parent | be15592a1c1551bb6136081ea995dca49e238c8f (diff) | |
download | gitlab-ce-8ce4b6093a2e64f21928dded6c58950f180d8c2a.tar.gz |
Move scoped_label into label presenter
When rendering a label we want to check 'scoped_label' feature
availability on a project/group where label is being used. For
this reason a label presenter is used in UI and information about
context project/group is passed to this presenter.
Diffstat (limited to 'spec/helpers/labels_helper_spec.rb')
-rw-r--r-- | spec/helpers/labels_helper_spec.rb | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/spec/helpers/labels_helper_spec.rb b/spec/helpers/labels_helper_spec.rb index a049b5a6133..58eaf991d6e 100644 --- a/spec/helpers/labels_helper_spec.rb +++ b/spec/helpers/labels_helper_spec.rb @@ -67,27 +67,29 @@ describe LabelsHelper do describe 'link_to_label' do let(:project) { create(:project) } let(:label) { create(:label, project: project) } + let(:subject) { nil } + let(:label_presenter) { label.present(issuable_subject: subject) } context 'without subject' do it "uses the label's project" do - expect(link_to_label(label)).to match %r{<a href="/#{label.project.full_path}/issues\?label_name%5B%5D=#{label.name}">.*</a>} + expect(link_to_label(label_presenter)).to match %r{<a href="/#{label.project.full_path}/issues\?label_name%5B%5D=#{label.name}">.*</a>} end end context 'with a project as subject' do let(:namespace) { build(:namespace, name: 'foo3') } - let(:another_project) { build(:project, namespace: namespace, name: 'bar3') } + let(:subject) { build(:project, namespace: namespace, name: 'bar3') } it 'links to project issues page' do - expect(link_to_label(label, subject: another_project)).to match %r{<a href="/foo3/bar3/issues\?label_name%5B%5D=#{label.name}">.*</a>} + expect(link_to_label(label_presenter)).to match %r{<a href="/foo3/bar3/issues\?label_name%5B%5D=#{label.name}">.*</a>} end end context 'with a group as subject' do - let(:group) { build(:group, name: 'bar') } + let(:subject) { build(:group, name: 'bar') } it 'links to group issues page' do - expect(link_to_label(label, subject: group)).to match %r{<a href="/groups/bar/-/issues\?label_name%5B%5D=#{label.name}">.*</a>} + expect(link_to_label(label_presenter)).to match %r{<a href="/groups/bar/-/issues\?label_name%5B%5D=#{label.name}">.*</a>} end end @@ -95,7 +97,7 @@ describe LabelsHelper do ['issue', :issue, 'merge_request', :merge_request].each do |type| context "set to #{type}" do it 'links to correct page' do - expect(link_to_label(label, type: type)).to match %r{<a href="/#{label.project.full_path}/#{type.to_s.pluralize}\?label_name%5B%5D=#{label.name}">.*</a>} + expect(link_to_label(label_presenter, type: type)).to match %r{<a href="/#{label.project.full_path}/#{type.to_s.pluralize}\?label_name%5B%5D=#{label.name}">.*</a>} end end end @@ -104,14 +106,14 @@ describe LabelsHelper do context 'with a tooltip argument' do context 'set to false' do it 'does not include the has-tooltip class' do - expect(link_to_label(label, tooltip: false)).not_to match /has-tooltip/ + expect(link_to_label(label_presenter, tooltip: false)).not_to match /has-tooltip/ end end end context 'with block' do it 'passes the block to link_to' do - link = link_to_label(label) { 'Foo' } + link = link_to_label(label_presenter) { 'Foo' } expect(link).to match('Foo') end end @@ -119,8 +121,8 @@ describe LabelsHelper do context 'without block' do it 'uses render_colored_label as the link content' do expect(self).to receive(:render_colored_label) - .with(label, tooltip: true).and_return('Foo') - expect(link_to_label(label)).to match('Foo') + .with(label_presenter, tooltip: true).and_return('Foo') + expect(link_to_label(label_presenter)).to match('Foo') end end end @@ -237,16 +239,24 @@ describe LabelsHelper do end end - describe 'labels_sorted_by_title' do + describe 'presented_labels_sorted_by_title' do + let(:labels) do + [build(:label, title: 'a'), + build(:label, title: 'B'), + build(:label, title: 'c'), + build(:label, title: 'D')] + end + it 'sorts labels alphabetically' do - label1 = double(:label, title: 'a') - label2 = double(:label, title: 'B') - label3 = double(:label, title: 'c') - label4 = double(:label, title: 'D') - labels = [label1, label2, label3, label4] - - expect(labels_sorted_by_title(labels)) - .to match_array([label2, label4, label1, label3]) + sorted_ids = presented_labels_sorted_by_title(labels, nil).map(&:id) + + expect(sorted_ids) + .to match_array([labels[1].id, labels[3].id, labels[0].id, labels[2].id]) + end + + it 'returns an array of label presenters' do + expect(presented_labels_sorted_by_title(labels, nil)) + .to all(be_a(LabelPresenter)) end end |