-
Notifications
You must be signed in to change notification settings - Fork 51
/
ETextArea.spec.js
93 lines (82 loc) · 2.4 KB
/
ETextArea.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
import { describe, beforeEach, test, expect } from 'vitest'
import Vue from 'vue'
import Vuetify from 'vuetify'
import formBaseComponents from '@/plugins/formBaseComponents'
import { mount as mountComponent } from '@vue/test-utils'
import ETextarea from '../ETextarea.vue'
import { mockEventClass } from '@/test/mockEventClass'
Vue.use(Vuetify)
Vue.use(formBaseComponents)
mockEventClass('ClipboardEvent')
mockEventClass('DragEvent')
describe('An ETextArea', () => {
let vuetify
const multiLineText = `
Here comes a text
with new lines
and new lines with \n in them
and tags <i>a</i>
`
const mount = (
options,
template = `
<div data-app>
<e-textarea label="test" v-model="data"/>
</div>
`
) => {
const app = Vue.component('App', {
components: { ETextarea },
data: () => ({ data: null }),
template: template,
})
return mountComponent(app, { vuetify, attachTo: document.body, ...options })
}
beforeEach(() => {
vuetify = new Vuetify()
})
test('looks like a textarea', async () => {
const wrapper = mount()
expect(wrapper).toMatchSnapshot('notext')
await wrapper.setData({ data: multiLineText })
expect(wrapper).toMatchSnapshot('withtext')
const mountWithMultiLine = mount(
{ data: () => ({ data: multiLineText }) },
`
<div data-app>
<e-textarea label="test" v-model="data" multi-line/>
</div>
`
)
expect(mountWithMultiLine).toMatchSnapshot('multiline')
const mountAsinControls = mount(
{ data: () => ({ data: multiLineText }) },
`
<div data-app>
<e-textarea
v-model="data"
label="test"
:rows="3"
auto-grow
/>
</div>
`
)
expect(mountAsinControls).toMatchSnapshot('mountAsInControls')
})
test('updates the text with the viewmodel', async () => {
const wrapper = mount()
await wrapper.setData({ data: multiLineText })
const textWithoutMultiLine = multiLineText
.replace(/\n\s*/g, ' ')
.replace(' ', ' ')
.replace('<i>', '')
.replace('</i>', '')
.trim()
expect(wrapper.find('.editor__content').text()).toBe(textWithoutMultiLine)
expect(wrapper.find('.e-form-container').element.getAttribute('value')).toBe(
multiLineText
)
expect(wrapper.vm.data).toBe(multiLineText)
})
})