Commit aaa07596 authored by Désirée Chevalier's avatar Désirée Chevalier Committed by Dan Davison

Update radio button e2e functionality

Adds a new method for interacting with radio buttons in e2e specs
Updates some selectors related to radio buttons
Updates touched files to conform with ruby style guides for parentheses
parent 2e9e1df7
...@@ -78,9 +78,12 @@ export default { ...@@ -78,9 +78,12 @@ export default {
}; };
</script> </script>
<template> <template>
<div data-qa-selector="admin_license_compliance_row"> <div
data-qa-selector="admin_license_compliance_container"
data-testid="admin-license-compliance-row"
>
<issue-status-icon :status="status" class="float-left gl-mr-3" /> <issue-status-icon :status="status" class="float-left gl-mr-3" />
<span class="js-license-name" data-qa-selector="license_name_content">{{ license.name }}</span> <span class="js-license-name">{{ license.name }}</span>
<div class="float-right"> <div class="float-right">
<div class="d-flex"> <div class="d-flex">
<gl-loading-icon v-if="loading" class="js-loading-icon d-flex align-items-center mr-2" /> <gl-loading-icon v-if="loading" class="js-loading-icon d-flex align-items-center mr-2" />
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
.container.blank-state-container .container.blank-state-container
.text-center .text-center
= custom_icon("missing_license") = custom_icon("missing_license")
%h4{ data: { qa_selector: 'missing_license' } } %h4{ data: { qa_selector: 'missing_license_content' } }
= s_('License|You do not have a license.') = s_('License|You do not have a license.')
- if License.eligible_for_trial? - if License.eligible_for_trial?
%p.trial-description= s_('License|You can start a free trial of GitLab Ultimate without any obligation or payment details.') %p.trial-description= s_('License|You can start a free trial of GitLab Ultimate without any obligation or payment details.')
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
.option-title .option-title
Upload <code>.gitlab-license</code> file Upload <code>.gitlab-license</code> file
.form-check .form-check
= radio_button_tag :license_type, :key, @license.data.present?, class: 'form-check-input' = radio_button_tag :license_type, :key, @license.data.present?, class: 'form-check-input', data: { qa_selector: 'license_type_key_radio' }
= label_tag :license_type_key, class: 'form-check-label' do = label_tag :license_type_key, class: 'form-check-label' do
.option-title .option-title
Enter license key Enter license key
...@@ -46,14 +46,14 @@ ...@@ -46,14 +46,14 @@
.col-sm-2.col-form-label .col-sm-2.col-form-label
= f.label :data, "License key" = f.label :data, "License key"
.col-sm-10 .col-sm-10
= f.text_area :data, class: "form-control license-key-field", rows: 20 = f.text_area :data, class: "form-control license-key-field", data: { qa_selector: 'license_key_field' }, rows: 20
.form-group.row .form-group.row
.col-sm-2 .col-sm-2
.col-sm-10 .col-sm-10
= label_tag :accept_eula, nil, class: 'form-check-label' do = label_tag :accept_eula, nil, class: 'form-check-label' do
= check_box_tag :accept_eula, data: { qa_selector: 'accept_eula' } = check_box_tag :accept_eula, nil, false, data: { qa_selector: 'accept_eula_checkbox' }
= _('Unless otherwise agreed to in writing with GitLab, by clicking "Upload License" you agree that your use of GitLab Software is subject to the %{eula_link_start}Terms of Service%{eula_link_end}.').html_safe % { eula_link_start: eula_link_start, eula_url: eula_url, eula_link_end: '</a>'.html_safe } = _('Unless otherwise agreed to in writing with GitLab, by clicking "Upload License" you agree that your use of GitLab Software is subject to the %{eula_link_start}Terms of Service%{eula_link_end}.').html_safe % { eula_link_start: eula_link_start, eula_url: eula_url, eula_link_end: '</a>'.html_safe }
.form-actions .form-actions
= f.submit 'Upload License', class: 'gl-button btn btn-confirm', disabled: true, id: 'js-upload-license' = f.submit 'Upload License', class: 'gl-button btn btn-confirm', data: { qa_selector: 'license_upload_button' }, disabled: true, id: 'js-upload-license'
...@@ -51,7 +51,7 @@ RSpec.describe 'EE > Projects > Licenses > Maintainer views policies', :js do ...@@ -51,7 +51,7 @@ RSpec.describe 'EE > Projects > Licenses > Maintainer views policies', :js do
end end
it 'displays the classification' do it 'displays the classification' do
selector = "div[data-qa-selector='admin_license_compliance_row']" selector = "div[data-testid='admin-license-compliance-row']"
expect(page).to have_selector(selector) expect(page).to have_selector(selector)
row = page.find(selector) row = page.find(selector)
......
...@@ -145,7 +145,6 @@ module QA ...@@ -145,7 +145,6 @@ module QA
autoload :Integrations, 'qa/ee/page/project/settings/integrations' autoload :Integrations, 'qa/ee/page/project/settings/integrations'
autoload :Repository, 'qa/ee/page/project/settings/repository' autoload :Repository, 'qa/ee/page/project/settings/repository'
autoload :PushRules, 'qa/ee/page/project/settings/push_rules' autoload :PushRules, 'qa/ee/page/project/settings/push_rules'
autoload :LicenseCompliance, 'qa/ee/page/project/settings/license_compliance'
autoload :IssueTemplateDefault, 'qa/ee/page/project/settings/issue_template_default.rb' autoload :IssueTemplateDefault, 'qa/ee/page/project/settings/issue_template_default.rb'
autoload :CICD, 'qa/ee/page/project/settings/ci_cd' autoload :CICD, 'qa/ee/page/project/settings/ci_cd'
autoload :PipelineSubscriptions, 'qa/ee/page/project/settings/pipeline_subscriptions' autoload :PipelineSubscriptions, 'qa/ee/page/project/settings/pipeline_subscriptions'
......
...@@ -6,7 +6,7 @@ module QA ...@@ -6,7 +6,7 @@ module QA
module Admin module Admin
class License < QA::Page::Base class License < QA::Page::Base
view 'ee/app/views/admin/licenses/missing.html.haml' do view 'ee/app/views/admin/licenses/missing.html.haml' do
element :missing_license element :missing_license_content
end end
view 'ee/app/views/admin/licenses/show.html.haml' do view 'ee/app/views/admin/licenses/show.html.haml' do
...@@ -18,25 +18,24 @@ module QA ...@@ -18,25 +18,24 @@ module QA
end end
view 'ee/app/views/admin/licenses/new.html.haml' do view 'ee/app/views/admin/licenses/new.html.haml' do
element :license_type, 'radio_button_tag :license_type' # rubocop:disable QA/ElementWithPattern element :accept_eula_checkbox
element :license_type_placeholder, 'Enter license key' # rubocop:disable QA/ElementWithPattern element :license_key_field
element :license_key_field, 'text_area :data' # rubocop:disable QA/ElementWithPattern element :license_type_key_radio
element :license_key_placeholder, 'label :data, "License key"' # rubocop:disable QA/ElementWithPattern element :license_upload_button
element :license_upload_button, "submit 'Upload License'" # rubocop:disable QA/ElementWithPattern
end end
def license? def license?
has_element?(:remove_license_link) || !has_element?(:missing_license) has_element?(:remove_license_link) || !has_element?(:missing_license_content)
end end
def add_new_license(key) def add_new_license(key)
raise 'License key empty!' if key.to_s.empty? raise 'License key empty!' if key.to_s.empty?
click_link 'Upload New License' click_element(:license_upload_link)
choose 'Enter license key' choose_element(:license_type_key_radio)
fill_in 'License key', with: key fill_element(:license_key_field, key)
check 'accept_eula' check_element(:accept_eula_checkbox)
click_button 'Upload License' click_element(:license_upload_button)
end end
end end
end end
......
...@@ -21,46 +21,45 @@ module QA ...@@ -21,46 +21,45 @@ module QA
end end
view 'ee/app/assets/javascripts/vue_shared/license_compliance/components/admin_license_management_row.vue' do view 'ee/app/assets/javascripts/vue_shared/license_compliance/components/admin_license_management_row.vue' do
element :admin_license_compliance_row element :admin_license_compliance_container
element :license_name_content
end end
def approve_license(license) def approve_license(license)
click_element :license_add_button click_element(:license_add_button)
expand_select_list expand_select_list
search_and_select_exact license search_and_select_exact(license)
find('.custom-control-label', text: 'Allow').click choose_element(:approved_license_radio, true)
click_element :add_license_submit_button click_element(:add_license_submit_button)
has_approved_license? license has_approved_license?(license)
end end
def has_approved_license?(name) def has_approved_license?(name)
has_element?(:admin_license_compliance_row, text: name) has_element?(:admin_license_compliance_container, text: name)
within_element(:admin_license_compliance_row, text: name) do within_element(:admin_license_compliance_container, text: name) do
has_element?(:status_success_icon) has_element?(:status_success_icon)
end end
end end
def deny_license(license) def deny_license(license)
click_element :license_add_button click_element(:license_add_button)
expand_select_list expand_select_list
search_and_select_exact license search_and_select_exact(license)
find('.custom-control-label', text: 'Deny').click choose_element(:blacklisted_license_radio, true)
click_element :add_license_submit_button click_element(:add_license_submit_button)
has_denied_license? license has_denied_license?(license)
end end
def has_denied_license?(name) def has_denied_license?(name)
has_element?(:admin_license_compliance_row, text: name) has_element?(:admin_license_compliance_container, text: name)
within_element(:admin_license_compliance_row, text: name) do within_element(:admin_license_compliance_container, text: name) do
has_element?(:status_failed_icon) has_element?(:status_failed_icon)
end end
end end
def open_tab def open_tab
click_element :policies_tab click_element(:policies_tab)
end end
end end
end end
......
# frozen_string_literal: true
module QA
module EE
module Page
module Project
module Settings
class LicenseCompliance < QA::Page::Base
include QA::Page::Component::Select2 # Select2 is an external library, so we can't add our own selectors
view 'ee/app/assets/javascripts/vue_shared/license_compliance/license_management.vue' do
element :license_add_button
end
view 'ee/app/assets/javascripts/vue_shared/license_compliance/components/add_license_form.vue' do
element :license_radio, 'data-qa-selector="`${option.value}_license_radio`"' # rubocop:disable QA/ElementWithPattern
element :add_license_submit_button
end
view 'ee/app/assets/javascripts/vue_shared/license_compliance/license_management.vue' do
element :license_compliance_list
end
view 'ee/app/assets/javascripts/vue_shared/license_compliance/components/admin_license_management_row.vue' do
element :admin_license_compliance_row
element :license_name_content
end
view 'app/assets/javascripts/reports/components/issue_status_icon.vue' do
element :icon_status, ':data-qa-selector="`status_${status}_icon`" ' # rubocop:disable QA/ElementWithPattern
end
def has_approved_license?(name)
within_element(:admin_license_compliance_row, text: name) do
has_element?(:status_success_icon)
end
end
def has_denied_license?(name)
within_element(:admin_license_compliance_row, text: name) do
has_element?(:status_failed_icon)
end
end
def approve_license(license)
click_element :license_add_button
expand_select_list
search_and_select license
click_element :approved_license_radio
click_element :add_license_submit_button
has_approved_license? license
end
def deny_license(license)
click_element :license_add_button
expand_select_list
search_and_select license
click_element :blacklisted_license_radio
click_element :add_license_submit_button
has_denied_license? license
end
end
end
end
end
end
end
...@@ -166,6 +166,26 @@ module QA ...@@ -166,6 +166,26 @@ module QA
end end
end end
# Method for selecting radios
def choose_element(name, click_by_js = false)
if find_element(name, visible: false).checked?
QA::Runtime::Logger.debug("#{name} is already selected")
return
end
retry_until(sleep_interval: 1) do
radio = find_element(name, visible: false)
# Some radio buttons are hidden by their labels and cannot be clicked directly
click_by_js ? page.execute_script("arguments[0].click();", radio) : radio.click
selected = find_element(name, visible: false).checked?
QA::Runtime::Logger.debug(selected ? "#{name} was selected" : "#{name} was not selected")
selected
end
end
# Use this to simulate moving the pointer to an element's coordinate # Use this to simulate moving the pointer to an element's coordinate
# and sending a click event. # and sending a click event.
# This is a helpful workaround when there is a transparent element overlapping # This is a helpful workaround when there is a transparent element overlapping
......
...@@ -20,11 +20,11 @@ module QA ...@@ -20,11 +20,11 @@ module QA
end end
def click_save_changes def click_save_changes
click_element :save_merge_request_changes_button click_element(:save_merge_request_changes_button)
end end
def enable_ff_only def enable_ff_only
click_element :merge_ff_radio_button click_element(:merge_ff_radio_button)
click_save_changes click_save_changes
end end
......
...@@ -81,7 +81,7 @@ module QA ...@@ -81,7 +81,7 @@ module QA
end end
def fill_element(name, content) def fill_element(name, content)
masked_content = name.to_s.include?('password') ? '*****' : content masked_content = name.to_s.match?(/token|key|password/) ? '*****' : content
log(%Q(filling :#{name} with "#{masked_content}")) log(%Q(filling :#{name} with "#{masked_content}"))
......
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