1# frozen_string_literal: true
2
3module QA
4  module Page
5    module Component
6      module LegacyClonePanel
7        extend QA::Page::PageConcern
8
9        def self.included(base)
10          super
11
12          base.view 'app/views/shared/_clone_panel.html.haml' do
13            element :clone_dropdown
14            element :clone_options_dropdown, '.clone-options-dropdown' # rubocop:disable QA/ElementWithPattern
15            element :clone_url, 'text_field_tag :clone_url' # rubocop:disable QA/ElementWithPattern
16          end
17        end
18
19        def choose_repository_clone_http
20          choose_repository_clone('HTTP', 'http')
21        end
22
23        def choose_repository_clone_ssh
24          # It's not always beginning with ssh:// so detecting with @
25          # would be more reliable because ssh would always contain it.
26          # We can't use .git because HTTP also contain that part.
27          choose_repository_clone('SSH', '@')
28        end
29
30        def repository_location
31          Git::Location.new(find('#clone_url').value)
32        end
33
34        private
35
36        def choose_repository_clone(kind, detect_text)
37          wait_until(reload: false) do
38            click_element :clone_dropdown
39
40            page.within('.clone-options-dropdown') do
41              click_link(kind)
42            end
43
44            # Ensure git clone textbox was updated
45            repository_location.git_uri.include?(detect_text)
46          end
47        end
48      end
49    end
50  end
51end
52