Skip to content

Commit 85cbd5e

Browse files
author
Arthur Ayvazov
committed
geophystech#137 User components forms tests.
1 parent b382dec commit 85cbd5e

10 files changed

+74
-62
lines changed

src/components/users/Authentication.vue

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
maxlength="150"
2222
pattern="[^@\s]+@[^@\s]+\.[^@\s]+"
2323
placeholder="Электронная почта"
24+
name="email"
2425
required>
2526
</b-form-input>
2627
<b-form-invalid-feedback>{{ form.messages.email }}</b-form-invalid-feedback>
@@ -34,6 +35,7 @@
3435
placeholder="Пароль"
3536
minlength="6"
3637
maxlength="150"
38+
name="password"
3739
required>
3840
</b-form-input>
3941
<b-form-invalid-feedback>{{ form.messages.password }}</b-form-invalid-feedback>

src/components/users/ConfirmPassword.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
:state="form.fields.password.state"
3333
v-model="form.fields.password.value"
3434
placeholder="Новый пароль"
35-
minlength="6"
35+
name="password"
3636
maxlength="150"
37+
minlength="6"
3738
required>
3839
</b-form-input>
3940
<b-form-invalid-feedback>{{ form.messages.password }}</b-form-invalid-feedback>

src/components/users/Registration.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
:disabled="form.fields.email.disabled"
4040
:state="form.fields.email.state"
4141
v-model="form.fields.email.value"
42-
maxlength="150"
4342
pattern="[^@\s]+@[^@\s]+\.[^@\s]+"
4443
placeholder="Электронная почта"
44+
maxlength="150"
45+
name="email"
4546
required>
4647
</b-form-input>
4748
<b-form-invalid-feedback>{{ form.messages.email }}</b-form-invalid-feedback>
@@ -53,8 +54,9 @@
5354
:state="form.fields.password.state"
5455
v-model="form.fields.password.value"
5556
placeholder="Пароль"
56-
minlength="6"
5757
maxlength="150"
58+
name="password"
59+
minlength="6"
5860
required>
5961
</b-form-input>
6062
<b-form-invalid-feedback>{{ form.messages.password }}</b-form-invalid-feedback>
@@ -67,6 +69,7 @@
6769
v-model="form.fields.company.value"
6870
placeholder="Организация"
6971
maxlength="150"
72+
name="company"
7073
required>
7174
</b-form-input>
7275
<b-form-invalid-feedback>{{ form.messages.company }}</b-form-invalid-feedback>
@@ -78,6 +81,7 @@
7881
:disabled="form.fields.purpose.disabled"
7982
:options="form.purposes.values"
8083
placeholder="Цель использования расширенных данных"
84+
name="purpose"
8185
required />
8286
<b-form-invalid-feedback>{{ form.messages.purpose }}</b-form-invalid-feedback>
8387
</b-form-group>
@@ -88,6 +92,7 @@
8892
:state="form.fields.fullname.state"
8993
v-model="form.fields.fullname.value"
9094
placeholder="Фамилия, имя и отчество"
95+
name="fullname"
9196
maxlength="150"
9297
required>
9398
</b-form-input>
@@ -107,6 +112,7 @@
107112
class="additional-info"
108113
placeholder="Дополнительная информация"
109114
maxlength="2000"
115+
name="additionalInfo"
110116
v-show="form.showAdditionalInfo">
111117
</b-form-textarea>
112118
</b-form-group>

src/components/users/ResetPassword.vue

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
maxlength="150"
3131
pattern="[^@\s]+@[^@\s]+\.[^@\s]+"
3232
placeholder="Электронная почта"
33+
name="email"
3334
required>
3435
</b-form-input>
3536
<b-form-invalid-feedback>{{ form.messages.email }}</b-form-invalid-feedback>

test/unit/specs/Filters.spec.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { shallowMount, createLocalVue } from '@vue/test-utils'
22
import Filters from '@/components/Filters'
33
import BootstrapVue from 'bootstrap-vue'
4-
import { $routerMocks, eventFilters } from '../utils'
4+
import { $routerMocks, describeCheckFormFields } from '../utils'
55
import $moment from 'moment'
66
import $http from 'axios'
77

@@ -28,18 +28,23 @@ describe('Filters.vue', () => {
2828
expect(wrapper.is(Filters)).to.eql(true)
2929
})
3030

