Skip to content

Commit 8aa825f

Browse files
committed
💚 test(e2e): add remains of e2e test [ci skip]
1 parent 151f39e commit 8aa825f

File tree

6 files changed

+87
-23
lines changed

6 files changed

+87
-23
lines changed

examples/component/index.html

+7-10
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
</head>
1616
<body>
1717
<div id="app">
18-
<validity ref="validity" field="select" :validators="{
18+
<validity ref="validity" field="select" v-model="validation" :validators="{
1919
selected: { props: { value: { message: 'not selected item!!' } } }
2020
}">
2121
<select2 :options="options" :value="selected" @input="handleValidate">
2222
<option value="0">----- Select one -----</option>
2323
</select2>
2424
</validity>
25-
<p class="errors" v-if="result.errors">{{result.value.selected}}</p>
25+
<p class="errors" v-if="validation.result.errors">{{validation.result.value.selected}}</p>
2626
</div>
2727
<script>
2828
new Vue({
@@ -32,7 +32,9 @@
3232
{ id: 1, text: 'Hello' },
3333
{ id: 2, text: 'World' }
3434
],
35-
result: {}
35+
validation: {
36+
result: {}
37+
}
3638
},
3739
validators: {
3840
selected: function (val) {
@@ -60,13 +62,8 @@
6062
}
6163
},
6264
mounted () {
63-
var self = this
64-
var $validity = this.$refs.validity
65-
$validity.$on('validate', function () {
66-
self.result = $validity.result
67-
})
68-
69-
$validity.validate()
65+
// initial validation
66+
this.$refs.validity.validate()
7067
},
7168
methods: {
7269
handleValidate: function (val) {

examples/select/multiple/index.html

+7-13
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<body>
1414
<div id="app">
1515
<label for="language">select your favorite programming languages</label><br />
16-
<validity field="lang" :validators="{ required: true, maxlength: 3 }">
17-
<select multiple size="10" @change="handleValidate">
16+
<validity ref="validity" field="lang" v-model="validation" :validators="{ required: true, maxlength: 3 }">
17+
<select multiple size="10" @change="$refs.validity.validate()">
1818
<option value="javascript">JavaScript</option>
1919
<option value="ruby">Ruby</option>
2020
<option value="python">Python</option>
@@ -28,21 +28,15 @@
2828
</select>
2929
</validity>
3030
<div class="errors">
31-
<p v-if="result.required">Required !!</p>
32-
<p v-if="result.maxlength">Sorry, The maximum is 3 languages !!</p>
31+
<p class="required" v-if="validation.result.required">Required !!</p>
32+
<p class="maxlength" v-if="validation.result.maxlength">Sorry, The maximum is 3 languages !!</p>
3333
</div>
3434
</div>
3535
<script>
3636
new Vue({
37-
data: { result: {} },
38-
methods: {
39-
handleValidate: function (e) {
40-
var self = this
41-
var $validity = e.target.$validity
42-
$validity.validate(function () {
43-
var result = $validity.result
44-
self.result = result
45-
})
37+
data: {
38+
validation: {
39+
result: {}
4640
}
4741
}
4842
}).$mount('#app')

test/e2e/commands/simulateEvent.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
exports.command = function (selector, event, cb) {
2+
return this.execute(function (selector, event, cb) {
3+
var e = document.createEvent('HTMLEvents')
4+
e.initEvent(event, true, true)
5+
var el = document.querySelector(selector)
6+
el.dispatchEvent(e)
7+
}, [selector, event, cb])
8+
}

test/e2e/test/component.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
component: function (browser) {
3+
browser
4+
.url('http://localhost:8080/examples/component/')
5+
// initial loaded
6+
.waitForElementVisible('#app', 1000)
7+
.waitForElementPresent('.errors', 1000)
8+
.assert.containsText('.errors', 'not selected item!!')
9+
// valid
10+
.click('.select2-selection__rendered')
11+
.click('.select2-results__option:nth-child(2)')
12+
.waitForElementNotPresent('.errors', 1000)
13+
// invalid
14+
.click('.select2-selection__rendered')
15+
.click('.select2-results__option:nth-child(1)')
16+
.waitForElementPresent('.errors', 1000)
17+
.assert.containsText('.errors', 'not selected item!!')
18+
.end()
19+
}
20+
}

test/e2e/test/select_basic.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
select_basic: function (browser) {
3+
browser
4+
.url('http://localhost:8080/examples/select/basic/')
5+
// initial loaded
6+
.waitForElementVisible('#app', 1000)
7+
.waitForElementNotPresent('.errors p', 1000)
8+
// valid
9+
.click('select option[value=javascript]')
10+
.waitForElementNotPresent('.errors p', 1000)
11+
// invalid
12+
.click('select option[value=""]')
13+
.waitForElementPresent('.errors p', 1000)
14+
.assert.containsText('.errors p', 'Required !!')
15+
.end()
16+
}
17+
}

test/e2e/test/select_multiple.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
select_multiple: function (browser) {
3+
browser
4+
.url('http://localhost:8080/examples/select/multiple/')
5+
// initial loaded
6+
.waitForElementVisible('#app', 1000)
7+
.waitForElementNotPresent('.errors .required', 1000)
8+
.waitForElementNotPresent('.errors .maxlength', 1000)
9+
// valid
10+
.click('select option[value=javascript]')
11+
.waitForElementNotPresent('.errors .required', 1000)
12+
.waitForElementNotPresent('.errors .maxlength', 1000)
13+
// invalid required
14+
.click('select option[value=javascript]') // not select
15+
.waitForElementPresent('.errors .required', 1000)
16+
.waitForElementNotPresent('.errors .maxlength', 1000)
17+
.assert.containsText('.errors .required', 'Required !!')
18+
// invalid maxlength
19+
.click('select option[value=javascript]')
20+
.click('select option[value=go]')
21+
.click('select option[value=lua]')
22+
.click('select option[value=ruby]')
23+
.waitForElementNotPresent('.errors .required', 1000)
24+
.waitForElementPresent('.errors .maxlength', 1000)
25+
.assert.containsText('.errors .maxlength', 'Sorry, The maximum is 3 languages !!')
26+
.end()
27+
}
28+
}

0 commit comments

Comments
 (0)