Skip to content

Commit cc3eccc

Browse files
committed
updated test unit
1 parent b722420 commit cc3eccc

12 files changed

+368
-31
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
docs
22
dist
3-
tests

tests/component/component.custom.spec.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { mount } from '@vue/test-utils'
22
import VueNumber from '../../src/component.vue'
33

4-
describe('VueNumber', () => {
5-
test('should emit input event with the new value on input', async () => {
4+
describe('VueNumber custom config', () => {
5+
test('should emit input event with the new maskedValue on input', async () => {
66
const wrapper = mount(VueNumber, {
77
propsData: {
88
value: 123456.893,
@@ -33,4 +33,36 @@ describe('VueNumber', () => {
3333

3434
expect(wrapper.vm.maskedValue).toBe('Rs.1.234,57%')
3535
})
36+
37+
test('should emit input event with the new unmaskedValue on input', async () => {
38+
const wrapper = mount(VueNumber, {
39+
propsData: {
40+
value: 123456.893,
41+
decimal: ',',
42+
separator: '.',
43+
prefix: 'Rs.',
44+
suffix: '%'
45+
}
46+
})
47+
48+
const input = wrapper.find('input')
49+
50+
await input.trigger('input')
51+
52+
expect(wrapper.vm.unmaskedValue).toBe('123456.89')
53+
54+
await input.trigger('blur')
55+
56+
expect(wrapper.vm.unmaskedValue).toBe('123456.89')
57+
58+
input.element.value = 1234.568
59+
60+
await input.trigger('input')
61+
62+
expect(wrapper.vm.unmaskedValue).toBe('1234.57')
63+
64+
await input.trigger('blur')
65+
66+
expect(wrapper.vm.unmaskedValue).toBe('1234.57')
67+
})
3668
})

tests/component/component.minimumFractionDigits.spec.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { mount } from '@vue/test-utils'
22
import VueNumber from '../../src/component.vue'
33

4-
describe('VueNumber', () => {
5-
test('should emit input event with minimum fraction digits', async () => {
4+
describe('VueNumber with minimum fraction digits', () => {
5+
test('should emit input event with the new maskedValue on input', async () => {
66
const wrapper = mount(VueNumber, {
77
propsData: {
88
value: 123456.893,
@@ -30,4 +30,33 @@ describe('VueNumber', () => {
3030

3131
expect(wrapper.vm.maskedValue).toBe('1,234.50')
3232
})
33+
34+
test('should emit input event with the new unmaskedValue on input', async () => {
35+
const wrapper = mount(VueNumber, {
36+
propsData: {
37+
value: 123456.893,
38+
minimumFractionDigits: 2
39+
}
40+
})
41+
42+
const input = wrapper.find('input')
43+
44+
await input.trigger('input')
45+
46+
expect(wrapper.vm.unmaskedValue).toBe('123456.89')
47+
48+
await input.trigger('blur')
49+
50+
expect(wrapper.vm.unmaskedValue).toBe('123456.89')
51+
52+
input.element.value = '1234.5'
53+
54+
await input.trigger('input')
55+
56+
expect(wrapper.vm.unmaskedValue).toBe('1234.5')
57+
58+
await input.trigger('blur')
59+
60+
expect(wrapper.vm.unmaskedValue).toBe('1234.5')
61+
})
3362
})

tests/component/component.range.spec.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { mount } from '@vue/test-utils'
22
import VueNumber from '../../src/component.vue'
33

4-
describe('VueNumber', () => {
5-
test('should emit input event within range', async () => {
4+
describe('VueNumber within range', () => {
5+
test('should emit input event with the new maskedValue on input', async () => {
66
const wrapper = mount(VueNumber, {
77
propsData: {
88
value: 1.893,
@@ -35,4 +35,38 @@ describe('VueNumber', () => {
3535

3636
expect(wrapper.vm.maskedValue).toBe('12.57')
3737
})
38+
39+
test('should emit input event with the new unmaskedValue on input', async () => {
40+
const wrapper = mount(VueNumber, {
41+
propsData: {
42+
value: 1.893,
43+
min: 0,
44+
max: 50
45+
}
46+
})
47+
48+
const input = wrapper.find('input')
49+
50+
await input.trigger('blur')
51+
52+
expect(wrapper.vm.unmaskedValue).toBe('1.89')
53+
54+
input.element.value = '1234.568'
55+
56+
await input.trigger('blur')
57+
58+
expect(wrapper.vm.unmaskedValue).toBe('50')
59+
60+
input.element.value = '-1234.568'
61+
62+
await input.trigger('blur')
63+
64+
expect(wrapper.vm.unmaskedValue).toBe('0')
65+
66+
input.element.value = '12.568'
67+
68+
await input.trigger('blur')
69+
70+
expect(wrapper.vm.unmaskedValue).toBe('12.57')
71+
})
3872
})

tests/component/component.reverseFill.spec.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { mount } from '@vue/test-utils'
22
import VueNumber from '../../src/component.vue'
33

4-
describe('VueNumber', () => {
5-
test('should emit input event with reverse fill', async () => {
4+
describe('VueNumber reverse fill', () => {
5+
test('should emit input event with the new maskedValue on input', async () => {
66
const wrapper = mount(VueNumber, {
77
propsData: {
88
value: 123456.893,
@@ -30,4 +30,33 @@ describe('VueNumber', () => {
3030

3131
expect(wrapper.vm.maskedValue).toBe('12,345.68')
3232
})
33+
34+
test('should emit input event with the new unmaskedValue on input', async () => {
35+
const wrapper = mount(VueNumber, {
36+
propsData: {
37+
value: 123456.893,
38+
reverseFill: true
39+
}
40+
})
41+
42+
const input = wrapper.find('input')
43+
44+
await input.trigger('input')
45+
46+
expect(wrapper.vm.unmaskedValue).toBe('123456.89')
47+
48+
await input.trigger('blur')
49+
50+
expect(wrapper.vm.unmaskedValue).toBe('123456.89')
51+
52+
input.element.value = '1234568'
53+
54+
await input.trigger('input')
55+
56+
expect(wrapper.vm.unmaskedValue).toBe('12345.68')
57+
58+
await input.trigger('blur')
59+
60+
expect(wrapper.vm.unmaskedValue).toBe('12345.68')
61+
})
3362
})

tests/component/component.spec.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { mount } from '@vue/test-utils'
22
import VueNumber from '../../src/component.vue'
33

44
describe('VueNumber', () => {
5-
test('should emit input event with the new value on input', async () => {
5+
it('renders an input element', () => {
6+
const wrapper = mount(VueNumber, {
7+
propsData: {
8+
value: '123'
9+
}
10+
})
11+
expect(wrapper.contains('input')).toBe(true)
12+
})
13+
14+
test('should emit input event with the new maskedValue on input', async () => {
615
const wrapper = mount(VueNumber, {
716
propsData: {
817
value: 123456.893
@@ -29,4 +38,32 @@ describe('VueNumber', () => {
2938

3039
expect(wrapper.vm.maskedValue).toBe('1,234.57')
3140
})
41+
42+
test('should emit input event with the new unmaskedValue on input', async () => {
43+
const wrapper = mount(VueNumber, {
44+
propsData: {
45+
value: 123456.893
46+
}
47+
})
48+
49+
const input = wrapper.find('input')
50+
51+
await input.trigger('input')
52+
53+
expect(wrapper.vm.unmaskedValue).toBe('123456.89')
54+
55+
await input.trigger('blur')
56+
57+
expect(wrapper.vm.unmaskedValue).toBe('123456.89')
58+
59+
input.element.value = '1234.568'
60+
61+
await input.trigger('input')
62+
63+
expect(wrapper.vm.unmaskedValue).toBe('1234.57')
64+
65+
await input.trigger('blur')
66+
67+
expect(wrapper.vm.unmaskedValue).toBe('1234.57')
68+
})
3269
})
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { mount } from '@vue/test-utils'
2+
import directive from '../../src/directive'
3+
4+
describe('v-number directive', () => {
5+
it('should emit input event with the new value on input', async () => {
6+
const wrapper = mount({
7+
template: `<input v-number="options" type="text" v-model="value" />`,
8+
directives: {
9+
number: directive
10+
},
11+
data() {
12+
return {
13+
value: 123456.893,
14+
options: {
15+
decimal: ',',
16+
separator: '.',
17+
prefix: 'Rs.',
18+
suffix: '%'
19+
}
20+
}
21+
}
22+
})
23+
24+
const input = wrapper.find('input')
25+
26+
await input.trigger('input')
27+
28+
expect(input.element.value).toBe('Rs.123.456,893%')
29+
30+
await input.trigger('blur')
31+
32+
expect(input.element.value).toBe('Rs.123.456,89%')
33+
34+
input.element.value = 1234.568
35+
36+
await input.trigger('input')
37+
38+
expect(input.element.value).toBe('Rs.1.234,568%')
39+
40+
await input.trigger('blur')
41+
42+
expect(input.element.value).toBe('Rs.1.234,57%')
43+
})
44+
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { mount } from '@vue/test-utils'
2+
import directive from '../../src/directive'
3+
4+
describe('v-number directive', () => {
5+
test('should emit input event with minimum fraction digits', async () => {
6+
const wrapper = mount({
7+
template: `<input v-number="options" type="text" v-model="value" />`,
8+
directives: {
9+
number: directive
10+
},
11+
data() {
12+
return {
13+
value: 123456.893,
14+
options: {
15+
minimumFractionDigits: 2
16+
}
17+
}
18+
}
19+
})
20+
21+
const input = wrapper.find('input')
22+
23+
await input.trigger('input')
24+
25+
expect(input.element.value).toBe('123,456.893')
26+
27+
await input.trigger('blur')
28+
29+
expect(input.element.value).toBe('123,456.89')
30+
31+
input.element.value = '1234.5'
32+
33+
await input.trigger('input')
34+
35+
expect(input.element.value).toBe('1,234.5')
36+
37+
await input.trigger('blur')
38+
39+
expect(input.element.value).toBe('1,234.50')
40+
})
41+
})
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { mount } from '@vue/test-utils'
2+
import directive from '../../src/directive'
3+
4+
describe('v-number directive', () => {
5+
it('should emit input event within range', async () => {
6+
const wrapper = mount({
7+
template: `<input v-number="options" type="text" v-model="value" />`,
8+
directives: {
9+
number: directive
10+
},
11+
data() {
12+
return {
13+
value: 1.53,
14+
options: {
15+
min: 0,
16+
max: 50
17+
}
18+
}
19+
}
20+
})
21+
22+
const input = wrapper.find('input')
23+
await input.trigger('input')
24+
25+
expect(input.element.value).toBe('1.53')
26+
27+
input.element.value = '1234.529'
28+
await input.trigger('blur')
29+
30+
expect(input.element.value).toBe('50')
31+
32+
input.element.value = '-1234.568'
33+
34+
await input.trigger('blur')
35+
36+
expect(input.element.value).toBe('0')
37+
38+
input.element.value = '12.568'
39+
40+
await input.trigger('blur')
41+
42+
expect(input.element.value).toBe('12.57')
43+
})
44+
})

0 commit comments

Comments
 (0)