Skip to content

Commit 618c44b

Browse files
chore(frontend): format lib tests with vitest/padding-around-all (#5877)
# Motivation We are going to add the vitest linter (PR #5797), but it raises quite a few issues. So, in preparation, for now we apply the rule [vitest/padding-around-all](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/padding-around-all.md) on the `lib` test folder.
1 parent 872ecbb commit 618c44b

File tree

68 files changed

+459
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+459
-0
lines changed

Diff for: src/frontend/src/tests/lib/api/idb.api.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ describe('idb.api', () => {
7373
// eslint-disable-next-line local-rules/prefer-object-params
7474
vi.mocked(idbKeyval.update).mockImplementation((_, updater) => {
7575
const updated = updater(mockAddress) as typeof mockAddress;
76+
7677
expect(updated.lastUsedTimestamp).toBeGreaterThan(mockAddress.lastUsedTimestamp);
78+
7779
return Promise.resolve();
7880
});
7981

@@ -116,7 +118,9 @@ describe('idb.api', () => {
116118
// eslint-disable-next-line local-rules/prefer-object-params
117119
vi.mocked(idbKeyval.update).mockImplementation((_, updater) => {
118120
const updated = updater(mockAddress) as typeof mockAddress;
121+
119122
expect(updated.lastUsedTimestamp).toBeGreaterThan(mockAddress.lastUsedTimestamp);
123+
120124
return Promise.resolve();
121125
});
122126

@@ -159,7 +163,9 @@ describe('idb.api', () => {
159163
// eslint-disable-next-line local-rules/prefer-object-params
160164
vi.mocked(idbKeyval.update).mockImplementation((_, updater) => {
161165
const updated = updater(mockAddress) as typeof mockAddress;
166+
162167
expect(updated.lastUsedTimestamp).toBeGreaterThan(mockAddress.lastUsedTimestamp);
168+
163169
return Promise.resolve();
164170
});
165171

@@ -174,7 +180,9 @@ describe('idb.api', () => {
174180
// eslint-disable-next-line local-rules/prefer-object-params
175181
vi.mocked(idbKeyval.update).mockImplementation((_, updater) => {
176182
const result = updater(undefined);
183+
177184
expect(result).toBeUndefined();
185+
178186
return Promise.resolve();
179187
});
180188

Diff for: src/frontend/src/tests/lib/canisters/reward.canister.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe('reward.canister', () => {
4545
});
4646

4747
const userData = await getUserInfo(queryParams);
48+
4849
expect(service.user_info).toHaveBeenCalledWith();
4950
expect(userData.is_vip.length).toBe(1);
5051
expect(fromNullable(userData.is_vip) === true).toBeTruthy();
@@ -65,6 +66,7 @@ describe('reward.canister', () => {
6566
});
6667

6768
const userData = await getUserInfo(queryParams);
69+
6870
expect(userData.is_vip.length).toBe(1);
6971
expect(fromNullable(userData.is_vip) === true).toBeFalsy();
7072
});
@@ -80,6 +82,7 @@ describe('reward.canister', () => {
8082
});
8183

8284
const result = getUserInfo(queryParams);
85+
8386
await expect(result).rejects.toThrow(mockResponseError);
8487
});
8588
});
@@ -98,6 +101,7 @@ describe('reward.canister', () => {
98101
});
99102

100103
const vipRewardResponse = await getNewVipReward();
104+
101105
expect(service.new_vip_reward).toHaveBeenCalledWith();
102106
expect(vipRewardResponse).toEqual(mockedRewardResponse);
103107
});
@@ -113,6 +117,7 @@ describe('reward.canister', () => {
113117
});
114118

115119
const result = getNewVipReward();
120+
116121
await expect(result).rejects.toThrow(mockResponseError);
117122
});
118123
});
@@ -128,6 +133,7 @@ describe('reward.canister', () => {
128133

129134
const vipReward = { code: '1234567890' };
130135
const claimResponse = await claimVipReward(vipReward);
136+
131137
expect(service.claim_vip_reward).toHaveBeenCalledWith(vipReward);
132138
expect(claimResponse).toEqual(mockedClaimResponse);
133139
});
@@ -143,6 +149,7 @@ describe('reward.canister', () => {
143149
});
144150

