-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCanisterSetupDialog.spec.ts
More file actions
77 lines (63 loc) · 2.36 KB
/
CanisterSetupDialog.spec.ts
File metadata and controls
77 lines (63 loc) · 2.36 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
74
75
76
77
import { Principal } from '@icp-sdk/core/principal';
import { flushPromises } from '@vue/test-utils';
import { describe, expect, it, vi } from 'vitest';
import { GetExternalCanisterResult } from '~/generated/station/station.did';
import { services } from '~/plugins/services.plugin';
import { StationService } from '~/services/station.service';
import { mount } from '~/test.utils';
import { ExtractOk } from '~/types/helper.types';
import CanisterSetupDialog from './CanisterSetupDialog.vue';
vi.mock('~/services/station.service', () => {
const mock: Partial<StationService> = {
withStationId: vi.fn().mockReturnThis(),
getExternalCanisterByCanisterId: vi
.fn()
.mockImplementation(() => Promise.reject(new Error('Failed to load canister'))),
fetchExternalCanisterFilters: vi.fn().mockImplementation(() =>
Promise.resolve({
labels: [['production']],
names: [],
}),
),
};
return {
StationService: vi.fn(() => mock),
};
});
describe('CanisterSetupDialog', () => {
it('renders the error card if load fails', async () => {
const wrapper = mount(CanisterSetupDialog, {
props: {
modelValue: true,
canisterId: Principal.anonymous(),
},
});
const dialog = wrapper.findComponent({ name: 'VDialog' });
expect(dialog.exists()).toBe(true);
// this is needed to wait for the load call to finish
await flushPromises();
const errorCard = document.querySelector('[data-test-id="canister-setup-error-card"]');
expect(errorCard).not.toBeNull();
wrapper.unmount();
});
it('renders default card if load is ok', async () => {
vi.spyOn(services().station, 'getExternalCanisterByCanisterId').mockResolvedValueOnce(
{} as ExtractOk<GetExternalCanisterResult>,
);
const wrapper = mount(CanisterSetupDialog, {
props: {
modelValue: true,
canisterId: undefined,
},
});
const dialog = wrapper.findComponent({ name: 'VDialog' });
expect(dialog.exists()).toBe(true);
// this is needed to wait for the load call to finish
await flushPromises();
const errorCard = document.querySelector('[data-test-id="canister-setup-error-card"]');
const okCard = document.querySelector('[data-test-id="canister-setup-ok-card"]');
expect(errorCard).toBeNull();
expect(okCard).not.toBeNull();
wrapper.unmount();
});
});