-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCanisterIdField.spec.ts
More file actions
55 lines (45 loc) · 1.93 KB
/
CanisterIdField.spec.ts
File metadata and controls
55 lines (45 loc) · 1.93 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
import { Principal } from '@icp-sdk/core/principal';
import { describe, expect, it } from 'vitest';
import { mount } from '~/test.utils';
import CanisterIdField from './CanisterIdField.vue';
describe('CanisterIdField', () => {
it('renders with no canisterId in the input', () => {
const input = mount(CanisterIdField);
const displayInput = input.findComponent({ name: 'VTextField' });
expect(displayInput.exists()).toBe(true);
expect(displayInput.props('modelValue')).toEqual(undefined);
});
it('renders with the provided cansiterId', async () => {
const input = mount(CanisterIdField, {
props: {
modelValue: Principal.anonymous(),
},
});
const displayInput = input.findComponent({ name: 'VTextField' });
expect(displayInput.props('modelValue')).toEqual(Principal.anonymous().toText());
expect(input.props('modelValue')).toEqual(Principal.anonymous());
});
it('on change canisterId the emitted change is with the principal format', async () => {
const input = mount(CanisterIdField, {
props: {
modelValue: Principal.anonymous(),
},
});
const displayInput = input.findComponent({ name: 'VTextField' });
const updatedPrincipal = Principal.fromUint8Array(Uint8Array.from([1, 2, 3, 4, 5]));
await displayInput.setValue(updatedPrincipal.toText());
expect(displayInput.props('modelValue')).toEqual(updatedPrincipal.toText());
expect(input.emitted('update:modelValue')).toEqual([[updatedPrincipal]]);
});
it('on invalid change sets the canister id to undefined', async () => {
const input = mount(CanisterIdField, {
props: {
modelValue: Principal.anonymous(),
},
});
const displayInput = input.findComponent({ name: 'VTextField' });
await displayInput.setValue('invalid');
expect(displayInput.props('modelValue')).toEqual('invalid');
expect(input.emitted('update:modelValue')).toEqual([[undefined]]);
});
});