Skip to content

Commit

Permalink
Better system tests for files (still skipped)
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Feb 28, 2018
1 parent c2c51e3 commit ae134b9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
6 changes: 3 additions & 3 deletions test/fixtures/active_storage/blobs.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
default:
key: 123abc
filename: default.jpg
filename: image.jpg
content_type: image/jpg
byte_size: 12345
checksum: 123abc
byte_size: 6400
checksum: 028ad8393792078a9d3fd93343a3387b

fragment:
key: 456def
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/comfy/cms/files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ default:
site: default
label: default file
description: default description
position: 0
position: 0
17 changes: 14 additions & 3 deletions test/fixtures/comfy/cms/layouts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,21 @@ child:
js: child_js
position: 0

with_attachments:
text_content:
site: default
label: Default Layout with Attachments
identifier: with_attachments
label: Default Layout with text content
identifier: text_content
parent:
content: |-
{{cms:text content}}
css: default_css
js: default_js
position: 0

text_content_with_attachments:
site: default
label: Default Layout with with text content and attachments
identifier: text_content_with_attachments
parent:
content: |-
{{cms:text content}}
Expand Down
24 changes: 19 additions & 5 deletions test/fixtures/comfy/cms/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,29 @@ child:
position: 0
is_published: true

with_attachments:
text_content:
site: default
parent:
target_page:
layout: with_attachments
label: Default Page with Attachments
slug: 'with-attachments'
full_path: '/with-attachments'
layout: text_content
label: Default Page with text content
slug: 'text-content'
full_path: '/text-content'
children_count: 0
position: 1
is_published: true
content_cache:


text_content_with_attachments:
site: default
parent:
target_page:
layout: text_content_with_attachments
label: Default Page with text content and attachments
slug: 'text-content-with-attachments'
full_path: '/text-content-with-attachments'
children_count: 0
position: 2
is_published: true
content_cache:
29 changes: 23 additions & 6 deletions test/system/files_frontend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,41 @@ class FilesFrontendTest < ApplicationSystemTestCase
end

def test_site_file_drag_and_drop
skip "TODO: Write this test"
file = comfy_cms_files(:default)
file.attachment = ActiveStorage::Blob.create_after_upload!(
io: file_fixture("image.jpg").open, filename: "image.jpg", content_type: "image/jpg")
file.save!

visit_p edit_comfy_admin_cms_site_page_path(site_id: @site, id: comfy_cms_pages(:text_content))
click_link title: "Open library"

skip "Drag'n'drop from iframe to parent has issues:
https://github.com/SeleniumHQ/selenium/issues/810"
drop_target = content_field
within_frame(:css, ".cms-files-modal iframe") do
find_link(file.label).drag_to(drop_target)
end
assert_equal "{{ cms:file_link #{file.id} }}", content_field.value
end

def test_page_file_drag_and_drop
page = comfy_cms_pages(:with_attachments)

# Upload a file.
visit_p edit_comfy_admin_cms_site_page_path(site_id: @site, id: page)
# Upload a page file.
visit_p edit_comfy_admin_cms_site_page_path(site_id: @site, id: comfy_cms_pages(:text_content_with_attachments))
attach_file Rails.root.join("test/fixtures/files/image.jpg"),
name: "page[fragments_attributes][1][files][]", multiple: true
click_button I18n.t("comfy.admin.cms.pages.form.update")
assert_link "image.jpg"

# Dragging the link should generate CMS markup.
skip "Drag'n'drop does not work for some reason"
content_field = find_field(name: "page[fragments_attributes][0][content]")
find_link("image.jpg").drag_to(content_field)
assert_equal '{{ cms:page_file_link attachments, filename: "image.jpg", as: image }}', content_field.value
end

private

def content_field
find_field(name: "page[fragments_attributes][0][content]")
end

end

0 comments on commit ae134b9

Please sign in to comment.