forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailValidationPage.test.js
More file actions
139 lines (131 loc) · 3.56 KB
/
EmailValidationPage.test.js
File metadata and controls
139 lines (131 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React from 'react'
import { theme, ChakraProvider } from '@chakra-ui/react'
import { MemoryRouter, Route } from 'react-router-dom'
import { render, waitFor } from '@testing-library/react'
import { I18nProvider } from '@lingui/react'
import { setupI18n } from '@lingui/core'
import { MockedProvider } from '@apollo/client/testing'
import { makeVar } from '@apollo/client'
import { en } from 'make-plural/plurals'
import EmailValidationPage from '../EmailValidationPage'
import { UserVarProvider } from '../../utilities/userState'
import { VERIFY_ACCOUNT } from '../../graphql/mutations'
const i18n = setupI18n({
locale: 'en',
messages: {
en: {},
},
localeData: {
en: { plurals: en },
},
})
const successMocks = [
{
request: {
query: VERIFY_ACCOUNT,
variables: {
verifyToken: 'fwsdGDFSGSDVA.gedafbedafded.bgdbsedbeagbe',
},
},
result: {
data: {
verifyAccount: {
result: {
status: 'Hello World',
__typename: 'VerifyAccountResult',
},
},
},
},
},
]
const failMocks = [
{
request: {
query: VERIFY_ACCOUNT,
},
result: {
data: {
verifyAccount: {
result: {
code: -96,
description: 'Hello World',
__typename: 'VerifyAccountError',
},
},
},
},
},
]
describe('<EmailValidationPage />', () => {
describe('after loading mutation', () => {
it('displays an error message', async () => {
const { queryByText } = render(
<MockedProvider mocks={failMocks}>
<UserVarProvider
userVar={makeVar({
jwt: null,
tfaSendMethod: null,
userName: null,
})}
>
<ChakraProvider theme={theme}>
<I18nProvider i18n={i18n}>
<MemoryRouter
initialEntries={[
'/validate/fwsdGDFSGSDVA.gedafbedafded.bgdbsedbeagbe',
]}
initialIndex={0}
>
<Route path="/validate/:verifyToken">
<EmailValidationPage />
</Route>
</MemoryRouter>
</I18nProvider>
</ChakraProvider>
</UserVarProvider>
</MockedProvider>,
)
await waitFor(() =>
expect(
queryByText(
/Your account email could not be verified at this time. Please try again./,
),
).toBeInTheDocument(),
)
})
it('displays a success message', async () => {
const { queryByText } = render(
<MockedProvider mocks={successMocks}>
<UserVarProvider
userVar={makeVar({
jwt: null,
tfaSendMethod: null,
userName: null,
})}
>
<ChakraProvider theme={theme}>
<I18nProvider i18n={i18n}>
<MemoryRouter
initialEntries={[
'/validate/fwsdGDFSGSDVA.gedafbedafded.bgdbsedbeagbe',
]}
initialIndex={0}
>
<Route path="/validate/:verifyToken">
<EmailValidationPage />
</Route>
</MemoryRouter>
</I18nProvider>
</ChakraProvider>
</UserVarProvider>
</MockedProvider>,
)
await waitFor(() =>
expect(
queryByText(/Your account email was successfully verified/),
).toBeInTheDocument(),
)
})
})
})