mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Add spec DownloadsHelper to support testing csv downloads with headless chrome
This commit is contained in:
38
spec/support/downloads_helper.rb
Normal file
38
spec/support/downloads_helper.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
module DownloadsHelper
|
||||
TIMEOUT = 10
|
||||
PATH = Rails.root.join("tmp", "downloads")
|
||||
|
||||
def downloaded_filename
|
||||
wait_for_download
|
||||
downloaded_filenames.first
|
||||
end
|
||||
|
||||
def downloaded_content
|
||||
wait_for_download
|
||||
File.read(downloaded_filename)
|
||||
end
|
||||
|
||||
def clear_downloads
|
||||
FileUtils.rm_f(downloaded_filenames)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def downloaded_filenames
|
||||
Dir[PATH.join("*")]
|
||||
end
|
||||
|
||||
def wait_for_download
|
||||
Timeout.timeout(TIMEOUT) do
|
||||
sleep 0.1 until downloaded?
|
||||
end
|
||||
end
|
||||
|
||||
def downloaded?
|
||||
!downloading? && downloaded_filenames.any?
|
||||
end
|
||||
|
||||
def downloading?
|
||||
downloaded_filenames.grep(/\.crdownload$/).any?
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user