1# frozen_string_literal: true 2 3module QA 4 module Page 5 module Component 6 module ContentEditor 7 extend QA::Page::PageConcern 8 9 def self.included(base) 10 super 11 12 base.view 'app/assets/javascripts/content_editor/components/content_editor.vue' do 13 element :content_editor_container 14 end 15 16 base.view 'app/assets/javascripts/content_editor/components/toolbar_text_style_dropdown.vue' do 17 element :text_style_dropdown 18 element :text_style_menu_item 19 end 20 21 base.view 'app/assets/javascripts/content_editor/components/toolbar_image_button.vue' do 22 element :file_upload_field 23 end 24 end 25 26 def add_heading(heading, text) 27 within_element(:content_editor_container) do 28 text_area.set(text) 29 # wait for text style option to become active after typing 30 has_active_element?(:text_style_dropdown, wait: 1) 31 click_element(:text_style_dropdown) 32 within_element(:text_style_dropdown) do 33 click_element(:text_style_menu_item, text_style: heading) 34 end 35 end 36 end 37 38 def upload_image(image_path) 39 within_element(:content_editor_container) do 40 # add image on a new line 41 text_area.send_keys(:return) 42 find_element(:file_upload_field, visible: false).send_keys(image_path) 43 end 44 end 45 46 private 47 48 def text_area 49 find('[contenteditable="true"]', visible: false) 50 end 51 end 52 end 53 end 54end 55