11import { jest , describe , test , expect , beforeEach } from '@jest/globals' ;
22
3- import { Preferences } from '../src/preferences.js' ;
4- import { UI } from '../src/ui.js' ;
3+ await jest . unstable_mockModule ( '../src/ui.js' , ( ) => ( {
4+ UI : {
5+ setTheme : jest . fn ( ) ,
6+ } ,
7+ } ) ) ;
58
6- UI . setTheme = jest . fn ( ) ;
9+ const { Preferences } = await import ( '../src/preferences.js' ) ;
10+ const { UI } = await import ( '../src/ui.js' ) ;
711
812describe ( 'Preferences Module' , ( ) => {
913 beforeEach ( ( ) => {
10- // 2. Set up the DOM structure expected by Preferences
1114 document . body . innerHTML = `
1215 <div class="preferences-list">
1316 <input type="checkbox" id="pref-persistence" />
1417 <input type="checkbox" id="pref-performance" />
1518 <input type="checkbox" id="pref-theme-dark" />
1619 <input type="checkbox" id="pref-custom-palette" />
20+ <input type="checkbox" id="pref-remember-files" />
1721 </div>
1822 ` ;
1923 localStorage . clear ( ) ;
@@ -41,7 +45,6 @@ describe('Preferences Module', () => {
4145 } ) ;
4246
4347 test ( 'init sets theme and attaches listeners' , ( ) => {
44- // 1. Setup localStorage so loadPreferences() sees the dark theme as active
4548 localStorage . setItem (
4649 Preferences . PREFS_KEY ,
4750 JSON . stringify ( {
@@ -52,15 +55,11 @@ describe('Preferences Module', () => {
5255
5356 const themeToggle = document . getElementById ( 'pref-theme-dark' ) ;
5457
55- // 2. Run init
5658 Preferences . init ( ) ;
5759
58- // Now it should be checked because loadPreferences() set it
5960 expect ( themeToggle . checked ) . toBe ( true ) ;
60- // And UI.setTheme should be called with 'dark'
6161 expect ( UI . setTheme ) . toHaveBeenCalledWith ( 'dark' ) ;
6262
63- // 3. Test the toggle listener
6463 themeToggle . checked = false ;
6564 themeToggle . dispatchEvent ( new Event ( 'change' ) ) ;
6665
0 commit comments