diff --git a/.gitignore b/.gitignore index 06f46a383..3d8e3b3af 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,3 @@ yarn-error.log* # typescript *.tsbuildinfo -next-env.d.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index fae8e3d8a..964a06e46 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { "typescript.tsdk": "node_modules/typescript/lib", - "typescript.enablePromptUseWorkspaceTsdk": true + "typescript.enablePromptUseWorkspaceTsdk": true, + "cSpell.words": ["Colour"] } diff --git a/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-child.fixture.ts b/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-child.fixture.ts index 34ba1cac9..6f25715ac 100644 --- a/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-child.fixture.ts +++ b/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-child.fixture.ts @@ -56,12 +56,13 @@ export class WeatherHealthAlertsChildPage { await expect(await regions.getByRole('listitem').all()).toHaveLength(9) for (let i = 0; i < alertList.length; i++) { + const expectedStatus = alertList[i].status === 'Green' ? 'No alert' : `${alertList[i].status.toLowerCase()} alert` const listItem = regions.getByRole('listitem').nth(i) await expect(listItem).toBeVisible() await expect(listItem.getByRole('heading', { level: 2, name: alertList[i].region })).toBeVisible() await expect(listItem.getByText(alertList[i].updated)).toBeVisible() - await expect(listItem.getByText(alertList[i].status, { exact: true })).toBeVisible() + await expect(listItem.getByText(expectedStatus, { exact: true })).toBeVisible() //TODO: Need to implement tags for mobile vs desktop tags CDD-2024 // if (this.isMobile) { diff --git a/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-map.fixture.ts b/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-map.fixture.ts index 66aa78d88..20e86dbf9 100644 --- a/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-map.fixture.ts +++ b/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-map.fixture.ts @@ -34,6 +34,28 @@ export class WeatherHealthAlertsMapPage { await expect(this.page.getByRole('button', { name: 'Exit map' })).toBeVisible() } + async hasMapKey() { + await expect(this.page.getByTestId('map-key')).toBeVisible() + } + + async hasUKHSALogo() { + await expect(this.page.getByTestId('logo-layer')).toBeVisible() + } + + async hasDisplayKeyButton() { + await expect(this.page.getByRole('button', { name: 'Display key' })).toBeVisible() + } + + async mapKeyCanBeMinimised() { + await expect(this.page.getByTestId('close-key-button')).toBeVisible() + await this.page.getByTestId('close-key-button').click() + } + + async clickDisplayKeyButton() { + await expect(this.page.getByRole('button', { name: 'Display key' })).toBeVisible() + await this.page.getByRole('button', { name: 'Display key' }).click() + } + async hasButton(name: ButtonNames) { await expect(this.page.getByRole('button', { name })).toBeVisible() } @@ -117,22 +139,35 @@ export class WeatherHealthAlertsMapPage { await this.page.keyboard.press('Tab') await this.page.keyboard.press('Tab') await this.page.keyboard.press('Tab') + await this.page.keyboard.press('Tab') await this.page.keyboard.press('Enter') } async zoomInWithKeyboard() { + await this.page.keyboard.press('Tab') await this.page.keyboard.press('Tab') await this.page.keyboard.press('Tab') await this.page.keyboard.press('Enter') await this.page.keyboard.press('Enter') } - async zoomOutWithKeyboard() { await this.page.keyboard.press('Tab') await this.page.keyboard.press('Enter') await this.page.keyboard.press('Enter') } + async closeKeyWithKeyboard() { + await this.page.keyboard.press('Tab') + await this.page.keyboard.press('Tab') + await this.page.keyboard.press('Enter') + } + + async openKeyWithKeyboard() { + await this.page.keyboard.press('Tab') + await this.page.keyboard.press('Tab') + await this.page.keyboard.press('Enter') + } + async accessRegionWithKeyboard(regionNumber: number) { await this.page.keyboard.press(`Digit${regionNumber}`) } diff --git a/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-region.fixture.ts b/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-region.fixture.ts index ece11ea5a..06487254a 100644 --- a/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-region.fixture.ts +++ b/e2e/fixtures/pages/weather-health-alerts/weather-health-alerts-region.fixture.ts @@ -64,11 +64,13 @@ export class WeatherHealthAlertsRegionPage { async hasAlertSummaryList({ type, status, start, end }: SummaryList) { const wrapper = this.page.getByLabel('Alert details') + const expectedStatus = status === 'Green' ? 'No alert' : `${status.toLowerCase()} alert` + await expect(wrapper.getByText('Type')).toBeVisible() await expect(wrapper.getByText(type)).toBeVisible() - await expect(wrapper.getByText('Colour')).toBeVisible() - await expect(wrapper.getByText(status)).toBeVisible() + await expect(wrapper.getByText('Alert', { exact: true })).toBeVisible() + await expect(wrapper.getByText(expectedStatus)).toBeVisible() await expect(wrapper.getByText('Start')).toBeVisible() await expect(wrapper.getByText(start)).toBeVisible() diff --git a/e2e/tests/weather-health-alerts/weather-health-alerts-map.e2e.ts b/e2e/tests/weather-health-alerts/weather-health-alerts-map.e2e.ts index 357766174..b78e8901d 100644 --- a/e2e/tests/weather-health-alerts/weather-health-alerts-map.e2e.ts +++ b/e2e/tests/weather-health-alerts/weather-health-alerts-map.e2e.ts @@ -17,6 +17,12 @@ test.describe('Weather health alerts map display', () => { await test.step('has all buttons', async () => { await weatherHealthAlertsMapPage.hasMapButtons() }) + await test.step('has map key', async () => { + await weatherHealthAlertsMapPage.hasMapKey() + }) + await test.step('has UKHSA logo overlay', async () => { + await weatherHealthAlertsMapPage.hasUKHSALogo() + }) }) test('Map overlay opens and can exit back to previous page', async ({ app, weatherHealthAlertsMapPage }) => { @@ -182,6 +188,105 @@ test.describe('Weather Health Alerts map interactivty', () => { await weatherHealthAlertsMapPage.hasHighlightedRegions(7) }) }) + + test('Key should be visible and closable with Mouse', async ({ app, weatherHealthAlertsMapPage }) => { + await test.step('open weather health alerts page', async () => { + await app.goto('/weather-health-alerts/cold?v=map&type=cold') + }) + await test.step('map is displaying', async () => { + await weatherHealthAlertsMapPage.dialogIsOpen('Weather health alerts map') + }) + await test.step('check interactive map has loaded', async () => { + await weatherHealthAlertsMapPage.hasMapLeaflet() + }) + await test.step('shows the map key', async () => { + await weatherHealthAlertsMapPage.hasMapKey() + }) + await test.step('can close the map key', async () => { + await weatherHealthAlertsMapPage.mapKeyCanBeMinimised() + }) + await test.step('shows the display key button', async () => { + await weatherHealthAlertsMapPage.hasDisplayKeyButton() + }) + }) + + test('Key should be visible and closable with Keyboard', async ({ app, weatherHealthAlertsMapPage }) => { + await test.step('open weather health alerts page', async () => { + await app.goto('/weather-health-alerts/cold?v=map&type=cold') + }) + await test.step('map is displaying', async () => { + await weatherHealthAlertsMapPage.dialogIsOpen('Weather health alerts map') + }) + await test.step('check interactive map has loaded', async () => { + await weatherHealthAlertsMapPage.hasMapLeaflet() + }) + await test.step('shows the map key', async () => { + await weatherHealthAlertsMapPage.hasMapKey() + }) + await test.step('can close the map key', async () => { + await weatherHealthAlertsMapPage.closeKeyWithKeyboard() + }) + await test.step('shows the display key button', async () => { + await weatherHealthAlertsMapPage.hasDisplayKeyButton() + }) + }) + + test('Key should be opened using the display key button with Mouse', async ({ app, weatherHealthAlertsMapPage }) => { + await test.step('open weather health alerts page', async () => { + await app.goto('/weather-health-alerts/cold?v=map&type=cold') + }) + await test.step('map is displaying', async () => { + await weatherHealthAlertsMapPage.dialogIsOpen('Weather health alerts map') + }) + await test.step('check interactive map has loaded', async () => { + await weatherHealthAlertsMapPage.hasMapLeaflet() + }) + await test.step('shows the map key', async () => { + await weatherHealthAlertsMapPage.hasMapKey() + }) + await test.step('can close the map key', async () => { + await weatherHealthAlertsMapPage.mapKeyCanBeMinimised() + }) + await test.step('shows the display key button', async () => { + await weatherHealthAlertsMapPage.hasDisplayKeyButton() + }) + await test.step('click the display key button', async () => { + await weatherHealthAlertsMapPage.clickDisplayKeyButton() + }) + await test.step('should display the map key', async () => { + await weatherHealthAlertsMapPage.hasMapKey() + }) + }) + + test('Key should be opened using the display key button with Keyboard', async ({ + app, + weatherHealthAlertsMapPage, + }) => { + await test.step('open weather health alerts page', async () => { + await app.goto('/weather-health-alerts/cold?v=map&type=cold') + }) + await test.step('map is displaying', async () => { + await weatherHealthAlertsMapPage.dialogIsOpen('Weather health alerts map') + }) + await test.step('check interactive map has loaded', async () => { + await weatherHealthAlertsMapPage.hasMapLeaflet() + }) + await test.step('shows the map key', async () => { + await weatherHealthAlertsMapPage.hasMapKey() + }) + await test.step('can close the map key', async () => { + await weatherHealthAlertsMapPage.closeKeyWithKeyboard() + }) + await test.step('shows the display key button', async () => { + await weatherHealthAlertsMapPage.hasDisplayKeyButton() + }) + await test.step('click the display key button', async () => { + await weatherHealthAlertsMapPage.openKeyWithKeyboard() + }) + await test.step('should display the map key', async () => { + await weatherHealthAlertsMapPage.hasMapKey() + }) + }) }) // Need to investigate flaky test: CDD-2136 diff --git a/next-env.d.ts b/next-env.d.ts new file mode 100644 index 000000000..40c3d6809 --- /dev/null +++ b/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information. diff --git a/public/assets/images/UKHSA_Lesser_Arms_Stacked_RGB.png b/public/assets/images/UKHSA_Lesser_Arms_Stacked_RGB.png new file mode 100644 index 000000000..a3479c79d Binary files /dev/null and b/public/assets/images/UKHSA_Lesser_Arms_Stacked_RGB.png differ diff --git a/public/locales/en/weatherHealthAlerts.json b/public/locales/en/weatherHealthAlerts.json index 700ddc905..2bf7a54b2 100644 --- a/public/locales/en/weatherHealthAlerts.json +++ b/public/locales/en/weatherHealthAlerts.json @@ -4,10 +4,12 @@ "exitBtn": "Exit map", "trigger": "View map of weather health alerts", "fatalError": "There is a problem with the map. Please try again later.", + "alert": "{{level}} alert", + "no-alert": "No alert", "alertDialog": { "dateKey": "Start", "expiryKey": "End", - "statusKey": "Colour", + "statusKey": "Alert", "textKey": "Description", "typeKey": "Type", "typeValue_heat": "Heat Health Alert", @@ -18,6 +20,7 @@ "alertCta": "Go to alert page" } }, + "showKeyBtn": "Display Key", "updated": "Updated {{value, time}} on {{ value, dateShort }}", "weatherAlert": "{{weatherType}}-health alert for {{regionName}}", "alertListLabel": "{{type}} health alerts", diff --git a/src/app/(topics)/(weather-health-alerts)/weather-health-alerts/[weather]/[region]/AlertBody.tsx b/src/app/(topics)/(weather-health-alerts)/weather-health-alerts/[weather]/[region]/AlertBody.tsx index dc03f8062..57c0bd2cb 100644 --- a/src/app/(topics)/(weather-health-alerts)/weather-health-alerts/[weather]/[region]/AlertBody.tsx +++ b/src/app/(topics)/(weather-health-alerts)/weather-health-alerts/[weather]/[region]/AlertBody.tsx @@ -18,7 +18,7 @@ import { import useWeatherHealthAlert from '@/app/hooks/queries/useWeatherHealthAlert' import useWeatherHealthAlertList from '@/app/hooks/queries/useWeatherHealthAlertList' import { useTranslation } from '@/app/i18n/client' -import { getTagVariantFromStatus } from '@/app/utils/weather-health-alert.utils' +import { getTailwindBackgroundFromColour, getTextColourCssFromColour } from '@/app/utils/weather-health-alert.utils' import { logger } from '@/lib/logger' interface AlertProps { @@ -100,9 +100,15 @@ export default function AlertBody({ relatedLinks, relatedLinksLayout, weather, r {t('map.alertDialog.statusKey')} - -
{status}
-
+
+ {status == 'Green' ? t('map.no-alert') : t('map.alert', { level: status.toLowerCase() })} +
{t('map.alertDialog.dateKey')} diff --git a/src/app/components/ui/ukhsa/List/ListItemStatus.spec.tsx b/src/app/components/ui/ukhsa/List/ListItemStatus.spec.tsx index f8985be27..282458e7e 100644 --- a/src/app/components/ui/ukhsa/List/ListItemStatus.spec.tsx +++ b/src/app/components/ui/ukhsa/List/ListItemStatus.spec.tsx @@ -84,18 +84,15 @@ describe('renders correct tag', () => { test('renders green tag', () => { const { getByText } = render() - expect(getByText('Green')).toHaveClass('govuk-tag--green') - expect(getByText('Green')).toHaveAttribute( - 'aria-label', - 'There is currently a Green heat alert status for East of England' - ) + expect(getByText('No alert')).toHaveClass('bg-green') + expect(getByText('No alert')).toHaveAttribute('aria-label', 'There are currently no alerts for East of England') }) test('renders yellow tag', () => { const { getByText } = render() - expect(getByText('Yellow')).toHaveClass('govuk-tag--yellow') - expect(getByText('Yellow')).toHaveAttribute( + expect(getByText('yellow alert')).toHaveClass('bg-custard') + expect(getByText('yellow alert')).toHaveAttribute( 'aria-label', 'There is currently a Yellow heat alert status for South East' ) @@ -104,8 +101,8 @@ describe('renders correct tag', () => { test('renders amber tag', () => { const { getByText } = render() - expect(getByText('Amber')).toHaveClass('govuk-tag--orange') - expect(getByText('Amber')).toHaveAttribute( + expect(getByText('amber alert')).toHaveClass('bg-orange') + expect(getByText('amber alert')).toHaveAttribute( 'aria-label', 'There is currently an Amber cold alert status for West Midlands' ) @@ -114,17 +111,10 @@ describe('renders correct tag', () => { test('renders red tag', () => { const { getByText } = render() - expect(getByText('Red')).toHaveClass('govuk-tag--red') - expect(getByText('Red')).toHaveAttribute( + expect(getByText('red alert')).toHaveClass('bg-red') + expect(getByText('red alert')).toHaveAttribute( 'aria-label', 'There is currently a Red cold alert status for East Midlands' ) }) - - test('renders no alerts tag', () => { - const { getByText } = render() - - expect(getByText('No alerts')).not.toHaveClass('govuk-tag') - expect(getByText('No alerts')).toHaveAttribute('aria-label', 'There are currently no alerts for London') - }) }) diff --git a/src/app/components/ui/ukhsa/List/ListItemStatus.tsx b/src/app/components/ui/ukhsa/List/ListItemStatus.tsx index 96ebfb4ea..f71e56e3d 100644 --- a/src/app/components/ui/ukhsa/List/ListItemStatus.tsx +++ b/src/app/components/ui/ukhsa/List/ListItemStatus.tsx @@ -17,7 +17,11 @@ interface ListItemStatusProps { } export const ListItemStatus = ({ children }: ListItemStatusProps) => { - return
{children}
+ return ( +
+ {children} +
+ ) } interface ListItemStatusIconProps { diff --git a/src/app/components/ui/ukhsa/List/ListItemStatusTag.tsx b/src/app/components/ui/ukhsa/List/ListItemStatusTag.tsx index 1608b6a04..747a6c4eb 100644 --- a/src/app/components/ui/ukhsa/List/ListItemStatusTag.tsx +++ b/src/app/components/ui/ukhsa/List/ListItemStatusTag.tsx @@ -4,9 +4,10 @@ import clsx from 'clsx' import { HealthAlertStatus, HealthAlertTypes } from '@/api/models/Alerts' import { useTranslation } from '@/app/i18n/client' +import { getTailwindBackgroundFromColour, getTextColourCssFromColour } from '@/app/utils/weather-health-alert.utils' interface ListItemStatusTagProps { - level: HealthAlertStatus | 'No alerts' + level: HealthAlertStatus region: string type: HealthAlertTypes } @@ -14,11 +15,11 @@ interface ListItemStatusTagProps { const ListItemStatusTag = ({ level, region, type }: ListItemStatusTagProps) => { const { t } = useTranslation('weatherHealthAlerts') - function getStatusKey(level: HealthAlertStatus | 'No alerts') { + function getStatusKey(level: HealthAlertStatus) { switch (level) { case 'Amber': return 'Amber' - case 'No alerts': + case 'Green': return 'None' default: return 'Initial' @@ -27,15 +28,14 @@ const ListItemStatusTag = ({ level, region, type }: ListItemStatusTagProps) => { return (
- {level} + {level == 'Green' ? t('map.no-alert') : t('map.alert', { level: level.toLowerCase() })}
) } diff --git a/src/app/components/ui/ukhsa/Map/Map.tsx b/src/app/components/ui/ukhsa/Map/Map.tsx index b2cdc02d1..52d4fc835 100644 --- a/src/app/components/ui/ukhsa/Map/Map.tsx +++ b/src/app/components/ui/ukhsa/Map/Map.tsx @@ -15,8 +15,10 @@ import { MapContainer } from 'react-leaflet' import { center, mapId, maxZoom, minZoom, zoom } from '@/app/constants/map.constants' import { AttributionControl } from './shared/controls/AttributionControl' +import { KeyControl } from './shared/controls/KeyControl' import { ZoomControl } from './shared/controls/ZoomControl' import { useMapRef } from './shared/hooks/useMapRef' +import { UKHSALogoLayer } from './shared/layers/UKHSALogoLayer' interface DefaultOptions extends ComponentProps { zoomControlPosition: ControlPosition @@ -54,6 +56,8 @@ const Map = ({ className={clsx('relative h-screen overflow-hidden ukhsa-focus', className)} zoomControl={false} > + + {children} diff --git a/src/app/components/ui/ukhsa/Map/shared/controls/HealthAlertControl.tsx b/src/app/components/ui/ukhsa/Map/shared/controls/HealthAlertControl.tsx index b54a7c539..9da56c46e 100644 --- a/src/app/components/ui/ukhsa/Map/shared/controls/HealthAlertControl.tsx +++ b/src/app/components/ui/ukhsa/Map/shared/controls/HealthAlertControl.tsx @@ -19,7 +19,7 @@ import { mapQueryKeys } from '@/app/constants/map.constants' import useWeatherHealthAlert from '@/app/hooks/queries/useWeatherHealthAlert' import { useTranslation } from '@/app/i18n/client' import { toSlug } from '@/app/utils/app.utils' -import { getTagVariantFromStatus } from '@/app/utils/weather-health-alert.utils' +import { getTailwindBackgroundFromColour, getTextColourCssFromColour } from '@/app/utils/weather-health-alert.utils' import { clsx } from '@/lib/clsx' const DialogSkeleton = () => ( @@ -73,8 +73,14 @@ const AlertDialogContent = () => { {t('map.alertDialog.statusKey')} -
- {status.toLowerCase()} +
+ {status == 'Green' ? t('map.no-alert') : t('map.alert', { level: status.toLowerCase() })}
@@ -118,7 +124,7 @@ export default function HealthAlertControl() { const [selectedFeatureId, setSelectedFeatureId] = useQueryState(mapQueryKeys.featureId, parseAsString) return ( - + { diff --git a/src/app/components/ui/ukhsa/Map/shared/controls/KeyControl.tsx b/src/app/components/ui/ukhsa/Map/shared/controls/KeyControl.tsx new file mode 100644 index 000000000..a5dccf1c6 --- /dev/null +++ b/src/app/components/ui/ukhsa/Map/shared/controls/KeyControl.tsx @@ -0,0 +1,71 @@ +'use client' + +import clsx from 'clsx' +import { ControlPosition } from 'leaflet' +import { KeyboardEvent, useState } from 'react' +import Control from 'react-leaflet-custom-control' + +import { HealthAlertStatus } from '@/api/models/Alerts' +import { useTranslation } from '@/app/i18n/client' +import { getTailwindBackgroundFromColour, getTextColourCssFromColour } from '@/app/utils/weather-health-alert.utils' + +interface KeyControlProps { + position: ControlPosition + keyItems: HealthAlertStatus[] +} + +export function KeyControl({ position, keyItems }: KeyControlProps) { + const { t } = useTranslation('weatherHealthAlerts') + const [showKey, setShowKey] = useState(true) + + function clickHandler() { + return { + onClick: () => setShowKey(!showKey), + onKeyDown: (event: KeyboardEvent) => { + console.log(event.key) + }, + } + } + + const renderKeyButton = () => ( + + ) + + const renderCloseButton = () => ( + + ) + + const renderKey = (keyItems: HealthAlertStatus[]) => { + return ( +
+
+

Key

+ {renderCloseButton()} +
+
+ {keyItems.map((colour, index) => { + return ( +
+

+ {colour == 'Green' ? t('map.no-alert') : t('map.alert', { level: colour.toLowerCase() })} +

+
+ ) + })} +
+
+ ) + } + + return {showKey ? renderKey(keyItems) : renderKeyButton()} +} diff --git a/src/app/components/ui/ukhsa/Map/shared/layers/UKHSALogoLayer.tsx b/src/app/components/ui/ukhsa/Map/shared/layers/UKHSALogoLayer.tsx new file mode 100644 index 000000000..d56e9ed23 --- /dev/null +++ b/src/app/components/ui/ukhsa/Map/shared/layers/UKHSALogoLayer.tsx @@ -0,0 +1,21 @@ +'use client' + +import { ControlPosition } from 'leaflet' +import Image from 'next/image' +import Control from 'react-leaflet-custom-control' + +import logo from '#/assets/images/UKHSA_Lesser_Arms_Stacked_RGB.png' + +interface LogoLayerProps { + position: ControlPosition +} + +export function UKHSALogoLayer({ position }: LogoLayerProps) { + return ( + +
+ Logo for the UK Health Security Agency +
+
+ ) +} diff --git a/src/app/utils/weather-health-alert.utils.spec.ts b/src/app/utils/weather-health-alert.utils.spec.ts index 1691edb02..432e19284 100644 --- a/src/app/utils/weather-health-alert.utils.spec.ts +++ b/src/app/utils/weather-health-alert.utils.spec.ts @@ -3,6 +3,8 @@ import { getCssVariableFromColour, getHoverCssVariableFromColour, getTagVariantFromStatus, + getTailwindBackgroundFromColour, + getTextColourCssFromColour, } from './weather-health-alert.utils' describe('getTagVariantFromStatus', () => { @@ -60,6 +62,24 @@ describe('getHoverCssVariableFromColour', () => { }) describe('getActiveCssVariableFromColour', () => { + test('Returns the correct CSS background colour for Green', () => { + expect(getTailwindBackgroundFromColour('Green')).toBe('bg-green') + }) + + test('Returns the correct CSS background colour for Amber', () => { + expect(getTailwindBackgroundFromColour('Amber')).toBe('bg-orange') + }) + + test('Returns the correct CSS background colour for Yellow', () => { + expect(getTailwindBackgroundFromColour('Yellow')).toBe('bg-custard') + }) + + test('Returns the correct CSS background colour for Red', () => { + expect(getTailwindBackgroundFromColour('Red')).toBe('bg-red') + }) +}) + +describe('getTailwindBackgroundFromColour', () => { test('Returns the correct active CSS variable for Green', () => { expect(getActiveCssVariableFromColour('Green')).toBe('var(--colour-green-darkest)') }) @@ -76,3 +96,13 @@ describe('getActiveCssVariableFromColour', () => { expect(getActiveCssVariableFromColour('Red')).toBe('var(--colour-red-darkest)') }) }) + +describe('getTextColourCssFromColour', () => { + test('Returns the correct CSS property', () => { + expect(getTextColourCssFromColour('Yellow')).toBe('text-black') + }) + + test.each([['Green'], ['Red'], ['Orange']])('Returns the correct CSS property when the input is %s', (colour) => { + expect(getTextColourCssFromColour(colour)).toBe('text-white') + }) +}) diff --git a/src/app/utils/weather-health-alert.utils.ts b/src/app/utils/weather-health-alert.utils.ts index e0f34fe51..b2064cc66 100644 --- a/src/app/utils/weather-health-alert.utils.ts +++ b/src/app/utils/weather-health-alert.utils.ts @@ -39,6 +39,13 @@ export enum ActiveColourVariableMap { Red = 'var(--colour-red-darkest)', } +export enum ColourBackgroundMap { + Green = 'bg-green', + Amber = 'bg-orange', + Yellow = 'bg-custard', + Red = 'bg-red', +} + export function getCssVariableFromColour(color: keyof typeof ColourVariableMap) { return ColourVariableMap[color] } @@ -50,3 +57,15 @@ export function getHoverCssVariableFromColour(color: keyof typeof HoverColourVar export function getActiveCssVariableFromColour(color: keyof typeof ActiveColourVariableMap) { return `${ActiveColourVariableMap[color]}` } + +export function getTailwindBackgroundFromColour(color: keyof typeof ColourBackgroundMap) { + return ColourBackgroundMap[color] +} + +export function getTextColourCssFromColour(colour: string) { + if (colour == 'Yellow') { + return 'text-black' + } else { + return 'text-white' + } +} diff --git a/tsconfig.json b/tsconfig.json index f0d84371b..7bf3ef235 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,8 @@ "incremental": true, "baseUrl": ".", "paths": { - "@/*": ["./src/*"] + "@/*": ["./src/*"], + "#/*": ["./public/*"] }, "types": ["jest", "node", "@testing-library/jest-dom", "@types/gtag.js"], "plugins": [