Skip to content

Commit

Permalink
Test that state in URL drives the forecasts displayed
Browse files Browse the repository at this point in the history
Now we are in a position to test that specifying the zone and day as URL parameters is sufficient to display the forecast for the given zone and day.
  • Loading branch information
patrickjfl committed Nov 15, 2024
1 parent c7f3f95 commit 003db17
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions spec/features/visitors/view_forecasts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,48 @@
expect_prediction(category: :temperature, level: :high)
end
end

describe "Viewing forecasts for a location and a day based on URL parameters" do
before do
barking_and_dagenham = FactoryBot.create(:zone, name: "Barking and Dagenham", cerc_id: 1)

zone_forecasts = [{zone: Zone.default, forecasts: [
Fixtures::API.zone_forecast(day: :today, air_pollution_status: :low, pollen: :low, temperature: :cold, uv: :low),
Fixtures::API.zone_forecast(day: :tomorrow, air_pollution_status: :low, pollen: :low, temperature: :cold, uv: :low),
Fixtures::API.zone_forecast(day: :day_after_tomorrow, air_pollution_status: :low, pollen: :low, temperature: :cold, uv: :low)
]}, {zone: barking_and_dagenham, forecasts: [
Fixtures::API.zone_forecast(day: :today, air_pollution_status: :high, pollen: :low, temperature: :normal, uv: :low),
Fixtures::API.zone_forecast(day: :tomorrow, air_pollution_status: :high, pollen: :high, temperature: :hot, uv: :high),
Fixtures::API.zone_forecast(day: :day_after_tomorrow, air_pollution_status: :high, pollen: :low, temperature: :normal, uv: :low)
]}]
stub_cerc_api_with(zone_forecasts)
end

it "shows the forecast for the chosen location" do
##
# When I visit the forecast URL with parameters specified for day and zone
#
# Then I see the air pollution forecast for the zone
# And I see predicted UV level for the new zone for today
# And I see predicted pollen level for the new zone for today
# And I see predicted temperature level for the new zone for today
##
visit forecast_path(params: {zone: "Barking and Dagenham", day: "tomorrow"})

# Predicted air pollution status for each day
expect_air_pollution_prediction(day: :today, value: :high)
expect_air_pollution_prediction(day: :tomorrow, value: :high)
expect_air_pollution_prediction(day: :day_after_tomorrow, value: :high)

# Predicted UV level for tomorrow
expect_prediction(category: :"ultraviolet-rays-uv", level: :high)

# Predicted pollen level for tomorrow
expect_prediction(category: :pollen, level: :high)

# Predicted temperature level for tomorrow
expect_prediction(category: :temperature, level: :high)
end
end
end
end

0 comments on commit 003db17

Please sign in to comment.