From baa40ffef320c2319cb50e7cda8f1d0a8b88c82a Mon Sep 17 00:00:00 2001 From: Greg Walker <142943695+greg-does-weather@users.noreply.github.com> Date: Tue, 8 Oct 2024 09:58:28 -0500 Subject: [PATCH] Fix: QPF table should say "rain" if there is no ice or snow, instead of "water" (#1866) * if there is only rain, say rain instead of water + tests * bump library --- .../data/testing/gridpoints/LZK/83,73.json | 2 +- .../data/testing/points/34.749,-92.275.json | 9 ++- tests/playwright/e2e/qpf-table.spec.js | 63 +++++++++++++++++++ .../new_weather_theme/assets/js/charts/qpf.js | 4 +- .../templates/partials/precip-table.html.twig | 27 ++++---- 5 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 tests/playwright/e2e/qpf-table.spec.js diff --git a/tests/api/data/testing/gridpoints/LZK/83,73.json b/tests/api/data/testing/gridpoints/LZK/83,73.json index 462800912..fc4187b35 100644 --- a/tests/api/data/testing/gridpoints/LZK/83,73.json +++ b/tests/api/data/testing/gridpoints/LZK/83,73.json @@ -5245,7 +5245,7 @@ }, { "validTime": "date:now +85 hours / PT6H", - "value": 0 + "value": 30 }, { "validTime": "date:now +91 hours / PT6H", diff --git a/tests/api/data/testing/points/34.749,-92.275.json b/tests/api/data/testing/points/34.749,-92.275.json index 63f179b63..4323a6910 100644 --- a/tests/api/data/testing/points/34.749,-92.275.json +++ b/tests/api/data/testing/points/34.749,-92.275.json @@ -1,6 +1,13 @@ { "@bundle": { - "name": "Many alerts" + "name": "Little Rock, AR", + "attributes": [ + "Many alerts", + "Day 1 has ice, snow, and water", + "Day 2 has snow and water", + "Day 3 has ice and water", + "Day 4 has rain" + ] }, "@context": [ "https://geojson.org/geojson-ld/geojson-context.jsonld", diff --git a/tests/playwright/e2e/qpf-table.spec.js b/tests/playwright/e2e/qpf-table.spec.js new file mode 100644 index 000000000..deba82118 --- /dev/null +++ b/tests/playwright/e2e/qpf-table.spec.js @@ -0,0 +1,63 @@ +/* eslint-disable no-await-in-loop, no-plusplus */ +const { test, expect } = require("@playwright/test"); + +const { describe, beforeEach } = test; + +describe("quantitative precipitation forecast table", () => { + beforeEach(async ({ page }) => { + await page.goto("http://localhost:8081/play/testing"); + await page.goto("http://localhost:8080/point/34.749/-92.275#daily"); + }); + + test("shows snow, ice, and water when all are present", async ({ page }) => { + const day = await page.locator(".wx-daily-forecast-block li").first(); + await day.locator("span.toggle-text").click(); + + const headings = await day.locator(".wx-precip-table thead th"); + + // period, snow, ice, [separator], water + await expect(headings).toHaveCount(5); + await expect(headings.nth(0)).toHaveText("Time Period"); + await expect(headings.nth(1)).toHaveText("Snow"); + await expect(headings.nth(2)).toHaveText("Ice"); + await expect(headings.nth(4)).toHaveText("Water"); + }); + + test("shows snow and water when there is no ice", async ({ page }) => { + const day = await page.locator(".wx-daily-forecast-block li").nth(1); + await day.locator("span.toggle-text").click(); + + const headings = await day.locator(".wx-precip-table thead th"); + + // period, snow, [separator], water + await expect(headings).toHaveCount(4); + await expect(headings.nth(0)).toHaveText("Time Period"); + await expect(headings.nth(1)).toHaveText("Snow"); + await expect(headings.nth(3)).toHaveText("Water"); + }); + + test("shows ice and water when there is no snow", async ({ page }) => { + const day = await page.locator(".wx-daily-forecast-block li").nth(2); + await day.locator("span.toggle-text").click(); + + const headings = await day.locator(".wx-precip-table thead th"); + + // period, ice, [separator], water + await expect(headings).toHaveCount(4); + await expect(headings.nth(0)).toHaveText("Time Period"); + await expect(headings.nth(1)).toHaveText("Ice"); + await expect(headings.nth(3)).toHaveText("Water"); + }); + + test("shows rain when there is no snow or ice", async ({ page }) => { + const day = await page.locator(".wx-daily-forecast-block li").nth(3); + await day.locator("span.toggle-text").click(); + + const headings = await day.locator(".wx-precip-table thead th"); + + // period, rain + await expect(headings).toHaveCount(2); + await expect(headings.nth(0)).toHaveText("Time Period"); + await expect(headings.nth(1)).toHaveText("Rain"); + }); +}); diff --git a/web/themes/new_weather_theme/assets/js/charts/qpf.js b/web/themes/new_weather_theme/assets/js/charts/qpf.js index b3f68653d..d2bf40bc9 100644 --- a/web/themes/new_weather_theme/assets/js/charts/qpf.js +++ b/web/themes/new_weather_theme/assets/js/charts/qpf.js @@ -52,6 +52,8 @@ const createCharts = async () => { const datasets = []; + const liquidTitle = ice.length > 0 || snow.length > 0 ? "Water" : "Rain"; + if (snow.length > 0) { datasets.push({ label: "Snow", @@ -82,7 +84,7 @@ const createCharts = async () => { } if (liquid.length > 0) { datasets.push({ - label: "Water", + label: liquidTitle, data: liquid, datalabels: { align: "end", diff --git a/web/themes/new_weather_theme/templates/partials/precip-table.html.twig b/web/themes/new_weather_theme/templates/partials/precip-table.html.twig index b035eed8b..382f5d5ef 100644 --- a/web/themes/new_weather_theme/templates/partials/precip-table.html.twig +++ b/web/themes/new_weather_theme/templates/partials/precip-table.html.twig @@ -9,12 +9,15 @@ {% set liquid = precipHours.periods | map(p => p.liquid) | json_encode %} {% set snow = '[]' %} {% set ice = '[]' %} + {% set liquidTitle = 'Rain' | t %} {% if precipHours.hasSnow %} {% set snow = precipHours.periods | map(p => p.snow) | json_encode %} + {% set liquidTitle = 'Water' | t %} {% endif %} {% if precipHours.hasIce %} {% set ice = precipHours.periods | map(p => p.ice) | json_encode %} + {% set liquidTitle = 'Water' | t %} {% endif %}
- {{ - "\"Water\" refers to the amount of water that is present in the precipitation. - The precipitation may actually fall in solid form such as ice or snow, in - liquid form as rain, or a mix of both." | t - }} -
-+ {{ + "\"Water\" refers to the amount of water that is present in the precipitation. + The precipitation may actually fall in solid form such as ice or snow, in + liquid form as rain, or a mix of both." | t + }} +
+