Commit de6e5507 authored by Peter Hegman's avatar Peter Hegman Committed by Kerri Miller

Add Rspec modal helpers

parent c867a760
...@@ -483,6 +483,43 @@ expect(page).to have_css '[data-testid="weight"]', text: 2 ...@@ -483,6 +483,43 @@ expect(page).to have_css '[data-testid="weight"]', text: 2
expect(page).to have_css '.atwho-view ul', visible: true expect(page).to have_css '.atwho-view ul', visible: true
``` ```
##### Interacting with modals
Use the `within_modal` helper to interact with [GitLab UI modals](https://gitlab-org.gitlab.io/gitlab-ui/?path=/story/base-modal--default).
```ruby
include Spec::Support::Helpers::ModalHelpers
within_modal do
expect(page).to have_link _('UI testing docs')
fill_in _('Search projects'), with: 'gitlab'
click_button 'Continue'
end
```
Furthermore, you can use `accept_gl_confirm` for confirmation modals that only need to be accepted.
This is helpful when migrating [`window.confirm()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm) to [`confirmAction`](https://gitlab.com/gitlab-org/gitlab/-/blob/ee280ed2b763d1278ad38c6e7e8a0aff092f617a/app/assets/javascripts/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal.js#L3).
```ruby
include Spec::Support::Helpers::ModalHelpers
accept_gl_confirm do
click_button 'Delete user'
end
```
You can also pass the expected confirmation message and button text to `accept_gl_confirm`.
```ruby
include Spec::Support::Helpers::ModalHelpers
accept_gl_confirm('Are you sure you want to delete this user?', button_text: 'Delete') do
click_button 'Delete user'
end
```
##### Other useful methods ##### Other useful methods
After you retrieve an element using a [finder method](#finders), you can invoke a number of After you retrieve an element using a [finder method](#finders), you can invoke a number of
......
...@@ -5,6 +5,7 @@ require 'spec_helper' ...@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'Groups > Members > Maintainer/Owner can override LDAP access levels' do RSpec.describe 'Groups > Members > Maintainer/Owner can override LDAP access levels' do
include WaitForRequests include WaitForRequests
include Spec::Support::Helpers::Features::MembersHelpers include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::ModalHelpers
let(:johndoe) { create(:user, name: 'John Doe') } let(:johndoe) { create(:user, name: 'John Doe') }
let(:maryjane) { create(:user, name: 'Mary Jane') } let(:maryjane) { create(:user, name: 'Mary Jane') }
...@@ -61,7 +62,7 @@ RSpec.describe 'Groups > Members > Maintainer/Owner can override LDAP access lev ...@@ -61,7 +62,7 @@ RSpec.describe 'Groups > Members > Maintainer/Owner can override LDAP access lev
click_button 'Edit permissions' click_button 'Edit permissions'
end end
page.within('[role="dialog"]') do within_modal do
expect(page).to have_content ldap_override_message expect(page).to have_content ldap_override_message
click_button 'Edit permissions' click_button 'Edit permissions'
end end
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Projects > Members > Member is removed from project', :js do RSpec.describe 'Projects > Members > Member is removed from project', :js do
include Spec::Support::Helpers::ModalHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:other_user) { create(:user) } let(:other_user) { create(:user) }
...@@ -18,7 +20,7 @@ RSpec.describe 'Projects > Members > Member is removed from project', :js do ...@@ -18,7 +20,7 @@ RSpec.describe 'Projects > Members > Member is removed from project', :js do
it 'user is removed from project' do it 'user is removed from project' do
click_button 'Leave' click_button 'Leave'
page.within('[role="dialog"]') do within_modal do
click_button('Leave') click_button('Leave')
end end
...@@ -32,7 +34,7 @@ RSpec.describe 'Projects > Members > Member is removed from project', :js do ...@@ -32,7 +34,7 @@ RSpec.describe 'Projects > Members > Member is removed from project', :js do
it 'user leaves project' do it 'user leaves project' do
click_button 'Leave' click_button 'Leave'
page.within('[role="dialog"]') do within_modal do
click_button('Leave') click_button('Leave')
end end
......
...@@ -6,6 +6,7 @@ RSpec.describe "Admin::Projects" do ...@@ -6,6 +6,7 @@ RSpec.describe "Admin::Projects" do
include Spec::Support::Helpers::Features::MembersHelpers include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper include Spec::Support::Helpers::Features::InviteMembersModalHelper
include Select2Helper include Select2Helper
include Spec::Support::Helpers::ModalHelpers
let(:user) { create :user } let(:user) { create :user }
let(:project) { create(:project) } let(:project) { create(:project) }
...@@ -145,7 +146,7 @@ RSpec.describe "Admin::Projects" do ...@@ -145,7 +146,7 @@ RSpec.describe "Admin::Projects" do
click_button 'Leave' click_button 'Leave'
end end
page.within('[role="dialog"]') do within_modal do
click_button('Leave') click_button('Leave')
end end
......
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe "Admin Runners" do RSpec.describe "Admin Runners" do
include StubENV include StubENV
include Spec::Support::Helpers::ModalHelpers
before do before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
...@@ -353,7 +354,7 @@ RSpec.describe "Admin Runners" do ...@@ -353,7 +354,7 @@ RSpec.describe "Admin Runners" do
end end
it 'dismisses runner installation modal' do it 'dismisses runner installation modal' do
page.within('[role="dialog"]') do within_modal do
click_button('Close', match: :first) click_button('Close', match: :first)
end end
......
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe 'Admin::Users::User' do RSpec.describe 'Admin::Users::User' do
include Spec::Support::Helpers::Features::AdminUsersHelpers include Spec::Support::Helpers::Features::AdminUsersHelpers
include Spec::Support::Helpers::ModalHelpers
let_it_be(:user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') } let_it_be(:user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') }
let_it_be(:current_user) { create(:admin) } let_it_be(:current_user) { create(:admin) }
...@@ -113,7 +114,7 @@ RSpec.describe 'Admin::Users::User' do ...@@ -113,7 +114,7 @@ RSpec.describe 'Admin::Users::User' do
click_action_in_user_dropdown(user_sole_owner_of_group.id, 'Delete user and contributions') click_action_in_user_dropdown(user_sole_owner_of_group.id, 'Delete user and contributions')
page.within('[role="dialog"]') do within_modal do
fill_in('username', with: user_sole_owner_of_group.name) fill_in('username', with: user_sole_owner_of_group.name)
click_button('Delete user and contributions') click_button('Delete user and contributions')
end end
...@@ -426,7 +427,7 @@ RSpec.describe 'Admin::Users::User' do ...@@ -426,7 +427,7 @@ RSpec.describe 'Admin::Users::User' do
click_button 'Confirm user' click_button 'Confirm user'
page.within('[role="dialog"]') do within_modal do
expect(page).to have_content("Confirm user #{unconfirmed_user.name}?") expect(page).to have_content("Confirm user #{unconfirmed_user.name}?")
expect(page).to have_content('This user has an unconfirmed email address. You may force a confirmation.') expect(page).to have_content('This user has an unconfirmed email address. You may force a confirmation.')
......
...@@ -6,6 +6,7 @@ RSpec.describe 'Groups > Members > Manage groups', :js do ...@@ -6,6 +6,7 @@ RSpec.describe 'Groups > Members > Manage groups', :js do
include Select2Helper include Select2Helper
include Spec::Support::Helpers::Features::MembersHelpers include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper include Spec::Support::Helpers::Features::InviteMembersModalHelper
include Spec::Support::Helpers::ModalHelpers
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
...@@ -92,7 +93,7 @@ RSpec.describe 'Groups > Members > Manage groups', :js do ...@@ -92,7 +93,7 @@ RSpec.describe 'Groups > Members > Manage groups', :js do
click_button 'Remove group' click_button 'Remove group'
end end
page.within('[role="dialog"]') do within_modal do
click_button('Remove group') click_button('Remove group')
end end
......
...@@ -5,6 +5,7 @@ require 'spec_helper' ...@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'Groups > Members > Manage members' do RSpec.describe 'Groups > Members > Manage members' do
include Spec::Support::Helpers::Features::MembersHelpers include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper include Spec::Support::Helpers::Features::InviteMembersModalHelper
include Spec::Support::Helpers::ModalHelpers
let_it_be(:user1) { create(:user, name: 'John Doe') } let_it_be(:user1) { create(:user, name: 'John Doe') }
let_it_be(:user2) { create(:user, name: 'Mary Jane') } let_it_be(:user2) { create(:user, name: 'Mary Jane') }
...@@ -170,7 +171,7 @@ RSpec.describe 'Groups > Members > Manage members' do ...@@ -170,7 +171,7 @@ RSpec.describe 'Groups > Members > Manage members' do
click_button 'Remove member' click_button 'Remove member'
end end
page.within('[role="dialog"]') do within_modal do
expect(page).to have_unchecked_field 'Also unassign this user from related issues and merge requests' expect(page).to have_unchecked_field 'Also unassign this user from related issues and merge requests'
click_button('Remove member') click_button('Remove member')
end end
......
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe 'Merge request > User posts diff notes', :js do RSpec.describe 'Merge request > User posts diff notes', :js do
include MergeRequestDiffHelpers include MergeRequestDiffHelpers
include Spec::Support::Helpers::ModalHelpers
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.source_project } let(:project) { merge_request.source_project }
...@@ -238,10 +239,8 @@ RSpec.describe 'Merge request > User posts diff notes', :js do ...@@ -238,10 +239,8 @@ RSpec.describe 'Merge request > User posts diff notes', :js do
def should_allow_dismissing_a_comment(line_holder, diff_side = nil) def should_allow_dismissing_a_comment(line_holder, diff_side = nil)
write_comment_on_line(line_holder, diff_side) write_comment_on_line(line_holder, diff_side)
find('.js-close-discussion-note-form').click accept_gl_confirm(s_('Notes|Are you sure you want to cancel creating this comment?')) do
find('.js-close-discussion-note-form').click
page.within('.modal') do
click_button 'OK'
end end
assert_comment_dismissal(line_holder) assert_comment_dismissal(line_holder)
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Two factor auths' do RSpec.describe 'Two factor auths' do
include Spec::Support::Helpers::ModalHelpers
context 'when signed in' do context 'when signed in' do
before do before do
sign_in(user) sign_in(user)
...@@ -70,7 +72,7 @@ RSpec.describe 'Two factor auths' do ...@@ -70,7 +72,7 @@ RSpec.describe 'Two factor auths' do
click_button 'Disable two-factor authentication' click_button 'Disable two-factor authentication'
page.within('[role="dialog"]') do within_modal do
click_button 'Disable' click_button 'Disable'
end end
...@@ -80,7 +82,7 @@ RSpec.describe 'Two factor auths' do ...@@ -80,7 +82,7 @@ RSpec.describe 'Two factor auths' do
click_button 'Disable two-factor authentication' click_button 'Disable two-factor authentication'
page.within('[role="dialog"]') do within_modal do
click_button 'Disable' click_button 'Disable'
end end
...@@ -112,7 +114,7 @@ RSpec.describe 'Two factor auths' do ...@@ -112,7 +114,7 @@ RSpec.describe 'Two factor auths' do
click_button 'Disable two-factor authentication' click_button 'Disable two-factor authentication'
page.within('[role="dialog"]') do within_modal do
click_button 'Disable' click_button 'Disable'
end end
......
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe 'Projects > Members > Groups with access list', :js do RSpec.describe 'Projects > Members > Groups with access list', :js do
include Spec::Support::Helpers::Features::MembersHelpers include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::ModalHelpers
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group, :public) } let_it_be(:group) { create(:group, :public) }
...@@ -70,7 +71,7 @@ RSpec.describe 'Projects > Members > Groups with access list', :js do ...@@ -70,7 +71,7 @@ RSpec.describe 'Projects > Members > Groups with access list', :js do
click_button 'Remove group' click_button 'Remove group'
end end
page.within('[role="dialog"]') do within_modal do
click_button('Remove group') click_button('Remove group')
end end
......
...@@ -5,6 +5,7 @@ require 'spec_helper' ...@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'Project members list', :js do RSpec.describe 'Project members list', :js do
include Spec::Support::Helpers::Features::MembersHelpers include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper include Spec::Support::Helpers::Features::InviteMembersModalHelper
include Spec::Support::Helpers::ModalHelpers
let_it_be(:user1) { create(:user, name: 'John Doe') } let_it_be(:user1) { create(:user, name: 'John Doe') }
let_it_be(:user2) { create(:user, name: 'Mary Jane') } let_it_be(:user2) { create(:user, name: 'Mary Jane') }
...@@ -93,7 +94,7 @@ RSpec.describe 'Project members list', :js do ...@@ -93,7 +94,7 @@ RSpec.describe 'Project members list', :js do
click_button 'Remove member' click_button 'Remove member'
end end
page.within('[role="dialog"]') do within_modal do
expect(page).to have_unchecked_field 'Also unassign this user from related issues and merge requests' expect(page).to have_unchecked_field 'Also unassign this user from related issues and merge requests'
click_button('Remove member') click_button('Remove member')
end end
......
...@@ -5,6 +5,7 @@ require 'spec_helper' ...@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'Projects > Settings > User manages project members' do RSpec.describe 'Projects > Settings > User manages project members' do
include Spec::Support::Helpers::Features::MembersHelpers include Spec::Support::Helpers::Features::MembersHelpers
include Select2Helper include Select2Helper
include Spec::Support::Helpers::ModalHelpers
let(:group) { create(:group, name: 'OpenSource') } let(:group) { create(:group, name: 'OpenSource') }
let(:project) { create(:project) } let(:project) { create(:project) }
...@@ -26,7 +27,7 @@ RSpec.describe 'Projects > Settings > User manages project members' do ...@@ -26,7 +27,7 @@ RSpec.describe 'Projects > Settings > User manages project members' do
click_button 'Remove member' click_button 'Remove member'
end end
page.within('[role="dialog"]') do within_modal do
expect(page).to have_unchecked_field 'Also unassign this user from related issues and merge requests' expect(page).to have_unchecked_field 'Also unassign this user from related issues and merge requests'
click_button('Remove member') click_button('Remove member')
end end
......
# frozen_string_literal: true
module Spec
module Support
module Helpers
module ModalHelpers
def within_modal
page.within('[role="dialog"]') do
yield
end
end
def accept_gl_confirm(text = nil, button_text: 'OK')
yield if block_given?
within_modal do
unless text.nil?
expect(page).to have_content(text)
end
click_button button_text
end
end
end
end
end
end
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