-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adjust rollup chunkSize WarningLimit to 1000 kb * convert dotHazardous field to controlled input * convert epaWaste to controlled field We need to be able to read the state of the field 'epaWaste' in order to conditionally display/disable other fields. * add zod validation schemas for dotInformation field and add as nested field in WasteLine while the dotInformation is optional if the shipement is not dotHazardous, we've also added a refine method to the wasteline schema so if dotHazardous is true, both fields in dotInformation is required * add static dotIdNumbers array temporaryily * add error message when DOT ID number is not provided * simplify wasteline zod refinements, remove old unused wasteline interfaces * add wasteDescription validation * add refinement that waste description is required if the waste is not DOT hazardous material * update logic for dotHazardous and epaWaste switches here's our logic, if dotHazardous then epaWaste can be true or false. However, if epaWaste is True then dotHazardous must be true * add callback function to toggle epaWaste and dotHazardous with unit test epaWaste and dotHazardous field depend on each other if epaWaste is true, then dotHazardous must be true. Converse, if dotHazardous is false, epaWaste must be false * add integration test showing that when epaWaste is false, federal waste code select is disabled * when epaWaste is set to false, all federal waste codes are removed from the wasteline
- Loading branch information
1 parent
283b408
commit dc7c88d
Showing
7 changed files
with
2,684 additions
and
151 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
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
109 changes: 109 additions & 0 deletions
109
client/src/components/Manifest/WasteLine/WasteLineForm.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,109 @@ | ||
import '@testing-library/jest-dom'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
import { renderWithProviders, screen } from 'test-utils'; | ||
import { describe, expect, test } from 'vitest'; | ||
import { WasteLineForm } from './WasteLineForm'; | ||
|
||
describe('WasteLineForm', () => { | ||
test('renders', () => { | ||
renderWithProviders( | ||
<WasteLineForm | ||
appendWaste={() => console.log('waste appended')} | ||
handleClose={() => console.log('close action handled')} | ||
/>, | ||
{} | ||
); | ||
expect(screen.getByText(/General/i)).toBeInTheDocument(); | ||
// screen.debug(undefined, Infinity); | ||
}); | ||
test('New waste lines set DOT haz material and EPA haz waste to true by default', () => { | ||
// Arrange | ||
renderWithProviders( | ||
<WasteLineForm | ||
appendWaste={() => console.log('waste appended')} | ||
handleClose={() => console.log('close action handled')} | ||
/>, | ||
{} | ||
); | ||
const epaWasteSwitch = screen.getByRole('checkbox', { name: /EPA Hazardous Waste?/i }); | ||
const dotHazSwitch = screen.getByRole('checkbox', { name: /DOT Hazardous/i }); | ||
expect(epaWasteSwitch).toBeChecked(); | ||
expect(dotHazSwitch).toBeChecked(); | ||
}); | ||
test('Setting DOT hazardous to false automatically set EPA waste to false', async () => { | ||
// Arrange | ||
renderWithProviders( | ||
<WasteLineForm | ||
appendWaste={() => console.log('waste appended')} | ||
handleClose={() => console.log('close action handled')} | ||
/>, | ||
{} | ||
); | ||
const epaWasteSwitch = await screen.findByRole('checkbox', { name: /EPA Hazardous Waste?/i }); | ||
const dotHazSwitch = await screen.findByRole('checkbox', { name: /DOT Hazardous/i }); | ||
// Act | ||
await userEvent.click(dotHazSwitch); | ||
// Assert | ||
expect(epaWasteSwitch).not.toBeChecked(); | ||
expect(dotHazSwitch).not.toBeChecked(); | ||
}); | ||
test('Setting EPA waste to true automatically set DOT Hazardous to true', async () => { | ||
// Arrange | ||
renderWithProviders( | ||
<WasteLineForm | ||
appendWaste={() => console.log('waste appended')} | ||
handleClose={() => console.log('close action handled')} | ||
/>, | ||
{} | ||
); | ||
const epaWasteSwitch = await screen.findByRole('checkbox', { name: /EPA Hazardous Waste?/i }); | ||
const dotHazSwitch = await screen.findByRole('checkbox', { name: /DOT Hazardous/i }); | ||
// first set both switches to false | ||
await userEvent.click(epaWasteSwitch); | ||
await userEvent.click(dotHazSwitch); | ||
// Check they are both false (unchecked) | ||
expect(epaWasteSwitch).not.toBeChecked(); | ||
expect(dotHazSwitch).not.toBeChecked(); | ||
// Act | ||
await userEvent.click(epaWasteSwitch); | ||
// Assert | ||
expect(epaWasteSwitch).toBeChecked(); | ||
expect(dotHazSwitch).toBeChecked(); | ||
}); | ||
test('If epaWaste is false, federal waste code select is disabled', async () => { | ||
// Arrange | ||
renderWithProviders( | ||
<WasteLineForm | ||
appendWaste={() => console.log('waste appended')} | ||
handleClose={() => console.log('close action handled')} | ||
/>, | ||
{} | ||
); | ||
const epaWasteSwitch = await screen.findByRole('checkbox', { name: /EPA Hazardous Waste?/i }); | ||
const federalWasteCodeSelect = await screen.findByLabelText('Federal Waste Codes'); | ||
// Act | ||
await userEvent.click(epaWasteSwitch); | ||
expect(epaWasteSwitch).not.toBeChecked(); // check EPA waste is false | ||
// Assert | ||
expect(federalWasteCodeSelect).toBeDisabled(); | ||
}); | ||
test('If epaWaste is false, federal waste codes are cleared', async () => { | ||
// Arrange | ||
renderWithProviders( | ||
<WasteLineForm | ||
appendWaste={() => console.log('waste appended')} | ||
handleClose={() => console.log('close action handled')} | ||
/>, | ||
{} | ||
); | ||
const epaWasteSwitch = await screen.findByRole('checkbox', { name: /EPA Hazardous Waste?/i }); | ||
const federalWasteCodeSelect = await screen.findByLabelText('Federal Waste Codes'); | ||
await userEvent.type(federalWasteCodeSelect, 'D001'); | ||
expect(federalWasteCodeSelect).toHaveValue('D001'); | ||
// Act | ||
await userEvent.click(epaWasteSwitch); | ||
// Assert | ||
expect(federalWasteCodeSelect).toHaveValue(''); | ||
}); | ||
}); |
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.