Skip to content

Commit 9add114

Browse files
committed
frontend: fix tests
1 parent 6be0f2a commit 9add114

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

frontend/src/components/RecoveryDataComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function RecoveryDataComponent(props: RecoveryDataProps) {
6969
id="recovery-confirmation"
7070
label={t("save_recovery_data_confirmation")}
7171
checked={confirmed.value}
72-
onChange={(e: any) => { confirmed.value = e.target.checked; }}
72+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { confirmed.value = e.currentTarget.checked; }}
7373
className="mt-3"
7474
/>
7575
)}

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ describe('RecoveryDataComponent', () => {
1818
const email = '[email protected]';
1919
const secret = new Uint8Array([1, 2, 3]);
2020

21+
// Mock the anchor click to avoid interference with other tests
22+
const clickSpy = vi
23+
.spyOn(HTMLAnchorElement.prototype as unknown as { click: () => void }, 'click')
24+
.mockImplementation(() => {
25+
// Mock implementation for testing. This is comment is to silence lint warnings
26+
});
27+
2128
render(<RecoveryDataComponent email={email} secret={secret} show={show} />);
2229

2330
expect(screen.getByTestId('modal-title').textContent).toBe('save_recovery_data');
@@ -51,13 +58,22 @@ describe('RecoveryDataComponent', () => {
5158

5259
fireEvent.click(closeButton);
5360
expect(show.value).toBe(false);
61+
62+
clickSpy.mockRestore();
5463
});
5564

5665
it('prevents closing modal until file is saved and confirmed', async () => {
5766
const { RecoveryDataComponent } = await importComponent();
5867

5968
const show = signal(true);
6069

70+
// Mock the anchor click to avoid interference with other tests
71+
const clickSpy = vi
72+
.spyOn(HTMLAnchorElement.prototype as unknown as { click: () => void }, 'click')
73+
.mockImplementation(() => {
74+
// Mock implementation for testing. This is comment is to silence lint warnings
75+
});
76+
6177
render(<RecoveryDataComponent email={'[email protected]'} secret={new Uint8Array()} show={show} />);
6278

6379
// Try to close the modal without saving/confirming - should not close
@@ -81,9 +97,11 @@ describe('RecoveryDataComponent', () => {
8197
await waitFor(() => {
8298
expect(closeButton).not.toBeDisabled();
8399
});
84-
100+
85101
fireEvent.click(closeButton);
86102
expect(show.value).toBe(false);
103+
104+
clickSpy.mockRestore();
87105
});
88106
});
89107

@@ -117,6 +135,11 @@ describe('saveRecoveryData', () => {
117135
expect(clickSpy).toHaveBeenCalledTimes(1);
118136
expect(revokeUrl).toHaveBeenCalledWith('blob:test-url');
119137

120-
expect(window.crypto.subtle.digest).toHaveBeenCalledWith('SHA-256', expect.anything());
138+
expect(window.crypto.subtle.digest).toHaveBeenCalledWith('SHA-256', expect.anything());
139+
140+
// Clean up spies
141+
createUrl.mockRestore();
142+
clickSpy.mockRestore();
143+
revokeUrl.mockRestore();
121144
});
122145
});

frontend/src/pages/Recovery.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ export function Recovery() {
148148
<p>{t("recovery.no_file_warning_body")}</p>
149149
<Form.Check
150150
type="checkbox"
151-
id="no-file-ack"
151+
id="acknowledge-no-file"
152152
label={t("recovery.no_file_warning_ack")}
153153
checked={acknowledgeNoFile.value}
154-
onChange={(e: any) => { acknowledgeNoFile.value = e.target.checked; }}
154+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => { acknowledgeNoFile.value = e.currentTarget.checked; }}
155155
/>
156156
</Modal.Body>
157157
<Modal.Footer>

0 commit comments

Comments
 (0)