145151
const result = claimVipReward({ code: '1234567890' });
152+
146153
await expect(result).rejects.toThrow(mockResponseError);
147154
});
148155
});
@@ -161,6 +168,7 @@ describe('reward.canister', () => {
161168
});
162169

163170
const referrerInfo = await getReferrerInfo(queryParams);
171+
164172
expect(service.referrer_info).toHaveBeenCalledWith();
165173
expect(referrerInfo).toEqual(mockedReferrerInfo);
166174
});
@@ -176,6 +184,7 @@ describe('reward.canister', () => {
176184
});
177185

178186
const result = getReferrerInfo(queryParams);
187+
179188
await expect(result).rejects.toThrow(mockResponseError);
180189
});
181190
});
@@ -189,6 +198,7 @@ describe('reward.canister', () => {
189198
});
190199

191200
await setReferrer(mockedReferrerCode);
201+
192202
expect(service.set_referrer).toHaveBeenCalledWith(mockedReferrerCode);
193203
});
194204

@@ -203,6 +213,7 @@ describe('reward.canister', () => {
203213
});
204214

205215
const result = setReferrer(mockedReferrerCode);
216+
206217
await expect(result).rejects.toThrow(mockResponseError);
207218
});
208219
});
@@ -219,6 +230,7 @@ describe('reward.canister', () => {
219230
});
220231

221232
await registerAirdropRecipient(mockUserSnapshot);
233+
222234
expect(service.register_airdrop_recipient).toHaveBeenCalledWith(mockUserSnapshot);
223235
});
224236

@@ -233,6 +245,7 @@ describe('reward.canister', () => {
233245
});
234246

235247
const result = registerAirdropRecipient(mockUserSnapshot);
248+
236249
await expect(result).rejects.toThrow(mockResponseError);
237250
});
238251
});

Diff for: src/frontend/src/tests/lib/components/auth/AuthHelpForm.spec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,32 @@ describe('AuthHelpForm', () => {
3333
});
3434

3535
const imageBanner: HTMLImageElement | null = container.querySelector(imageBannerSelector);
36+
3637
expect(imageBanner).toBeInTheDocument();
3738

3839
expect(getByText(get(i18n).auth.help.text.subtitle)).toBeInTheDocument();
3940

4041
const lostIdentityButton: HTMLButtonElement | null = container.querySelector(
4142
lostIdentityButtonSelector
4243
);
44+
4345
expect(lostIdentityButton).toBeInTheDocument();
4446
expect(getByText(get(i18n).auth.help.text.lost_identity)).toBeInTheDocument();
4547

4648
const securityButton: HTMLButtonElement | null =
4749
container.querySelector(securityButtonSelector);
50+
4851
expect(securityButton).toBeInTheDocument();
4952
expect(getByText(get(i18n).auth.help.text.security)).toBeInTheDocument();
5053

5154
const gotConfusedButton: HTMLButtonElement | null =
5255
container.querySelector(gotConfusedButtonSelector);
56+
5357
expect(gotConfusedButton).toBeInTheDocument();
5458
expect(getByText(get(i18n).auth.help.text.got_confused)).toBeInTheDocument();
5559

5660
const otherButton: HTMLButtonElement | null = container.querySelector(otherButtonSelector);
61+
5762
expect(otherButton).toBeInTheDocument();
5863
expect(getByText(get(i18n).auth.help.text.other)).toBeInTheDocument();
5964

