From 0770ab76e5894549a5d2538289dba365ae4e120f Mon Sep 17 00:00:00 2001 From: Neil MacDougall Date: Thu, 28 Mar 2024 16:58:39 +0000 Subject: [PATCH] Add unit tests for etcd banner fix (#10692) * Add unit tests for etcd banner fix * Fix lint issues --- .../__tests__/EtcdInfoBanner.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 shell/components/__tests__/EtcdInfoBanner.test.ts diff --git a/shell/components/__tests__/EtcdInfoBanner.test.ts b/shell/components/__tests__/EtcdInfoBanner.test.ts new file mode 100644 index 00000000000..5caa0ce9780 --- /dev/null +++ b/shell/components/__tests__/EtcdInfoBanner.test.ts @@ -0,0 +1,39 @@ +import { mount } from '@vue/test-utils'; +import EtcdInfoBanner from '../EtcdInfoBanner.vue'; +import { cleanHtmlDirective } from '@shell/plugins/clean-html-directive'; +import { CATALOG } from '@shell/config/types'; + +describe('component: EtcdInfoBanner', () => { + it('should perform fetch correctly', async() => { + const mockCanList = jest.fn((resource: string) => true); + const mockDispatch = jest.fn((resource: string, param: any) => ({ data: { result: [] } })); + + const wrapper = mount( + EtcdInfoBanner, + { + directives: { cleanHtmlDirective }, + mocks: { + $store: { + getters: { + 'i18n/t': () => 'Test', + currentProduct: { inStore: 'cluster' }, + 'cluster/canList': mockCanList, + currentCluster: { id: 'local' }, + }, + dispatch: mockDispatch, + }, + $fetchState: { pending: false } + } + }); + + await (EtcdInfoBanner as any).fetch.call(wrapper.vm); + + // canList should have been called once + expect(mockCanList.mock.calls).toHaveLength(1); + expect(mockCanList.mock.calls[0][0]).toBe(CATALOG.APP); + + // check that the if in the find method worked correctly + expect(mockDispatch.mock.calls).toHaveLength(4); + expect(mockDispatch.mock.calls[0][0]).toBe('cluster/find'); + }); +});