Skip to content

Commit

Permalink
add unit test for siteTypeSelect showing the component limits the ava…
Browse files Browse the repository at this point in the history
…ilable options depending on the siteType prop
  • Loading branch information
dpgraham4401 committed Sep 25, 2023
1 parent 24fb6a6 commit 9f3abb1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
43 changes: 39 additions & 4 deletions client/src/components/Manifest/SiteSelect/SiteTypeSelect.spec.tsx
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();
});
});
4 changes: 2 additions & 2 deletions client/src/components/Manifest/SiteSelect/SiteTypeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Form } from 'react-bootstrap';
import { Control, Controller } from 'react-hook-form';

interface SiteTypeSelectProps {
siteType: RcraSiteType | undefined;
value: RcraSiteType | undefined;
siteType?: RcraSiteType;
value?: RcraSiteType;
handleChange: (siteType: RcraSiteType) => void;
control: Control;
disabled?: boolean;
Expand Down

0 comments on commit 9f3abb1

Please sign in to comment.