Skip to content

Commit

Permalink
Merge 9989ea8 into dd12646
Browse files Browse the repository at this point in the history
  • Loading branch information
anitagraham committed Dec 15, 2014
2 parents dd12646 + 9989ea8 commit eecab90
Show file tree
Hide file tree
Showing 14 changed files with 524 additions and 184 deletions.
75 changes: 51 additions & 24 deletions images/spec/features/refinery/admin/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,73 @@ module Refinery

describe "Admin Images Tab", type: :feature do
refinery_login_with :refinery_user
include_context 'admin images tab'

context 'when there are no images' do
let(:initial_path) { refinery.admin_images_path(view: %w(grid list).sample) }
include_context 'no existing images'

it 'says there are no images'do
visit refinery.admin_images_path
expect(page).to have_content(::I18n.t('no_images_yet', scope: 'refinery.admin.images.records'))
end

it_behaves_like 'an image uploader'
it_has_behaviour 'uploads images'
end

context 'when there is one image' do
let!(:image) { FactoryGirl.create(:image) }
let(:initial_path) { refinery.admin_images_path(view: %w(grid list).sample) }
include_context 'one image'

it_behaves_like 'an image index'
it_behaves_like 'an image deleter'
it_behaves_like 'an image uploader'
it_has_behaviour 'indexes images'
it_has_behaviour 'shows list and grid views'
it_has_behaviour 'shows an image preview'
it_has_behaviour 'deletes an image'
it_has_behaviour 'uploads images'
end

context 'when there are many images' do
let!(:image) { FactoryGirl.create(:image) }
let!(:alt_image) { FactoryGirl.create(:alternate_image) }
let!(:another_image) { FactoryGirl.create(:another_image) }
let(:initial_path) { refinery.admin_images_path(view: %w(grid list).sample) }

it_behaves_like 'an image index'
it_behaves_like 'an image deleter'
it_behaves_like 'an image uploader'
include_context 'many images'

it_has_behaviour 'indexes images'
it_has_behaviour 'shows list and grid views'
it_has_behaviour 'paginates the list of images'
it_has_behaviour 'shows an image preview'
it_has_behaviour 'deletes an image'
it_has_behaviour 'uploads images'
# it_has_behaviour 'edits an image'
end

end

describe 'Page Edit Images tab' do
# it_behaves_like 'an image uploader'
# it behaves_like 'an image editor'
# it behaves_like 'an image previewer'
# it_behaves_like 'an image index'
# it behaves_like 'an image inserter'
# it behaves_like 'an image deleter'
end
describe 'Page Edit tab - Insert Image', type: :feature do
refinery_login_with :refinery_user

include_context 'Visual Editor - add image'

around(:each) do
page.within_frame(dialog_frame_id) do

context 'when there are no images' do
include_context 'no existing images'
it_has_behaviour 'uploads images'
end

end
context 'when there is one image' do
include_context 'one image'

it_has_behaviour 'indexes images'
it_has_behaviour 'paginates the list of images'
it_has_behaviour 'uploads images'
end

context 'when there are many images' do
include_context 'many images'

it_has_behaviour 'indexes images'
it_has_behaviour 'paginates the list of images'
it_has_behaviour 'uploads images'
end
end
end

end
end
16 changes: 16 additions & 0 deletions images/spec/support/shared contexts/admin_images_tab.rb
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
5 changes: 5 additions & 0 deletions images/spec/support/shared contexts/many_images.rb
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
3 changes: 3 additions & 0 deletions images/spec/support/shared contexts/no_images.rb
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
3 changes: 3 additions & 0 deletions images/spec/support/shared contexts/one_image.rb
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 images/spec/support/shared contexts/visual_editor_add_image.rb
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
32 changes: 32 additions & 0 deletions images/spec/support/shared examples/image_deleter.rb
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
2 changes: 2 additions & 0 deletions images/spec/support/shared examples/image_editor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shared_examples 'an image editor' do
end
111 changes: 111 additions & 0 deletions images/spec/support/shared examples/image_indexer.rb
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
41 changes: 41 additions & 0 deletions images/spec/support/shared examples/image_previewer.rb
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
36 changes: 36 additions & 0 deletions images/spec/support/shared examples/image_uploader.rb
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
Loading

0 comments on commit eecab90

Please sign in to comment.