diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 06:10:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-25 06:10:36 +0000 |
commit | 866b1f8ed7db9b29b1188ffcba309b92572f354b (patch) | |
tree | 48f59dd9b5a292e58e8ce20fbff7e95b6178afe1 /spec/helpers | |
parent | 01fbd09ea9ea4eeae52ed9fb4f7cc4dd97b4eb69 (diff) | |
download | gitlab-ce-866b1f8ed7db9b29b1188ffcba309b92572f354b.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/events_helper_spec.rb | 24 | ||||
-rw-r--r-- | spec/helpers/integrations_helper_spec.rb | 50 | ||||
-rw-r--r-- | spec/helpers/todos_helper_spec.rb | 29 |
3 files changed, 103 insertions, 0 deletions
diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb index 7005b3dc53e..39901047b0f 100644 --- a/spec/helpers/events_helper_spec.rb +++ b/spec/helpers/events_helper_spec.rb @@ -4,6 +4,30 @@ require 'spec_helper' RSpec.describe EventsHelper do include Gitlab::Routing + include Banzai::Filter::OutputSafety + + describe '#link_to_author' do + let(:user) { create(:user) } + let(:event) { create(:event, author: user) } + + it 'returns a link to the author' do + name = user.name + expect(helper.link_to_author(event)).to eq(link_to(name, user_path(user.username), title: name)) + end + + it 'returns the author name if the author is not present' do + event.author = nil + + expect(helper.link_to_author(event)).to eq(escape_once(event.author_name)) + end + + it 'returns "You" if the author is the current user' do + allow(helper).to receive(:current_user).and_return(user) + + name = _('You') + expect(helper.link_to_author(event, self_added: true)).to eq(link_to(name, user_path(user.username), title: name)) + end + end describe '#event_target_path' do subject { helper.event_target_path(event.present) } diff --git a/spec/helpers/integrations_helper_spec.rb b/spec/helpers/integrations_helper_spec.rb index 95dfc51e8fd..3e5ec9b5348 100644 --- a/spec/helpers/integrations_helper_spec.rb +++ b/spec/helpers/integrations_helper_spec.rb @@ -150,4 +150,54 @@ RSpec.describe IntegrationsHelper do end end end + + describe '#integration_issue_type' do + using RSpec::Parameterized::TableSyntax + let_it_be(:issue) { create(:issue) } + + where(:issue_type, :expected_i18n_issue_type) do + "issue" | _('Issue') + "incident" | _('Incident') + "test_case" | _('Test case') + "requirement" | _('Requirement') + "task" | _('Task') + end + + with_them do + before do + issue.update!(issue_type: issue_type) + end + + it "return the correct i18n issue type" do + expect(described_class.integration_issue_type(issue.issue_type)).to eq(expected_i18n_issue_type) + end + end + + it "only consider these enumeration values are valid" do + expected_valid_types = %w[issue incident test_case requirement task] + expect(Issue.issue_types.keys).to contain_exactly(*expected_valid_types) + end + end + + describe '#integration_todo_target_type' do + using RSpec::Parameterized::TableSyntax + let!(:todo) { create(:todo, commit_id: '123') } + + where(:target_type, :expected_i18n_target_type) do + "Commit" | _("Commit") + "Issue" | _("Issue") + "MergeRequest" | _("Merge Request") + 'Epic' | _('Epic') + DesignManagement::Design.name | _('design') + AlertManagement::Alert.name | _('alert') + end + + with_them do + before do + todo.update!(target_type: target_type) + end + + it { expect(described_class.integration_todo_target_type(todo.target_type)).to eq(expected_i18n_target_type) } + end + end end diff --git a/spec/helpers/todos_helper_spec.rb b/spec/helpers/todos_helper_spec.rb index c64d5990cd9..49e3c6dd740 100644 --- a/spec/helpers/todos_helper_spec.rb +++ b/spec/helpers/todos_helper_spec.rb @@ -310,4 +310,33 @@ RSpec.describe TodosHelper do it { expect(helper.todos_filter_params[:state]).to eq(result) } end end + + describe '#todo_action_name' do + using RSpec::Parameterized::TableSyntax + + where(:action, :self_added?, :expected_action_name) do + Todo::ASSIGNED | false | s_('Todos|assigned you') + Todo::ASSIGNED | true | s_('Todos|assigned') + Todo::REVIEW_REQUESTED | true | s_('Todos|requested a review of') + Todo::MENTIONED | true | format(s_("Todos|mentioned %{who} on"), who: s_('Todos|yourself')) + Todo::MENTIONED | false | format(s_("Todos|mentioned %{who} on"), who: _('you')) + Todo::DIRECTLY_ADDRESSED | true | format(s_("Todos|mentioned %{who} on"), who: s_('Todos|yourself')) + Todo::DIRECTLY_ADDRESSED | false | format(s_("Todos|mentioned %{who} on"), who: _('you')) + Todo::BUILD_FAILED | true | s_('Todos|The pipeline failed in') + Todo::MARKED | true | s_('Todos|added a todo for') + Todo::APPROVAL_REQUIRED | true | format(s_("Todos|set %{who} as an approver for"), who: s_('Todos|yourself')) + Todo::APPROVAL_REQUIRED | false | format(s_("Todos|set %{who} as an approver for"), who: _('you')) + Todo::UNMERGEABLE | true | s_('Todos|Could not merge') + Todo::MERGE_TRAIN_REMOVED | true | s_("Todos|Removed from Merge Train:") + end + + with_them do + before do + alert_todo.action = action + alert_todo.user = self_added? ? alert_todo.author : user + end + + it { expect(helper.todo_action_name(alert_todo)).to eq(expected_action_name) } + end + end end |