Module: Capybara::UploadModal

Defined in:
lib/decidim/dev/test/rspec_support/dynamic_attach.rb

Instance Method Summary collapse

Instance Method Details

#click_remove(front_interface) ⇒ Object



38
39
40
# File 'lib/decidim/dev/test/rspec_support/dynamic_attach.rb', line 38

def click_remove(front_interface)
  front_interface ? click_on("Remove") : find(".remove-upload-item").click
end

#dynamically_attach_file(name, file_location, options = {}) ⇒ Object

Replaces attach_file. Beware that modal does not open within form!



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/decidim/dev/test/rspec_support/dynamic_attach.rb', line 9

def dynamically_attach_file(name, file_location, options = {})
  find("##{name}_button").click
  filename = options[:filename] || file_location.to_s.split("/").last

  yield if block_given?

  front_interface = options.fetch(:front_interface, true)

  within ".upload-modal" do
    click_remove(front_interface) if options[:remove_before]
    input_element = find("input[type='file']", visible: :all)
    input_element.attach_file(file_location)
    within "[data-filename='#{filename}']" do
      expect(page).to have_css(filled_selector(front_interface), wait: 5)
      expect(page).to have_content(filename.first(12)) if front_interface
    end
    all(title_input(front_interface)).last.set(options[:title]) if options.has_key?(:title)
    click_on("Save") unless options[:keep_modal_open]
  end
end

#filled_selector(front_interface) ⇒ Object



30
31
32
# File 'lib/decidim/dev/test/rspec_support/dynamic_attach.rb', line 30

def filled_selector(front_interface)
  front_interface ? "li progress[value='100']" : "div.progress-bar.filled"
end

#title_input(front_interface) ⇒ Object



34
35
36
# File 'lib/decidim/dev/test/rspec_support/dynamic_attach.rb', line 34

def title_input(front_interface)
  front_interface ? "input[type='text']" : "input.attachment-title"
end