Commit f1a48967 authored by Coung Ngo's avatar Coung Ngo Committed by Rémy Coutable

Improve `gfm_autocomplete_spec.rb` performance

Improve performance by removing nested `visit` calls
and extracting creation of objects to `let_it_be`
parent c53c936d
...@@ -7,12 +7,14 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -7,12 +7,14 @@ RSpec.describe 'GFM autocomplete', :js do
let_it_be(:user_xss) { create(:user, name: user_xss_title, username: 'xss.user') } let_it_be(:user_xss) { create(:user, name: user_xss_title, username: 'xss.user') }
let_it_be(:user) { create(:user, name: '💃speciąl someone💃', username: 'someone.special') } let_it_be(:user) { create(:user, name: '💃speciąl someone💃', username: 'someone.special') }
let_it_be(:user2) { create(:user, name: 'Marge Simpson', username: 'msimpson') } let_it_be(:user2) { create(:user, name: 'Marge Simpson', username: 'msimpson') }
let_it_be(:group) { create(:group, name: 'Ancestor') } let_it_be(:group) { create(:group, name: 'Ancestor') }
let_it_be(:child_group) { create(:group, parent: group, name: 'My group') } let_it_be(:child_group) { create(:group, parent: group, name: 'My group') }
let_it_be(:project) { create(:project, group: child_group) } let_it_be(:project) { create(:project, group: child_group) }
let_it_be(:label) { create(:label, project: project, title: 'special+') }
let(:issue) { create(:issue, project: project) } let_it_be(:issue) { create(:issue, project: project, assignees: [user]) }
let_it_be(:label) { create(:label, project: project, title: 'special+') }
let_it_be(:snippet) { create(:project_snippet, project: project, title: 'code snippet') }
before_all do before_all do
project.add_maintainer(user) project.add_maintainer(user)
...@@ -21,16 +23,35 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -21,16 +23,35 @@ RSpec.describe 'GFM autocomplete', :js do
end end
describe 'when tribute_autocomplete feature flag is off' do describe 'when tribute_autocomplete feature flag is off' do
describe 'new issue page' do
before do before do
stub_feature_flags(tribute_autocomplete: false) stub_feature_flags(tribute_autocomplete: false)
sign_in(user) sign_in(user)
visit project_issue_path(project, issue) visit new_project_issue_path(project)
wait_for_requests wait_for_requests
end end
it 'allows quick actions' do
fill_in 'Description', with: '/'
expect(find_autocomplete_menu).to be_visible
end
end
describe 'issue description' do describe 'issue description' do
let(:issue_to_edit) { create(:issue, project: project) }
before do
stub_feature_flags(tribute_autocomplete: false)
sign_in(user)
visit project_issue_path(project, issue_to_edit)
wait_for_requests
end
it 'updates with GFM reference' do it 'updates with GFM reference' do
click_button 'Edit title and description' click_button 'Edit title and description'
...@@ -58,6 +79,16 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -58,6 +79,16 @@ RSpec.describe 'GFM autocomplete', :js do
end end
end end
describe 'issue comment' do
before do
stub_feature_flags(tribute_autocomplete: false)
sign_in(user)
visit project_issue_path(project, issue)
wait_for_requests
end
describe 'triggering autocomplete' do describe 'triggering autocomplete' do
it 'only opens autocomplete menu when trigger character is after whitespace', :aggregate_failures do it 'only opens autocomplete menu when trigger character is after whitespace', :aggregate_failures do
fill_in 'Comment', with: 'testing@' fill_in 'Comment', with: 'testing@'
...@@ -222,7 +253,7 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -222,7 +253,7 @@ RSpec.describe 'GFM autocomplete', :js do
find_highlighted_autocomplete_item.click find_highlighted_autocomplete_item.click
expect(find_autocomplete_menu).to have_text(user.username) expect(find_autocomplete_menu).to have_text(user2.username)
end end
it 'does not limit quick actions autocomplete list to 5' do it 'does not limit quick actions autocomplete list to 5' do
...@@ -233,35 +264,13 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -233,35 +264,13 @@ RSpec.describe 'GFM autocomplete', :js do
end end
context 'assignees' do context 'assignees' do
let(:issue_assignee) { create(:issue, project: project) }
let(:unassigned_user) { create(:user) }
before do
issue_assignee.update(assignees: [user])
project.add_maintainer(unassigned_user)
end
it 'lists users who are currently not assigned to the issue when using /assign' do it 'lists users who are currently not assigned to the issue when using /assign' do
visit project_issue_path(project, issue_assignee)
fill_in 'Comment', with: '/as' fill_in 'Comment', with: '/as'
find_highlighted_autocomplete_item.click find_highlighted_autocomplete_item.click
expect(find_autocomplete_menu).not_to have_text(user.username) expect(find_autocomplete_menu).not_to have_text(user.username)
expect(find_autocomplete_menu).to have_text(unassigned_user.username) expect(find_autocomplete_menu).to have_text(user2.username)
end
it 'shows dropdown on new issue form' do
visit new_project_issue_path(project)
fill_in 'Description', with: '/ass'
find_highlighted_autocomplete_item.click
expect(find_autocomplete_menu).to have_text(unassigned_user.username)
expect(find_autocomplete_menu).to have_text(user.username)
end end
end end
...@@ -334,7 +343,6 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -334,7 +343,6 @@ RSpec.describe 'GFM autocomplete', :js do
# This is meant to protect against this issue https://gitlab.com/gitlab-org/gitlab/-/issues/228729 # This is meant to protect against this issue https://gitlab.com/gitlab-org/gitlab/-/issues/228729
it 'keeps autocomplete key listeners' do it 'keeps autocomplete key listeners' do
visit project_issue_path(project, issue)
note = find_field('Comment') note = find_field('Comment')
start_comment_with_emoji(note, '.atwho-view li') start_comment_with_emoji(note, '.atwho-view li')
...@@ -374,7 +382,7 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -374,7 +382,7 @@ RSpec.describe 'GFM autocomplete', :js do
end end
context 'project snippets' do context 'project snippets' do
let!(:object) { create(:project_snippet, project: project, title: 'code snippet') } let!(:object) { snippet }
let(:expected_body) { object.to_reference } let(:expected_body) { object.to_reference }
it_behaves_like 'autocomplete suggestions' it_behaves_like 'autocomplete suggestions'
...@@ -424,18 +432,21 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -424,18 +432,21 @@ RSpec.describe 'GFM autocomplete', :js do
end end
end end
end end
end
describe 'when tribute_autocomplete feature flag is on' do describe 'when tribute_autocomplete feature flag is on' do
describe 'issue description' do
let(:issue_to_edit) { create(:issue, project: project) }
before do before do
stub_feature_flags(tribute_autocomplete: true) stub_feature_flags(tribute_autocomplete: true)
sign_in(user) sign_in(user)
visit project_issue_path(project, issue) visit project_issue_path(project, issue_to_edit)
wait_for_requests wait_for_requests
end end
describe 'issue description' do
it 'updates with GFM reference' do it 'updates with GFM reference' do
click_button 'Edit title and description' click_button 'Edit title and description'
...@@ -455,6 +466,16 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -455,6 +466,16 @@ RSpec.describe 'GFM autocomplete', :js do
end end
end end
describe 'issue comment' do
before do
stub_feature_flags(tribute_autocomplete: true)
sign_in(user)
visit project_issue_path(project, issue)
wait_for_requests
end
describe 'triggering autocomplete' do describe 'triggering autocomplete' do
it 'only opens autocomplete menu when trigger character is after whitespace', :aggregate_failures do it 'only opens autocomplete menu when trigger character is after whitespace', :aggregate_failures do
fill_in 'Comment', with: 'testing@' fill_in 'Comment', with: 'testing@'
...@@ -586,18 +607,7 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -586,18 +607,7 @@ RSpec.describe 'GFM autocomplete', :js do
end end
context 'assignees' do context 'assignees' do
let(:issue_assignee) { create(:issue, project: project) }
let(:unassigned_user) { create(:user) }
before do
issue_assignee.update(assignees: [user])
project.add_maintainer(unassigned_user)
end
it 'lists users who are currently not assigned to the issue when using /assign' do it 'lists users who are currently not assigned to the issue when using /assign' do
visit project_issue_path(project, issue_assignee)
note = find_field('Comment') note = find_field('Comment')
note.native.send_keys('/assign ') note.native.send_keys('/assign ')
# The `/assign` ajax response might replace the one by `@` below causing a failed test # The `/assign` ajax response might replace the one by `@` below causing a failed test
...@@ -607,12 +617,10 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -607,12 +617,10 @@ RSpec.describe 'GFM autocomplete', :js do
wait_for_requests wait_for_requests
expect(find_tribute_autocomplete_menu).not_to have_text(user.username) expect(find_tribute_autocomplete_menu).not_to have_text(user.username)
expect(find_tribute_autocomplete_menu).to have_text(unassigned_user.username) expect(find_tribute_autocomplete_menu).to have_text(user2.username)
end end
it 'lists users who are currently not assigned to the issue when using /assign on the second line' do it 'lists users who are currently not assigned to the issue when using /assign on the second line' do
visit project_issue_path(project, issue_assignee)
note = find_field('Comment') note = find_field('Comment')
note.native.send_keys('/assign @user2') note.native.send_keys('/assign @user2')
note.native.send_keys(:enter) note.native.send_keys(:enter)
...@@ -624,7 +632,7 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -624,7 +632,7 @@ RSpec.describe 'GFM autocomplete', :js do
wait_for_requests wait_for_requests
expect(find_tribute_autocomplete_menu).not_to have_text(user.username) expect(find_tribute_autocomplete_menu).not_to have_text(user.username)
expect(find_tribute_autocomplete_menu).to have_text(unassigned_user.username) expect(find_tribute_autocomplete_menu).to have_text(user2.username)
end end
end end
...@@ -700,7 +708,6 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -700,7 +708,6 @@ RSpec.describe 'GFM autocomplete', :js do
# This is meant to protect against this issue https://gitlab.com/gitlab-org/gitlab/-/issues/228729 # This is meant to protect against this issue https://gitlab.com/gitlab-org/gitlab/-/issues/228729
it 'keeps autocomplete key listeners' do it 'keeps autocomplete key listeners' do
visit project_issue_path(project, issue)
note = find_field('Comment') note = find_field('Comment')
start_comment_with_emoji(note, '.tribute-container li') start_comment_with_emoji(note, '.tribute-container li')
...@@ -740,7 +747,7 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -740,7 +747,7 @@ RSpec.describe 'GFM autocomplete', :js do
end end
context 'project snippets' do context 'project snippets' do
let!(:object) { create(:project_snippet, project: project, title: 'code snippet') } let!(:object) { snippet }
let(:expected_body) { object.to_reference } let(:expected_body) { object.to_reference }
it_behaves_like 'autocomplete suggestions' it_behaves_like 'autocomplete suggestions'
...@@ -760,6 +767,7 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -760,6 +767,7 @@ RSpec.describe 'GFM autocomplete', :js do
it_behaves_like 'autocomplete suggestions' it_behaves_like 'autocomplete suggestions'
end end
end end
end
private private
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment