Commit 1cf5e3de authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'cngo-improve-gfm_autocomplete_spec-performance' into 'master'

Improve `gfm_autocomplete_spec.rb` performance

See merge request gitlab-org/gitlab!57246
parents 295018dd f1a48967
......@@ -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) { create(:user, name: '💃speciąl someone💃', username: 'someone.special') }
let_it_be(:user2) { create(:user, name: 'Marge Simpson', username: 'msimpson') }
let_it_be(:group) { create(:group, name: 'Ancestor') }
let_it_be(:child_group) { create(:group, parent: group, name: 'My 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
project.add_maintainer(user)
......@@ -21,16 +23,35 @@ RSpec.describe 'GFM autocomplete', :js do
end
describe 'when tribute_autocomplete feature flag is off' do
describe 'new issue page' do
before do
stub_feature_flags(tribute_autocomplete: false)
sign_in(user)
visit project_issue_path(project, issue)
visit new_project_issue_path(project)
wait_for_requests
end
it 'allows quick actions' do
fill_in 'Description', with: '/'
expect(find_autocomplete_menu).to be_visible
end
end
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
click_button 'Edit title and description'
......@@ -58,6 +79,16 @@ RSpec.describe 'GFM autocomplete', :js do
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
it 'only opens autocomplete menu when trigger character is after whitespace', :aggregate_failures do
fill_in 'Comment', with: 'testing@'
......@@ -222,7 +253,7 @@ RSpec.describe 'GFM autocomplete', :js do
find_highlighted_autocomplete_item.click
expect(find_autocomplete_menu).to have_text(user.username)
expect(find_autocomplete_menu).to have_text(user2.username)
end
it 'does not limit quick actions autocomplete list to 5' do
......@@ -233,35 +264,13 @@ RSpec.describe 'GFM autocomplete', :js do
end
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
visit project_issue_path(project, issue_assignee)
fill_in 'Comment', with: '/as'
find_highlighted_autocomplete_item.click
expect(find_autocomplete_menu).not_to have_text(user.username)
expect(find_autocomplete_menu).to have_text(unassigned_user.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)
expect(find_autocomplete_menu).to have_text(user2.username)
end
end
......@@ -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
it 'keeps autocomplete key listeners' do
visit project_issue_path(project, issue)
note = find_field('Comment')
start_comment_with_emoji(note, '.atwho-view li')
......@@ -374,7 +382,7 @@ RSpec.describe 'GFM autocomplete', :js do
end
context 'project snippets' do
let!(:object) { create(:project_snippet, project: project, title: 'code snippet') }
let!(:object) { snippet }
let(:expected_body) { object.to_reference }
it_behaves_like 'autocomplete suggestions'
......@@ -424,18 +432,21 @@ RSpec.describe 'GFM autocomplete', :js do
end
end
end
end
describe 'when tribute_autocomplete feature flag is on' do
describe 'issue description' do
let(:issue_to_edit) { create(:issue, project: project) }
before do
stub_feature_flags(tribute_autocomplete: true)
sign_in(user)
visit project_issue_path(project, issue)
visit project_issue_path(project, issue_to_edit)
wait_for_requests
end
describe 'issue description' do
it 'updates with GFM reference' do
click_button 'Edit title and description'
......@@ -455,6 +466,16 @@ RSpec.describe 'GFM autocomplete', :js do
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
it 'only opens autocomplete menu when trigger character is after whitespace', :aggregate_failures do
fill_in 'Comment', with: 'testing@'
......@@ -586,18 +607,7 @@ RSpec.describe 'GFM autocomplete', :js do
end
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
visit project_issue_path(project, issue_assignee)
note = find_field('Comment')
note.native.send_keys('/assign ')
# The `/assign` ajax response might replace the one by `@` below causing a failed test
......@@ -607,12 +617,10 @@ RSpec.describe 'GFM autocomplete', :js do
wait_for_requests
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
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.native.send_keys('/assign @user2')
note.native.send_keys(:enter)
......@@ -624,7 +632,7 @@ RSpec.describe 'GFM autocomplete', :js do
wait_for_requests
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
......@@ -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
it 'keeps autocomplete key listeners' do
visit project_issue_path(project, issue)
note = find_field('Comment')
start_comment_with_emoji(note, '.tribute-container li')
......@@ -740,7 +747,7 @@ RSpec.describe 'GFM autocomplete', :js do
end
context 'project snippets' do
let!(:object) { create(:project_snippet, project: project, title: 'code snippet') }
let!(:object) { snippet }
let(:expected_body) { object.to_reference }
it_behaves_like 'autocomplete suggestions'
......@@ -760,6 +767,7 @@ RSpec.describe 'GFM autocomplete', :js do
it_behaves_like 'autocomplete suggestions'
end
end
end
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