-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCanisterInstallDialog.spec.ts
More file actions
64 lines (50 loc) · 2.06 KB
/
CanisterInstallDialog.spec.ts
File metadata and controls
64 lines (50 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Principal } from '@icp-sdk/core/principal';
import { describe, expect, it, vi } from 'vitest';
import { StationService } from '~/services/station.service';
import { mount } from '~/test.utils';
import CanisterInstallDialog from './CanisterInstallDialog.vue';
vi.mock('~/services/station.service', () => {
const mock: Partial<StationService> = {
withStationId: vi.fn().mockReturnThis(),
changeExternalCanister: vi.fn().mockImplementation(() => Promise.reject()),
};
return {
StationService: vi.fn(() => mock),
};
});
describe('CanisterInstallDialog', () => {
it('renders default card open is true', () => {
const wrapper = mount(CanisterInstallDialog, {
props: {
open: true,
canisterId: Principal.fromText('r7inp-6aaaa-aaaaa-aaabq-cai'),
attach: true, // disables teleport in VDialog
},
});
const dialog = wrapper.findComponent({ name: 'VDialog' });
expect(dialog.exists()).toBe(true);
const container = dialog.find('[data-test-id="canister-install-card"]');
expect(container).not.toBeNull();
wrapper.unmount();
});
it('triggers submit when on click of save button', async () => {
const wrapper = mount(CanisterInstallDialog, {
props: {
open: true,
canisterId: Principal.fromText('r7inp-6aaaa-aaaaa-aaabq-cai'),
attach: true, // disables teleport in VDialog
},
});
const form = wrapper.findComponent({ name: 'CanisterInstallForm' });
expect(form.exists()).toBe(true);
const wrapperVm = wrapper.vm as typeof wrapper.vm & { triggerFormSubmit: boolean };
expect(wrapperVm.triggerFormSubmit).toBe(false);
const saveBtn = wrapper.find('[data-test-id="canister-install-save-button"]');
await saveBtn.trigger('click');
// triggerSubmit is only set to false if the parent component first sets it to true first,
// instead of checking on the parent data directly, we check on the emitted event
// to avoid race conditions
expect(form.emitted('update:triggerSubmit')?.[0]).toEqual([false]);
wrapper.unmount();
});
});