Skip to content

Commit 4fbf741

Browse files
Sotatek-DukeVuVu Van Duc
andauthored
feat(ui): Fix flakeys test (#997)
* feat(ui): Fix flakeys test * feat(ui): clean up DOM after test --------- Co-authored-by: Vu Van Duc <[email protected]>
1 parent e78ac25 commit 4fbf741

File tree

2 files changed

+97
-48
lines changed

2 files changed

+97
-48
lines changed

src/ui/pages/Menu/components/Settings/components/ManagePassword/ManagePassword.test.tsx

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe("Manage password", () => {
107107
});
108108

109109
test("Cancel alert", async () => {
110-
const { queryByTestId, getByTestId, unmount } = render(
110+
const { queryByTestId, getByTestId, queryByText } = render(
111111
<Provider store={storeMocked}>
112112
<ManagePassword />
113113
</Provider>
@@ -126,6 +126,15 @@ describe("Manage password", () => {
126126
fireEvent.click(getByTestId("settings-item-toggle-password"));
127127
});
128128

129+
await waitFor(() => {
130+
expect(
131+
queryByText(
132+
TRANSLATIONS.tabs.menu.tab.settings.sections.security.managepassword
133+
.page.alert.enablemessage
134+
)
135+
).toBeVisible();
136+
});
137+
129138
await waitFor(() => {
130139
expect(
131140
getByTestId("alert-cancel-enable-password").getAttribute("is-open")
@@ -141,6 +150,15 @@ describe("Manage password", () => {
141150
);
142151
});
143152

153+
await waitFor(() => {
154+
expect(
155+
queryByText(
156+
TRANSLATIONS.tabs.menu.tab.settings.sections.security.managepassword
157+
.page.alert.enablemessage
158+
)
159+
).toBeNull();
160+
});
161+
144162
await waitFor(() => {
145163
expect(
146164
getByTestId("alert-cancel-enable-password").getAttribute("is-open")
@@ -149,17 +167,11 @@ describe("Manage password", () => {
149167
expect(queryByTestId("create-password-modal")).toBe(null);
150168
});
151169

152-
unmount();
170+
document.getElementsByTagName("html")[0].innerHTML = "";
153171
});
154172

155173
test("Password not set", async () => {
156-
const {
157-
queryByTestId,
158-
getByTestId,
159-
getByText,
160-
findByText,
161-
getAllByTestId,
162-
} = render(
174+
const { queryByTestId, getByTestId, getByText, queryByText } = render(
163175
<Provider store={storeMocked}>
164176
<ManagePassword />
165177
</Provider>
@@ -174,23 +186,30 @@ describe("Manage password", () => {
174186
fireEvent.click(getByTestId("settings-item-toggle-password"));
175187
});
176188

177-
const text = await waitFor(async () => {
178-
return await findByText(
179-
TRANSLATIONS.tabs.menu.tab.settings.sections.security.managepassword
180-
.page.alert.enablemessage
181-
);
182-
});
183-
184189
await waitFor(() => {
185-
expect(text).toBeVisible();
190+
expect(
191+
getByText(
192+
TRANSLATIONS.tabs.menu.tab.settings.sections.security.managepassword
193+
.page.alert.enablemessage
194+
)
195+
).toBeVisible();
186196
});
187197

188198
act(() => {
189199
fireEvent.click(
190-
getAllByTestId("alert-cancel-enable-password-confirm-button")[0]
200+
getByTestId("alert-cancel-enable-password-confirm-button")
191201
);
192202
});
193203

204+
await waitFor(() => {
205+
expect(
206+
queryByText(
207+
TRANSLATIONS.tabs.menu.tab.settings.sections.security.managepassword
208+
.page.alert.enablemessage
209+
)
210+
).toBeNull();
211+
});
212+
194213
await waitFor(() => {
195214
expect(getByText("1")).toBeVisible();
196215
});
@@ -200,6 +219,8 @@ describe("Manage password", () => {
200219
await waitFor(() => {
201220
expect(getByTestId("create-password-modal")).toBeVisible();
202221
});
222+
223+
document.getElementsByTagName("html")[0].innerHTML = "";
203224
});
204225

205226
test("Disable password option", async () => {
@@ -233,7 +254,7 @@ describe("Manage password", () => {
233254
dispatch: dispatchMock,
234255
};
235256

236-
const { queryByTestId, getByTestId, findByText } = render(
257+
const { queryByTestId, getByTestId, queryByText, getByText } = render(
237258
<Provider store={storeMocked}>
238259
<ManagePassword />
239260
</Provider>
@@ -248,19 +269,28 @@ describe("Manage password", () => {
248269
fireEvent.click(getByTestId("settings-item-toggle-password"));
249270
});
250271

251-
const text = await findByText(
252-
TRANSLATIONS.tabs.menu.tab.settings.sections.security.managepassword.page
253-
.alert.disablemessage
254-
);
255-
256272
await waitFor(() => {
257-
expect(text).toBeVisible();
273+
expect(
274+
getByText(
275+
TRANSLATIONS.tabs.menu.tab.settings.sections.security.managepassword
276+
.page.alert.disablemessage
277+
)
278+
).toBeVisible();
258279
});
259280

260281
act(() => {
261282
fireEvent.click(getByTestId("alert-cancel-confirm-button"));
262283
});
263284

285+
await waitFor(() => {
286+
expect(
287+
queryByText(
288+
TRANSLATIONS.tabs.menu.tab.settings.sections.security.managepassword
289+
.page.alert.disablemessage
290+
)
291+
).toBeNull();
292+
});
293+
264294
await waitFor(() => {
265295
expect(getByTestId("verify-password-value")).toBeVisible();
266296
expect(getByTestId("forgot-hint-btn")).toBeVisible();

src/ui/pages/NotificationDetails/components/CredentialRequest/CredentialRequestInformation/CredentialRequestInformation.test.tsx

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("Credential request information", () => {
6363
...mockStore(initialState),
6464
dispatch: dispatchMock,
6565
};
66-
const { getByText, getByTestId, queryByText } = render(
66+
const { getByText, getByTestId, queryByText, unmount } = render(
6767
<Provider store={storeMocked}>
6868
<CredentialRequestInformation
6969
pageId="multi-sign"
@@ -105,14 +105,20 @@ describe("Credential request information", () => {
105105
);
106106

107107
await waitFor(() => {
108-
expect(deleteNotificationMock).toBeCalled();
109108
expect(
110109
queryByText(
111110
EN_TRANSLATIONS.tabs.notifications.details.credential.request
112111
.information.alert.textdecline
113112
)
114113
).toBeNull();
115114
});
115+
116+
await waitFor(() => {
117+
expect(deleteNotificationMock).toBeCalled();
118+
});
119+
120+
unmount();
121+
document.getElementsByTagName("body")[0].innerHTML = "";
116122
});
117123
});
118124

@@ -477,21 +483,22 @@ describe("Credential request information: multisig", () => {
477483

478484
const back = jest.fn();
479485

480-
const { getByText, getByTestId, getAllByText, getAllByTestId } = render(
481-
<Provider store={storeMocked}>
482-
<CredentialRequestInformation
483-
pageId="multi-sign"
484-
activeStatus
485-
onBack={back}
486-
onAccept={jest.fn()}
487-
userAID="member-2"
488-
notificationDetails={notificationsFix[4]}
489-
credentialRequest={credRequestFix}
490-
linkedGroup={linkedGroup}
491-
onReloadData={jest.fn()}
492-
/>
493-
</Provider>
494-
);
486+
const { getByText, getByTestId, getAllByText, queryByText, unmount } =
487+
render(
488+
<Provider store={storeMocked}>
489+
<CredentialRequestInformation
490+
pageId="multi-sign"
491+
activeStatus
492+
onBack={back}
493+
onAccept={jest.fn()}
494+
userAID="member-2"
495+
notificationDetails={notificationsFix[4]}
496+
credentialRequest={credRequestFix}
497+
linkedGroup={linkedGroup}
498+
onReloadData={jest.fn()}
499+
/>
500+
</Provider>
501+
);
495502

496503
await waitFor(() => {
497504
expect(
@@ -553,21 +560,33 @@ describe("Credential request information: multisig", () => {
553560

554561
await waitFor(() => {
555562
expect(
556-
getAllByTestId("multisig-request-alert-decline")[0]
557-
).toHaveTextContent(
558-
EN_TRANSLATIONS.tabs.notifications.details.credential.request
559-
.information.alert.textdecline
560-
);
563+
getByText(
564+
EN_TRANSLATIONS.tabs.notifications.details.credential.request
565+
.information.alert.textdecline
566+
)
567+
).toBeVisible();
561568
});
562569

563570
act(() => {
564571
fireEvent.click(
565-
getAllByTestId("multisig-request-alert-decline-confirm-button")[0]
572+
getByTestId("multisig-request-alert-decline-confirm-button")
566573
);
567574
});
568575

576+
await waitFor(() => {
577+
expect(
578+
queryByText(
579+
EN_TRANSLATIONS.tabs.notifications.details.credential.request
580+
.information.alert.textdecline
581+
)
582+
).toBeNull();
583+
});
584+
569585
await waitFor(() => {
570586
expect(deleteNotificationMock).toBeCalled();
571587
});
588+
589+
unmount();
590+
document.getElementsByTagName("body")[0].innerHTML = "";
572591
});
573592
});

0 commit comments

Comments
 (0)