navigationSlice.test.ts1.8 KBView on GitHub /**
* Tests for NavigationSlice — category getter/setter and reset
*/
import { act } from '@testing-library/react';
import { useCedarStore } from '@/modules/cedar-os/src/store/CedarStore';
const resetNav = () =>
useCedarStore.setState((s) => ({
...s,
category: 'All Mail',
}));
beforeEach(resetNav);
afterEach(resetNav);
// ---------------------------------------------------------------------------
// setCategory
// ---------------------------------------------------------------------------
describe('setCategory', () => {
it('sets the category to a new value', () => {
act(() => useCedarStore.getState().setCategory('Inbox'));
expect(useCedarStore.getState().category).toBe('Inbox');
});
it('replaces an existing category', () => {
act(() => useCedarStore.getState().setCategory('Sent'));
act(() => useCedarStore.getState().setCategory('Drafts'));
expect(useCedarStore.getState().category).toBe('Drafts');
});
it('accepts arbitrary string values', () => {
act(() => useCedarStore.getState().setCategory('Custom Label'));
expect(useCedarStore.getState().category).toBe('Custom Label');
});
});
// ---------------------------------------------------------------------------
// resetNavigationState
// ---------------------------------------------------------------------------
describe('resetNavigationState', () => {
it('resets category to "All Mail"', () => {
act(() => useCedarStore.getState().setCategory('Inbox'));
act(() => useCedarStore.getState().resetNavigationState());
expect(useCedarStore.getState().category).toBe('All Mail');
});
it('is idempotent when already at initial state', () => {
act(() => useCedarStore.getState().resetNavigationState());
expect(useCedarStore.getState().category).toBe('All Mail');
});
});