Last active
August 29, 2015 14:11
-
-
Save anitagraham/70421f648fc3efdde1b9 to your computer and use it in GitHub Desktop.
Shared contexts and Shared examples
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
#refinerycms/images/spec/support/shared examples/image_indexer.rb | |
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 | |
# page.within_frame(dialog_frame_id) do | |
expect(page).to have_selector(index_item_selector, count: image_count) | |
# end | |
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 |
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
#refinerycms/images/spec/features/refinery/admin/images_spec.rb | |
require "spec_helper" | |
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 | |
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_has_behaviour 'uploads images' | |
end | |
context 'when there is one image' do | |
include_context 'one image' | |
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 | |
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 tab - Insert Image', type: :feature do | |
refinery_login_with :refinery_user | |
include_context 'Visual Editor - add image' | |
context 'when there are no images' do | |
include_context 'no existing images' | |
it_has_behaviour 'uploads images' | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment