-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCanisterMonitorDialog.spec.ts
More file actions
73 lines (56 loc) · 2.24 KB
/
CanisterMonitorDialog.spec.ts
File metadata and controls
73 lines (56 loc) · 2.24 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
65
66
67
68
69
70
71
72
73
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 { flushPromises } from '@vue/test-utils';
import { services } from '~/plugins/services.plugin';
import CanisterMonitorDialog from '~/components/external-canisters/CanisterMonitorDialog.vue';
vi.mock('~/services/station.service', () => {
const mock: Partial<StationService> = {
withStationId: vi.fn().mockReturnThis(),
monitorExternalCanister: vi.fn().mockImplementation(() => Promise.reject()),
};
return {
StationService: vi.fn(() => mock),
};
});
describe('CanisterMonitorDialog', () => {
it('renders default card open is true', () => {
const wrapper = mount(CanisterMonitorDialog, {
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-monitor-card"]');
expect(container).not.toBeNull();
wrapper.unmount();
});
it('triggers submit when on click of save button', async () => {
const monitorMethod = vi
.spyOn(services().station, 'monitorExternalCanister')
.mockImplementation(() => Promise.reject());
const wrapper = mount(CanisterMonitorDialog, {
props: {
open: true,
canisterId: Principal.fromText('r7inp-6aaaa-aaaaa-aaabq-cai'),
attach: true, // disables teleport in VDialog
},
});
const strategyInput = wrapper.findComponent({ name: 'VSelect' });
await strategyInput.setValue('Always');
await flushPromises();
const nextBtn = wrapper.find('[data-test-id="monitor-dialog-stepper-next"]');
await nextBtn.trigger('click');
const obtainInput = wrapper.findComponent({ name: 'VSelect' });
await obtainInput.setValue('StationDefault');
const saveBtn = wrapper.find('[data-test-id="monitor-dialog-submit"]');
await saveBtn.trigger('click');
await flushPromises();
expect(monitorMethod).toHaveBeenCalledOnce();
wrapper.unmount();
});
});