Module: Capybara::UploadModal

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

Instance Method Summary collapse

Instance Method Details

#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
# 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?

  within ".upload-modal" do
    find(".remove-upload-item").click 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("div.progress-bar.filled", wait: 5)
    end
    all("input.attachment-title").last.set(options[:title]) if options.has_key?(:title)
    click_button "Save" unless options[:keep_modal_open]
  end
end