-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathprediction_spec.rb
67 lines (55 loc) · 3.28 KB
/
prediction_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true
require "rails_helper"
require 'custom_matchers'
describe "Display a planting", :js do
describe 'planting perennial' do
let(:garden) { FactoryBot.create(:garden, location: 'Edinburgh') }
let(:crop) { FactoryBot.create(:crop, name: 'feijoa', perennial: true) }
let(:planting) { FactoryBot.create(:planting, crop:, garden:, owner: garden.owner) }
describe 'no harvest to predict from' do
before { visit planting_path(planting) }
it { expect(planting.harvest_months).to eq({}) }
it { expect(page).to have_content 'We need more data on this crop in your latitude.' }
end
describe 'harvests used to predict' do
before do
FactoryBot.create(:harvest, planting:, crop:, harvested_at: '1 May 2019')
FactoryBot.create(:harvest, planting:, crop:, harvested_at: '18 June 2019')
FactoryBot.create_list(:harvest, 4, planting:, crop:, harvested_at: '18 August 2019')
end
before { visit planting_path(planting) }
it { expect(page.find_by_id('month-1')[:class]).not_to include("badge-harvesting") }
it { expect(page.find_by_id('month-2')[:class]).not_to include("badge-harvesting") }
it { expect(page.find_by_id('month-5')[:class]).to include("badge-harvesting") }
it { expect(page.find_by_id('month-6')[:class]).to include("badge-harvesting") }
it { expect(page.find_by_id('month-8')[:class]).to include("badge-harvesting") }
end
describe 'nearby plantings used to predict' do
# Note the locations used need to be stubbed in geocoder
before do
# Near by planting with harvests
nearby_garden = FactoryBot.create(:garden, location: 'Greenwich, UK')
nearby_planting = FactoryBot.create(:planting, crop:,
garden: nearby_garden, owner: nearby_garden.owner, planted_at: '1 January 2000')
FactoryBot.create(:harvest, planting: nearby_planting, crop:,
harvested_at: '1 May 2019')
FactoryBot.create(:harvest, planting: nearby_planting, crop:,
harvested_at: '18 June 2019')
FactoryBot.create_list(:harvest, 4, planting: nearby_planting, crop:,
harvested_at: '18 August 2008')
# far away planting harvests
faraway_garden = FactoryBot.create(:garden, location: 'Amundsen-Scott Base, Antarctica')
faraway_planting = FactoryBot.create(:planting, garden: faraway_garden, crop:,
owner: faraway_garden.owner, planted_at: '16 May 2001')
FactoryBot.create_list(:harvest, 4, planting: faraway_planting, crop:,
harvested_at: '18 December 2006')
end
before { visit planting_path(planting) }
it { expect(page.find_by_id('month-1')[:class]).not_to include("badge-harvesting") }
it { expect(page.find_by_id('month-2')[:class]).not_to include("badge-harvesting") }
it { expect(page.find_by_id('month-5')[:class]).to include("badge-harvesting") }
it { expect(page.find_by_id('month-6')[:class]).to include("badge-harvesting") }
it { expect(page.find_by_id('month-8')[:class]).to include("badge-harvesting") }
end
end
end