-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCanisterSnapshotRemoveDialog.spec.ts
More file actions
59 lines (48 loc) · 1.99 KB
/
Copy pathCanisterSnapshotRemoveDialog.spec.ts
File metadata and controls
59 lines (48 loc) · 1.99 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
import { Principal } from '@icp-sdk/core/principal';
import { describe, expect, it, vi } from 'vitest';
import { services } from '~/plugins/services.plugin';
import { StationService } from '~/services/station.service';
import { mount } from '~/test.utils';
import CanisterSnapshotRemoveDialog from './CanisterSnapshotRemoveDialog.vue';
vi.mock('~/services/station.service', () => {
const mock: Partial<StationService> = {
withStationId: vi.fn().mockReturnThis(),
removeExternalCanisterSnapshot: vi.fn().mockImplementation(() => Promise.reject()),
};
return {
StationService: vi.fn(() => mock),
};
});
describe('CanisterSnapshotRemoveDialog', () => {
it('renders default card open is true', () => {
const wrapper = mount(CanisterSnapshotRemoveDialog, {
props: {
open: true,
canisterId: Principal.fromText('r7inp-6aaaa-aaaaa-aaabq-cai'),
snapshot: { snapshotId: '1', takenAtTimestamp: '2024-12-01T10:00:00Z', totalSize: 100 },
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-snapshot-delete-card"]');
expect(container).not.toBeNull();
wrapper.unmount();
});
it('triggers submit when on click of save button', async () => {
const removeSnapshotMethod = vi
.spyOn(services().station, 'removeExternalCanisterSnapshot')
.mockImplementation(() => Promise.reject());
const wrapper = mount(CanisterSnapshotRemoveDialog, {
props: {
open: true,
canisterId: Principal.fromText('r7inp-6aaaa-aaaaa-aaabq-cai'),
snapshot: { snapshotId: '1', takenAtTimestamp: '2024-12-01T10:00:00Z', totalSize: 100 },
attach: true, // disables teleport in VDialog
},
});
const saveBtn = wrapper.find('[data-test-id="submit-btn"]');
await saveBtn.trigger('click');
expect(removeSnapshotMethod).toHaveBeenCalled();
});
});