31-
describe('Check filter fields', () => {
32-
33-
for (let item of Object.entries(eventFilters))
34-
{
35-
const [filterName, filterConf] = item
36-
const field = wrapper.find(`${filterConf.tag}[name="${filterName}"]`)
37-
38-
it(`Check filter ${filterName}`, () => {
39-
expect(field.exists()).to.eql(true)
40-
})
31+
describeCheckFormFields(wrapper, {
32+
label: 'Check filter fields',
33+
fields: {
34+
datetime_max: { tag: 'flat-pickr-stub' },
35+
datetime_min: { tag: 'flat-pickr-stub' },
36+
depth_max: { tag: 'b-form-input-stub' },
37+
depth_min: { tag: 'b-form-input-stub' },
38+
has_mt: { tag: 'b-form-checkbox-stub' },
39+
mag_max: { tag: 'b-form-input-stub' },
40+
mag_min: { tag: 'b-form-input-stub' },
41+
lat_max: { tag: 'b-form-input-stub' },
42+
lat_min: { tag: 'b-form-input-stub' },
43+
lon_max: { tag: 'b-form-input-stub' },
44+
lon_min: { tag: 'b-form-input-stub' },
45+
rms_max: { tag: 'b-form-input-stub' },
46+
sta_num_min: { tag: 'b-form-input-stub' }
4147
}
42-
4348
})
4449

4550
})
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { shallowMount, createLocalVue } from '@vue/test-utils'
22
import Authentication from '@/components/users/Authentication'
33
import BootstrapVue from 'bootstrap-vue'
4-
import { $routerMocks, RouterLink } from '../../utils'
4+
import {$routerMocks, RouterLink, describeCheckFormFields} from '../../utils'
55
import $moment from 'moment'
66
import $http from 'axios'
77

@@ -12,19 +12,24 @@ describe('users/Authentication.vue', () => {
1212

1313
const wrapper = shallowMount(Authentication, {
1414
mocks: Object.assign({ $http, $moment }, $routerMocks),
15+
stubs: { RouterLink },
1516
propsData: {
1617
form: {
1718

1819
}
1920
},
20-
stubs: {
21-
RouterLink
22-
},
2321
localVue
2422
})
2523

2624
it('Check component Authentication', () => {
2725
expect(wrapper.is(Authentication)).to.eql(true)
2826
})
2927

28+
describeCheckFormFields(wrapper, {
29+
fields: {
30+
email: {tag: 'b-form-input-stub'},
31+
password: {tag: 'b-form-input-stub'}
32+
}
33+
})
34+
3035
})

test/unit/specs/users/ConfirmPassword.spec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { shallowMount, createLocalVue } from '@vue/test-utils'
22
import ConfirmPassword from '@/components/users/ConfirmPassword'
33
import BootstrapVue from 'bootstrap-vue'
4-
import {$routerMocks} from '../../utils'
4+
import {$routerMocks, describeCheckFormFields} from '../../utils'
55
import $moment from 'moment'
66
import $http from 'axios'
77

@@ -24,4 +24,8 @@ describe('users/ConfirmPassword.vue', () => {
2424
expect(wrapper.is(ConfirmPassword)).to.eql(true)
2525
})
2626

27+
describeCheckFormFields(wrapper, {
28+
password: {tag: 'b-form-input-stub'}
29+
})
30+
2731
})

test/unit/specs/users/Registration.spec.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { shallowMount, createLocalVue } from '@vue/test-utils'
22
import Registration from '@/components/users/Registration'
33
import BootstrapVue from 'bootstrap-vue'
4-
import { $routerMocks, RouterLink } from '../../utils'
4+
import {$routerMocks, describeCheckFormFields, RouterLink} from '../../utils'
55
import $moment from 'moment'
66
import $http from 'axios'
77

@@ -28,4 +28,13 @@ describe('users/Registration.vue', () => {
2828
expect(wrapper.is(Registration)).to.eql(true)
2929
})
3030

31+
describeCheckFormFields(wrapper, {
32+
email: {tag: 'b-form-input-stub'},
33+
password: {tag: 'b-form-input-stub'},
34+
company: {tag: 'b-form-input-stub'},
35+
purpose: {tag: 'b-form-select-stub'},
36+
fullname: {tag: 'b-form-input-stub'},
37+
additionalInfo: {tag: 'b-form-textarea-stub'}
38+
})
39+
3140
})

test/unit/specs/users/ResetPassword.spec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { shallowMount, createLocalVue } from '@vue/test-utils'
22
import ResetPassword from '@/components/users/ResetPassword'
33
import BootstrapVue from 'bootstrap-vue'
4-
import {$routerMocks} from '../../utils'
4+
import {$routerMocks, describeCheckFormFields} from '../../utils'
55
import $moment from 'moment'
66
import $http from 'axios'
77

@@ -24,4 +24,8 @@ describe('users/ResetPassword.vue', () => {
2424
expect(wrapper.is(ResetPassword)).to.eql(true)
2525
})
2626

27+
describeCheckFormFields(wrapper, {
28+
email: {tag: 'b-form-input-stub'}
29+
})
30+
2731
})

test/unit/utils.js

+15-40
Original file line numberDiff line numberDiff line change
@@ -40,44 +40,19 @@ export const RouterLink = {
4040
props: ['to']
4141
}
4242

43-
export const eventFilters = {
44-
datetime_max: {
45-
tag: 'flat-pickr-stub'
46-
},
47-
datetime_min: {
48-
tag: 'flat-pickr-stub'
49-
},
50-
depth_max: {
51-
tag: 'b-form-input-stub'
52-
},
53-
depth_min: {
54-
tag: 'b-form-input-stub'
55-
},
56-
has_mt: {
57-
tag: 'b-form-checkbox-stub'
58-
},
59-
mag_max: {
60-
tag: 'b-form-input-stub'
61-
},
62-
mag_min: {
63-
tag: 'b-form-input-stub'
64-
},
65-
lat_max: {
66-
tag: 'b-form-input-stub'
67-
},
68-
lat_min: {
69-
tag: 'b-form-input-stub'
70-
},
71-
lon_max: {
72-
tag: 'b-form-input-stub'
73-
},
74-
lon_min: {
75-
tag: 'b-form-input-stub'
76-
},
77-
rms_max: {
78-
tag: 'b-form-input-stub'
79-
},
80-
sta_num_min: {
81-
tag: 'b-form-input-stub'
82-
}
43+
export function describeCheckFormFields(wrapper, {fields = {}, label = 'Check form fields'} = {})
44+
{
45+
describe(label, () => {
46+
47+
for (let item of Object.entries(fields))
48+
{
49+
const [fieldName, fieldConf] = item
50+
const field = wrapper.find(`${fieldConf.tag}[name="${fieldName}"]`)
51+
52+
it(`Check field ${fieldName}`, () => {
53+
expect(field.exists()).to.eql(true)
54+
})
55+
}
56+
57+
})
8358
}

0 commit comments

Comments
 (0)