-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes actual/forecast dropdown to radio buttons
- Loading branch information
Showing
4 changed files
with
89 additions
and
45 deletions.
There are no files selected for viewing
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,61 @@ | ||
import { FormControl, FormControlLabel, FormLabel, Radio, RadioGroup } from '@mui/material' | ||
import React from 'react' | ||
import { RunType } from 'features/fba/pages/FireBehaviourAdvisoryPage' | ||
import { isNull } from 'lodash' | ||
import { theme } from 'app/theme' | ||
|
||
export interface ActualForecastControlProps { | ||
runType: RunType | ||
setRunType: React.Dispatch<React.SetStateAction<RunType>> | ||
} | ||
const ActualForecastControl = ({ runType, setRunType }: ActualForecastControlProps) => { | ||
const changeHandler = (_: React.ChangeEvent<{}>, value: any | null) => { | ||
if (!isNull(value)) { | ||
setRunType(value) | ||
} | ||
} | ||
return ( | ||
<FormControl | ||
variant="outlined" | ||
sx={{ | ||
border: '1px solid rgba(0, 0, 0, 0.23)', | ||
borderRadius: '4px', | ||
padding: '8px 12px 4px', | ||
position: 'relative', | ||
margin: theme.spacing(1) | ||
}} | ||
> | ||
<FormLabel | ||
sx={{ | ||
fontSize: '0.75rem', | ||
color: 'rgba(0, 0, 0, 0.6)', | ||
position: 'absolute', | ||
top: '-10px', | ||
left: '12px', | ||
backgroundColor: 'white', | ||
padding: '0 4px' | ||
}} | ||
> | ||
Time Frame | ||
</FormLabel> | ||
<RadioGroup row defaultValue={runType} onChange={changeHandler}> | ||
<FormControlLabel | ||
value={RunType.ACTUAL} | ||
control={ | ||
<Radio inputProps={{ 'data-testid': 'actual-radio' } as React.InputHTMLAttributes<HTMLInputElement>} /> | ||
} | ||
label="Actual" | ||
/> | ||
<FormControlLabel | ||
value={RunType.FORECAST} | ||
control={ | ||
<Radio inputProps={{ 'data-testid': 'forecast-radio' } as React.InputHTMLAttributes<HTMLInputElement>} /> | ||
} | ||
label="Forecast" | ||
/> | ||
</RadioGroup> | ||
</FormControl> | ||
) | ||
} | ||
|
||
export default React.memo(ActualForecastControl) |
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
web/src/features/fba/components/actualForecastControl.test.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,22 @@ | ||
import React from 'react' | ||
import { render, fireEvent } from '@testing-library/react' | ||
import ActualForecastControl from './ActualForecastControl' | ||
import { RunType } from 'features/fba/pages/FireBehaviourAdvisoryPage' | ||
|
||
describe('ActualForecastControl', () => { | ||
const mockSetRunType = jest.fn() | ||
|
||
it('should render the radio button selector with the correct default', () => { | ||
const { getByTestId } = render(<ActualForecastControl runType={RunType.FORECAST} setRunType={mockSetRunType} />) | ||
const forecastButton = getByTestId('forecast-radio') | ||
expect(forecastButton).toBeChecked() | ||
}) | ||
|
||
it('should call setRunType with the correct value when a radio button is selected', () => { | ||
const { getByTestId } = render(<ActualForecastControl runType={RunType.FORECAST} setRunType={mockSetRunType} />) | ||
fireEvent.click(getByTestId('actual-radio')) | ||
expect(mockSetRunType).toHaveBeenCalledWith(RunType.ACTUAL) | ||
fireEvent.click(getByTestId('forecast-radio')) | ||
expect(mockSetRunType).toHaveBeenCalledWith(RunType.FORECAST) | ||
}) | ||
}) |
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