diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/helpers/blob_helper_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/helpers/blob_helper_spec.rb')
-rw-r--r-- | spec/helpers/blob_helper_spec.rb | 110 |
1 files changed, 106 insertions, 4 deletions
diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index fe975aa7723..3ba9f39d21a 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -30,6 +30,8 @@ RSpec.describe BlobHelper do let(:namespace) { create(:namespace, name: 'gitlab') } let(:project) { create(:project, :repository, namespace: namespace) } + subject(:link) { helper.edit_blob_button(project, 'master', 'README.md') } + before do allow(helper).to receive(:current_user).and_return(nil) allow(helper).to receive(:can?).and_return(true) @@ -53,15 +55,49 @@ RSpec.describe BlobHelper do end it 'returns a link with the proper route' do - link = helper.edit_blob_button(project, 'master', 'README.md') - expect(Capybara.string(link).find_link('Edit')[:href]).to eq("/#{project.full_path}/-/edit/master/README.md") end it 'returns a link with the passed link_opts on the expected route' do - link = helper.edit_blob_button(project, 'master', 'README.md', link_opts: { mr_id: 10 }) + link_with_mr = helper.edit_blob_button(project, 'master', 'README.md', link_opts: { mr_id: 10 }) - expect(Capybara.string(link).find_link('Edit')[:href]).to eq("/#{project.full_path}/-/edit/master/README.md?mr_id=10") + expect(Capybara.string(link_with_mr).find_link('Edit')[:href]).to eq("/#{project.full_path}/-/edit/master/README.md?mr_id=10") + end + + context 'when edit is the primary button' do + before do + stub_feature_flags(web_ide_primary_edit: false) + end + + it 'is rendered as primary' do + expect(link).not_to match(/btn-inverted/) + end + + it 'passes on primary tracking attributes' do + parsed_link = Capybara.string(link).find_link('Edit') + + expect(parsed_link[:'data-track-event']).to eq("click_edit") + expect(parsed_link[:'data-track-label']).to eq("Edit") + expect(parsed_link[:'data-track-property']).to eq(nil) + end + end + + context 'when Web IDE is the primary button' do + before do + stub_feature_flags(web_ide_primary_edit: true) + end + + it 'is rendered as inverted' do + expect(link).to match(/btn-inverted/) + end + + it 'passes on secondary tracking attributes' do + parsed_link = Capybara.string(link).find_link('Edit') + + expect(parsed_link[:'data-track-event']).to eq("click_edit") + expect(parsed_link[:'data-track-label']).to eq("Edit") + expect(parsed_link[:'data-track-property']).to eq("secondary") + end end end @@ -246,6 +282,16 @@ RSpec.describe BlobHelper do expect(helper.show_suggest_pipeline_creation_celebration?).to be_falsey end end + + context 'blob does not have auxiliary view' do + before do + allow(blob).to receive(:auxiliary_viewer).and_return(nil) + end + + it 'is false' do + expect(helper.show_suggest_pipeline_creation_celebration?).to be_falsey + end + end end context 'experiment disabled' do @@ -285,6 +331,62 @@ RSpec.describe BlobHelper do end end + describe `#ide_edit_button` do + let_it_be(:namespace) { create(:namespace, name: 'gitlab') } + let_it_be(:project) { create(:project, :repository, namespace: namespace) } + let_it_be(:current_user) { create(:user) } + let(:can_push_code) { true } + let(:blob) { project.repository.blob_at('refs/heads/master', 'README.md') } + + subject(:link) { helper.ide_edit_button(project, 'master', 'README.md', blob: blob) } + + before do + allow(helper).to receive(:current_user).and_return(current_user) + allow(helper).to receive(:can?).with(current_user, :push_code, project).and_return(can_push_code) + allow(helper).to receive(:can_collaborate_with_project?).and_return(true) + end + + it 'returns a link with a Web IDE route' do + expect(Capybara.string(link).find_link('Web IDE')[:href]).to eq("/-/ide/project/#{project.full_path}/edit/master/-/README.md") + end + + context 'when edit is the primary button' do + before do + stub_feature_flags(web_ide_primary_edit: false) + end + + it 'is rendered as inverted' do + expect(link).to match(/btn-inverted/) + end + + it 'passes on secondary tracking attributes' do + parsed_link = Capybara.string(link).find_link('Web IDE') + + expect(parsed_link[:'data-track-event']).to eq("click_edit_ide") + expect(parsed_link[:'data-track-label']).to eq("Web IDE") + expect(parsed_link[:'data-track-property']).to eq("secondary") + end + end + + context 'when Web IDE is the primary button' do + before do + stub_feature_flags(web_ide_primary_edit: true) + end + + it 'is rendered as primary' do + expect(link).not_to match(/btn-inverted/) + end + + it 'passes on primary tracking attributes' do + parsed_link = Capybara.string(link).find_link('Web IDE') + + expect(parsed_link[:'data-track-event']).to eq("click_edit_ide") + expect(parsed_link[:'data-track-label']).to eq("Web IDE") + expect(parsed_link[:'data-track-property']).to eq(nil) + end + end + end + describe '#ide_edit_path' do let(:project) { create(:project) } let(:current_user) { create(:user) } |