Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lcampbell2 committed Jul 27, 2023
1 parent 64b849e commit 1bb828f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 96 deletions.
10 changes: 6 additions & 4 deletions frontend/src/auth/TwoFactorAuthenticatePage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
import { t, Trans } from '@lingui/macro'
import { useLingui } from '@lingui/react'
import { Box, Button, Heading, Stack, useToast } from '@chakra-ui/react'
import { Box, Button, Heading, Stack, Text, useToast } from '@chakra-ui/react'
import { useHistory, useLocation, useParams } from 'react-router-dom'
import { useMutation } from '@apollo/client'
import { Formik } from 'formik'
import { ErrorMessage, Formik } from 'formik'

import { LoadingMessage } from '../components/LoadingMessage'
import { AuthenticateField } from '../components/fields/AuthenticateField'
Expand Down Expand Up @@ -111,9 +111,11 @@ export default function TwoFactorAuthenticatePage() {
<Trans>Two Factor Authentication</Trans>
</Heading>

<AuthenticateField sendMethod={sendMethod} mb="4" />

<Stack align="center">
<AuthenticateField sendMethod={sendMethod} />
<Text color="red">
<ErrorMessage name="twoFactorCode" />
</Text>
<Button variant="primary" isLoading={isSubmitting} type="submit">
<Trans>Submit</Trans>
</Button>
Expand Down
44 changes: 14 additions & 30 deletions frontend/src/auth/__tests__/TwoFactorAuthenticatePage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@ describe('<TwoFactorAuthenticatePage />', () => {
it('renders correctly', async () => {
const { getByText } = render(
<MockedProvider>
<UserVarProvider
userVar={makeVar({ jwt: null, tfaSendMethod: null, userName: null })}
>
<UserVarProvider userVar={makeVar({ jwt: null, tfaSendMethod: null, userName: null })}>
<ChakraProvider theme={theme}>
<I18nProvider i18n={i18n}>
<MemoryRouter
initialEntries={['/authenticate/phone/authenticate-token-test']}
initialIndex={0}
>
<MemoryRouter initialEntries={['/authenticate/phone/authenticate-token-test']} initialIndex={0}>
<Route path="/authenticate/:sendMethod/:authenticateToken">
<TwoFactorAuthenticatePage />
</Route>
Expand All @@ -47,9 +42,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
</MockedProvider>,
)

await waitFor(() =>
expect(getByText(/Two Factor Authentication/)).toBeInTheDocument(),
)
await waitFor(() => expect(getByText(/Two Factor Authentication/)).toBeInTheDocument())
})

describe('given no input', () => {
Expand All @@ -67,12 +60,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
>
<ChakraProvider theme={theme}>
<I18nProvider i18n={i18n}>
<MemoryRouter
initialEntries={[
'/authenticate/phone/authenticate-token-test',
]}
initialIndex={0}
>
<MemoryRouter initialEntries={['/authenticate/phone/authenticate-token-test']} initialIndex={0}>
<Route path="/authenticate/:sendMethod/:authenticateToken">
<TwoFactorAuthenticatePage />
</Route>
Expand All @@ -86,9 +74,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
fireEvent.click(submitButton)

await waitFor(() => {
expect(
getByText(/Code field must not be empty/i),
).toBeInTheDocument()
expect(getByText(/Code field must not be empty/i)).toBeInTheDocument()
})
})
})
Expand Down Expand Up @@ -126,7 +112,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
initialIndex: 0,
})

const { container, getByRole, queryByText } = render(
const { getAllByRole, getByRole, queryByText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserVarProvider
userVar={makeVar({
Expand All @@ -148,7 +134,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
</MockedProvider>,
)

const twoFactorCode = container.querySelector('#twoFactorCode')
const twoFactorCode = getAllByRole('textbox', { name: 'Please enter your pin code' })[0]
const form = getByRole('form')

fireEvent.change(twoFactorCode, {
Expand All @@ -160,9 +146,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
fireEvent.submit(form)

await waitFor(() => {
expect(
queryByText(/Unable to sign in to your account, please try again./i),
)
expect(queryByText(/Unable to sign in to your account, please try again./i))
})
})
it('client-side error', async () => {
Expand Down Expand Up @@ -202,7 +186,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
initialIndex: 0,
})

const { container, getByRole, queryByText } = render(
const { getAllByRole, getByRole, queryByText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserVarProvider
userVar={makeVar({
Expand All @@ -224,7 +208,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
</MockedProvider>,
)

const twoFactorCode = container.querySelector('#twoFactorCode')
const twoFactorCode = getAllByRole('textbox', { name: 'Please enter your pin code' })[0]
const form = getByRole('form')

fireEvent.change(twoFactorCode, {
Expand Down Expand Up @@ -276,7 +260,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
initialIndex: 0,
})

const { container, getByRole, queryByText } = render(
const { getAllByRole, getByRole, queryByText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserVarProvider
userVar={makeVar({
Expand All @@ -298,7 +282,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
</MockedProvider>,
)

const twoFactorCode = container.querySelector('#twoFactorCode')
const twoFactorCode = getAllByRole('textbox', { name: 'Please enter your pin code' })[0]
const form = getByRole('form')

fireEvent.change(twoFactorCode, {
Expand Down Expand Up @@ -358,7 +342,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
initialIndex: 0,
})

const { container, getByRole } = render(
const { getAllByRole, getByRole } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<UserVarProvider
userVar={makeVar({
Expand All @@ -380,7 +364,7 @@ describe('<TwoFactorAuthenticatePage />', () => {
</MockedProvider>,
)

const twoFactorCode = container.querySelector('#twoFactorCode')
const twoFactorCode = getAllByRole('textbox', { name: 'Please enter your pin code' })[0]
const form = getByRole('form')

fireEvent.change(twoFactorCode, {
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/fields/AuthenticateField.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function AuthenticateField({ name = 'twoFactorCode', sendMethod }) {
<FormLabel htmlFor={name} fontWeight="bold" textAlign="center">
{codeSendMessage + ' ' + t`Please enter your two factor code below.`}
</FormLabel>
<HStack justify="center" mb="4">
<HStack justify="center">
<PinInput
id={name}
otp
Expand All @@ -34,12 +34,12 @@ function AuthenticateField({ name = 'twoFactorCode', sendMethod }) {
name={name}
onChange={(val) => form.setFieldValue(field.name, val)}
>
<PinInputField borderColor="black" />
<PinInputField borderColor="black" />
<PinInputField borderColor="black" />
<PinInputField borderColor="black" />
<PinInputField borderColor="black" />
<PinInputField borderColor="black" />
<PinInputField borderColor="black" isRequired={true} />
<PinInputField borderColor="black" isRequired={true} />
<PinInputField borderColor="black" isRequired={true} />
<PinInputField borderColor="black" isRequired={true} />
<PinInputField borderColor="black" isRequired={true} />
<PinInputField borderColor="black" isRequired={true} />
</PinInput>
</HStack>
</FormControl>
Expand Down
55 changes: 0 additions & 55 deletions frontend/src/components/fields/__tests__/AuthenticateField.test.js

This file was deleted.

0 comments on commit 1bb828f

Please sign in to comment.