Skip to content

Commit a59da70

Browse files
committed
add tests
1 parent ba59202 commit a59da70

File tree

6 files changed

+337
-502
lines changed

6 files changed

+337
-502
lines changed

src/screens/ManageTag/ManageTag.test.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { RenderResult } from '@testing-library/react';
44
import {
55
act,
66
cleanup,
7+
fireEvent,
78
render,
89
screen,
910
waitFor,
@@ -80,11 +81,11 @@ const renderManageTag = (link: ApolloLink): RenderResult => {
8081
element={<div data-testid="organizationTagsScreen"></div>}
8182
/>
8283
<Route
83-
path="/orgtags/:orgId/managetag/:tagId"
84+
path="/orgtags/:orgId/manageTag/:tagId"
8485
element={<ManageTag />}
8586
/>
8687
<Route
87-
path="/orgtags/:orgId/subtags/:tagId"
88+
path="/orgtags/:orgId/subTags/:tagId"
8889
element={<div data-testid="subTagsScreen"></div>}
8990
/>
9091
<Route
@@ -337,31 +338,32 @@ describe('Manage Tag Page', () => {
337338
});
338339
});
339340

340-
test('paginates between different pages', async () => {
341-
renderManageTag(link);
341+
test('Fetches more assigned members with infinite scroll', async () => {
342+
const { getByText } = renderManageTag(link);
342343

343344
await wait();
344345

345346
await waitFor(() => {
346-
expect(screen.getByTestId('nextPagBtn')).toBeInTheDocument();
347+
expect(getByText(translations.addPeopleToTag)).toBeInTheDocument();
347348
});
348-
userEvent.click(screen.getByTestId('nextPagBtn'));
349349

350-
await waitFor(() => {
351-
expect(screen.getAllByTestId('memberName')[0]).toHaveTextContent(
352-
'member 6',
353-
);
354-
});
350+
// Get the initial number of tags loaded
351+
const initialAssignedMembersDataLength =
352+
screen.getAllByTestId('viewProfileBtn').length;
355353

356-
await waitFor(() => {
357-
expect(screen.getByTestId('previousPageBtn')).toBeInTheDocument();
354+
// Set scroll position to the bottom of the window
355+
fireEvent.scroll(window, {
356+
target: { scrollY: document.documentElement.scrollHeight },
358357
});
359-
userEvent.click(screen.getByTestId('previousPageBtn'));
360358

361359
await waitFor(() => {
362-
expect(screen.getAllByTestId('memberName')[0]).toHaveTextContent(
363-
'member 1',
360+
const finalAssignedMembersDataLength =
361+
screen.getAllByTestId('viewProfileBtn').length;
362+
expect(finalAssignedMembersDataLength).toBeGreaterThan(
363+
initialAssignedMembersDataLength,
364364
);
365+
366+
expect(getByText(translations.addPeopleToTag)).toBeInTheDocument();
365367
});
366368
});
367369

src/screens/ManageTag/ManageTagMocks.ts

Lines changed: 83 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ export const MOCKS = [
1717
query: USER_TAGS_ASSIGNED_MEMBERS,
1818
variables: {
1919
id: '1',
20-
after: null,
21-
before: null,
22-
first: 5,
23-
last: null,
20+
first: TAGS_QUERY_PAGE_SIZE,
2421
},
2522
},
2623
result: {
@@ -69,36 +66,6 @@ export const MOCKS = [
6966
},
7067
cursor: '5',
7168
},
72-
],
73-
pageInfo: {
74-
startCursor: '1',
75-
endCursor: '5',
76-
hasNextPage: true,
77-
hasPreviousPage: false,
78-
},
79-
totalCount: 6,
80-
},
81-
},
82-
},
83-
},
84-
},
85-
{
86-
request: {
87-
query: USER_TAGS_ASSIGNED_MEMBERS,
88-
variables: {
89-
id: '1',
90-
after: '5',
91-
before: null,
92-
first: 5,
93-
last: null,
94-
},
95-
},
96-
result: {
97-
data: {
98-
getUserTag: {
99-
name: 'tag1',
100-
usersAssignedTo: {
101-
edges: [
10269
{
10370
node: {
10471
_id: '6',
@@ -107,14 +74,46 @@ export const MOCKS = [
10774
},
10875
cursor: '6',
10976
},
77+
{
78+
node: {
79+
_id: '7',
80+
firstName: 'member',
81+
lastName: '7',
82+
},
83+
cursor: '7',
84+
},
85+
{
86+
node: {
87+
_id: '8',
88+
firstName: 'member',
89+
lastName: '8',
90+
},
91+
cursor: '8',
92+
},
93+
{
94+
node: {
95+
_id: '9',
96+
firstName: 'member',
97+
lastName: '9',
98+
},
99+
cursor: '9',
100+
},
101+
{
102+
node: {
103+
_id: '10',
104+
firstName: 'member',
105+
lastName: '10',
106+
},
107+
cursor: '10',
108+
},
110109
],
111110
pageInfo: {
112-
startCursor: '6',
113-
endCursor: '6',
114-
hasNextPage: false,
115-
hasPreviousPage: true,
111+
startCursor: '1',
112+
endCursor: '10',
113+
hasNextPage: true,
114+
hasPreviousPage: false,
116115
},
117-
totalCount: 6,
116+
totalCount: 12,
118117
},
119118
},
120119
},
@@ -125,10 +124,8 @@ export const MOCKS = [
125124
query: USER_TAGS_ASSIGNED_MEMBERS,
126125
variables: {
127126
id: '1',
128-
after: null,
129-
before: '6',
130-
first: null,
131-
last: 5,
127+
first: TAGS_QUERY_PAGE_SIZE,
128+
after: '10',
132129
},
133130
},
134131
result: {
@@ -139,52 +136,28 @@ export const MOCKS = [
139136
edges: [
140137
{
141138
node: {
142-
_id: '1',
139+
_id: '11',
143140
firstName: 'member',
144-
lastName: '1',
141+
lastName: '11',
145142
},
146-
cursor: '1',
147-
},
148-
{
149-
node: {
150-
_id: '2',
151-
firstName: 'member',
152-
lastName: '2',
153-
},
154-
cursor: '2',
155-
},
156-
{
157-
node: {
158-
_id: '3',
159-
firstName: 'member',
160-
lastName: '3',
161-
},
162-
cursor: '3',
163-
},
164-
{
165-
node: {
166-
_id: '4',
167-
firstName: 'member',
168-
lastName: '4',
169-
},
170-
cursor: '4',
143+
cursor: '11',
171144
},
172145
{
173146
node: {
174-
_id: '5',
147+
_id: '12',
175148
firstName: 'member',
176-
lastName: '5',
149+
lastName: '12',
177150
},
178-
cursor: '5',
151+
cursor: '12',
179152
},
180153
],
181154
pageInfo: {
182-
startCursor: '1',
183-
endCursor: '5',
184-
hasNextPage: true,
185-
hasPreviousPage: false,
155+
startCursor: '11',
156+
endCursor: '12',
157+
hasNextPage: false,
158+
hasPreviousPage: true,
186159
},
187-
totalCount: 6,
160+
totalCount: 12,
188161
},
189162
},
190163
},
@@ -195,7 +168,7 @@ export const MOCKS = [
195168
query: USER_TAGS_MEMBERS_TO_ASSIGN_TO,
196169
variables: {
197170
id: '1',
198-
first: 7,
171+
first: TAGS_QUERY_PAGE_SIZE,
199172
},
200173
},
201174
result: {
@@ -260,11 +233,35 @@ export const MOCKS = [
260233
},
261234
cursor: '7',
262235
},
236+
{
237+
node: {
238+
_id: '8',
239+
firstName: 'member',
240+
lastName: '8',
241+
},
242+
cursor: '8',
243+
},
244+
{
245+
node: {
246+
_id: '9',
247+
firstName: 'member',
248+
lastName: '9',
249+
},
250+
cursor: '9',
251+
},
252+
{
253+
node: {
254+
_id: '10',
255+
firstName: 'member',
256+
lastName: '10',
257+
},
258+
cursor: '10',
259+
},
263260
],
264261
pageInfo: {
265262
startCursor: '1',
266-
endCursor: '7',
267-
hasNextPage: true,
263+
endCursor: '10',
264+
hasNextPage: false,
268265
hasPreviousPage: false,
269266
},
270267
totalCount: 10,
@@ -504,10 +501,7 @@ export const MOCKS_ERROR_ASSIGNED_MEMBERS = [
504501
query: USER_TAGS_ASSIGNED_MEMBERS,
505502
variables: {
506503
id: '1',
507-
after: null,
508-
before: null,
509-
first: 5,
510-
last: null,
504+
first: TAGS_QUERY_PAGE_SIZE,
511505
},
512506
},
513507
error: new Error('Mock Graphql Error'),
@@ -533,10 +527,7 @@ export const MOCKS_ERROR_TAG_ANCESTORS = [
533527
query: USER_TAGS_ASSIGNED_MEMBERS,
534528
variables: {
535529
id: '1',
536-
after: null,
537-
before: null,
538-
first: 5,
539-
last: null,
530+
first: TAGS_QUERY_PAGE_SIZE,
540531
},
541532
},
542533
result: {
@@ -547,11 +538,11 @@ export const MOCKS_ERROR_TAG_ANCESTORS = [
547538
edges: [],
548539
pageInfo: {
549540
startCursor: '1',
550-
endCursor: '5',
551-
hasNextPage: true,
541+
endCursor: '1',
542+
hasNextPage: false,
552543
hasPreviousPage: false,
553544
},
554-
totalCount: 6,
545+
totalCount: 1,
555546
},
556547
},
557548
},

0 commit comments

Comments
 (0)