Skip to content

Commit

Permalink
Cleanup app-web tests
Browse files Browse the repository at this point in the history
  • Loading branch information
haworku committed Feb 6, 2024
1 parent 93997e6 commit 6b20930
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { screen, waitFor } from '@testing-library/react'

import { renderWithProviders } from '../../../testHelpers'
import { renderWithProviders } from '../../testHelpers'
import { RateEdit } from './RateEdit'
import {
fetchCurrentUserMock,
fetchRateMockSuccess,
mockValidStateUser,
} from '../../../testHelpers/apolloMocks'
import { RoutesRecord } from '../../../constants'
} from '../../testHelpers/apolloMocks'
import { RoutesRecord } from '../../constants'
import { Route, Routes } from 'react-router-dom'

// Wrap test component in some top level routes to allow getParams to be tested
Expand Down Expand Up @@ -45,7 +45,9 @@ describe('RateEdit', () => {
})

await waitFor(() => {
expect(screen.queryByTestId('rate-edit')).toBeInTheDocument()
expect(
screen.queryByTestId('single-rate-edit')
).toBeInTheDocument()
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {
UpdateInformation,
useFetchRateQuery,
useSubmitRateMutation,
} from '../../../gen/gqlClient'
} from '../../gen/gqlClient'
import { GridContainer } from '@trussworks/react-uswds'
import { Loading } from '../../../components'
import { GenericErrorPage } from '../../Errors/GenericErrorPage'
import { RateDetailsV2 } from '../../StateSubmission/RateDetails/V2/RateDetailsV2'
import { RouteT, RoutesRecord } from '../../../constants'
import { PageBannerAlerts } from '../../StateSubmission/StateSubmissionForm'
import { useAuth } from '../../../contexts/AuthContext'
import { FormContainer } from '../../StateSubmission/FormContainer'
import { Loading } from '../../components'
import { GenericErrorPage } from '../Errors/GenericErrorPage'
import { RateDetailsV2 } from '../StateSubmission/RateDetails/V2/RateDetailsV2'
import { RouteT, RoutesRecord } from '../../constants'
import { PageBannerAlerts } from '../StateSubmission/StateSubmissionForm'
import { useAuth } from '../../contexts/AuthContext'
import { FormContainer } from '../StateSubmission/FormContainer'

export type SubmitOrUpdateRate = (
rateID: string,
Expand Down
12 changes: 9 additions & 3 deletions services/app-web/src/pages/RateSummary/RateSummary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { RateSummary } from './RateSummary'
import { RoutesRecord } from '../../constants'
import { Route, Routes } from 'react-router-dom'
import { RateEdit } from '../RateSubmission/RateEdit/RateEdit'
import { RateEdit } from '../RateEdit/RateEdit'

// Wrap test component in some top level routes to allow getParams to be tested
const wrapInRoutes = (children: React.ReactNode) => {
Expand Down Expand Up @@ -177,11 +177,17 @@ describe('RateSummary', () => {
)

await waitFor(() => {
expect(screen.queryByTestId('rate-edit')).toBeInTheDocument()
expect(
screen.queryByTestId('single-rate-edit')
).toBeInTheDocument()
})
})

it('renders expected error page when rate ID is invalid', async () => {
const consoleWarnMock = jest
.spyOn(console, 'warn')
.mockImplementation()

renderWithProviders(wrapInRoutes(<RateSummary />), {
apolloProvider: {
mocks: [
Expand All @@ -198,7 +204,7 @@ describe('RateSummary', () => {
},
featureFlags: { 'rate-edit-unlock': true },
})

expect(consoleWarnMock).toHaveBeenCalled() // apollo testing mocks will console warn that your query is invalid - this is intentional
expect(await screen.findByText('System error')).toBeInTheDocument()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const SingleRateCertSchema = (_activeFeatureFlags: FeatureFlagSettings) =>
rateDocuments: validateFileItemsListSingleUpload({ required: true }),
supportingDocuments: validateFileItemsList({ required: false }),
hasSharedRateCert: _activeFeatureFlags['rate-edit-unlock']? Yup.string(): Yup.string().defined('You must select yes or no'),
packagesWithSharedRateCerts: _activeFeatureFlags['rate-edit-unlock']? Yup.array()
.when('hasSharedRateCert', {
is: 'YES',
then: Yup.array().min(
1,
'You must select at least one submission'
),
})
.required(): Yup.array().optional(),
packagesWithSharedRateCerts: _activeFeatureFlags['rate-edit-unlock']? Yup.array().optional(): Yup.array()
.when('hasSharedRateCert', {
is: 'YES',
then: Yup.array().min(
1,
'You must select at least one submission'
),
})
.required(),
rateProgramIDs: Yup.array().min(1, 'You must select a program'),
rateType: Yup.string().defined(
'You must choose a rate certification type'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
RateRevision,
} from '../../../../gen/gqlClient'
import { SingleRateCertV2 } from './SingleRateCertV2'
import type { SubmitOrUpdateRate } from '../../../RateSubmission/RateEdit/RateEdit'
import type { SubmitOrUpdateRate } from '../../../RateEdit/RateEdit'

export type RateDetailFormValues = {
id: Rate['id']
Expand Down
2 changes: 2 additions & 0 deletions services/app-web/src/testHelpers/apolloMocks/rateDataMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const rateRevisionDataMock = (data?: Partial<RateRevision>): RateRevision => {
certifyingActuaryContacts: [
{
__typename: 'ActuaryContact',
id: '123-cert-actuary',
name: 'Actuary Contact Person',
titleRole: 'Actuary Contact Title',
email: 'actuarycontact@example.com',
Expand All @@ -128,6 +129,7 @@ const rateRevisionDataMock = (data?: Partial<RateRevision>): RateRevision => {
addtlActuaryContacts: [
{
__typename: 'ActuaryContact',
id: '123-additional-actuary',
name: 'Additional actuary name',
titleRole: 'Additional actuary title',
email: 'additonalactuary@example.com',
Expand Down

0 comments on commit 6b20930

Please sign in to comment.