Added feature more feature tests on plantings creation for progress bars' status

This commit is contained in:
AELOGICA
2015-07-02 09:43:37 +08:00
parent f13a66391c
commit 516274b2b7
3 changed files with 110 additions and 23 deletions

View File

@@ -74,14 +74,14 @@
%li= "Days until maturity: 0"
- elsif !planting.finished_at.nil?
- if ((p = planting.finished_at - DateTime.now).to_i) <= 0
p = 0
- p = 0
%li= "Days until maturity: #{p.to_i}"
- elsif planting.days_before_maturity.nil?
%li= "Days until maturity: unknown"
- else
- if ((p = (planting.planted_at + planting.days_before_maturity) - DateTime.now).to_i) <= 0
p = 0
- p = 0
%li= "Days until maturity: #{p.to_i}"
%td{:colspan => "3"}

View File

@@ -40,17 +40,25 @@
Yes (no date specified)
%p
%b Days until maturity:
- if @planting.finished and @planting.finished_at?
= "#{(@planting.finished_at - DateTime.now).to_i}"
- if @planting.finished?
%b
= " 0"
- elsif !@planting.finished_at.nil?
- if ((p = @planting.finished_at - DateTime.now).to_i) <= 0
- p = 0
%b
= " #{p.to_i}"
- elsif @planting.days_before_maturity.nil?
= "unknown"
%b
= " unknown"
- else
= "#{((@planting.planted_at + @planting.days_before_maturity) - DateTime.now).to_i}"
- if ((p = (@planting.planted_at + @planting.days_before_maturity) - DateTime.now).to_i) <= 0
- p = 0
%b
= " #{p.to_i}"
%p
%b= render 'planting_progress', planting: @planting
- if can? :edit, @planting or can? :destroy, @planting
%p
- if can? :edit, @planting

View File

@@ -30,22 +30,101 @@ feature "Planting a crop", :js => true do
expect(page).to have_content "Progress: 0% - Days before maturity unknown"
end
scenario "Creating a new planting with known days before maturity" do
fill_autocomplete "crop", :with => "mai"
select_from_autocomplete "maize"
within "form#new_planting" do
fill_in "When", :with => "2015-06-15"
fill_in "How many?", :with => 42
select "cutting", :from => "Planted from:"
select "semi-shade", :from => "Sun or shade?"
check "finished"
fill_in "Finished date", :with => "2015-06-25"
fill_in "Tell us more about it", :with => "It's rad."
click_button "Save"
describe "Progress bar status on planting creation" do
before(:each) do
DateTime.stub(:now){DateTime.new(2015, 10, 20, 10, 34)}
login_as(member)
visit new_planting_path
sync_elasticsearch([maize])
end
expect(page).to have_content "Planting was successfully created"
expect(page).to_not have_content "Progress: 0% - Days before maturity unknown"
it "should show that it is not planted yet" do
fill_autocomplete "crop", :with => "mai"
select_from_autocomplete "maize"
within "form#new_planting" do
fill_in "When", :with => "2015-12-15"
fill_in "How many?", :with => 42
select "cutting", :from => "Planted from:"
select "semi-shade", :from => "Sun or shade?"
fill_in "Tell us more about it", :with => "It's rad."
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "Progress: 0% - not planted yet"
end
it "should show that days before maturity is unknown" do
fill_autocomplete "crop", :with => "mai"
select_from_autocomplete "maize"
within "form#new_planting" do
fill_in "When", :with => "2015-9-15"
fill_in "How many?", :with => 42
select "cutting", :from => "Planted from:"
select "semi-shade", :from => "Sun or shade?"
fill_in "Tell us more about it", :with => "It's rad."
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "Progress: 0% - Days before maturity unknown"
expect(page).to have_content "Days until maturity: unknown"
end
it "should show that planting is in progress" do
fill_autocomplete "crop", :with => "mai"
select_from_autocomplete "maize"
within "form#new_planting" do
fill_in "When", :with => "2015-10-15"
fill_in "How many?", :with => 42
select "cutting", :from => "Planted from:"
select "semi-shade", :from => "Sun or shade?"
fill_in "Tell us more about it", :with => "It's rad."
fill_in "Finished date", :with => "2015-10-30"
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to_not have_content "Progress: 0% - not planted yet"
expect(page).to_not have_content "Progress: 0% - Days before maturity unknown"
end
it "should show that planting is 100% complete (no date specified)" do
fill_autocomplete "crop", :with => "mai"
select_from_autocomplete "maize"
within "form#new_planting" do
fill_in "When", :with => "2015-10-15"
fill_in "How many?", :with => 42
select "cutting", :from => "Planted from:"
select "semi-shade", :from => "Sun or shade?"
fill_in "Tell us more about it", :with => "It's rad."
check "Mark as finished"
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "Progress: 100%"
expect(page).to have_content "Yes (no date specified)"
expect(page).to have_content "Days until maturity: 0"
end
it "should show that planting is 100% complete (date specified)" do
fill_autocomplete "crop", :with => "mai"
select_from_autocomplete "maize"
within "form#new_planting" do
fill_in "When", :with => "2015-10-15"
fill_in "How many?", :with => 42
select "cutting", :from => "Planted from:"
select "semi-shade", :from => "Sun or shade?"
fill_in "Tell us more about it", :with => "It's rad."
fill_in "Finished date", :with => "2015-10-19"
click_button "Save"
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "Progress: 100%"
expect(page).to have_content "Days until maturity: 0"
end
end
scenario "Planting from crop page" do
@@ -124,7 +203,7 @@ feature "Planting a crop", :js => true do
end
expect(page).to have_content "Planting was successfully created"
expect(page).to have_content "Finished: Yes (no date specified)"
expect(page).to have_content "Progress: 0% - Days before maturity unknown"
expect(page).to have_content "Progress: 100%"
end
describe "Marking a planting as finished from the show page" do