Add store tests with mocked axios and apiError

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 19:30:33 +08:00
parent 83c2db7582
commit 529e9a4aa1
12 changed files with 1260 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { setActivePinia, createPinia } from 'pinia';
import { useModalStore } from '@/stores/modal.js';
import { MODAL_ACCT_INFO, MODAL_DELETE } from '@/constants/constants.js';
describe('modalStore', () => {
let store;
beforeEach(() => {
setActivePinia(createPinia());
store = useModalStore();
});
it('has default state', () => {
expect(store.isModalOpen).toBe(false);
expect(store.whichModal).toBe(MODAL_ACCT_INFO);
});
it('openModal sets isModalOpen and whichModal', () => {
store.openModal(MODAL_DELETE);
expect(store.isModalOpen).toBe(true);
expect(store.whichModal).toBe(MODAL_DELETE);
});
it('closeModal sets isModalOpen to false', async () => {
store.openModal(MODAL_DELETE);
await store.closeModal();
expect(store.isModalOpen).toBe(false);
});
});