From 309cbf0713fb86121f95a4f9db3910460c0b633c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 17 Jun 2026 14:52:25 +0000 Subject: [PATCH] test: add unit tests for slideInPanel store Add 12 unit tests covering the slideInPanel Vuex store: - state factory: correct initial values (isOpen, isClosing, component, componentProps) - mutations.open: sets isOpen, stores component, defaults componentProps to {}, uses provided componentProps - mutations.close: immediately sets isOpen=false and isClosing=true, defers component/componentProps/isClosing reset to 500ms (via fake timers) - namespaced: confirms namespaced flag Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- shell/store/__tests__/slideInPanel.test.ts | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 shell/store/__tests__/slideInPanel.test.ts diff --git a/shell/store/__tests__/slideInPanel.test.ts b/shell/store/__tests__/slideInPanel.test.ts new file mode 100644 index 00000000000..11a268db100 --- /dev/null +++ b/shell/store/__tests__/slideInPanel.test.ts @@ -0,0 +1,117 @@ +import slideInPanelStore, { SlideInPanelState } from '../slideInPanel'; + +const { state: makeState, mutations } = slideInPanelStore; + +const DEFAULT_STATE: SlideInPanelState = { + isOpen: false, + isClosing: false, + component: null, + componentProps: {}, +}; + +describe('store: slideInPanel', () => { + let state: SlideInPanelState; + + beforeEach(() => { + state = makeState(); + }); + + describe('state', () => { + it('returns the correct initial state', () => { + expect(state).toStrictEqual(DEFAULT_STATE); + }); + }); + + describe('mutations: open', () => { + const fakeComponent = { name: 'FakePanel' } as any; + + it('sets isOpen to true', () => { + mutations.open(state, { component: fakeComponent }); + + expect(state.isOpen).toBe(true); + }); + + it('stores the component', () => { + mutations.open(state, { component: fakeComponent }); + + expect(state.component).toBe(fakeComponent); + }); + + it('defaults componentProps to {} when not provided', () => { + mutations.open(state, { component: fakeComponent }); + + expect(state.componentProps).toStrictEqual({}); + }); + + it('uses provided componentProps', () => { + const props = { foo: 'bar', count: 3 }; + + mutations.open(state, { component: fakeComponent, componentProps: props }); + + expect(state.componentProps).toStrictEqual({ foo: 'bar', count: 3 }); + }); + }); + + describe('mutations: close', () => { + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + }); + + it('sets isOpen to false immediately', () => { + state.isOpen = true; + mutations.close(state); + + expect(state.isOpen).toBe(false); + }); + + it('sets isClosing to true immediately', () => { + mutations.close(state); + + expect(state.isClosing).toBe(true); + }); + + it('does not clear component immediately', () => { + const fakeComponent = { name: 'FakePanel' } as any; + + mutations.open(state, { component: fakeComponent }); + mutations.close(state); + + expect(state.component).not.toBeNull(); + }); + + it('clears component to null after 500ms', () => { + const fakeComponent = { name: 'FakePanel' } as any; + + mutations.open(state, { component: fakeComponent }); + mutations.close(state); + jest.advanceTimersByTime(500); + + expect(state.component).toBeNull(); + }); + + it('clears componentProps to {} after 500ms', () => { + mutations.open(state, { component: { name: 'C' } as any, componentProps: { x: 1 } }); + mutations.close(state); + jest.advanceTimersByTime(500); + + expect(state.componentProps).toStrictEqual({}); + }); + + it('sets isClosing to false after 500ms', () => { + mutations.close(state); + jest.advanceTimersByTime(500); + + expect(state.isClosing).toBe(false); + }); + }); + + describe('namespaced', () => { + it('is namespaced', () => { + expect(slideInPanelStore.namespaced).toBe(true); + }); + }); +});