Commit 42c6654a authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'qa-add-terms-page-intermediary-page' into 'master'

Add Terms intermediary page

Closes #212145

See merge request gitlab-org/gitlab!28248
parents 1258d375 bd371179
......@@ -26,7 +26,7 @@
%ul.nav.navbar-nav
%li.header-user.dropdown
= link_to current_user, class: user_dropdown_class, data: { toggle: "dropdown" } do
= image_tag avatar_icon_for_user(current_user, 23), width: 23, height: 23, class: "header-user-avatar qa-user-avatar"
= image_tag avatar_icon_for_user(current_user, 23), width: 23, height: 23, class: "header-user-avatar", data: { qa_selector: 'user_avatar' }
= sprite_icon('angle-down', css_class: 'caret-down')
.dropdown-menu.dropdown-menu-right
= render 'layouts/header/current_user_dropdown'
......
- redirect_params = { redirect: @redirect } if @redirect
.card-body.rendered-terms
.card-body.rendered-terms{ data: { qa_selector: 'terms_content' } }
= markdown_field(@term, :terms)
- if current_user
.card-footer.footer-block.clearfix
- if can?(current_user, :accept_terms, @term)
.float-right
= button_to accept_term_path(@term, redirect_params), class: 'btn btn-success prepend-left-8' do
= button_to accept_term_path(@term, redirect_params), class: 'btn btn-success prepend-left-8', data: { qa_selector: 'accept_terms_button' } do
= _('Accept terms')
- else
.pull-right
......
......@@ -168,6 +168,7 @@ module QA
autoload :Menu, 'qa/page/main/menu'
autoload :OAuth, 'qa/page/main/oauth'
autoload :SignUp, 'qa/page/main/sign_up'
autoload :Terms, 'qa/page/main/terms'
end
module Settings
......
......@@ -10,9 +10,10 @@ module QA
sign_in(as: as, address: address)
yield
result = yield
Page::Main::Menu.perform(&:sign_out)
result
end
def while_signed_in_as_admin(address: :gitlab)
......
......@@ -14,6 +14,20 @@ module QA
ElementNotFound = Class.new(RuntimeError)
class NoRequiredElementsError < RuntimeError
def initialize(page_class)
@page_class = page_class
super
end
def to_s
<<~MSG.strip % { page: @page_class }
%{page} has no required elements.
See https://docs.gitlab.com/ee/development/testing_guide/end_to_end/dynamic_element_validation.html#required-elements
MSG
end
end
def_delegators :evaluator, :view, :views
def initialize
......@@ -250,6 +264,8 @@ module QA
end
def element_selector_css(name, *attributes)
return name.selector_css if name.is_a? Page::Element
Page::Element.new(name, *attributes).selector_css
end
......@@ -296,10 +312,24 @@ module QA
views.flat_map(&:elements)
end
def self.required_elements
elements.select(&:required?)
end
def send_keys_to_element(name, keys)
find_element(name).send_keys(keys)
end
def visible?
raise NoRequiredElementsError.new(self.class) if self.class.required_elements.empty?
self.class.required_elements.each do |required_element|
return false if has_no_element? required_element
end
true
end
class DSL
attr_reader :views
......
......@@ -159,7 +159,13 @@ module QA
fill_element :login_field, user.username
fill_element :password_field, user.password
click_element :sign_in_button, !skip_page_validation && Page::Main::Menu
click_element :sign_in_button
Page::Main::Terms.perform do |terms|
terms.accept_terms if terms.visible?
end
Page::Main::Menu.validate_elements_present! unless skip_page_validation
end
def set_initial_password_if_present
......
# frozen_string_literal: true
module QA
module Page::Main
class Terms < Page::Base
view 'app/views/layouts/terms.html.haml' do
element :user_avatar, required: true
end
view 'app/views/users/terms/index.html.haml' do
element :terms_content, required: true
element :accept_terms_button
end
def accept_terms
click_element :accept_terms_button, Page::Main::Menu
end
end
end
end
......@@ -10,9 +10,7 @@ module QA
base_page.wait_if_retry_later
elements.each do |element|
next unless element.required?
required_elements.each do |element|
unless base_page.has_element?(element.name, wait: QA::Support::Repeater::DEFAULT_MAX_WAIT_TIME)
raise Validatable::PageValidationError, "#{element.name} did not appear on #{self.name} as expected"
end
......
......@@ -107,4 +107,76 @@ describe QA::Page::Base do
end
end
end
context 'elements' do
subject do
Class.new(described_class) do
view 'path/to/some/view.html.haml' do
element :something, required: true
element :something_else
end
end
end
describe '#elements' do
it 'returns all elements' do
expect(subject.elements.size).to eq(2)
end
end
describe '#required_elements' do
it 'returns only required elements' do
expect(subject.required_elements.size).to eq(1)
end
end
describe '#visible?', 'Page is currently visible' do
let(:page) { subject.new }
context 'with elements' do
context 'on the page' do
before do
# required elements not there, meaning not on page
allow(page).to receive(:has_no_element?).and_return(false)
end
it 'is visible' do
expect(page).to be_visible
end
end
context 'not on the page' do
before do
# required elements are not on the page
allow(page).to receive(:has_no_element?).and_return(true)
end
it 'is not visible' do
expect(page).not_to be_visible
end
end
it 'does not raise error if page has elements' do
expect { page.visible? }.not_to raise_error
end
end
context 'no elements' do
subject do
Class.new(described_class) do
view 'path/to/some/view.html.haml' do
element :something
element :something_else
end
end
end
let(:page) { subject.new }
it 'raises error if page has no required elements' do
expect { page.visible? }.to raise_error(described_class::NoRequiredElementsError)
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