Skip to content

Commit 5524480

Browse files
committed
frontend: fix linting
1 parent 7032d79 commit 5524480

File tree

2 files changed

+80
-28
lines changed

2 files changed

+80
-28
lines changed

frontend/src/components/__tests__/register.test.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ vi.mock('react-i18next', () => ({
2222
initReactI18next: vi.fn().mockResolvedValue({
2323
type: "i18n"
2424
}),
25-
Trans: ({ children }: any) => children,
25+
Trans: ({ children }: { children: React.ReactNode }) => children,
2626
useTranslation: () => ({
2727
t: vi.fn((key: string) => key),
2828
}),
@@ -35,7 +35,12 @@ vi.mock("../Navbar", () => {
3535
});
3636

3737
vi.mock('../PasswordComponent', () => ({
38-
PasswordComponent: ({ onChange, isInvalid, invalidMessage, controlId }: any) => {
38+
PasswordComponent: ({ onChange, isInvalid, invalidMessage, controlId }: {
39+
onChange: (value: string) => void;
40+
isInvalid: boolean;
41+
invalidMessage: string;
42+
controlId: string;
43+
}) => {
3944
return <div>
4045
<input
4146
type="textbox"
@@ -50,7 +55,11 @@ vi.mock('../PasswordComponent', () => ({
5055
}));
5156

5257
vi.mock('../recovery_data_component', () => ({
53-
RecoveryDataComponent: ({ show, email, secret }: any) => (
58+
RecoveryDataComponent: ({ show, email, secret }: {
59+
show: { value: boolean };
60+
email: string;
61+
secret: Uint8Array;
62+
}) => (
5463
show?.value ? (
5564
<div data-testid="recovery-modal">
5665
Recovery modal for {email} with secret length: {secret.length}
@@ -65,8 +74,11 @@ vi.mock('links', () => ({
6574
}));
6675

6776
describe('Register Component', () => {
77+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6878
let mockSodium: any;
79+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6980
let mockUtils: any;
81+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7082
let mockShowAlert: any;
7183

7284
beforeEach(async () => {
@@ -150,7 +162,7 @@ describe('Register Component', () => {
150162
});
151163

152164
it('validates form fields correctly', async () => {
153-
const { container } = render(<Register />);
165+
render(<Register />);
154166
const submitButton = screen.getByTestId('submit-button');
155167

156168
fireEvent.click(submitButton);
@@ -164,7 +176,7 @@ describe('Register Component', () => {
164176
});
165177

166178
it('validates password pattern', async () => {
167-
const { container } = render(<Register />);
179+
render(<Register />);
168180
const passwordInputs = screen.getAllByTestId('password-input');
169181
const passwordInput = passwordInputs[0];
170182
const confirmPasswordInput = passwordInputs[1];
@@ -183,7 +195,7 @@ describe('Register Component', () => {
183195
});
184196

185197
it('validates password confirmation match', async () => {
186-
const { container } = render(<Register />);
198+
render(<Register />);
187199
const passwordInput = screen.getByRole('textbox', { name: 'password' });
188200
const confirmPasswordInput = screen.getByRole('textbox', { name: 'confirm_password' });
189201

@@ -201,7 +213,7 @@ describe('Register Component', () => {
201213
});
202214

203215
it('requires privacy policy acceptance', async () => {
204-
const { container } = render(<Register />);
216+
render(<Register />);
205217
const nameInput = screen.getByRole('textbox', { name: 'name' });
206218
const emailInput = screen.getByRole('textbox', { name: 'email' });
207219
const passwordInput = screen.getByRole('textbox', { name: 'password' });
@@ -224,7 +236,7 @@ describe('Register Component', () => {
224236
});
225237

226238
it('requires terms and conditions acceptance', async () => {
227-
const { container } = render(<Register />);
239+
render(<Register />);
228240
const nameInput = screen.getByRole('textbox', { name: 'name' });
229241
const emailInput = screen.getByRole('textbox', { name: 'email' });
230242
const passwordInput = screen.getByRole('textbox', { name: 'password' });
@@ -247,7 +259,7 @@ describe('Register Component', () => {
247259
});
248260

249261
it('submits registration with valid data', async () => {
250-
const { container } = render(<Register />);
262+
render(<Register />);
251263

252264
const nameInput = screen.getByRole('textbox', { name: 'name' });
253265
const emailInput = screen.getByRole('textbox', { name: 'email' });
@@ -289,7 +301,7 @@ describe('Register Component', () => {
289301
});
290302

291303
it('shows success alert on successful registration', async () => {
292-
const { container } = render(<Register />);
304+
render(<Register />);
293305

294306
// Fill and submit valid form
295307
const nameInput = screen.getByTestId('text-input');
@@ -319,7 +331,7 @@ describe('Register Component', () => {
319331
});
320332

321333
it('shows recovery modal after successful registration', async () => {
322-
const { container } = render(<Register />);
334+
render(<Register />);
323335

324336
const nameInput = screen.getByRole('textbox', { name: 'name' });
325337
const emailInput = screen.getByRole('textbox', { name: 'email' });
@@ -348,7 +360,7 @@ describe('Register Component', () => {
348360
error: 'Registration failed',
349361
});
350362

351-
const { container } = render(<Register />);
363+
render(<Register />);
352364

353365
const nameInput = screen.getByTestId('text-input');
354366
const emailInput = screen.getByTestId('email-input');
@@ -376,7 +388,7 @@ describe('Register Component', () => {
376388
it('handles salt generation error', async () => {
377389
mockUtils.get_salt.mockRejectedValue('Salt generation failed');
378390

379-
const { container } = render(<Register />);
391+
render(<Register />);
380392

381393
const nameInput = screen.getByTestId('text-input');
382394
const emailInput = screen.getByTestId('email-input');
@@ -400,7 +412,7 @@ describe('Register Component', () => {
400412
});
401413

402414
it('calls checkPassword when password fields change', async () => {
403-
const { container } = render(<Register />);
415+
render(<Register />);
404416
const passwordInput = screen.getByRole('textbox', { name: 'password' });
405417
const confirmPasswordInput = screen.getByRole('textbox', { name: 'confirm_password' });
406418
const submitButton = screen.getByTestId('submit-button');

frontend/src/test-setup.ts

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,61 @@ interface MockComponentProps {
77
[key: string]: unknown;
88
}
99

10-
interface ModalProps extends MockComponentProps {
11-
show?: boolean;
10+
interface CollapseProps extends MockComponentProps {
11+
in?: boolean;
12+
}
13+
14+
interface DropdownButtonProps extends MockComponentProps {
15+
title?: string;
1216
}
1317

1418
interface FormControlProps extends MockComponentProps {
19+
onChange?: (event: Event) => void;
20+
value?: string | number;
21+
isInvalid?: boolean;
22+
type?: string;
1523
as?: string;
24+
controlId?: string;
1625
}
1726

18-
interface CollapseProps extends MockComponentProps {
19-
in?: boolean;
27+
interface FormCheckProps extends MockComponentProps {
28+
checked?: boolean;
29+
label?: string;
30+
isInvalid?: boolean;
2031
}
2132

22-
interface DropdownButtonProps extends MockComponentProps {
33+
interface FormFeedbackProps extends MockComponentProps {
34+
children?: ComponentChildren;
35+
type?: string;
36+
}
37+
38+
interface ModalProps extends MockComponentProps {
39+
show?: boolean;
40+
onHide?: () => void;
41+
}
42+
43+
interface ModalHeaderProps extends MockComponentProps {
44+
closeButton?: boolean;
45+
}
46+
47+
interface TabsProps extends MockComponentProps {
48+
activeKey?: string;
49+
onSelect?: (key: string | null) => void;
50+
}
51+
52+
interface TabProps extends MockComponentProps {
53+
eventKey?: string;
2354
title?: string;
2455
}
2556

57+
interface AlertProps extends MockComponentProps {
58+
variant?: string;
59+
}
60+
61+
interface ButtonProps extends MockComponentProps {
62+
type?: string;
63+
}
64+
2665
// Mock react-bootstrap components with simple HTML elements
2766
vi.mock('react-bootstrap', () => {
2867
const Form = ({ children, ...props }: MockComponentProps) =>
@@ -42,7 +81,7 @@ vi.mock('react-bootstrap', () => {
4281
Form.Label = ({ children, controlId, ...props }: MockComponentProps) =>
4382
h('label', { ...props, htmlFor: controlId }, children);
4483

45-
Form.Control = ({ onChange, value, isInvalid, type, as, controlId, ...props }: any) => {
84+
Form.Control = ({ onChange, value, isInvalid, type, as, controlId, ...props }: FormControlProps) => {
4685
if (as === 'textarea') {
4786
return h('textarea', {
4887
...props,
@@ -65,7 +104,7 @@ vi.mock('react-bootstrap', () => {
65104
});
66105
};
67106

68-
Form.Check = ({ checked, label, isInvalid, ...props }: any) =>
107+
Form.Check = ({ checked, label, isInvalid, ...props }: FormCheckProps) =>
69108
h('div', {}, [
70109
h('input', {
71110
...props,
@@ -77,18 +116,19 @@ vi.mock('react-bootstrap', () => {
77116
h('label', {}, label)
78117
]);
79118

80-
(Form.Control as any).Feedback = ({ children, type, ...props }: any) =>
119+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
120+
(Form.Control as any).Feedback = ({ children, type, ...props }: FormFeedbackProps) =>
81121
h('div', { ...props, 'data-testid': `${type}-feedback` }, children);
82122

83-
const Modal = ({ children, show, onHide, ...props }: any) =>
123+
const Modal = ({ children, show, onHide, ...props }: ModalProps) =>
84124
show ? h('div', { ...props, 'data-testid': 'modal' }, [
85125
h('div', { className: 'modal-content' }, [
86126
children,
87127
h('button', { onClick: onHide, 'data-testid': 'modal-close' }, 'Close')
88128
])
89129
]) : null;
90130

91-
Modal.Header = ({ children, closeButton, ...props }: any) =>
131+
Modal.Header = ({ children, closeButton, ...props }: ModalHeaderProps) =>
92132
h('div', { ...props, 'data-testid': 'modal-header' }, [
93133
children,
94134
closeButton && h('button', { 'data-testid': 'modal-close' }, 'x')
@@ -139,21 +179,21 @@ vi.mock('react-bootstrap', () => {
139179
InputGroup.Text = ({ children, ...props }: MockComponentProps) =>
140180
h('span', { ...props, className: 'input-group-text' }, children);
141181

142-
const Tabs = ({ children, activeKey, onSelect, ...props }: any) =>
182+
const Tabs = ({ children, activeKey: _activeKey, onSelect: _onSelect, ...props }: TabsProps) =>
143183
h('div', { ...props, className: 'tabs' }, children);
144184

145-
const Tab = ({ children, eventKey, title, ...props }: any) =>
185+
const Tab = ({ children, eventKey: _eventKey, title: _title, ...props }: TabProps) =>
146186
h('div', { ...props, className: 'tab-pane' }, children);
147187

148-
const Alert = ({ children, variant, ...props }: any) =>
188+
const Alert = ({ children, variant, ...props }: AlertProps) =>
149189
h('div', { ...props, className: `alert alert-${variant || 'primary'}` }, children);
150190

151191
const Spinner = ({ ...props }: MockComponentProps) =>
152192
h('div', { ...props, className: 'spinner' }, 'Loading...');
153193

154194
return {
155195
Alert,
156-
Button: ({ children, type, ...props }: any) => h('button', { ...props, type, 'data-testid': 'submit-button' }, children),
196+
Button: ({ children, type, ...props }: ButtonProps) => h('button', { ...props, type, 'data-testid': 'submit-button' }, children),
157197
ButtonGroup: ({ children, ...props }: MockComponentProps) => h('div', { ...props }, children),
158198
Card,
159199
Col: ({ children, ...props }: MockComponentProps) => h('div', { ...props, className: 'col' }, children),

0 commit comments

Comments
 (0)