Skip to content

Commit 59fff85

Browse files
committed
fix switch style & fix input tests & switch tests.
1 parent d2ad009 commit 59fff85

File tree

11 files changed

+175
-88
lines changed

11 files changed

+175
-88
lines changed

build/karma.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ module.exports = function (config) {
7070
resolve('test/components/input.js'),
7171
resolve('test/components/image.js'),
7272
resolve('test/components/render-function.js'),
73+
resolve('test/components/switch.js'),
7374
resolve('test/components/text.js'),
7475
resolve('test/core/style.js'),
75-
'../test/utils/**/*.js',
76-
'../test/modules/**/*.js',
77-
'../test/misc/**/*.js'
76+
'../test/utils/*.js',
77+
'../test/modules/*.js',
78+
'../test/misc/*.js'
7879
///////////////////////////////////////////
7980
// '../test/core/*.js',
8081
// '../test/!(utils|core)/*.js'
@@ -102,8 +103,6 @@ module.exports = function (config) {
102103
browserDisconnectTimeout: 10000,
103104
preprocessors: {
104105
'../test/**/*.js': ['rollup', 'coverage']
105-
// '../src/**/*.js': ['rollup', 'coverage']
106-
// '../test/**/!(components|examples|core)/!(component).js': ['rollup', 'coverage']
107106
},
108107
rollupPreprocessor: rollupConfig,
109108

examples/components/switch.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div>
3+
<div class="ct">
4+
<switch class="switch" checked="false"></switch>
5+
<switch class="switch" checked="true"></switch>
6+
</div>
7+
</div>
8+
</template>
9+
10+
<style scoped>
11+
.ct {
12+
height: 300px;
13+
background-color: #f7f7f7;
14+
align-items: center;
15+
justify-content: center;
16+
}
17+
.switch {
18+
margin: 20px;
19+
}
20+
</style>

examples/test/components/switch.vue

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<template>
2+
<div>
3+
<div class="switch-ct">
4+
<text class="label">simple</text>
5+
<switch ref="simple"></switch>
6+
</div>
7+
<div class="switch-ct">
8+
<text class="label">checked</text>
9+
<switch ref="checked" checked="true"></switch>
10+
</div>
11+
<div class="switch-ct">
12+
<text class="label">disabled</text>
13+
<switch ref="disabledChecked" disabled="true" checked="true"></switch>
14+
<switch ref="disabled" disabled="true"></switch>
15+
</div>
16+
<div class="switch-ct">
17+
<text class="label">onchange</text>
18+
<switch ref="change" @change="onchange"></switch>
19+
<text ref="changeInfo" class="info">{{checked}}</text>
20+
</div>
21+
</div>
22+
</template>
23+
24+
<script>
25+
export default {
26+
data () {
27+
return {
28+
checked: false
29+
}
30+
},
31+
methods: {
32+
onchange (event) {
33+
console.log(`onchage, value: ${event.value}`)
34+
this.checked = event.value
35+
this.callSpy && this.callSpy('change', event.value)
36+
}
37+
}
38+
}
39+
</script>
40+
41+
<style scoped>
42+
.switch-ct {
43+
flex-direction: row;
44+
justify-content: flex-start;
45+
margin-top: 60px;
46+
}
47+
.label {
48+
font-size: 40px;
49+
line-height: 60px;
50+
width: 350px;
51+
color: #666;
52+
text-align: right;
53+
margin-right: 20px;
54+
}
55+
.info {
56+
font-size: 30px;
57+
line-height: 60px;
58+
color: #BBB;
59+
margin-left: 10px;
60+
}
61+
</style>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "weex-vue-render",
33
"description": "Web renderer for weex project written in Vue DSL.",
4-
"version": "1.0.14",
4+
"version": "1.0.15",
55
"license": "Apache-2.0",
66
"main": "dist/index.common.js",
77
"keywords": [
@@ -25,7 +25,7 @@
2525
"build:plugins": "node build/build.js plugins",
2626
"build:examples": "node build/build-examples",
2727
"build:test": "node build/build-examples --test",
28-
"test": "npm run build:test && karma start build/karma.config.js",
28+
"test": "npm run build:test && node --max_old_space_size=4096 node_modules/karma/bin/karma start build/karma.config.js",
2929
"ci": "npm run test",
3030
"serve": "serve -p 12580"
3131
},

packages/weex-vue-render/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ App.$el = '#root'
3131
new App()
3232
```
3333

34-
> If import the UMD formated bundle to the html, then you dont't have to call `init` manually.
34+
> The way to require ES modules and CommonJS modules may have a slice of difference between different versions of Vue and Vue-loader, and this is totally depending on Vue and the loader, so please check out related documents.
35+
36+
> If your import the UMD formated bundle to the html, then you dont't have to call `init` manually.
3537
3638
```html
3739
<script>{{Vue runtime}}</script>

packages/weex-vue-render/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "weex-vue-render",
3-
"version": "1.0.14",
3+
"version": "1.0.15",
44
"description": "Web renderer for weex project written in Vue DSL.",
55
"license": "Apache-2.0",
66
"main": "dist/index.common.js",

src/components/switch/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
import './style.css'
1920

2021
function getSwitch (weex) {
2122
const { extractComponentStyle } = weex
22-
const { createEvent } = weex.utils
23+
const { dispatchNativeEvent } = weex.utils
2324

2425
return {
2526
name: 'weex-switch',
@@ -41,7 +42,7 @@ function getSwitch (weex) {
4142
},
4243
computed: {
4344
wrapperClass () {
44-
const classArray = ['weex-switch']
45+
const classArray = ['weex-el', 'weex-switch']
4546
this.isChecked && classArray.push('weex-switch-checked')
4647
this.isDisabled && classArray.push('weex-switch-disabled')
4748
return classArray.join(' ')
@@ -52,7 +53,7 @@ function getSwitch (weex) {
5253
// TODO: handle the events
5354
if (!this.isDisabled) {
5455
this.isChecked = !this.isChecked
55-
this.$emit('change', createEvent(this, 'change', { value: this.isChecked }))
56+
dispatchNativeEvent(this.$el, 'change', { value: this.isChecked })
5657
}
5758
}
5859
},
@@ -64,8 +65,8 @@ function getSwitch (weex) {
6465
const handler = evt => {
6566
this.toggle()
6667
}
67-
this._removeClickHandler = el.removeEventListener.bind(el, 'click', handler)
68-
el.addEventListener('click', handler)
68+
this._removeClickHandler = el.removeEventListener.bind(el, 'weex$tap', handler)
69+
el.addEventListener('weex$tap', handler)
6970
}
7071
}
7172
},
@@ -79,10 +80,6 @@ function getSwitch (weex) {
7980
},
8081

8182
render (createElement) {
82-
/* istanbul ignore next */
83-
// if (process.env.NODE_ENV === 'development') {
84-
// validateStyles('switch', this.$vnode.data && this.$vnode.data.staticStyle)
85-
// }
8683
return createElement('span', {
8784
attrs: { 'weex-type': 'switch' },
8885
staticClass: this.wrapperClass,

src/components/switch/style.css

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
.weex-switch {
2121
border: 0.013333rem solid #dfdfdf;
2222
cursor: pointer;
23-
display: inline-block;
24-
position: relative;
2523
vertical-align: middle;
26-
-webkit-user-select: none;
27-
-moz-user-select: none;
28-
-ms-user-select: none;
2924
user-select: none;
3025
box-sizing: content-box;
3126
background-clip: content-box;
@@ -36,8 +31,6 @@
3631
border-color: #dfdfdf;
3732
box-shadow: #dfdfdf 0 0 0 0 inset;
3833
border-radius: 0.8rem;
39-
-webkit-transition: border 0.4s, box-shadow 0.4s, background-color 1.2s;
40-
-moz-transition: border 0.4s, box-shadow 0.4s, background-color 1.2s;
4134
transition: border 0.4s, box-shadow 0.4s, background-color 1.2s;
4235
}
4336

@@ -65,8 +58,6 @@
6558
position: absolute;
6659
top: 0;
6760
left: 0;
68-
-webkit-transition: background-color 0.4s, left 0.2s;
69-
-moz-transition: background-color 0.4s, left 0.2s;
7061
transition: background-color 0.4s, left 0.2s;
7162
}
7263

test/components/input.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
* under the License.
1818
*/
1919
import { init } from '../helper'
20+
import input from '../../src/components/input'
2021

2122
init('components input', (Vue, helper) => {
2223

2324
const id = 'components.input'
2425
const spys = ['input', 'change']
2526
let vm, refs
27+
const { toArray } = helper.utils
2628

2729
before(() => {
2830
vm = helper.createVm(id, {
29-
spys
31+
spys,
32+
plugins: [input]
3033
})
3134
refs = vm.$refs
3235
})
@@ -37,14 +40,16 @@ init('components input', (Vue, helper) => {
3740

3841
describe('basic input behaviours', function () {
3942
it('<input> components.', function () {
43+
debugger
4044
expect(refs.txtInput.nodeName.toLowerCase()).to.equal('p')
4145
expect(refs.txtChange.nodeName.toLowerCase()).to.equal('p')
42-
expect(refs.inputText.nodeName.toLowerCase()).to.equal('input')
43-
expect(refs.inputText.type.toLowerCase()).to.equal('text')
46+
expect(refs.inputText.$el.nodeName.toLowerCase()).to.equal('input')
47+
expect(toArray(refs.inputText.$el.classList)).include.members(['weex-input', 'weex-el'])
48+
expect(refs.inputText.$el.type.toLowerCase()).to.equal('text')
4449
})
4550

4651
it('emit input events.', function (done) {
47-
const input = refs.inputText
52+
const input = refs.inputText.$el
4853
helper.utils.once(input, 'input', function (e) {
4954
expect(e.target.value).to.be.equal('abc')
5055
done()
@@ -55,7 +60,7 @@ init('components input', (Vue, helper) => {
5560
})
5661

5762
it('emit change events.', function (done) {
58-
const input = refs.inputText
63+
const input = refs.inputText.$el
5964
helper.utils.once(input, 'change', function (e) {
6065
expect(e.target.value).to.be.equal('def')
6166
done()
@@ -66,7 +71,7 @@ init('components input', (Vue, helper) => {
6671
})
6772

6873
it('v-model for two way data binding', function (done) {
69-
const input = refs.vModelInput
74+
const input = refs.vModelInput.$el
7075
const text = refs.vModelText
7176
const prevValue = 'two way binding value'
7277
const newValue = 'v-model works!'
@@ -81,7 +86,7 @@ init('components input', (Vue, helper) => {
8186
})
8287

8388
it('return key default', function (done) {
84-
const input = refs.inputReturnDefault
89+
const input = refs.inputReturnDefault.$el
8590
helper.utils.dispatchEvent(input, 'keyup', {
8691
keyCode: 13
8792
}, function () {
@@ -91,7 +96,7 @@ init('components input', (Vue, helper) => {
9196
})
9297

9398
it('return key go', function (done) {
94-
const input = refs.inputReturnDefault
99+
const input = refs.inputReturnDefault.$el
95100
helper.utils.dispatchEvent(input, 'keyup', {
96101
keyCode: 13
97102
}, function () {
@@ -101,7 +106,7 @@ init('components input', (Vue, helper) => {
101106
})
102107

103108
it('return key next', function (done) {
104-
const input = refs.inputReturnDefault
109+
const input = refs.inputReturnDefault.$el
105110
helper.utils.dispatchEvent(input, 'keyup', {
106111
keyCode: 13
107112
}, function () {
@@ -111,7 +116,7 @@ init('components input', (Vue, helper) => {
111116
})
112117

113118
it('return key search', function (done) {
114-
const input = refs.inputReturnDefault
119+
const input = refs.inputReturnDefault.$el
115120
helper.utils.dispatchEvent(input, 'keyup', {
116121
keyCode: 13
117122
}, function () {
@@ -121,7 +126,7 @@ init('components input', (Vue, helper) => {
121126
})
122127

123128
it('return key send', function (done) {
124-
const input = refs.inputReturnDefault
129+
const input = refs.inputReturnDefault.$el
125130
helper.utils.dispatchEvent(input, 'keyup', {
126131
keyCode: 13
127132
}, function () {
@@ -131,7 +136,7 @@ init('components input', (Vue, helper) => {
131136
})
132137

133138
it('return key done', function (done) {
134-
const input = refs.inputReturnDefault
139+
const input = refs.inputReturnDefault.$el
135140
helper.utils.dispatchEvent(input, 'keyup', {
136141
keyCode: 13
137142
}, function () {

0 commit comments

Comments
 (0)