Skip to content

Commit 4e4979a

Browse files
committed
frontend: fix linting
1 parent 190a15f commit 4e4979a

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

frontend/src/pages/User.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
*/
1919

2020
import { Component } from "preact";
21-
import { Form, Button, Modal } from "react-bootstrap";
21+
import { Form, Button, Modal, Card, Container } from "react-bootstrap";
2222
import { useState } from "preact/hooks";
2323
import { fetchClient, isDebugMode, PASSWORD_PATTERN, concat_salts, generate_hash, generate_random_bytes, get_salt, get_salt_for_user } from "../utils";
2424
import sodium from "libsodium-wrappers";
2525
import { logout } from "../components/Navbar";
2626
import { useTranslation } from "react-i18next";
27-
import { Card, Container } from "react-bootstrap";
2827
import { signal } from "@preact/signals";
2928
import { PasswordComponent } from "../components/PasswordComponent";
3029
import i18n from "../i18n";

frontend/src/pages/__tests__/User.test.tsx

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
11
import { render, fireEvent, waitFor, screen } from '@testing-library/preact';
2-
import { beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { beforeEach, describe, expect, it, vi, type Mock } from 'vitest';
33
import { User } from '../User';
44

55
describe('User Component', () => {
6-
let mockUtils: any;
7-
let mockShowAlert: any;
8-
let mockLogout: any;
9-
let mockSodium: any;
10-
let mockBase64: any;
6+
type FetchClientMock = {
7+
GET: Mock;
8+
PUT: Mock;
9+
DELETE: Mock;
10+
};
11+
12+
type UtilsMock = {
13+
fetchClient: FetchClientMock;
14+
generate_hash: Mock;
15+
generate_random_bytes: Mock;
16+
get_salt: Mock;
17+
get_salt_for_user: Mock;
18+
concat_salts: Mock;
19+
isDebugMode: { value: boolean };
20+
};
21+
22+
type SodiumMock = {
23+
default: {
24+
crypto_secretbox_open_easy: Mock;
25+
crypto_secretbox_easy: Mock;
26+
};
27+
};
28+
29+
type Base64Mock = {
30+
Base64: {
31+
toUint8Array: Mock;
32+
};
33+
};
34+
35+
let mockUtils: UtilsMock;
36+
let mockShowAlert: Mock;
37+
let mockLogout: Mock;
38+
let mockSodium: SodiumMock;
39+
let mockBase64: Base64Mock;
1140

1241
const mockUserData = {
1342
id: 'user-123',
@@ -24,13 +53,13 @@ describe('User Component', () => {
2453
beforeEach(async () => {
2554
vi.clearAllMocks();
2655

27-
const { showAlert } = await import('../../components/Alert') as any;
56+
const { showAlert } = (await import('../../components/Alert')) as unknown as { showAlert: Mock };
2857
mockShowAlert = showAlert;
2958

30-
const { logout } = await import('../../components/Navbar') as any;
59+
const { logout } = (await import('../../components/Navbar')) as unknown as { logout: Mock };
3160
mockLogout = logout;
3261

33-
mockUtils = await import('../../utils') as any;
62+
mockUtils = (await import('../../utils')) as unknown as UtilsMock;
3463
mockUtils.fetchClient.GET.mockResolvedValue({
3564
data: mockUserData,
3665
error: null,
@@ -50,15 +79,17 @@ describe('User Component', () => {
5079
mockUtils.get_salt_for_user.mockResolvedValue(new Uint8Array([13, 14, 15, 16]));
5180
mockUtils.concat_salts.mockReturnValue(new Uint8Array([17, 18, 19, 20]));
5281

53-
mockSodium = await vi.importMock('libsodium-wrappers') as any;
82+
mockSodium = (await vi.importMock('libsodium-wrappers')) as unknown as SodiumMock;
5483
mockSodium.default.crypto_secretbox_open_easy.mockReturnValue(new Uint8Array([21, 22, 23, 24]));
5584
mockSodium.default.crypto_secretbox_easy.mockReturnValue(new Uint8Array([25, 26, 27, 28]));
5685

57-
mockBase64 = await vi.importMock('js-base64') as any;
86+
mockBase64 = (await vi.importMock('js-base64')) as unknown as Base64Mock;
5887
mockBase64.Base64.toUint8Array.mockReturnValue(new Uint8Array([29, 30, 31, 32]));
5988

6089
vi.spyOn(window.localStorage, 'getItem').mockReturnValue('base64encodedSalt');
90+
// eslint-disable-next-line @typescript-eslint/no-empty-function
6191
vi.spyOn(window.localStorage, 'setItem').mockImplementation(() => {});
92+
// eslint-disable-next-line @typescript-eslint/no-empty-function
6293
vi.spyOn(window.localStorage, 'removeItem').mockImplementation(() => {});
6394
});
6495

@@ -189,7 +220,6 @@ describe('User Component', () => {
189220
});
190221

191222
const nameInput = screen.getByDisplayValue('John Doe');
192-
const submitButton = screen.getByText('save_changes');
193223

194224
fireEvent.change(nameInput, { target: { value: 'Jane Doe' } });
195225

0 commit comments

Comments
 (0)