-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow updates of the base forecast date (#203)
* Initial addition of base forecast date picker * Updating the base forecast date updates the displayed data * Ensured all time scales use the same start and end * Added new datetime component * Added loading spinner when changing the base forecast date * Make the city data charts auto zoom to the in-situ data * Remove accidental checking of debug text * Pulled the table header into a new component and sorted styling * Reset the height of the top black bar * Updated the date field in the header to use dark mode * Updates to some failing jest tests * Added extra UI tests * Added jest tests for BaseForecastDatetimePicker * Added missing newline and updated date comparison * Added some extra tests to get code coverage up * Added jest tests for loading spinner usage * Updated package-lock.json after merge conflict
- Loading branch information
1 parent
d75e8fe
commit d7dbf1a
Showing
24 changed files
with
2,462 additions
and
750 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
air-quality-ui/src/components/header/BaseForecastDatetimePicker.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import '@testing-library/jest-dom' | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react' | ||
import { DateTime } from 'luxon' | ||
|
||
import { BaseForecastDatetimePicker } from './BaseForecastDatetimePicker' | ||
|
||
const mockSetBaseForecastDateTime: (val: DateTime) => void = jest.fn() | ||
|
||
jest.mock('../../context', () => ({ | ||
useForecastContext: jest.fn().mockReturnValue({ | ||
forecastBaseDate: DateTime.fromISO('2024-06-01T03:00:00', { zone: 'utc' }), | ||
maxInSituDate: DateTime.fromISO('2024-06-10T09:00:00', { zone: 'utc' }), | ||
setForecastBaseDate: (x: DateTime) => mockSetBaseForecastDateTime(x), | ||
}), | ||
})) | ||
|
||
describe('BaseForecastDatetimePicker component', () => { | ||
it('Displays date picker', async () => { | ||
render(<BaseForecastDatetimePicker />) | ||
expect(screen.getByLabelText('Base Forecast Date')).toBeInTheDocument() | ||
}) | ||
it('Sets forecast base date on change', async () => { | ||
render(<BaseForecastDatetimePicker />) | ||
const datePicker = screen.getByLabelText('Base Forecast Date') | ||
const updatedDate = DateTime.fromISO('2024-06-03T12:00:00', { zone: 'UTC' }) | ||
|
||
fireEvent.change(datePicker, { target: { value: '03/06/2024 12:00' } }) | ||
await waitFor(() => { | ||
expect(mockSetBaseForecastDateTime).toHaveBeenCalledWith(updatedDate) | ||
}) | ||
}) | ||
}) |
35 changes: 35 additions & 0 deletions
35
air-quality-ui/src/components/header/BaseForecastDatetimePicker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ThemeProvider, createTheme } from '@mui/material/styles' | ||
import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon' | ||
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker' | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider' | ||
import { DateTime } from 'luxon' | ||
|
||
import { useForecastContext } from '../../context' | ||
|
||
export const BaseForecastDatetimePicker = (): JSX.Element => { | ||
const { forecastBaseDate, setForecastBaseDate } = useForecastContext() | ||
const darkTheme = createTheme({ | ||
palette: { | ||
mode: 'dark', | ||
}, | ||
}) | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterLuxon} adapterLocale="en-gb"> | ||
<ThemeProvider theme={darkTheme}> | ||
<DateTimePicker | ||
sx={{ '.MuiFormLabel-root': { color: 'white' } }} | ||
label="Base Forecast Date" | ||
disableFuture={true} | ||
skipDisabled={true} | ||
timeSteps={{ minutes: 720 }} | ||
value={forecastBaseDate} | ||
onChange={(newValue) => { | ||
const valueToSet = newValue == null ? DateTime.utc() : newValue | ||
setForecastBaseDate(valueToSet) | ||
}} | ||
/> | ||
</ThemeProvider> | ||
</LocalizationProvider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
import '@testing-library/jest-dom' | ||
import { render, screen } from '@testing-library/react' | ||
import { BrowserRouter } from 'react-router-dom' | ||
|
||
import { Header } from './Header' | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useMatches: jest.fn().mockReturnValue([]), | ||
})) | ||
jest.mock('./Toolbar', () => ({ Toolbar: () => 'mocked toolbar' })) | ||
|
||
describe('Header component', () => { | ||
it('shows application name', () => { | ||
render(<Header />, { | ||
wrapper: BrowserRouter, | ||
}) | ||
render(<Header />) | ||
expect(screen.getByTestId('vairify-logo')).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { Outlet } from 'react-router-dom' | ||
|
||
import { ForecastContextProvider } from '../../context' | ||
import { Header } from '../header/Header' | ||
|
||
export default function Layout() { | ||
return ( | ||
<> | ||
<Header /> | ||
<main> | ||
<Outlet /> | ||
</main> | ||
<ForecastContextProvider> | ||
<Header /> | ||
<main> | ||
<Outlet /> | ||
</main> | ||
</ForecastContextProvider> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
air-quality-ui/src/components/single-city/SiteMeasurementsChart.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.