diff --git a/qa/qa/ee/page/admin/settings/templates.rb b/qa/qa/ee/page/admin/settings/templates.rb index 97fab4a59c41e8c1ea205be192cf44ece3c2fe24..023ddceddc6a7949b07be0152fba7483622bd426 100644 --- a/qa/qa/ee/page/admin/settings/templates.rb +++ b/qa/qa/ee/page/admin/settings/templates.rb @@ -7,7 +7,7 @@ module Admin module Settings class Templates < QA::Page::Base include ::QA::Page::Settings::Common - include ::QA::Page::Component::Select2 + include ::QA::Page::Component::Dropdown view 'ee/app/views/admin/application_settings/_custom_templates_form.html.haml' do element :custom_project_template_container @@ -29,7 +29,14 @@ def choose_custom_project_template(path) within_element(:custom_project_template_container) do clear_current_selection_if_present expand_select_list + + unless use_select2? + search_and_select(path) + click_element(:save_changes_button) + return # rubocop:disable Cop/AvoidReturnFromBlocks + end end + search_and_select(path) click_element(:save_changes_button) end diff --git a/qa/qa/ee/page/group/settings/general.rb b/qa/qa/ee/page/group/settings/general.rb index f73e1acf1364429bfd67f4b4127001ab8473f442..90c3efe75d67db53a6ffe9c3f46a152945a51b0c 100644 --- a/qa/qa/ee/page/group/settings/general.rb +++ b/qa/qa/ee/page/group/settings/general.rb @@ -12,7 +12,7 @@ def self.prepended(base) super base.class_eval do - prepend ::QA::Page::Component::Select2 + prepend ::QA::Page::Component::Dropdown prepend ::QA::Page::Settings::Common view 'ee/app/views/groups/_custom_project_templates_setting.html.haml' do @@ -57,7 +57,16 @@ def choose_custom_project_template(path) within_element(:custom_project_templates_container) do clear_current_selection_if_present expand_select_list + + unless use_select2? + search_and_select(path) + click_element(:save_changes_button) + return # rubocop:disable Cop/AvoidReturnFromBlocks + end end + + # TODO: Remove the following two lines and the use_select2? + # check above once ff vue_group_select is default. search_and_select(path) click_element(:save_changes_button) end diff --git a/qa/qa/page/component/dropdown.rb b/qa/qa/page/component/dropdown.rb new file mode 100644 index 0000000000000000000000000000000000000000..2d05bea50a9919d5dc9d272cfdf1670d187f0cf3 --- /dev/null +++ b/qa/qa/page/component/dropdown.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +module QA + module Page + module Component + module Dropdown + include Select2 + + def select_item(item_text) + return super if use_select2? + + find('li.gl-new-dropdown-item', text: item_text, match: :prefer_exact).click + end + + def has_item?(item_text) + return super if use_select2? + + has_css?('li.gl-new-dropdown-item', text: item_text, match: :prefer_exact) + end + + def current_selection + return super if use_select2? + + expand_select_list unless dropdown_open? + find('span.gl-new-dropdown-button-text').text + end + + def clear_current_selection_if_present + return super if use_select2? + + expand_select_list unless dropdown_open? + + if has_css?('button[data-testid="listbox-reset-button"]') + find('button[data-testid="listbox-reset-button"]').click + elsif dropdown_open? + expand_select_list + end + end + + def search_item(item_text) + return super if use_select2? + + find('div.gl-search-box-by-type input[type="Search"]').set(item_text) + wait_for_search_to_complete + end + + def search_and_select(item_text) + return super if use_select2? + + QA::Runtime::Logger.info "Searching and selecting: #{item_text}" + + search_item(item_text) + + unless has_item?(item_text) + raise QA::Page::Base::ElementNotFound, %(Couldn't find option named "#{item_text}") + end + + select_item(item_text) + end + + def search_and_select_exact(item_text) + return super if use_select2? + + QA::Runtime::Logger.info "Searching and selecting: #{item_text}" + + search_item(item_text) + + unless has_item?(item_text) + raise QA::Page::Base::ElementNotFound, %(Couldn't find option named "#{item_text}") + end + + find('li.gl-new-dropdown-item span:nth-child(2)', text: item_text, exact_text: true).click + end + + def expand_select_list + return super if use_select2? + + find('svg.dropdown-chevron').click + end + + def wait_for_search_to_complete + return super if use_select2? + + Support::WaitForRequests.wait_for_requests + + has_css?('div[data-testid="listbox-search-loader"]', wait: 1) + has_no_css?('div[data-testid="listbox-search-loader"]') + end + + def dropdown_open? + return super if use_select2? + + has_css?('ul.gl-new-dropdown-contents', wait: 1) + end + + private + + # rubocop:disable Gitlab/PredicateMemoization + def use_select2? + @use_select2 ||= has_css?('.select2-container', wait: 1) + end + # rubocop:enable Gitlab/PredicateMemoization + end + end + end +end