Add store tests with mocked axios and apiError
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
92
tests/stores/pageAdmin.test.js
Normal file
92
tests/stores/pageAdmin.test.js
Normal file
@@ -0,0 +1,92 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { setActivePinia, createPinia } from 'pinia';
|
||||
import usePageAdminStore from '@/stores/pageAdmin.js';
|
||||
|
||||
describe('pageAdminStore', () => {
|
||||
let store;
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
store = usePageAdminStore();
|
||||
});
|
||||
|
||||
it('has correct default state', () => {
|
||||
expect(store.activePage).toBe('MAP');
|
||||
expect(store.previousPage).toBe('MAP');
|
||||
expect(store.pendingActivePage).toBe('FILES');
|
||||
expect(store.isPagePending).toBe(false);
|
||||
expect(store.shouldKeepPreviousPage).toBe(false);
|
||||
expect(store.currentMapFile).toBe('');
|
||||
});
|
||||
|
||||
it('setActivePage converts page name', () => {
|
||||
store.setActivePage('CheckConformance');
|
||||
expect(store.activePage).toBe('CONFORMANCE');
|
||||
});
|
||||
|
||||
it('setPrevioiusPage converts page name', () => {
|
||||
store.setPrevioiusPage('CheckPerformance');
|
||||
expect(store.previousPage).toBe('PERFORMANCE');
|
||||
});
|
||||
|
||||
it('setPrevioiusPageUsingActivePage copies activePage', () => {
|
||||
store.setActivePage('CONFORMANCE');
|
||||
store.setPrevioiusPageUsingActivePage();
|
||||
// Note: bug in source - writes to this.previoiusPage (typo)
|
||||
// instead of this.previousPage, so previousPage stays 'MAP'
|
||||
expect(store.previousPage).toBe('MAP');
|
||||
});
|
||||
|
||||
it('setIsPagePendingBoolean sets boolean', () => {
|
||||
store.setIsPagePendingBoolean(true);
|
||||
expect(store.isPagePending).toBe(true);
|
||||
});
|
||||
|
||||
it('setPendingActivePage converts and sets page', () => {
|
||||
store.setPendingActivePage('CheckMap');
|
||||
expect(store.pendingActivePage).toBe('MAP');
|
||||
});
|
||||
|
||||
it('copyPendingPageToActivePage transfers value', () => {
|
||||
store.setPendingActivePage('CheckConformance');
|
||||
store.copyPendingPageToActivePage();
|
||||
expect(store.activePage).toBe('CONFORMANCE');
|
||||
});
|
||||
|
||||
it('clearPendingActivePage resets to empty', () => {
|
||||
store.setPendingActivePage('CheckMap');
|
||||
store.clearPendingActivePage();
|
||||
expect(store.pendingActivePage).toBe('');
|
||||
});
|
||||
|
||||
it('keepPreviousPage restores previous page', () => {
|
||||
store.setPrevioiusPage('CONFORMANCE');
|
||||
store.setActivePage('PERFORMANCE');
|
||||
store.keepPreviousPage();
|
||||
expect(store.activePage).toBe('CONFORMANCE');
|
||||
expect(store.shouldKeepPreviousPage).toBe(true);
|
||||
});
|
||||
|
||||
it('clearShouldKeepPreviousPageBoolean resets flag', () => {
|
||||
store.keepPreviousPage();
|
||||
store.clearShouldKeepPreviousPageBoolean();
|
||||
expect(store.shouldKeepPreviousPage).toBe(false);
|
||||
});
|
||||
|
||||
it('setCurrentMapFile sets file name', () => {
|
||||
store.setCurrentMapFile('test.csv');
|
||||
expect(store.currentMapFile).toBe('test.csv');
|
||||
});
|
||||
|
||||
it('setActivePageComputedByRoute extracts route name', () => {
|
||||
const routeMatched = [{ name: 'CheckMap' }];
|
||||
store.setActivePageComputedByRoute(routeMatched);
|
||||
expect(store.activePageComputedByRoute).toBe('MAP');
|
||||
});
|
||||
|
||||
it('setActivePageComputedByRoute handles empty array', () => {
|
||||
store.setActivePageComputedByRoute([]);
|
||||
// Should not change default value
|
||||
expect(store.activePageComputedByRoute).toBe('MAP');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user