-
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.
add unit test for siteTypeSelect showing the component limits the ava…
…ilable options depending on the siteType prop
- Loading branch information
1 parent
24fb6a6
commit 9f3abb1
Showing
2 changed files
with
41 additions
and
6 deletions.
There are no files selected for viewing
43 changes: 39 additions & 4 deletions
43
client/src/components/Manifest/SiteSelect/SiteTypeSelect.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 |
---|---|---|
@@ -1,22 +1,57 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { RcraSiteType } from 'components/Manifest/manifestSchema'; | ||
import { SiteTypeSelect } from 'components/Manifest/SiteSelect/SiteTypeSelect'; | ||
import React, { useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { renderWithProviders } from 'test-utils'; | ||
import { createMockSite } from 'test-utils/fixtures'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
function TestComponent() { | ||
function TestComponent({ siteType }: { siteType?: RcraSiteType }) { | ||
const [mockSiteType, setMockSiteType] = useState(); | ||
const handleChange = (siteType: any) => setMockSiteType(siteType); | ||
const { control } = useForm(); | ||
// @ts-ignore | ||
return <SiteTypeSelect siteType={mockSiteType} setSiteType={setMockSiteType} control={control} />; | ||
return ( | ||
<SiteTypeSelect | ||
siteType={siteType} | ||
value={mockSiteType} | ||
handleChange={handleChange} | ||
control={control} | ||
/> | ||
); | ||
} | ||
|
||
describe('SiteTypeSelect', () => { | ||
test('renders', () => { | ||
const mySite = createMockSite(); | ||
renderWithProviders(<TestComponent />); | ||
expect(screen.queryByTestId('siteTypeSelect')).toBeDefined(); | ||
}); | ||
test('site options are limited when site type is Generator', () => { | ||
renderWithProviders(<TestComponent siteType={'Generator'} />); | ||
// screen.debug(undefined, Infinity); | ||
expect(screen.queryByRole('option', { name: /generator/i })).toBeDefined(); | ||
expect(screen.queryByRole('option', { name: /Transporter/i })).toBeNull(); | ||
expect(screen.queryByRole('option', { name: /Tsdf/i })).toBeNull(); | ||
}); | ||
test('site options are limited when site type is transporter', () => { | ||
renderWithProviders(<TestComponent siteType={'Transporter'} />); | ||
// screen.debug(undefined, Infinity); | ||
expect(screen.queryByRole('option', { name: /generator/i })).toBeDefined(); | ||
expect(screen.queryByRole('option', { name: /Transporter/i })).toBeDefined(); | ||
expect(screen.queryByRole('option', { name: /Tsdf/i })).toBeNull(); | ||
}); | ||
test('All options are available when site Type is Tsdf', () => { | ||
renderWithProviders(<TestComponent siteType={'Tsdf'} />); | ||
// screen.debug(undefined, Infinity); | ||
expect(screen.queryByRole('option', { name: /generator/i })).toBeDefined(); | ||
expect(screen.queryByRole('option', { name: /Transporter/i })).toBeDefined(); | ||
expect(screen.queryByRole('option', { name: /Tsdf/i })).toBeDefined(); | ||
}); | ||
test('All options are available when site Type is undefined', () => { | ||
renderWithProviders(<TestComponent />); | ||
// screen.debug(undefined, Infinity); | ||
expect(screen.queryByRole('option', { name: /generator/i })).toBeDefined(); | ||
expect(screen.queryByRole('option', { name: /Transporter/i })).toBeDefined(); | ||
expect(screen.queryByRole('option', { name: /Tsdf/i })).toBeDefined(); | ||
}); | ||
}); |
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