@@ -80,37 +85,53 @@ describe('AuthHelpForm', () => {
8085
const lostIdentityButton: HTMLButtonElement | null = container.querySelector(
8186
lostIdentityButtonSelector
8287
);
88+
8389
expect(lostIdentityButton).toBeInTheDocument();
90+
8491
await waitFor(() => {
8592
lostIdentityButton?.click();
93+
8694
expect(onLostIdentityMock).toHaveBeenCalledOnce();
8795
});
96+
8897
expect(analyticSpy).toHaveBeenCalledWith({ name: TRACK_HELP_LOST_INTERNET_IDENTITY });
8998

9099
const securityButton: HTMLButtonElement | null =
91100
container.querySelector(securityButtonSelector);
101+
92102
expect(securityButton).toBeInTheDocument();
103+
93104
await waitFor(() => {
94105
securityButton?.click();
106+
95107
expect(onOtherMock).toHaveBeenCalledTimes(1);
96108
});
109+
97110
expect(analyticSpy).toHaveBeenCalledWith({ name: TRACK_HELP_CONCERNED_ABOUT_SECURITY });
98111

99112
const gotConfusedButton: HTMLButtonElement | null =
100113
container.querySelector(gotConfusedButtonSelector);
114+
101115
expect(gotConfusedButton).toBeInTheDocument();
116+
102117
await waitFor(() => {
103118
gotConfusedButton?.click();
119+
104120
expect(onOtherMock).toHaveBeenCalledTimes(2);
105121
});
122+
106123
expect(analyticSpy).toHaveBeenCalledWith({ name: TRACK_HELP_GOT_CONFUSED });
107124

108125
const otherButton: HTMLButtonElement | null = container.querySelector(otherButtonSelector);
126+
109127
expect(otherButton).toBeInTheDocument();
128+
110129
await waitFor(() => {
111130
otherButton?.click();
131+
112132
expect(onOtherMock).toHaveBeenCalledTimes(3);
113133
});
134+
114135
expect(analyticSpy).toHaveBeenCalledWith({ name: TRACK_HELP_OTHER });
115136
});
116137
});

Diff for: src/frontend/src/tests/lib/components/auth/AuthHelpIdentityForm.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,31 @@ describe('AuthHelpIdentityForm', () => {
3030
});
3131

3232
const imageBanner: HTMLImageElement | null = container.querySelector(imageBannerSelector);
33+
3334
expect(imageBanner).toBeInTheDocument();
3435

3536
expect(getByText(get(i18n).auth.help.text.identity_legacy_description)).toBeInTheDocument();
3637

3738
const signInButton: HTMLButtonElement | null = container.querySelector(signInButtonSelector);
39+
3840
expect(signInButton).toBeInTheDocument();
3941
expect(getByText(get(i18n).auth.help.text.identity_legacy_sign_in)).toBeInTheDocument();
4042

4143
const learnMoreAnchor: HTMLAnchorElement | null =
4244
container.querySelector(learnMoreAnchorSelector);
45+
4346
expect(learnMoreAnchor).toBeInTheDocument();
4447
expect(learnMoreAnchor?.href).toBe(OISY_FIND_INTERNET_IDENTITY_URL);
4548
expect(
4649
getByText(replaceOisyPlaceholders(get(i18n).auth.help.text.identity_learn_more))
4750
).toBeInTheDocument();
4851

4952
const backButton: HTMLButtonElement | null = container.querySelector(backButtonSelector);
53+
5054
expect(backButton).toBeInTheDocument();
5155

5256
const doneButton: HTMLButtonElement | null = container.querySelector(doneButtonSelector);
57+
5358
expect(doneButton).toBeInTheDocument();
5459
});
5560

