Skip to content

Commit 1ce797c

Browse files
committed
frontend: fix tests
1 parent 511302a commit 1ce797c

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

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

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
import { render, screen, fireEvent, waitFor, within } from '@testing-library/preact';
2-
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
33
import { signal } from '@preact/signals';
44

55
// Use dynamic import so we can spy on named exports from the module
66
const importComponent = () => import('../RecoveryDataComponent');
77

88
describe('RecoveryDataComponent', () => {
9+
const originalOrigin = globalThis.origin;
10+
911
beforeEach(() => {
1012
vi.clearAllMocks();
13+
// Mock the origin global variable
14+
Object.defineProperty(globalThis, 'origin', {
15+
value: 'https://my.warp-charger.com',
16+
writable: true,
17+
configurable: true,
18+
});
19+
});
20+
21+
afterEach(() => {
22+
// Restore original origin
23+
Object.defineProperty(globalThis, 'origin', {
24+
value: originalOrigin,
25+
writable: true,
26+
configurable: true,
27+
});
1128
});
1229

1330
it('renders modal content when shown and triggers save with confirmation', async () => {
@@ -106,14 +123,31 @@ describe('RecoveryDataComponent', () => {
106123
});
107124

108125
describe('saveRecoveryData', () => {
126+
const originalOrigin = globalThis.origin;
127+
109128
beforeEach(() => {
110129
vi.clearAllMocks();
130+
// Mock the origin global variable
131+
Object.defineProperty(globalThis, 'origin', {
132+
value: 'https://my.warp-charger.com',
133+
writable: true,
134+
configurable: true,
135+
});
136+
});
137+
138+
afterEach(() => {
139+
// Restore original origin
140+
Object.defineProperty(globalThis, 'origin', {
141+
value: originalOrigin,
142+
writable: true,
143+
configurable: true,
144+
});
111145
});
112146

113147
it('creates a downloadable backup file and revokes URL', async () => {
114148
const { saveRecoveryData } = await importComponent();
115149

116-
const email = '[email protected]';
150+
const email = '[email protected]';
117151
const secret = new Uint8Array([9, 8, 7, 6]);
118152

119153
const createUrl = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:test-url');
@@ -122,7 +156,7 @@ describe('saveRecoveryData', () => {
122156
const clickSpy = vi
123157
.spyOn(HTMLAnchorElement.prototype as unknown as { click: () => void }, 'click')
124158
.mockImplementation(function (this: HTMLAnchorElement) {
125-
expect(this.download).toBe('john_doe_at_example_com_my_warp_charger_com_recovery_data');
159+
expect(this.download).toBe('john_doe_at_example_com_my_warp-charger.com_recovery_data');
126160
});
127161

128162
const hashBytes = new Uint8Array([1, 2, 3, 4]).buffer;

0 commit comments

Comments
 (0)