-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathArrayInput.spec.js
More file actions
115 lines (108 loc) · 3.34 KB
/
ArrayInput.spec.js
File metadata and controls
115 lines (108 loc) · 3.34 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { installQuasarPlugin } from '@quasar/quasar-app-extension-testing-unit-jest';
import { shallowMount } from '@vue/test-utils';
import ArrayInput from 'src/components/inputs/ArrayInput';
import { createI18n } from 'vue-i18n';
import i18nConfiguration from 'src/i18n';
import { ComponentAttributeDefinition } from 'leto-modelizer-plugin-core';
installQuasarPlugin();
describe('Test component: ArrayInput', () => {
const global = {
stubs: {
qSelect: true,
},
plugins: [
createI18n({
locale: 'en-US',
allowComposition: true,
messages: i18nConfiguration,
}),
],
};
describe('Test variables initialization', () => {
describe('Test prop: attribute', () => {
it('should be an object containing value', () => {
const wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: new ComponentAttributeDefinition(),
},
},
global,
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
expect(wrapper.vm.attribute.value).toEqual(['test']);
});
});
describe('Test variable: localValue', () => {
it('should match attribute.value', () => {
const wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: new ComponentAttributeDefinition(),
},
},
global,
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
expect(wrapper.vm.localValue).toEqual(['test']);
});
});
describe('Test variable: options', () => {
it('should not be null when the attribute has a definition and rules with values', () => {
const wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: new ComponentAttributeDefinition({
rules: {
values: ['value1', 'value2', 'value3'],
},
}),
},
},
global,
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
expect(wrapper.vm.options).toEqual(['value1', 'value2', 'value3']);
});
it('should be null when the attribute has a definition with no rules', () => {
const wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: new ComponentAttributeDefinition(),
},
},
global,
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
expect(wrapper.vm.options).toBeNull();
});
it('should be null and not raise an error when the attribute has no definition', () => {
const wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: null,
},
},
global,
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
expect(wrapper.vm.options).toBeNull();
});
});
});
});