|
|
|
@@ -5,58 +5,88 @@ feature "crop detail page" do
|
|
|
|
|
let(:crop) { FactoryGirl.create(:crop) }
|
|
|
|
|
|
|
|
|
|
context "varieties" do
|
|
|
|
|
let!(:roma1) { FactoryGirl.create(:crop, :name => 'Roma tomato 1', :parent => crop) }
|
|
|
|
|
let!(:roma2) { FactoryGirl.create(:crop, :name => 'Roma tomato 2', :parent => crop) }
|
|
|
|
|
let!(:roma3) { FactoryGirl.create(:crop, :name => 'Roma tomato 3', :parent => crop) }
|
|
|
|
|
let!(:roma4) { FactoryGirl.create(:crop, :name => 'Roma tomato 4', :parent => crop) }
|
|
|
|
|
|
|
|
|
|
scenario "The crop has 4 varieties" do
|
|
|
|
|
scenario "The crop DOES NOT have varieties" do
|
|
|
|
|
visit crop_path(crop)
|
|
|
|
|
|
|
|
|
|
within ".varieties" do
|
|
|
|
|
expect(page).to have_no_selector('li', text: /tomato/i)
|
|
|
|
|
expect(page).to have_no_selector('button', text: /Show+/i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario "The crop has one variety" do
|
|
|
|
|
roma1 = FactoryGirl.create(:crop, :name => 'Roma tomato 1', :parent => crop)
|
|
|
|
|
|
|
|
|
|
visit crop_path(crop)
|
|
|
|
|
|
|
|
|
|
# It lists all 5 items (note: including the top level item.)
|
|
|
|
|
# It DOES NOT have "Show all/less" toggle link
|
|
|
|
|
expect(page).to have_css('li', text: /tomato/i, count: 5)
|
|
|
|
|
expect(page).to have_no_css('button', text: /Show all+/i)
|
|
|
|
|
expect(page).to have_no_css('button', text: /Show less+/i)
|
|
|
|
|
within ".varieties" do
|
|
|
|
|
# It lists all 2 items (note: including the top level item.)
|
|
|
|
|
expect(page).to have_selector('li', text: /tomato/i, count: 2)
|
|
|
|
|
# It DOES NOT have "Show all/less" toggle link
|
|
|
|
|
expect(page).to have_no_selector('button', text: /Show+/i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario "The crop has more than 4 varieties", :js => true do
|
|
|
|
|
roma5 = FactoryGirl.create(:crop, :name => 'Roma tomato 5', :parent => crop)
|
|
|
|
|
context "many" do
|
|
|
|
|
|
|
|
|
|
visit crop_path(crop)
|
|
|
|
|
let!(:roma1) { FactoryGirl.create(:crop, :name => 'Roma tomato 1', :parent => crop) }
|
|
|
|
|
let!(:roma2) { FactoryGirl.create(:crop, :name => 'Roma tomato 2', :parent => crop) }
|
|
|
|
|
let!(:roma3) { FactoryGirl.create(:crop, :name => 'Roma tomato 3', :parent => crop) }
|
|
|
|
|
let!(:roma4) { FactoryGirl.create(:crop, :name => 'Roma tomato 4', :parent => crop) }
|
|
|
|
|
|
|
|
|
|
# It lists the first 5 items (note: including the top level item.)
|
|
|
|
|
# It HAS have "Show all" toggle link but not "Show less" link
|
|
|
|
|
expect(page).to have_css('li', text: /tomato/i, count: 5)
|
|
|
|
|
expect(page).to have_css('li', text: 'Roma tomato 4')
|
|
|
|
|
expect(page).to have_no_css('li', text: 'Roma tomato 5')
|
|
|
|
|
expect(page).to have_css('button', text: /Show all+/i)
|
|
|
|
|
expect(page).to have_no_css('button', text: /Show less+/i)
|
|
|
|
|
scenario "The crop has 4 varieties" do
|
|
|
|
|
|
|
|
|
|
# Clik "Show all" link
|
|
|
|
|
page.find('button', :text => /Show all+/).click
|
|
|
|
|
visit crop_path(crop)
|
|
|
|
|
|
|
|
|
|
# It lists all 6 items (note: including the top level item.)
|
|
|
|
|
# It HAS have "Show all" toggle link but not "Show less" link
|
|
|
|
|
expect(page).to have_css('li', text: /tomato/i, count: 6)
|
|
|
|
|
expect(page).to have_css('li', text: 'Roma tomato 4')
|
|
|
|
|
expect(page).to have_css('li', text: 'Roma tomato 5')
|
|
|
|
|
expect(page).to have_no_selector('button', text: /Show all+/i)
|
|
|
|
|
expect(page).to have_selector('button', text: /Show less+/i)
|
|
|
|
|
within ".varieties" do
|
|
|
|
|
# It lists all 5 items (note: including the top level item.)
|
|
|
|
|
expect(page).to have_selector('li', text: /tomato/i, count: 5)
|
|
|
|
|
# It DOES NOT have "Show all/less" toggle link
|
|
|
|
|
expect(page).to have_no_selector('button', text: /Show+/i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Clik "Show less" link
|
|
|
|
|
page.find('button', :text => /Show less+/).click
|
|
|
|
|
scenario "The crop has 5 varieties, including grandchild", :js => true do
|
|
|
|
|
roma_child1 = FactoryGirl.create(:crop, :name => 'Roma tomato child 1', :parent => roma4)
|
|
|
|
|
|
|
|
|
|
# It lists 5 items (note: including the top level item.)
|
|
|
|
|
# It HAS have "Show all" toggle link but not "Show less" link
|
|
|
|
|
expect(page).to have_css('li', text: /tomato/i, count: 5)
|
|
|
|
|
expect(page).to have_css('li', text: 'Roma tomato 4')
|
|
|
|
|
expect(page).to have_no_css('li', text: 'Roma tomato 5')
|
|
|
|
|
expect(page).to have_selector('button', text: /Show all+/i)
|
|
|
|
|
expect(page).to have_no_selector('button', text: /Show less+/i)
|
|
|
|
|
visit crop_path(crop)
|
|
|
|
|
|
|
|
|
|
within ".varieties" do
|
|
|
|
|
|
|
|
|
|
# It lists the first 5 items (note: including the top level item.)
|
|
|
|
|
# It HAS have "Show all" toggle link but not "Show less" link
|
|
|
|
|
expect(page).to have_selector('li', text: /tomato/i, count: 5)
|
|
|
|
|
expect(page).to have_selector('li', text: 'Roma tomato 4')
|
|
|
|
|
expect(page).to have_no_selector('li', text: 'Roma tomato child 1')
|
|
|
|
|
# It shows the total number (5) correctly
|
|
|
|
|
expect(page).to have_selector('button', text: /Show all 5 +/i)
|
|
|
|
|
expect(page).to have_no_selector('button', text: /Show less+/i)
|
|
|
|
|
|
|
|
|
|
# Clik "Show all" link
|
|
|
|
|
page.find('button', :text => /Show all+/).click
|
|
|
|
|
|
|
|
|
|
# It lists all 6 items (note: including the top level item.)
|
|
|
|
|
# It HAS have "Show less" toggle link but not "Show all" link
|
|
|
|
|
expect(page).to have_selector('li', text: /tomato/i, count: 6)
|
|
|
|
|
expect(page).to have_selector('li', text: 'Roma tomato 4')
|
|
|
|
|
expect(page).to have_selector('li', text: 'Roma tomato child 1')
|
|
|
|
|
expect(page).to have_no_selector('button', text: /Show all+/i)
|
|
|
|
|
expect(page).to have_selector('button', text: /Show less+/i)
|
|
|
|
|
|
|
|
|
|
# Clik "Show less" link
|
|
|
|
|
page.find('button', :text => /Show less+/).click
|
|
|
|
|
|
|
|
|
|
# It lists 5 items (note: including the top level item.)
|
|
|
|
|
# It HAS have "Show all" toggle link but not "Show less" link
|
|
|
|
|
expect(page).to have_selector('li', text: /tomato/i, count: 5)
|
|
|
|
|
expect(page).to have_selector('li', text: 'Roma tomato 4')
|
|
|
|
|
expect(page).to have_no_selector('li', text: 'Roma tomato child 1')
|
|
|
|
|
expect(page).to have_selector('button', text: /Show all 5 +/i)
|
|
|
|
|
expect(page).to have_no_selector('button', text: /Show less+/i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "signed in member" do
|
|
|
|
|