Skip to content

Commit

Permalink
Add unit tests for etcd banner fix (#10692)
Browse files Browse the repository at this point in the history
* Add unit tests for etcd banner fix

* Fix lint issues
  • Loading branch information
nwmac committed Mar 28, 2024
1 parent 3a351ff commit 0770ab7
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions shell/components/__tests__/EtcdInfoBanner.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 0770ab7

Please sign in to comment.