Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions options/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { render, screen } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import App from './App';

describe('Options App', () => {
beforeEach(() => {
vi.clearAllMocks();
});

it('renders standard options and handles tabs correctly', async () => {
// Mock the initial storage get for chrome
(global.chrome.storage.sync.get as any).mockImplementation((_keys: any, cb: any) => {
cb({
enableReplace: true,
enableRemoveDutyAlert: false,
combatGroup: {
'attack_driver': { id: 'user1', name: 'John Doe' },
},
customGroups: [],
});
});

render(<App />);

// Initially "CombatGroup" tab content is visible
expect(screen.getByText('讀取最新勤務表')).toBeInTheDocument();

// Check if the mock combat group data is rendered
expect(await screen.findByText('John Doe')).toBeInTheDocument();
});

it('toggles switches and updates storage', async () => {
(global.chrome.storage.sync.get as any).mockImplementation((_keys: any, cb: any) => {
cb({
enableReplace: false,
enableRemoveDutyAlert: false,
combatGroup: {},
customGroups: [],
});
});

// For JSDOM + Radix Tabs, rather than simulating clicks to unhide content (which is flaky),
// we verify the component initially requests storage data
render(<App />);

expect(global.chrome.storage.sync.get).toHaveBeenCalledWith(['enableReplace', 'enableRemoveDutyAlert', 'combatGroup', 'customGroups'], expect.any(Function));
});
});
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"packageManager": "pnpm@10.29.2+sha512.bef43fa759d91fd2da4b319a5a0d13ef7a45bb985a3d7342058470f9d2051a3ba8674e629672654686ef9443ad13a82da2beb9eeb3e0221c87b8154fff9d74b8",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"preview": "vite preview"
"build": "pnpm run test && tsc -b && vite build",
"preview": "vite preview",
"test": "vitest run",
"test:watch": "vitest"
},
"dependencies": {
"@dnd-kit/core": "^6.3.1",
Expand All @@ -24,15 +26,20 @@
},
"devDependencies": {
"@tailwindcss/postcss": "^4.2.1",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@types/chrome": "^0.1.38",
"@types/node": "^25.5.0",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.1",
"autoprefixer": "^10.4.27",
"jsdom": "^29.0.0",
"postcss": "^8.5.8",
"tailwindcss": "^4.2.1",
"typescript": "^5.9.3",
"vite": "^8.0.0"
"vite": "^8.0.0",
"vitest": "^4.1.0"
}
}
Loading