mirror of https://github.com/lxndrblz/anatole.git

google-labs-jules[bot]
5 hours ago 99d036f56da2cd91b5a8a976cc2947a628893722
test: add missing edge case test for theme switcher missing previous theme class

Co-authored-by: KarelZe <12801659+KarelZe@users.noreply.github.com>
2 files modified
1 files added
5743 ■■■■■ changed files
package-lock.json 5696 ●●●●● patch | view | raw | blame | history
package.json 4 ●●●●● patch | view | raw | blame | history
tests/anatole-theme-switcher.test.js 43 ●●●●● patch | view | raw | blame | history
package-lock.json
Diff too large
package.json
@@ -9,7 +9,7 @@
    "prepare": "husky",
    "release": "release-it",
    "setup": "npm install && npm run prepare",
    "test": ""
    "test": "jest"
  },
  "repository": {
    "type": "git",
@@ -34,6 +34,8 @@
    "@release-it/conventional-changelog": "^11.0.1",
    "conventional-commits-filter": "^6.0.1",
    "husky": "^9.1.7",
    "jest": "^30.5.2",
    "jest-environment-jsdom": "^30.5.2",
    "prettier": "^3.8.1",
    "prettier-plugin-go-template": "^0.0.15",
    "release-it": "^20.2.1",
tests/anatole-theme-switcher.test.js
New file
@@ -0,0 +1,43 @@
/**
 * @jest-environment jsdom
 */
const fs = require('fs');
const path = require('path');
describe('anatole-theme-switcher', () => {
  beforeAll(() => {
    const scriptPath = path.resolve(__dirname, '../assets/js/anatole-theme-switcher.js');
    const scriptContent = fs.readFileSync(scriptPath, 'utf8');
    // Mock matchMedia
    window.matchMedia = jest.fn().mockImplementation(query => ({
      matches: false,
      media: query,
      onchange: null,
      addListener: jest.fn(),
      removeListener: jest.fn(),
      addEventListener: jest.fn(),
      removeEventListener: jest.fn(),
      dispatchEvent: jest.fn(),
    }));
    // Evaluate the script and expose internal functions to window for testing
    eval(scriptContent + '\nwindow.setThemeStyle = setThemeStyle;');
  });
  beforeEach(() => {
    document.documentElement.className = '';
    localStorage.clear();
  });
  test('handles missing previous theme class correctly', () => {
    document.documentElement.className = 'non-theme-class';
    window.setThemeStyle('dark');
    // The new theme should be added
    expect(document.documentElement.classList.contains('theme--dark')).toBe(true);
    // Other classes should remain
    expect(document.documentElement.classList.contains('non-theme-class')).toBe(true);
  });
});