minor improvements

This commit is contained in:
Shiho Takagi committed 2015-03-17 11:40:32 +11:00
1 parent 0c6b6e0e0e
commit c253c86787
5 files changed
+94 -62

No files matched your search

+2 -2
View File
@@ -48,6 +48,6 @@ function showCropMap(cropmap) {
cropmap.addLayer(markers); cropmap.addLayer(markers);
} }
$('.btn.toggle').click(function () { $('.btn.toggle.crop-hierarchy').click(function () {
$('.toggle').toggleClass('hide'); $('.toggle.crop-hierarchy').toggleClass('hide');
}); });
@@ -320,5 +320,3 @@ html, body {
.hide { .hide {
display: none; display: none;
} }
+6 -4
View File
@@ -1,9 +1,11 @@
%ul %ul
- @count ||= 5 - @count ||= 0
- unless defined? max
- max = 0 # list all without "show all" toggle button
- display_crops.each do |c| - display_crops.each do |c|
%li.crop-hierarchy{:class => @count <= 0 ? ['hide', 'toggle'] : []} %li.crop-hierarchy{:class => max != 0 && @count >= max ? ['hide', 'toggle'] : []}
= link_to c, c = link_to c, c
- @count -= 1 - @count += 1
- if c.varieties.present? - if c.varieties.present?
- c.varieties.each do |v| - c.varieties.each do |v|
= render :partial => 'hierarchy', :locals => { :display_crops => [ v ] } = render :partial => 'hierarchy', :locals => { :display_crops => [ v ], :max => max }
+17 -15
View File
@@ -1,18 +1,20 @@
- if crop.parent .varieties
%p - if crop.parent
= crop.name %p
is a variety of = crop.name
= succeed "." do is a variety of
= link_to crop.parent, crop.parent = succeed "." do
= link_to crop.parent, crop.parent
- unless crop.varieties.empty? - unless crop.varieties.empty?
%p %p
Varieties of #{crop.name}: Varieties of #{crop.name}:
= render :partial => 'hierarchy', :locals => { :display_crops => [ crop ] } - max = 5
- if @count < 0 = render :partial => 'hierarchy', :locals => { :display_crops => [ crop ], :max => max }
= button_tag "Show all #{crop.varieties.size} varieties", :class => 'btn btn-link toggle' - if max != 0 && @count > max
= button_tag "Show less varieties", :class => 'btn btn-link toggle hide' = button_tag "Show all #{@count-1} varieties", :class => 'btn btn-link toggle crop-hierarchy'
= button_tag "Show less varieties", :class => 'btn btn-link toggle crop-hierarchy hide'
- if ! crop.parent and crop.varieties.empty? - if ! crop.parent and crop.varieties.empty?
%p None known. %p None known.
+69 -39
View File
@@ -5,58 +5,88 @@ feature "crop detail page" do
let(:crop) { FactoryGirl.create(:crop) } let(:crop) { FactoryGirl.create(:crop) }
context "varieties" do 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) visit crop_path(crop)
# It lists all 5 items (note: including the top level item.) within ".varieties" do
# It DOES NOT have "Show all/less" toggle link # It lists all 2 items (note: including the top level item.)
expect(page).to have_css('li', text: /tomato/i, count: 5) expect(page).to have_selector('li', text: /tomato/i, count: 2)
expect(page).to have_no_css('button', text: /Show all+/i) # It DOES NOT have "Show all/less" toggle link
expect(page).to have_no_css('button', text: /Show less+/i) expect(page).to have_no_selector('button', text: /Show+/i)
end
end end
scenario "The crop has more than 4 varieties", :js => true do context "many" do
roma5 = FactoryGirl.create(:crop, :name => 'Roma tomato 5', :parent => crop)
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.) scenario "The crop has 4 varieties" do
# 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)
# Clik "Show all" link visit crop_path(crop)
page.find('button', :text => /Show all+/).click
# It lists all 6 items (note: including the top level item.) within ".varieties" do
# It HAS have "Show all" toggle link but not "Show less" link # It lists all 5 items (note: including the top level item.)
expect(page).to have_css('li', text: /tomato/i, count: 6) expect(page).to have_selector('li', text: /tomato/i, count: 5)
expect(page).to have_css('li', text: 'Roma tomato 4') # It DOES NOT have "Show all/less" toggle link
expect(page).to have_css('li', text: 'Roma tomato 5') expect(page).to have_no_selector('button', text: /Show+/i)
expect(page).to have_no_selector('button', text: /Show all+/i) end
expect(page).to have_selector('button', text: /Show less+/i) end
# Clik "Show less" link scenario "The crop has 5 varieties, including grandchild", :js => true do
page.find('button', :text => /Show less+/).click roma_child1 = FactoryGirl.create(:crop, :name => 'Roma tomato child 1', :parent => roma4)
# It lists 5 items (note: including the top level item.) visit crop_path(crop)
# It HAS have "Show all" toggle link but not "Show less" link
expect(page).to have_css('li', text: /tomato/i, count: 5) within ".varieties" do
expect(page).to have_css('li', text: 'Roma tomato 4')
expect(page).to have_no_css('li', text: 'Roma tomato 5') # It lists the first 5 items (note: including the top level item.)
expect(page).to have_selector('button', text: /Show all+/i) # It HAS have "Show all" toggle link but not "Show less" link
expect(page).to have_no_selector('button', text: /Show less+/i) 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
end end
context "signed in member" do context "signed in member" do