Welcome to mirror list, hosted at ThFree Co, Russian Federation.

content_editor.rb « component « page « qa « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f7b055b6052a93f521188b39bc959e119f0a519e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true

module QA
  module Page
    module Component
      module ContentEditor
        extend QA::Page::PageConcern

        def self.included(base)
          super

          base.view 'app/assets/javascripts/content_editor/components/content_editor.vue' do
            element :content_editor_container
          end

          base.view 'app/assets/javascripts/content_editor/components/toolbar_text_style_dropdown.vue' do
            element :text_style_dropdown
            element :text_style_menu_item
          end

          base.view 'app/assets/javascripts/content_editor/components/toolbar_image_button.vue' do
            element :file_upload_field
          end

          base.view 'app/assets/javascripts/pages/shared/wikis/components/wiki_form.vue' do
            element :wiki_hidden_content
          end
        end

        def add_heading(heading, text)
          within_element(:content_editor_container) do
            text_area.set(text)
            # wait for text style option to become active after typing
            has_active_element?(:text_style_dropdown, wait: 1)
            click_element(:text_style_dropdown)
            within_element(:text_style_dropdown) do
              click_element(:text_style_menu_item, text_style: heading)
            end
          end
        end

        def upload_image(image_path)
          within_element(:content_editor_container) do
            # add image on a new line
            text_area.send_keys(:return)
            find_element(:file_upload_field, visible: false).send_keys(image_path)
          end

          QA::Support::Retrier.retry_on_exception do
            source = find_element(:wiki_hidden_content, visible: false)
            source.value =~ %r{uploads/.*#{::File.basename(image_path)}}
          end
        end

        private

        def text_area
          find('[contenteditable="true"]', visible: false)
        end
      end
    end
  end
end