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
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
After you retrieve an element using a [finder method](#finders), you can invoke a number of
......
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'Groups > Members > Maintainer/Owner can override LDAP access levels' do
include WaitForRequests
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::ModalHelpers
let(:johndoe) { create(:user, name: 'John Doe') }
let(:maryjane) { create(:user, name: 'Mary Jane') }
......@@ -61,7 +62,7 @@ RSpec.describe 'Groups > Members > Maintainer/Owner can override LDAP access lev
click_button 'Edit permissions'
end
page.within('[role="dialog"]') do
within_modal do
expect(page).to have_content ldap_override_message
click_button 'Edit permissions'
end
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe 'Projects > Members > Member is removed from project', :js do
include Spec::Support::Helpers::ModalHelpers
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:other_user) { create(:user) }
......@@ -18,7 +20,7 @@ RSpec.describe 'Projects > Members > Member is removed from project', :js do
it 'user is removed from project' do
click_button 'Leave'
page.within('[role="dialog"]') do
within_modal do
click_button('Leave')
end
......@@ -32,7 +34,7 @@ RSpec.describe 'Projects > Members > Member is removed from project', :js do
it 'user leaves project' do
click_button 'Leave'
page.within('[role="dialog"]') do
within_modal do
click_button('Leave')
end
......
......@@ -6,6 +6,7 @@ RSpec.describe "Admin::Projects" do
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper
include Select2Helper
include Spec::Support::Helpers::ModalHelpers
let(:user) { create :user }
let(:project) { create(:project) }
......@@ -145,7 +146,7 @@ RSpec.describe "Admin::Projects" do
click_button 'Leave'
end
page.within('[role="dialog"]') do
within_modal do
click_button('Leave')
end
......
......@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe "Admin Runners" do
include StubENV
include Spec::Support::Helpers::ModalHelpers
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
......@@ -353,7 +354,7 @@ RSpec.describe "Admin Runners" do
end
it 'dismisses runner installation modal' do
page.within('[role="dialog"]') do
within_modal do
click_button('Close', match: :first)
end
......
......@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe 'Admin::Users::User' do
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(:current_user) { create(:admin) }
......@@ -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')
page.within('[role="dialog"]') do
within_modal do
fill_in('username', with: user_sole_owner_of_group.name)
click_button('Delete user and contributions')
end
......@@ -426,7 +427,7 @@ RSpec.describe 'Admin::Users::User' do
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('This user has an unconfirmed email address. You may force a confirmation.')
......
......@@ -6,6 +6,7 @@ RSpec.describe 'Groups > Members > Manage groups', :js do
include Select2Helper
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper
include Spec::Support::Helpers::ModalHelpers
let_it_be(:user) { create(:user) }
......@@ -92,7 +93,7 @@ RSpec.describe 'Groups > Members > Manage groups', :js do
click_button 'Remove group'
end
page.within('[role="dialog"]') do
within_modal do
click_button('Remove group')
end
......
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'Groups > Members > Manage members' do
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper
include Spec::Support::Helpers::ModalHelpers
let_it_be(:user1) { create(:user, name: 'John Doe') }
let_it_be(:user2) { create(:user, name: 'Mary Jane') }
......@@ -170,7 +171,7 @@ RSpec.describe 'Groups > Members > Manage members' do
click_button 'Remove member'
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'
click_button('Remove member')
end
......
......@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe 'Merge request > User posts diff notes', :js do
include MergeRequestDiffHelpers
include Spec::Support::Helpers::ModalHelpers
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.source_project }
......@@ -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)
write_comment_on_line(line_holder, diff_side)
find('.js-close-discussion-note-form').click
page.within('.modal') do
click_button 'OK'
accept_gl_confirm(s_('Notes|Are you sure you want to cancel creating this comment?')) do
find('.js-close-discussion-note-form').click
end
assert_comment_dismissal(line_holder)
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe 'Two factor auths' do
include Spec::Support::Helpers::ModalHelpers
context 'when signed in' do
before do
sign_in(user)
......@@ -70,7 +72,7 @@ RSpec.describe 'Two factor auths' do
click_button 'Disable two-factor authentication'
page.within('[role="dialog"]') do
within_modal do
click_button 'Disable'
end
......@@ -80,7 +82,7 @@ RSpec.describe 'Two factor auths' do
click_button 'Disable two-factor authentication'
page.within('[role="dialog"]') do
within_modal do
click_button 'Disable'
end
......@@ -112,7 +114,7 @@ RSpec.describe 'Two factor auths' do
click_button 'Disable two-factor authentication'
page.within('[role="dialog"]') do
within_modal do
click_button 'Disable'
end
......
......@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe 'Projects > Members > Groups with access list', :js do
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::ModalHelpers
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group, :public) }
......@@ -70,7 +71,7 @@ RSpec.describe 'Projects > Members > Groups with access list', :js do
click_button 'Remove group'
end
page.within('[role="dialog"]') do
within_modal do
click_button('Remove group')
end
......
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'Project members list', :js do
include Spec::Support::Helpers::Features::MembersHelpers
include Spec::Support::Helpers::Features::InviteMembersModalHelper
include Spec::Support::Helpers::ModalHelpers
let_it_be(:user1) { create(:user, name: 'John Doe') }
let_it_be(:user2) { create(:user, name: 'Mary Jane') }
......@@ -93,7 +94,7 @@ RSpec.describe 'Project members list', :js do
click_button 'Remove member'
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'
click_button('Remove member')
end
......
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'Projects > Settings > User manages project members' do
include Spec::Support::Helpers::Features::MembersHelpers
include Select2Helper
include Spec::Support::Helpers::ModalHelpers
let(:group) { create(:group, name: 'OpenSource') }
let(:project) { create(:project) }
......@@ -26,7 +27,7 @@ RSpec.describe 'Projects > Settings > User manages project members' do
click_button 'Remove member'
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'
click_button('Remove member')
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