From c65eace0151b524e7acb5ac52aafd8bd818e5dc0 Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Thu, 20 Nov 2014 01:17:52 -0300 Subject: [PATCH] [media-panel-improvements] Test coverage --- features/blog.feature | 2 +- features/media_panel_upload_files.feature | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ features/step_definitions/media_panel.rb | 30 ++++++++++++++++++++++++++++++ features/step_definitions/web_steps.rb | 3 ++- 4 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 features/media_panel_upload_files.feature create mode 100644 features/step_definitions/media_panel.rb diff --git a/features/blog.feature b/features/blog.feature index fe245b6..c4a6783 100644 --- a/features/blog.feature +++ b/features/blog.feature @@ -124,7 +124,7 @@ Feature: blog Then I should not see "Delete cover image" # the step for attaching a file on the input only works with capybara 1.1.2, but it requires rails 1.9.3 - @selenium-fixme + @selenium Scenario: display cover image after uploading an image as the blog cover Given the following blogs | owner | name | diff --git a/features/media_panel_upload_files.feature b/features/media_panel_upload_files.feature new file mode 100644 index 0000000..3060f3f --- /dev/null +++ b/features/media_panel_upload_files.feature @@ -0,0 +1,238 @@ +Feature: uploads items on media panel + As a noosfero user + I want to uploads items when creating or editing articles + + Background: + Given the following users + | login | name | + | joaosilva | Joao Silva | + And feature "media_panel" is enabled on environment + And I am logged in as "joaosilva" + And I am on /myprofile/joaosilva/cms/new?type=TinyMceArticle + + Scenario: see media panel collapsed + Then I should see "Insert media" + And I should not see an element ".show-media-panel" + + @selenium + Scenario: expand media panel + When I follow "Show/Hide" + Then I should see an element ".show-media-panel" + + @selenium + Scenario: upload file showing percentage and name + When I follow "Show/Hide" + And I attach the file "public/images/rails.png" to "file" + Then I should see "100%" + And I should see "rails.png" + + @selenium + Scenario: upload multiple files + When I follow "Show/Hide" + And I attach the file "public/images/rails.png" to "file" + And I attach the file "public/503.jpg" to "file" + Then I should see "rails.png" within "#file-1" + And I should see "503.jpg" within "#file-2" + + @selenium + Scenario: show error when upload fails + When I follow "Show/Hide" + And I attach the file "public/images/rails.png" to "file" + # uploads the same file twice to induce error (unique name validation) + And I attach the file "public/images/rails.png" to "file" + Then I should see "rails.png" within "#file-1" + And I should see "100%" within "#file-1" + But I should see "Validation failed: Slug The title (article name) is already being used by another article, please use another title." within "#file-2" + And The page should contain "div.error-message" + + @selenium + Scenario: select destination folder + When I follow "Show/Hide" + And I attach the file "public/images/rails.png" to "file" + And I select "joaosilva" from "parent_id" within "#media-upload-form" + And I attach the file "public/503.jpg" to "file" + And I go to joaosilva's cms + Then I should not see "rails.png" + But I should see "503.jpg" + When I follow "Gallery" + Then I should see "rails.png" + But I should not see "503.jpg" + + @selenium + Scenario: create new folder with parent + Given I follow "Show/Hide" + And I should see "joaosilva" within "#media-upload-form" + And I should see "joaosilva/Gallery" within "#media-upload-form" + And I should see "joaosilva" within "#published-media" + And I should see "joaosilva/Gallery" within "#published-media" + + When I follow "New folder" + And I select "joaosilva" from "parent_id" within "#new-folder-dialog" + And I fill in "Name" with "Main folder" within "#new-folder-dialog" + And I press "Create" + Then I should see "joaosilva" within "#media-upload-form" + And I should see "joaosilva/Gallery" within "#media-upload-form" + And I should see "joaosilva/Main folder" within "#media-upload-form" + And "joaosilva/Main folder" should be selected for "parent_id" within "#media-upload-form" + And I should see "joaosilva" within "#published-media" + And I should see "joaosilva/Gallery" within "#published-media" + And I should see "joaosilva/Main folder" within "#published-media" + + When I follow "New folder" + And I select "joaosilva/Gallery" from "parent_id" within "#new-folder-dialog" + And I fill in "Name" with "Gallery folder" within "#new-folder-dialog" + And I press "Create" + Then I should see "joaosilva" within "#media-upload-form" + And I should see "joaosilva/Gallery" within "#media-upload-form" + And I should see "joaosilva/Main folder" within "#media-upload-form" + And I should see "joaosilva/Gallery/Gallery folder" within "#media-upload-form" + And "joaosilva/Gallery/Gallery folder" should be selected for "parent_id" within "#media-upload-form" + And I should see "joaosilva" within "#published-media" + And I should see "joaosilva/Gallery" within "#published-media" + And I should see "joaosilva/Main folder" within "#published-media" + And I should see "joaosilva/Gallery/Gallery folder" within "#published-media" + + @selenium + Scenario: select type when create new folder + When I follow "Show/Hide" + And I follow "New folder" + And I choose "Folder" within "#new-folder-dialog" + And I fill in "Name" with "Main new folder" within "#new-folder-dialog" + And I press "Create" + Then I should see "joaosilva/Gallery/Main new folder" within "#parent_id" + When I follow "New folder" + And I choose "Gallery" within "#new-folder-dialog" + And I fill in "Name" with "Gallery new folder" within "#new-folder-dialog" + And I press "Create" + And I go to joaosilva's cms + And I follow "Gallery" + Then I should see "Folder" within "tr[title='Main new folder'] td.article-mime" + And I should see "Gallery" within "tr[title='Gallery new folder'] td.article-mime" + + @selenium + Scenario: hide and show upload list + When I follow "Show/Hide" + And I attach the file "public/images/rails.png" to "file" + And I attach the file "public/503.jpg" to "file" + And I follow "Hide all uploads" + Then I should not see "503.jpg" + And I should not see "rails.png" + When I follow "Show all uploads" + Then I should see "503.jpg" + And I should see "rails.png" + + @selenium + Scenario: update recent media after file upload + Given the following files + | owner | file | mime | + | joaosilva | other-pic.jpg | image/jpeg | + When I go to /myprofile/joaosilva/cms/new?type=TinyMceArticle + And I follow "Show/Hide" + And I select "Recent media" from "parent_id" within "#published-media" + Then I should see div with title "other-pic.jpg" within ".items" + When I select "joaosilva" from "parent_id" within "#media-upload-form" + And I attach the file "public/503.jpg" to "file" + Then I should see div with title "503.jpg" within ".items" + And I should see div with title "other-pic.jpg" within ".items" + When I select "joaosilva/Gallery" from "parent_id" within "#media-upload-form" + And I attach the file "public/images/rails.png" to "file" + And I attach the file "public/robots.txt" to "file" + Then I should see div with title "rails.png" within ".items" + And I should see div with title "503.jpg" within ".items" + And I should see div with title "other-pic.jpg" within ".items" + And I should see "robots.txt" link + + @selenium + Scenario: select folder to show items + Given the following galleries + | owner | name | + | joaosilva | other-gallery | + And the following files + | owner | file | mime | parent | + | joaosilva | rails.png | image/png | other-gallery | + | joaosilva | other-pic.jpg | image/jpeg | gallery | + When I go to /myprofile/joaosilva/cms/new?type=TinyMceArticle + And I follow "Show/Hide" + And I select "joaosilva/Gallery" from "parent_id" within "#published-media" + Then I should see div with title "other-pic.jpg" within ".items" + And I should not see div with title "rails.png" within ".items" + When I select "joaosilva/other-gallery" from "parent_id" within "#published-media" + Then I should see div with title "rails.png" within ".items" + And I should not see div with title "other-pic.jpg" within ".items" + + @selenium + Scenario: update selected folder content when upload file to same folder + Given the following galleries + | owner | name | + | joaosilva | other-gallery | + And the following files + | owner | file | mime | parent | + | joaosilva | other-pic.jpg | image/jpeg | gallery | + When I go to /myprofile/joaosilva/cms/new?type=TinyMceArticle + And I follow "Show/Hide" + And I select "joaosilva/Gallery" from "parent_id" within "#published-media" + And I select "joaosilva/Gallery" from "parent_id" within "#media-upload-form" + And I attach the file "public/503.jpg" to "file" + Then I should see div with title "other-pic.jpg" within ".items" + And I should see div with title "503.jpg" within ".items" + + When I select "joaosilva/other-gallery" from "parent_id" within "#media-upload-form" + And I attach the file "public/robots.txt" to "file" + Then I should see div with title "other-pic.jpg" within ".items" + And I should see div with title "503.jpg" within ".items" + And I should not see "robots.txt" within ".items" + + @selenium + Scenario: filter media with search + Given the following galleries + | owner | name | + | joaosilva | other-gallery | + And the following files + | owner | file | mime | parent | + | joaosilva | rails.png | image/png | other-gallery | + When I go to /myprofile/joaosilva/cms/new?type=TinyMceArticle + And I follow "Show/Hide" + And I select "Recent media" from "parent_id" within "#published-media" + And I fill in "Search" with "rails" within "#published-media" + Then I should see div with title "rails.png" within ".items" + When I select "joaosilva/Gallery" from "parent_id" within "#published-media" + And I fill in "Search" with "rails" within "#published-media" + Then I should not see div with title "rails.png" within ".items" + When I select "joaosilva/other-gallery" from "parent_id" within "#published-media" + And I fill in "Search" with "rails" within "#published-media" + Then I should see div with title "rails.png" within ".items" + + @selenium + Scenario: separete images from non-images + When I follow "Show/Hide" + Then I should not see "Images" + And I should not see "Files" + When I attach the file "public/robots.txt" to "file" + And I attach the file "public/images/rails.png" to "file" + Then I should see "Files" + And I should see "robots.txt" within ".generics" + But I should not see "rails.png" within ".generics" + And I should see "Images" + And I should see div with title "rails.png" within ".images" + But I should not see div with title "robots.txt" within ".images" + + @selenium + Scenario: view all media button if there are too many uploads + Given the following galleries + | owner | name | + | joaosilva | other-gallery | + | joaosilva | my-gallery | + And the following files + | owner | file | mime | parent | + | joaosilva | rails.png | image/png | other-gallery | + | joaosilva | other-pic.jpg | image/jpeg | other-gallery | + | joaosilva | rails.png | image/png | my-gallery | + | joaosilva | other-pic.jpg | image/jpeg | my-gallery | + | joaosilva | rails.png | image/png | gallery | + | joaosilva | other-pic.jpg | image/jpeg | gallery | + When I go to /myprofile/joaosilva/cms/new?type=TinyMceArticle + And I follow "Show/Hide" + And I should not see "View all" + And I attach the file "public/503.jpg" to "file" + Then I should see "View all" link + And I should see div with title "503.jpg" within ".images" diff --git a/features/step_definitions/media_panel.rb b/features/step_definitions/media_panel.rb new file mode 100644 index 0000000..27a63b8 --- /dev/null +++ b/features/step_definitions/media_panel.rb @@ -0,0 +1,30 @@ +Then /^I should (not )?see an element "([^"]*)"$/ do |negate, selector| + expectation = negate ? :should_not : :should + page.html.send(expectation, have_css(selector)) +end + +Then /^"([^"]*)" should be selected for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector| + with_scope(selector) do + field_labeled(field).find(:xpath, ".//option[@selected = 'selected'][text() = '#{value}']").should be_present + end +end + +Then /^(?:|I )should see div with title "([^"]*)"(?: within "([^"]*)")?$/ do |name, selector| + with_scope(selector) do + if page.respond_to? :should + page.should have_xpath(".//div[@title='#{name}']") + else + assert page.has_xpath?(".//div[@title='#{name}']") + end + end +end + +Then /^(?:|I )should not see div with title "([^"]*)"(?: within "([^"]*)")?$/ do |name, selector| + with_scope(selector) do + if page.respond_to? :should + page.should have_no_xpath(".//div[@title='#{name}']") + else + assert page.has_no_xpath?(".//div[@title='#{name}']") + end + end +end diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index 3274cef..5da1b6b 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -99,6 +99,7 @@ When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector| end When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector| + path = File.expand_path(path).gsub('/', File::ALT_SEPARATOR || File::SEPARATOR) with_scope(selector) do attach_file(field, path) end @@ -252,7 +253,7 @@ Then /^display "([^\"]*)"$/ do |element| end Then /^there should be a div with class "([^"]*)"$/ do |klass| - should have_selector('div', :class => klass) + should have_selector("div.#{klass}") end When /^(?:|I )follow exact "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector| -- libgit2 0.21.2