-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
524 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
shared_context 'admin images tab' do | ||
let(:open_image_dialog) { click_on(::I18n.t('create_new_image', :scope => 'refinery.admin.images.actions')) } | ||
let(:dialog_frame_id) {'dialog_iframe'} | ||
let(:initial_path) { refinery.admin_images_path(view: %w(grid list).sample) } | ||
let(:select_upload) {} | ||
|
||
let(:index_item_selector) {'#records li'} | ||
|
||
let(:gridview_img_selector) {' > img'} | ||
let(:gridview_title_selector) {'[tooltip]'} | ||
let(:gridview_alt_selector) {'[alt]'} | ||
|
||
let(:listview_title_selector) {' > span.title'} | ||
let(:listview_alt_selector) {' > span.alt'} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
shared_context 'many images' do | ||
let!(:image) { FactoryGirl.create(:image) } | ||
let!(:alt_image) { FactoryGirl.create(:alternate_image) } | ||
let!(:another_image) { FactoryGirl.create(:another_image) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
shared_context "no existing images" do | ||
let(:image) { FactoryGirl.create(:image) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
shared_context "one image" do | ||
let!(:image) { FactoryGirl.create(:image) } | ||
end |
23 changes: 23 additions & 0 deletions
23
images/spec/support/shared contexts/visual_editor_add_image.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
shared_context 'Visual Editor - add image' do | ||
|
||
let(:page_for_image) { | ||
page = Refinery::Page.create :title => "Add Image to me" | ||
# we need page parts so that there's a visual editor | ||
Refinery::Pages.default_parts.each_with_index do |default_page_part, index| | ||
page.parts.create(:title => default_page_part, :body => nil, :position => index) | ||
end | ||
page | ||
} | ||
|
||
let(:select_upload) {choose(::I18n.t('new_image', :scope => 'refinery.admin.images.insert')) } | ||
|
||
let(:initial_path) { | ||
refinery.edit_admin_page_path(page_for_image) | ||
click_link("Add Image") | ||
} | ||
let(:dialog_frame_id) {'dialog_frame'} | ||
let(:index_item_selector) {'#existing_image_area_content ul li img'} | ||
let(:title_attribute_selector) {'[title]'} | ||
let(:alt_attribute_selector) {'[alt]'} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
shared_examples_for 'deletes an image' do | ||
before do | ||
raise "please set let(:initial_path)" if initial_path.blank? | ||
ensure_on(initial_path) | ||
end | ||
|
||
let(:image_count) {[Refinery::Image.count, Refinery::Images.pages_per_admin_index].min} | ||
let(:deleting_an_image) { | ||
-> { | ||
first("#records li").click_link(::I18n.t('delete', scope: 'refinery.admin.images')) | ||
} | ||
} | ||
|
||
it 'has a delete image link for each image' do | ||
expect(page).to have_selector('#records.images li a.confirm-delete', count: image_count) | ||
end | ||
|
||
it "removes an image" do | ||
expect(deleting_an_image).to change(Refinery::Image, :count).by(-1) | ||
end | ||
|
||
it 'says the image has been removed' do | ||
expect(page).to have_selector(".images_list li:first") | ||
image_title = find(".images_list li:first").first("img")[:title] || # grid view | ||
find(".images_list li:first").first("span.title").text # list view | ||
expect(image_title).to be_present | ||
|
||
first(".images_list li:first").click_link(::I18n.t('delete', scope: 'refinery.admin.images')) | ||
expect(page).to have_content(::I18n.t('destroyed', scope: 'refinery.crudify', what: "'#{image_title}'")) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
shared_examples 'an image editor' do | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
shared_examples_for 'indexes images' do | ||
|
||
let(:image_count) {[Refinery::Image.count, Refinery::Images.pages_per_admin_index].min} | ||
|
||
before do | ||
raise "please set let(:initial_path)" if initial_path.blank? | ||
ensure_on(initial_path) | ||
end | ||
|
||
it 'shows all the images', js: true do | ||
expect(page).to have_selector(index_item_selector, count: image_count) | ||
end | ||
|
||
end # image index | ||
|
||
shared_examples_for 'shows list and grid views' do | ||
|
||
let(:image_count) {[Refinery::Image.count, Refinery::Images.pages_per_admin_index].min} | ||
|
||
before do | ||
raise "please set let(:initial_path)" if initial_path.blank? | ||
ensure_on(initial_path) | ||
end | ||
|
||
context "when in grid view" do | ||
|
||
before { ensure_on(current_path + "?view=grid") } | ||
|
||
it 'shows the images with thumbnails', js: true do | ||
expect(page).to have_selector(index_item_selector << gridview_img_selector, count: image_count) | ||
end | ||
|
||
it 'makes the title attribute of each image available', js: true do | ||
expect(page).to have_selector(index_item_selector << gridview_img_selector << gridview_title_selector, count: image_count) | ||
end | ||
|
||
it 'makes the alt attribute of each image available', js: true do | ||
expect(page).to have_selector(index_item_selector << gridview_img_selector << gridview_alt_selector, count: image_count) | ||
end | ||
|
||
it 'has an option to switch to list view' do | ||
expect(page).to have_content(::I18n.t('switch_to', view_name: 'list', scope: 'refinery.admin.images.index.view')) | ||
end | ||
|
||
end # grid view | ||
|
||
context "when in list view" do | ||
|
||
before do | ||
ensure_on(current_path + "?view=list") | ||
end | ||
|
||
it 'makes the title attribute of each image available', js: true do | ||
expect(page).to have_selector(index_item_selector << listview_title_selector, count: image_count) | ||
end | ||
|
||
it 'makes the alt attribute of each image available' do | ||
expect(page).to have_selector(index_item_selector << listview_alt_selector, count: image_count) | ||
end | ||
|
||
it 'has an option to switch to grid view' do | ||
ensure_on(current_path + '?view=list') | ||
|
||
expect(page).to have_content(::I18n.t('switch_to', view_name: 'grid', scope: 'refinery.admin.images.index.view')) | ||
end | ||
|
||
end # list view | ||
end | ||
|
||
shared_examples_for 'paginates the list of images' do | ||
|
||
let(:image_count) {[Refinery::Image.count, Refinery::Images.pages_per_admin_index].min} | ||
|
||
before do | ||
raise "please set let(:initial_path)" if initial_path.blank? | ||
ensure_on(initial_path) | ||
end | ||
|
||
describe 'pagination', unless: Refinery::Image.count <= 2 do | ||
before { | ||
Refinery::Images.pages_per_admin_index = 2 | ||
Refinery::Images.pages_per_dialog_that_have_size_options = 2 } | ||
|
||
it 'divides the index into pages' do | ||
expect(page).to have_selector("div.pagination em.current") | ||
end | ||
|
||
context 'when on the first page' do | ||
it 'shows a link for the next page' do | ||
ensure_on(current_path + '?from_page=1&page=1') | ||
expect(page).to have_selector("a.next_page[rel='next']") | ||
end | ||
|
||
it 'has disabled the previous page link' do | ||
expect(page).to have_selector('.previous_page.disabled') | ||
end | ||
end | ||
|
||
context 'when on the last page' do | ||
it 'shows a link for the previous page' do | ||
ensure_on(current_path + '?from_page=1&page=2') | ||
expect(page).to have_selector("a.previous_page[rel='prev start']") | ||
end | ||
|
||
it 'has disabled the next link' do | ||
expect(page).to have_selector('.next_page.disabled') | ||
end | ||
|
||
end | ||
end # pagination | ||
end # image index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
def preview_image | ||
preview_window = window_opened_by do | ||
image_url | ||
first("#records li").click_link('Eye') | ||
end | ||
|
||
page.within_window preview_window do | ||
expect(page).to have_image(image_url) | ||
end | ||
preview_window.close | ||
end | ||
|
||
shared_examples 'shows an image preview' do | ||
before do | ||
raise "please set let(:initial_path)" if initial_path.blank? | ||
ensure_on(initial_path) | ||
end | ||
|
||
let(:image_url) {first("#records li .actions").find_link('Eye')[:href]} | ||
|
||
context "when in list view" do | ||
before do | ||
ensure_on(current_path + "?view=list") | ||
end | ||
|
||
it 'displays the image in a new window', js: true do | ||
preview_image() | ||
end | ||
end | ||
|
||
|
||
context "when in grid view" do | ||
before do | ||
ensure_on(current_path + "?view=grid") | ||
end | ||
|
||
it 'displays the image in a new window', js: true do | ||
preview_image | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
shared_examples 'uploads images' do | ||
before do | ||
raise "please set let(:initial_path)" if initial_path.blank? | ||
ensure_on(initial_path) | ||
end | ||
|
||
let(:uploading_an_image) { | ||
-> { | ||
open_image_dialog | ||
page.within_frame(dialog_frame_id) do | ||
select_upload | ||
attach_file 'image_image', image_path | ||
fill_in 'image_image_title', with: 'Image With Dashes' | ||
fill_in 'image_image_alt', with: "Alt description for image" | ||
click_button ::I18n.t('save', scope: 'refinery.admin.form_actions') | ||
end | ||
} | ||
} | ||
|
||
context 'the image type is acceptable' do | ||
let(:image_path) {Refinery.roots('refinery/images').join("spec/fixtures/image-with-dashes.jpg")} | ||
it 'uploads an image', :js => true do | ||
expect(uploading_an_image).to change(Refinery::Image, :count).by(1) | ||
end | ||
end | ||
|
||
context 'the image type is not acceptable' do | ||
let(:image_path) {Refinery.roots('refinery/images').join("spec/fixtures/cape-town-tide-table.pdf")} | ||
it 'rejects the image', :js => true do | ||
expect(uploading_an_image).to_not change(Refinery::Image, :count) | ||
page.within_frame(dialog_frame_id) do | ||
expect(page).to have_content(::I18n.t('incorrect_format', :scope => 'activerecord.errors.models.refinery/image')) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.