Skip to content

Commit

Permalink
Add integration tests for air quality alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickjfl committed Nov 1, 2024
1 parent 2bfd2b2 commit 48c863a
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 3 deletions.
62 changes: 59 additions & 3 deletions spec/feature_steps/air_quality_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def when_i_look_at_the_forecasts
click_link("View forecasts")
end

def when_i_look_at_the_forecasts_v2
visit root_path
click_link("View new style forecasts")
end

def expect_to_see_alert_date_for(day)
date = case day
when :today
Expand All @@ -41,6 +46,19 @@ def expect_to_see_alert_date_for(day)
expect(page).to have_content("air quality alert for #{date}")
end

def expect_to_see_alert_date_for_v2(day)
date = case day
when :today
Date.today.strftime("%d %b %Y")
when :tomorrow
Date.tomorrow.strftime("%d %b %Y")
when :day_after_tomorrow
(Date.tomorrow + 1.day).strftime("%d %b %Y")
end

expect(page).to have_content("air quality alert for #{date}")
end

def expect_to_see_alert_level(level)
label = case level
when :moderate
Expand All @@ -54,12 +72,23 @@ def expect_to_see_alert_level(level)
expect(page).to have_css(".alert-level", text: label)
end

def expect_to_see_alert_level_v2(level)
label = case level
when :moderate
"Moderate"
when :high
"High"
when :very_high
"Very high"
end

expect(page).to have_css(".daqi-label", text: label)
end

def expect_to_see_guidance_for(level)
expect(page).to have_content(I18n.t("air_quality_alert.#{level}.guidance.title"))
expect(page).to have_content(
ActionController::Base.helpers.strip_tags(
I18n.t("air_quality_alert.#{level}.guidance.detail_html")
)
I18n.t("air_quality_alert.#{level}.guidance.detail_html").truncate(20, omission: "")
)
end

Expand All @@ -71,6 +100,33 @@ def then_i_see_an_air_quality_alert_of_high_for_today
end
end

def then_i_see_an_air_quality_alert_of_high_for_today_v2
within(".today[data-date='#{Date.today}']") do
expect_to_see_alert_level_v2(:high)
end
within(".alert-guidance") do
expect_to_see_guidance_for(:high)
end
end

def then_i_see_an_air_quality_alert_of_moderate_for_tomorrow_v2
within(".tomorrow[data-date='#{Date.tomorrow}']") do
expect_to_see_alert_level_v2(:moderate)
end
within(".alert-guidance") do
expect_to_see_guidance_for(:moderate)
end
end

def then_i_see_an_air_quality_alert_of_v_high_for_day_after_tomorrow_v2
within(".day_after_tomorrow[data-date='#{Date.tomorrow + 1.day}']") do
expect_to_see_alert_level_v2(:very_high)
end
within(".alert-guidance") do
expect_to_see_guidance_for(:very_high)
end
end

def and_i_see_an_air_quality_alert_of_moderate_for_tomorrow
within(".alert-level-moderate[data-alert-date='#{Date.tomorrow}']") do
expect_to_see_alert_date_for(:tomorrow)
Expand Down
46 changes: 46 additions & 0 deletions spec/features/visitors/view_styled_air_quality_alerts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Feature: View air quality alerts
# - So that I can take appropriate protective action
# - As a visitor
# - I want to see Air quality alerts for air pollution predictions with warning
# statuses above "low"
RSpec.feature "Air quality alerts", feature: true do
around do |example|
env_vars = {
CERC_API_HOST_URL: "https://cerc.example.com",
CERC_API_KEY: "SECRET-API-KEY",
CERC_API_CACHE_LIMIT_MINS: "60",
MAPTILER_API_KEY: "TOPSECRET"
}
ClimateControl.modify(env_vars) { example.run }
end

include AirQualitySteps, ForecastSteps

before do
given_an_air_pollution_prediction_for_today_w_high_warning_status
and_an_air_pollution_prediction_for_tomorrow_w_moderate_warning_status
and_an_air_pollution_prediction_for_day_after_tomorrow_w_v_high_warning_status
and_the_response_from_cercs_api_is_stubbed_accordingly
end

scenario "View air quality alert for today" do
when_i_look_at_the_forecasts_v2
then_i_see_an_air_quality_alert_of_high_for_today_v2
end

scenario "View air quality alert for tomorrow", js: true do
visit root_path
when_i_select_view_forecasts_v2
and_i_switch_to_the_tab_for_tomorrow

then_i_see_an_air_quality_alert_of_moderate_for_tomorrow_v2
end

scenario "View air quality alert for the day after tomorrow", js: true do
visit root_path
when_i_select_view_forecasts_v2
and_i_switch_to_the_tab_for_day_after_tomorrow

then_i_see_an_air_quality_alert_of_v_high_for_day_after_tomorrow_v2
end
end

0 comments on commit 48c863a

Please sign in to comment.