@@ -70,24 +75,33 @@ describe('AuthHelpIdentityForm', () => {
7075
expect(authSpy).not.toHaveBeenCalled();
7176

7277
const backButton: HTMLButtonElement | null = container.querySelector(backButtonSelector);
78+
7379
expect(backButton).toBeInTheDocument();
80+
7481
await waitFor(() => {
7582
backButton?.click();
83+
7684
expect(onBackMock).toHaveBeenCalledOnce();
7785
});
7886

7987
const doneButton: HTMLButtonElement | null = container.querySelector(doneButtonSelector);
88+
8089
expect(doneButton).toBeInTheDocument();
90+
8191
await waitFor(() => {
8292
doneButton?.click();
93+
8394
expect(onDoneMock).toHaveBeenCalledOnce();
8495
});
8596

8697
const signInButton: HTMLButtonElement | null = container.querySelector(signInButtonSelector);
98+
8799
expect(signInButton).toBeInTheDocument();
100+
88101
await waitFor(() => {
89102
signInButton?.click();
90103
});
104+
91105
expect(onDoneMock).toHaveBeenCalledTimes(2);
92106
expect(authSpy).toHaveBeenCalledWith({ domain: 'ic0.app' });
93107
});

Diff for: src/frontend/src/tests/lib/components/auth/AuthHelpOtherForm.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ describe('AuthHelpOtherForm', () => {
3939
const introductionAnchor: HTMLAnchorElement | null = container.querySelector(
4040
introductionAnchorSelector
4141
);
42+
4243
expect(introductionAnchor).toBeInTheDocument();
4344
expect(introductionAnchor?.href).toBe(`${OISY_DOCS_URL}/`);
4445
expect(
4546
getByText(replaceOisyPlaceholders(get(i18n).auth.help.text.other_introduction))
4647
).toBeInTheDocument();
4748

4849
const docsAnchor: HTMLAnchorElement | null = container.querySelector(docsAnchorSelector);
50+
4951
expect(docsAnchor).toBeInTheDocument();
5052
expect(docsAnchor?.href).toBe(OISY_INTERNET_IDENTITY_URL);
5153
expect(
@@ -54,6 +56,7 @@ describe('AuthHelpOtherForm', () => {
5456

5557
const privateKeyAnchor: HTMLAnchorElement | null =
5658
container.querySelector(privateKeyAnchorSelector);
59+
5760
expect(privateKeyAnchor).toBeInTheDocument();
5861
expect(privateKeyAnchor?.href).toBe(OISY_FAQ_URL);
5962
expect(
@@ -63,16 +66,19 @@ describe('AuthHelpOtherForm', () => {
6366
const assetControlAnchor: HTMLAnchorElement | null = container.querySelector(
6467
assetControlAnchorSelector
6568
);
69+
6670
expect(assetControlAnchor).toBeInTheDocument();
6771
expect(assetControlAnchor?.href).toBe(OISY_ACCESS_CONTROL_URL);
6872
expect(
6973
getByText(replaceOisyPlaceholders(get(i18n).auth.help.text.other_asset_control))
7074
).toBeInTheDocument();
7175

7276
const backButton: HTMLButtonElement | null = container.querySelector(backButtonSelector);
77+
7378
expect(backButton).toBeInTheDocument();
7479

7580
const doneButton: HTMLButtonElement | null = container.querySelector(doneButtonSelector);
81+
7682
expect(doneButton).toBeInTheDocument();
7783
});
7884

@@ -91,16 +97,22 @@ describe('AuthHelpOtherForm', () => {
9197
expect(onDoneMock).not.toHaveBeenCalled();
9298

9399
const backButton: HTMLButtonElement | null = container.querySelector(backButtonSelector);
100+
94101
expect(backButton).toBeInTheDocument();
102+
95103
await waitFor(() => {
96104
backButton?.click();
105+
97106
expect(onBackMock).toHaveBeenCalledOnce();
98107
});
99108

100109
const doneButton: HTMLButtonElement | null = container.querySelector(doneButtonSelector);
110+
101111
expect(doneButton).toBeInTheDocument();
112+
102113
await waitFor(() => {
103114
doneButton?.click();
115+
104116
expect(onDoneMock).toHaveBeenCalledOnce();
105117
});
106118
});

0 commit comments

Comments
 (0)