forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrganizationAffiliations.test.js
More file actions
154 lines (145 loc) · 4.76 KB
/
OrganizationAffiliations.test.js
File metadata and controls
154 lines (145 loc) · 4.76 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import React from 'react'
import { render, waitFor } from '@testing-library/react'
import { MockedProvider } from '@apollo/client/testing'
import { MemoryRouter, Route } from 'react-router-dom'
import { theme, ThemeProvider } from '@chakra-ui/core'
import { UserVarProvider } from '../UserState'
import { PAGINATED_ORG_AFFILIATIONS } from '../graphql/queries'
import { I18nProvider } from '@lingui/react'
import { setupI18n } from '@lingui/core'
import { OrganizationAffiliations } from '../OrganizationAffiliations'
import matchMediaPolyfill from 'mq-polyfill'
import { makeVar } from '@apollo/client'
const i18n = setupI18n({
locale: 'en',
messages: {
en: {},
},
localeData: {
en: {},
},
})
matchMediaPolyfill(window)
window
.matchMedia('(min-width: 920px)') // Create MediaQueryList instance
.addListener(console.log) // Subscribe to MQ mode changes
/**
* For dispatching resize event
* we must implement window.resizeTo in jsdom
*/
window.resizeTo = function resizeTo(width, height) {
Object.assign(this, {
innerWidth: width,
innerHeight: height,
outerWidth: width,
outerHeight: height,
}).dispatchEvent(new this.Event('resize'))
}
describe('<OrganizationAffiliations />', () => {
describe('given the url /organisations/tbs-sct-gc-ca', () => {
it('displays user affiliations using the tbs-sct-gc-ca slug', async () => {
window.resizeTo(1024, 768)
const orgSlug = 'tbs-sct-gc-ca'
const mocks = [
{
request: {
query: PAGINATED_ORG_AFFILIATIONS,
variables: { slug: 'tbs-sct-gc-ca', first: 10 },
},
result: {
data: {
findOrganizationBySlug: {
id: 'testid',
affiliations: {
pageInfo: {
hasNextPage: false,
endCursor: 'string',
hasPreviousPage: false,
startCursor: 'string',
},
totalCount: 15,
edges: [
{
cursor: 'string',
node: {
permission: 'SUPER_ADMIN',
user: {
id: 'MjQyMzg1MTM1OQ==',
userName: 'Jabari_Larson@hotmail.com',
displayName: 'Jabari Larson',
},
},
},
{
cursor: 'string',
node: {
permission: 'SUPER_ADMIN',
user: {
id: 'NjYzODA5ODE1OA==',
userName: 'Joel_Nienow77@yahoo.com',
displayName: 'Joel Nienow',
},
},
},
{
cursor: 'string',
node: {
permission: 'ADMIN',
user: {
id: 'NzQyMzU3NDYzMw==',
userName: 'Cara.Olson81@yahoo.com',
displayName: 'Cara Olson',
},
},
},
{
cursor: 'string',
node: {
permission: 'USER',
user: {
id: 'Nzc0Mjg2MjM2Ng==',
userName: 'Rahul.Wintheiser10@yahoo.com',
displayName: 'Rahul Wintheiser',
},
},
},
],
},
},
},
},
},
]
const { getByText } = render(
<ThemeProvider theme={theme}>
<I18nProvider i18n={i18n}>
<MockedProvider mocks={mocks} addTypename={false}>
<UserVarProvider
userVar={makeVar({
jwt: null,
tfaSendMethod: null,
userName: null,
})}
>
<MemoryRouter
initialEntries={['/organization/tbs-sct-gc-ca']}
initialIndex={0}
>
<Route path="/organization/:orgSlug">
<OrganizationAffiliations orgSlug={orgSlug} />
</Route>
</MemoryRouter>
</UserVarProvider>
</MockedProvider>
</I18nProvider>
</ThemeProvider>,
)
await waitFor(() => {
expect(getByText('Jabari_Larson@hotmail.com')).toBeInTheDocument()
})
await waitFor(() => {
expect(getByText('Cara Olson')).toBeInTheDocument()
})
})
})
})