11import { 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' ;
33import { signal } from '@preact/signals' ;
44
55// Use dynamic import so we can spy on named exports from the module
66const importComponent = ( ) => import ( '../RecoveryDataComponent' ) ;
77
88describe ( '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
108125describe ( '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