Skip to content

Commit 5829759

Browse files
committed
feat: update failing tests
1 parent ba48e35 commit 5829759

3 files changed

Lines changed: 103 additions & 91 deletions

File tree

src/projectmanager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ class ProjectManager {
1010
#libraryContainer;
1111

1212
constructor() {
13-
this.#currentProject =
14-
this.#loadFromStorage() || this.#createEmptyProject();
1513
this.#isReplaying = false;
1614
this.#libraryContainer = null;
15+
this.#currentProject = this.#createEmptyProject();
1716
}
1817

1918
init() {
19+
this.#currentProject =
20+
this.#loadFromStorage() || this.#createEmptyProject();
21+
2022
dbManager.init().then(async () => {
2123
await this.#hydrateActiveFiles();
2224
this.renderLibrary();

tests/preferences.test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import { 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

812
describe('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

Comments
 (0)