forked from EnergySage/es-ds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEsFormTextarea.spec.js
105 lines (92 loc) · 3.32 KB
/
EsFormTextarea.spec.js
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
import { mount } from '@vue/test-utils';
import EsFormTextarea from '@/src/lib-components/EsFormTextarea.vue';
import jestVue from '@/tests/jest.vue.config';
describe('EsFormTextarea', () => {
// Basic test; should exist for most components
test('<EsFormTextarea />', async () => {
const wrapper = mount(EsFormTextarea, {
...jestVue,
slots: {
label: 'Notes',
},
propsData: {
id: 'myID',
},
});
const a11y = await axe(wrapper.element);
expect(wrapper.vm).toBeTruthy();
expect(wrapper.html()).toMatchSnapshot();
expect(a11y).toHaveNoViolations();
});
// Test slots are there
test('<EsFormTextarea>slots</EsFormTextarea>', async () => {
const wrapper = mount(EsFormTextarea, {
...jestVue,
slots: {
label: 'Notes',
message: 'Enter your notes here.',
errorMessage: 'Please enter a valid value.',
successMessage: 'Your response has been submitted successfully.',
},
propsData: {
id: 'myID',
},
});
expect(wrapper.vm).toBeTruthy();
expect(wrapper.html()).toMatchSnapshot();
expect(wrapper.vm.$slots.label[0].text).toBe('Notes');
expect(wrapper.vm.$slots.message[0].text).toBe('Enter your notes here.');
expect(wrapper.vm.$slots.errorMessage[0].text).toBe('Please enter a valid value.');
expect(wrapper.vm.$slots.successMessage[0].text).toBe('Your response has been submitted successfully.');
});
// Test label structure
test('<EsFormTextarea <label /> />', async () => {
const wrapper = mount(EsFormTextarea, {
...jestVue,
propsData: {
id: 'myID',
required: true,
},
});
expect(wrapper.vm).toBeTruthy();
expect(wrapper.html()).toMatchSnapshot();
const label = wrapper.find('label');
expect(label.exists()).toBe(true);
expect(label.find('*').exists()).toBe(true);
});
// Test props
test('<EsFormTextarea props />', async () => {
const wrapper = mount(EsFormTextarea, {
...jestVue,
propsData: {
id: 'myID',
required: true,
},
});
expect(wrapper.vm).toBeTruthy();
expect(wrapper.html()).toMatchSnapshot();
expect(wrapper.props('id')).toBe('myID');
expect(wrapper.props('state')).toBeNull();
});
// Test v-model
test('<EsFormTextarea v-model />', async () => {
const wrapper = mount({
...jestVue,
data() {
return {
textValue: '',
};
},
template: '<div> <EsFormTextarea data-testid="testTextarea" id="testId" v-model="textValue" /> </div>',
components: {
EsFormTextarea,
},
});
const testString = 'Test String';
const testTextarea = wrapper.find('[data-testid="testTextarea"]');
await testTextarea.setValue(testString);
expect(wrapper.vm).toBeTruthy();
expect(wrapper.html()).toMatchSnapshot();
expect(wrapper.vm.textValue).toBe(testString);
});
});