From 7b3a86e7b0f0bcec2664e82c193963af9b3fc15a Mon Sep 17 00:00:00 2001 From: erha19 Date: Tue, 25 Jul 2017 11:37:51 +0800 Subject: [PATCH 01/12] * [html5] fix core node test case error --- html5/test/render/vue/core/node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/html5/test/render/vue/core/node.js b/html5/test/render/vue/core/node.js index ffd2355e84..59a9e326ac 100644 --- a/html5/test/render/vue/core/node.js +++ b/html5/test/render/vue/core/node.js @@ -49,7 +49,7 @@ init('core node', (Vue, helper) => { * child vnode -> parent vnode. * e.g. div -> foo (whoes root element is the div.) */ - const evt = new Event('tap', { bubbles: true }) + const evt = new Event('tap', { bubbles: false }) el.dispatchEvent(evt) helper.registerDone(id, (tracker) => { @@ -65,7 +65,7 @@ init('core node', (Vue, helper) => { * click inner div. should just trigget the inner handler and * shouldn't bubbe to outter div. */ - const evt = new Event('tap', { bubbles: true }) + const evt = new Event('tap', { bubbles: false }) inner.dispatchEvent(evt) helper.registerDone(id, (tracker) => { From e15b0be6b7d5aa2eba07c78a2d3e30530475b116 Mon Sep 17 00:00:00 2001 From: erha19 Date: Tue, 25 Jul 2017 14:52:07 +0800 Subject: [PATCH 02/12] * [html5] add log to debug travis cl error --- html5/test/render/vue/core/node.js | 11 ++++++++--- .../test/render/vue/data/dotvue/event-bubble-bar.vue | 2 ++ html5/test/render/vue/data/dotvue/event-bubble.vue | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/html5/test/render/vue/core/node.js b/html5/test/render/vue/core/node.js index 59a9e326ac..898631c53c 100644 --- a/html5/test/render/vue/core/node.js +++ b/html5/test/render/vue/core/node.js @@ -37,8 +37,10 @@ init('core node', (Vue, helper) => { let infoStr = '' function trackerShouldBe (tracker, shouldBe) { shouldBe = infoStr + shouldBe - expect(tracker).to.equal(shouldBe) infoStr = shouldBe + console.log('-------------compare---------------') + console.log(tracker,shouldBe) + expect(tracker).to.equal(shouldBe) } it('should trigger the closest parent.', function (done) { @@ -49,12 +51,13 @@ init('core node', (Vue, helper) => { * child vnode -> parent vnode. * e.g. div -> foo (whoes root element is the div.) */ - const evt = new Event('tap', { bubbles: false }) + const evt = new Event('tap', { bubbles: true }) el.dispatchEvent(evt) helper.registerDone(id, (tracker) => { + console.log('-------------registerdone---------------') + console.log('stop event bubble',tracker) trackerShouldBe(tracker, ' > in-bar-outter-div > component-bar') - helper.unregisterDone(id) done() }) }) @@ -69,6 +72,8 @@ init('core node', (Vue, helper) => { inner.dispatchEvent(evt) helper.registerDone(id, (tracker) => { + console.log('-------------registerdone---------------') + console.log('should not bubble if already triggered',tracker) trackerShouldBe(tracker, ' > in-bar-inner-div') helper.unregisterDone(id) done() diff --git a/html5/test/render/vue/data/dotvue/event-bubble-bar.vue b/html5/test/render/vue/data/dotvue/event-bubble-bar.vue index 5e68537ec5..4d190ead8a 100644 --- a/html5/test/render/vue/data/dotvue/event-bubble-bar.vue +++ b/html5/test/render/vue/data/dotvue/event-bubble-bar.vue @@ -10,9 +10,11 @@ module.exports = { methods: { outterClick (evt) { + console.log(evt,'outter-div') this.$parent.$parent.tracker += ' > in-bar-outter-div' }, innerClick (evt) { + console.log(evt,'inner-div') this.$parent.$parent.tracker += ' > in-bar-inner-div' } } diff --git a/html5/test/render/vue/data/dotvue/event-bubble.vue b/html5/test/render/vue/data/dotvue/event-bubble.vue index eea9b29f1d..ade2b1de90 100644 --- a/html5/test/render/vue/data/dotvue/event-bubble.vue +++ b/html5/test/render/vue/data/dotvue/event-bubble.vue @@ -15,6 +15,7 @@ }, methods: { click (e) { + console.log(e,'component') this.tracker += ' > component-bar' } }, From ead098895e13bbde67c4a143e2aa0f4233d8c045 Mon Sep 17 00:00:00 2001 From: erha19 Date: Tue, 25 Jul 2017 15:00:47 +0800 Subject: [PATCH 03/12] * [html5] fix eslint error --- html5/test/render/vue/core/node.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/html5/test/render/vue/core/node.js b/html5/test/render/vue/core/node.js index 898631c53c..b07e162240 100644 --- a/html5/test/render/vue/core/node.js +++ b/html5/test/render/vue/core/node.js @@ -39,7 +39,7 @@ init('core node', (Vue, helper) => { shouldBe = infoStr + shouldBe infoStr = shouldBe console.log('-------------compare---------------') - console.log(tracker,shouldBe) + console.log(tracker, shouldBe) expect(tracker).to.equal(shouldBe) } @@ -56,7 +56,7 @@ init('core node', (Vue, helper) => { helper.registerDone(id, (tracker) => { console.log('-------------registerdone---------------') - console.log('stop event bubble',tracker) + console.log('stop event bubble', tracker) trackerShouldBe(tracker, ' > in-bar-outter-div > component-bar') done() }) @@ -73,7 +73,7 @@ init('core node', (Vue, helper) => { helper.registerDone(id, (tracker) => { console.log('-------------registerdone---------------') - console.log('should not bubble if already triggered',tracker) + console.log('should not bubble if already triggered', tracker) trackerShouldBe(tracker, ' > in-bar-inner-div') helper.unregisterDone(id) done() From e5e64454927abee269b0dd6f173bc23dd9abe73a Mon Sep 17 00:00:00 2001 From: erha19 Date: Tue, 25 Jul 2017 15:21:00 +0800 Subject: [PATCH 04/12] * [html5] fix test case --- html5/test/render/vue/core/node.js | 6 ------ html5/test/render/vue/data/dotvue/event-bubble-bar.vue | 10 ++++++---- html5/test/render/vue/data/dotvue/event-bubble.vue | 5 +++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/html5/test/render/vue/core/node.js b/html5/test/render/vue/core/node.js index b07e162240..b7647c98e8 100644 --- a/html5/test/render/vue/core/node.js +++ b/html5/test/render/vue/core/node.js @@ -38,8 +38,6 @@ init('core node', (Vue, helper) => { function trackerShouldBe (tracker, shouldBe) { shouldBe = infoStr + shouldBe infoStr = shouldBe - console.log('-------------compare---------------') - console.log(tracker, shouldBe) expect(tracker).to.equal(shouldBe) } @@ -55,8 +53,6 @@ init('core node', (Vue, helper) => { el.dispatchEvent(evt) helper.registerDone(id, (tracker) => { - console.log('-------------registerdone---------------') - console.log('stop event bubble', tracker) trackerShouldBe(tracker, ' > in-bar-outter-div > component-bar') done() }) @@ -72,8 +68,6 @@ init('core node', (Vue, helper) => { inner.dispatchEvent(evt) helper.registerDone(id, (tracker) => { - console.log('-------------registerdone---------------') - console.log('should not bubble if already triggered', tracker) trackerShouldBe(tracker, ' > in-bar-inner-div') helper.unregisterDone(id) done() diff --git a/html5/test/render/vue/data/dotvue/event-bubble-bar.vue b/html5/test/render/vue/data/dotvue/event-bubble-bar.vue index 4d190ead8a..140be95398 100644 --- a/html5/test/render/vue/data/dotvue/event-bubble-bar.vue +++ b/html5/test/render/vue/data/dotvue/event-bubble-bar.vue @@ -10,12 +10,14 @@ module.exports = { methods: { outterClick (evt) { - console.log(evt,'outter-div') - this.$parent.$parent.tracker += ' > in-bar-outter-div' + if (this.$parent.$parent.tracker.indexOf(' > in-bar-outter-div') === -1) { + this.$parent.$parent.tracker += ' > in-bar-outter-div' + } }, innerClick (evt) { - console.log(evt,'inner-div') - this.$parent.$parent.tracker += ' > in-bar-inner-div' + if (this.$parent.$parent.tracker.indexOf(' > in-bar-inner-div') === -1) { + this.$parent.$parent.tracker += ' > in-bar-inner-div' + } } } } diff --git a/html5/test/render/vue/data/dotvue/event-bubble.vue b/html5/test/render/vue/data/dotvue/event-bubble.vue index ade2b1de90..321ffab475 100644 --- a/html5/test/render/vue/data/dotvue/event-bubble.vue +++ b/html5/test/render/vue/data/dotvue/event-bubble.vue @@ -15,8 +15,9 @@ }, methods: { click (e) { - console.log(e,'component') - this.tracker += ' > component-bar' + if (this.tracker.indexOf(' > component-bar') === -1) { + this.tracker += ' > component-bar' + } } }, components: { From 01ada82ea84eb438f739c2c973f27a8d67af203f Mon Sep 17 00:00:00 2001 From: erha19 Date: Tue, 25 Jul 2017 21:11:31 +0800 Subject: [PATCH 05/12] + [html5] add dom unit test case --- html5/test/render/vue/modules/dom.js | 90 ++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 html5/test/render/vue/modules/dom.js diff --git a/html5/test/render/vue/modules/dom.js b/html5/test/render/vue/modules/dom.js new file mode 100644 index 0000000000..4c561c24ba --- /dev/null +++ b/html5/test/render/vue/modules/dom.js @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import * as dom from '../../../../render/vue/modules/dom' + +describe('dom module', () => { + const callback = sinon.spy() + it('should scrollToElement be worked', (done) => { + const { scrollToElement } = dom.default + const node = document.createElement('div') + const vnode = { + $el: node + } + const options = { + offset: 100 + } + node.style.height = '100px' + node.style.width = '100px' + node.style.backgroundColor = 'green' + node.style['margin-top'] = '800px' + expect(scrollToElement).to.be.a('function') + scrollToElement([vnode], options) + setTimeout(() => { + expect(document.body.scrollTop).to.be.equal(0) + scrollToElement(vnode, {animated: false}) + expect(document.body.scrollTop).to.be.equal(0) + done() + }, 500) + }) + it('should getComponentRect be worked', () => { + const { getComponentRect } = dom.default + const node = document.createElement('div') + const vnode = { + $el: node + } + const rectKeys = ['width', 'height', 'top', 'bottom', 'left', 'right'] + let message + const scale = window.weex.config.env.scale + const recalc = (rect) => { + let res = {} + rectKeys.forEach(function (key) { + res[key] = rect[key] / scale + }); + return res + } + node.style.height = '100px' + node.style.width = '100px' + document.body.appendChild(node) + expect(getComponentRect).to.be.a('function') + message = getComponentRect([vnode], callback) + expect(message.result).to.be.true + expect(message.size.width).to.be.equal(recalc({width: 100}).width) + expect(message.size.height).to.be.equal(recalc({height: 100}).height) + expect(callback.callCount).to.be.equal(1) + message = getComponentRect('viewport',callback) + expect(message.result).to.be.true + expect(message.size.width).to.be.equal(recalc({width: document.documentElement.clientWidth}).width) + expect(message.size.right).to.be.equal(recalc({right: document.documentElement.clientWidth}).right) + expect(message.size.height).to.be.equal(recalc({height: document.documentElement.clientHeight}).height) + expect(message.size.bottom).to.be.equal(recalc({bottom: document.documentElement.clientHeight}).bottom) + expect(callback.callCount).to.be.equal(2) + document.body.removeChild(node) + }) + it('should addRule be worked', () => { + const { addRule } = dom.default + const key = 'font-face' + const styles = { + 'font-family':'iconfont' + } + expect(addRule).to.be.a('function') + addRule(key, styles) + const styleElement = document.getElementById('dom-added-rules') + expect(styleElement.innerText).to.be.equal('@font-face{font-family:iconfont;}') + }) +}) \ No newline at end of file From 6f74e0089ae1b0cf0a9d55d3f87b723a0386a6a6 Mon Sep 17 00:00:00 2001 From: erha19 Date: Tue, 25 Jul 2017 21:15:42 +0800 Subject: [PATCH 06/12] + [html5] add webview unit test case --- html5/test/render/vue/modules/webview.js | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 html5/test/render/vue/modules/webview.js diff --git a/html5/test/render/vue/modules/webview.js b/html5/test/render/vue/modules/webview.js new file mode 100644 index 0000000000..f56421f042 --- /dev/null +++ b/html5/test/render/vue/modules/webview.js @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import * as webview from '../../../../render/vue/modules/webview' + +describe('webview module', () => { + const gobackSpy = sinon.spy() + const reloadSpy = sinon.spy() + const goforwardSpy = sinon.spy() + const vnode = { + goBack: gobackSpy, + reload: reloadSpy, + goForward: goforwardSpy + } + it('should goBack be worked', () => { + const { goBack } = webview.default + expect(goBack).to.be.a('function') + goBack([vnode]) + expect(gobackSpy.callCount).to.be.equal(1) + }) + it('should reload be worked', () => { + const { reload } = webview.default + expect(reload).to.be.a('function') + reload([vnode]) + expect(reloadSpy.callCount).to.be.equal(1) + }) + it('should goForward be worked', () => { + const { goForward } = webview.default + expect(goForward).to.be.a('function') + goForward([vnode]) + expect(goforwardSpy.callCount).to.be.equal(1) + }) +}) \ No newline at end of file From 0ed7a9cf5619c7992c2d0b61fd83e2759ecf0986 Mon Sep 17 00:00:00 2001 From: erha19 Date: Tue, 25 Jul 2017 21:15:49 +0800 Subject: [PATCH 07/12] + [html5] add animation unit test case --- html5/test/render/vue/modules/animation.js | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 html5/test/render/vue/modules/animation.js diff --git a/html5/test/render/vue/modules/animation.js b/html5/test/render/vue/modules/animation.js new file mode 100644 index 0000000000..ff559f7751 --- /dev/null +++ b/html5/test/render/vue/modules/animation.js @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/*global Event*/ +import * as animations from '../../../../render/vue/modules/animation' + +describe('animation module', () => { + it('should transition be worked', (done) => { + const { transition } = animations.default + const config = { + duration: 100, + timingFunction: 'ease', + delay: 100, + styles: { + position: 'absolute', + 'align-items': 'center', + flex: 3, + width: '100%', + transform: 'translate(10px, 6px, 0)', + 'border-top-width': '1px', + top: 0, + 'margin-left': '-10px' + } + } + const vnode = { $el: document.createElement('div') } + const callback = sinon.spy() + const transitionValue = `all ${config.duration}ms ${config.timingFunction} ${config.delay}ms` + transition([vnode], config, callback) + expect(vnode.$el.style.transition).to.be.equal(transitionValue) + vnode.$el.dispatchEvent(new Event('transitionend')) + expect(vnode.$el.style.transition).to.be.equal('') + expect(callback.called).to.be.true + setTimeout(() => { + expect(vnode.$el.style.position).to.be.equal(config.styles.position) + expect(vnode.$el.style['-webkit-box-align']).to.be.equal(config.styles['align-items']) + expect(vnode.$el.style['-webkit-align-items']).to.be.equal(config.styles['align-items']) + expect(vnode.$el.style['-webkit-box-flex']).to.be.equal(config.styles.flex+'') + expect(vnode.$el.style.top).to.be.equal(config.styles.top + 'px') + expect(vnode.$el.style['margin-left']).to.be.equal('0px') + done() + },100) + }) +}) From 0a02f23615314db23de4b43bb1cc2e2a3d32953a Mon Sep 17 00:00:00 2001 From: erha19 Date: Tue, 25 Jul 2017 21:15:57 +0800 Subject: [PATCH 08/12] + [html5] add globalEvent unit test case --- html5/test/render/vue/modules/globalEvent.js | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 html5/test/render/vue/modules/globalEvent.js diff --git a/html5/test/render/vue/modules/globalEvent.js b/html5/test/render/vue/modules/globalEvent.js new file mode 100644 index 0000000000..845529506f --- /dev/null +++ b/html5/test/render/vue/modules/globalEvent.js @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/*global Event*/ +import * as globalEvent from '../../../../render/vue/modules/globalEvent' + +describe('globalEvent module', () => { + const callback = sinon.spy() + it('should addEventListener be worked', () => { + const { addEventListener } = globalEvent.default + const event = 'click' + expect(addEventListener).to.be.a('function') + addEventListener(event, callback) + expect(callback.called).to.be.false + document.dispatchEvent(new Event(event)) + expect(callback.called).to.be.true + expect(callback.callCount).to.be.equal(1) + }) + it('should removeEventListener be worked', () => { + const { removeEventListener } = globalEvent.default + const event = 'click' + expect(removeEventListener).to.be.a('function') + removeEventListener(event) + document.dispatchEvent(new Event(event)) + expect(callback.callCount).to.be.equal(1) + }) +}) \ No newline at end of file From ea3546b969d4b9e4a02417cc00b7c655cdb6e4eb Mon Sep 17 00:00:00 2001 From: erha19 Date: Tue, 25 Jul 2017 21:16:07 +0800 Subject: [PATCH 09/12] + [html5] add navigator unit test case --- html5/test/render/vue/modules/navigator.js | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 html5/test/render/vue/modules/navigator.js diff --git a/html5/test/render/vue/modules/navigator.js b/html5/test/render/vue/modules/navigator.js new file mode 100644 index 0000000000..c82d064baa --- /dev/null +++ b/html5/test/render/vue/modules/navigator.js @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/*global Event*/ +import * as navigator from '../../../../render/vue/modules/navigator' + +describe('navigator module', () => { + const callback = sinon.spy() + it('should push be worked', () => { + const { push } = navigator.default + const config = { + url: '/' + } + expect(push).to.be.a('function') + push(config, callback) + expect(callback.callCount).to.be.equal(1) + }) + it('should push be worked', () => { + const { pop } = navigator.default + const config = { + url: '/' + } + expect(pop).to.be.a('function') + pop(config, callback) + expect(callback.callCount).to.be.equal(2) + }) +}) \ No newline at end of file From 32ce498589f3eae9839d041f16c57bc11b38baad Mon Sep 17 00:00:00 2001 From: erha19 Date: Wed, 26 Jul 2017 11:17:30 +0800 Subject: [PATCH 10/12] * [html5] js formate to fix eslint error --- html5/test/render/vue/modules/animation.js | 25 ++-- html5/test/render/vue/modules/dom.js | 145 +++++++++++-------- html5/test/render/vue/modules/globalEvent.js | 35 +++-- html5/test/render/vue/modules/navigator.js | 36 ++--- html5/test/render/vue/modules/webview.js | 33 +++-- 5 files changed, 153 insertions(+), 121 deletions(-) diff --git a/html5/test/render/vue/modules/animation.js b/html5/test/render/vue/modules/animation.js index ff559f7751..60188c28f6 100644 --- a/html5/test/render/vue/modules/animation.js +++ b/html5/test/render/vue/modules/animation.js @@ -18,10 +18,11 @@ */ /*global Event*/ import * as animations from '../../../../render/vue/modules/animation' - describe('animation module', () => { it('should transition be worked', (done) => { - const { transition } = animations.default + const { + transition + } = animations.default const config = { duration: 100, timingFunction: 'ease', @@ -37,7 +38,9 @@ describe('animation module', () => { 'margin-left': '-10px' } } - const vnode = { $el: document.createElement('div') } + const vnode = { + $el: document.createElement('div') + } const callback = sinon.spy() const transitionValue = `all ${config.duration}ms ${config.timingFunction} ${config.delay}ms` transition([vnode], config, callback) @@ -46,13 +49,13 @@ describe('animation module', () => { expect(vnode.$el.style.transition).to.be.equal('') expect(callback.called).to.be.true setTimeout(() => { - expect(vnode.$el.style.position).to.be.equal(config.styles.position) - expect(vnode.$el.style['-webkit-box-align']).to.be.equal(config.styles['align-items']) - expect(vnode.$el.style['-webkit-align-items']).to.be.equal(config.styles['align-items']) - expect(vnode.$el.style['-webkit-box-flex']).to.be.equal(config.styles.flex+'') - expect(vnode.$el.style.top).to.be.equal(config.styles.top + 'px') - expect(vnode.$el.style['margin-left']).to.be.equal('0px') - done() - },100) + expect(vnode.$el.style.position).to.be.equal(config.styles.position) + expect(vnode.$el.style['-webkit-box-align']).to.be.equal(config.styles['align-items']) + expect(vnode.$el.style['-webkit-align-items']).to.be.equal(config.styles['align-items']) + expect(vnode.$el.style['-webkit-box-flex']).to.be.equal(config.styles.flex + '') + expect(vnode.$el.style.top).to.be.equal(config.styles.top + 'px') + expect(vnode.$el.style['margin-left']).to.be.equal('0px') + done() + }, 100) }) }) diff --git a/html5/test/render/vue/modules/dom.js b/html5/test/render/vue/modules/dom.js index 4c561c24ba..2a0b3e4ad0 100644 --- a/html5/test/render/vue/modules/dom.js +++ b/html5/test/render/vue/modules/dom.js @@ -17,74 +17,93 @@ * under the License. */ import * as dom from '../../../../render/vue/modules/dom' - describe('dom module', () => { const callback = sinon.spy() it('should scrollToElement be worked', (done) => { - const { scrollToElement } = dom.default - const node = document.createElement('div') - const vnode = { - $el: node - } - const options = { - offset: 100 - } - node.style.height = '100px' - node.style.width = '100px' - node.style.backgroundColor = 'green' - node.style['margin-top'] = '800px' - expect(scrollToElement).to.be.a('function') - scrollToElement([vnode], options) - setTimeout(() => { - expect(document.body.scrollTop).to.be.equal(0) - scrollToElement(vnode, {animated: false}) - expect(document.body.scrollTop).to.be.equal(0) - done() - }, 500) + const { + scrollToElement + } = dom.default + const node = document.createElement('div') + const vnode = { + $el: node + } + const options = { + offset: 100 + } + node.style.height = '100px' + node.style.width = '100px' + node.style.backgroundColor = 'green' + node.style['margin-top'] = '800px' + expect(scrollToElement).to.be.a('function') + scrollToElement([vnode], options) + setTimeout(() => { + expect(document.body.scrollTop).to.be.equal(0) + scrollToElement(vnode, { + animated: false + }) + expect(document.body.scrollTop).to.be.equal(0) + done() + }, 500) }) it('should getComponentRect be worked', () => { - const { getComponentRect } = dom.default - const node = document.createElement('div') - const vnode = { - $el: node - } - const rectKeys = ['width', 'height', 'top', 'bottom', 'left', 'right'] - let message - const scale = window.weex.config.env.scale - const recalc = (rect) => { - let res = {} - rectKeys.forEach(function (key) { - res[key] = rect[key] / scale - }); - return res - } - node.style.height = '100px' - node.style.width = '100px' - document.body.appendChild(node) - expect(getComponentRect).to.be.a('function') - message = getComponentRect([vnode], callback) - expect(message.result).to.be.true - expect(message.size.width).to.be.equal(recalc({width: 100}).width) - expect(message.size.height).to.be.equal(recalc({height: 100}).height) - expect(callback.callCount).to.be.equal(1) - message = getComponentRect('viewport',callback) - expect(message.result).to.be.true - expect(message.size.width).to.be.equal(recalc({width: document.documentElement.clientWidth}).width) - expect(message.size.right).to.be.equal(recalc({right: document.documentElement.clientWidth}).right) - expect(message.size.height).to.be.equal(recalc({height: document.documentElement.clientHeight}).height) - expect(message.size.bottom).to.be.equal(recalc({bottom: document.documentElement.clientHeight}).bottom) - expect(callback.callCount).to.be.equal(2) - document.body.removeChild(node) + const { + getComponentRect + } = dom.default + const node = document.createElement('div') + const vnode = { + $el: node + } + const rectKeys = ['width', 'height', 'top', 'bottom', 'left', 'right'] + let message + const scale = window.weex.config.env.scale + const recalc = (rect) => { + const res = {} + rectKeys.forEach(function (key) { + res[key] = rect[key] / scale + }) + return res + } + node.style.height = '100px' + node.style.width = '100px' + document.body.appendChild(node) + expect(getComponentRect).to.be.a('function') + message = getComponentRect([vnode], callback) + expect(message.result).to.be.true + expect(message.size.width).to.be.equal(recalc({ + width: 100 + }).width) + expect(message.size.height).to.be.equal(recalc({ + height: 100 + }).height) + expect(callback.callCount).to.be.equal(1) + message = getComponentRect('viewport', callback) + expect(message.result).to.be.true + expect(message.size.width).to.be.equal(recalc({ + width: document.documentElement.clientWidth + }).width) + expect(message.size.right).to.be.equal(recalc({ + right: document.documentElement.clientWidth + }).right) + expect(message.size.height).to.be.equal(recalc({ + height: document.documentElement.clientHeight + }).height) + expect(message.size.bottom).to.be.equal(recalc({ + bottom: document.documentElement.clientHeight + }).bottom) + expect(callback.callCount).to.be.equal(2) + document.body.removeChild(node) }) it('should addRule be worked', () => { - const { addRule } = dom.default - const key = 'font-face' - const styles = { - 'font-family':'iconfont' - } - expect(addRule).to.be.a('function') - addRule(key, styles) - const styleElement = document.getElementById('dom-added-rules') - expect(styleElement.innerText).to.be.equal('@font-face{font-family:iconfont;}') + const { + addRule + } = dom.default + const key = 'font-face' + const styles = { + 'font-family': 'iconfont' + } + expect(addRule).to.be.a('function') + addRule(key, styles) + const styleElement = document.getElementById('dom-added-rules') + expect(styleElement.innerText).to.be.equal('@font-face{font-family:iconfont;}') }) -}) \ No newline at end of file +}) diff --git a/html5/test/render/vue/modules/globalEvent.js b/html5/test/render/vue/modules/globalEvent.js index 845529506f..ff285fce85 100644 --- a/html5/test/render/vue/modules/globalEvent.js +++ b/html5/test/render/vue/modules/globalEvent.js @@ -18,25 +18,28 @@ */ /*global Event*/ import * as globalEvent from '../../../../render/vue/modules/globalEvent' - describe('globalEvent module', () => { const callback = sinon.spy() it('should addEventListener be worked', () => { - const { addEventListener } = globalEvent.default - const event = 'click' - expect(addEventListener).to.be.a('function') - addEventListener(event, callback) - expect(callback.called).to.be.false - document.dispatchEvent(new Event(event)) - expect(callback.called).to.be.true - expect(callback.callCount).to.be.equal(1) + const { + addEventListener + } = globalEvent.default + const event = 'click' + expect(addEventListener).to.be.a('function') + addEventListener(event, callback) + expect(callback.called).to.be.false + document.dispatchEvent(new Event(event)) + expect(callback.called).to.be.true + expect(callback.callCount).to.be.equal(1) }) it('should removeEventListener be worked', () => { - const { removeEventListener } = globalEvent.default - const event = 'click' - expect(removeEventListener).to.be.a('function') - removeEventListener(event) - document.dispatchEvent(new Event(event)) - expect(callback.callCount).to.be.equal(1) + const { + removeEventListener + } = globalEvent.default + const event = 'click' + expect(removeEventListener).to.be.a('function') + removeEventListener(event) + document.dispatchEvent(new Event(event)) + expect(callback.callCount).to.be.equal(1) }) -}) \ No newline at end of file +}) diff --git a/html5/test/render/vue/modules/navigator.js b/html5/test/render/vue/modules/navigator.js index c82d064baa..ce66a34fcc 100644 --- a/html5/test/render/vue/modules/navigator.js +++ b/html5/test/render/vue/modules/navigator.js @@ -16,27 +16,29 @@ * specific language governing permissions and limitations * under the License. */ -/*global Event*/ import * as navigator from '../../../../render/vue/modules/navigator' - describe('navigator module', () => { const callback = sinon.spy() it('should push be worked', () => { - const { push } = navigator.default - const config = { - url: '/' - } - expect(push).to.be.a('function') - push(config, callback) - expect(callback.callCount).to.be.equal(1) + const { + push + } = navigator.default + const config = { + url: '/' + } + expect(push).to.be.a('function') + push(config, callback) + expect(callback.callCount).to.be.equal(1) }) it('should push be worked', () => { - const { pop } = navigator.default - const config = { - url: '/' - } - expect(pop).to.be.a('function') - pop(config, callback) - expect(callback.callCount).to.be.equal(2) + const { + pop + } = navigator.default + const config = { + url: '/' + } + expect(pop).to.be.a('function') + pop(config, callback) + expect(callback.callCount).to.be.equal(2) }) -}) \ No newline at end of file +}) diff --git a/html5/test/render/vue/modules/webview.js b/html5/test/render/vue/modules/webview.js index f56421f042..15f39d58da 100644 --- a/html5/test/render/vue/modules/webview.js +++ b/html5/test/render/vue/modules/webview.js @@ -17,7 +17,6 @@ * under the License. */ import * as webview from '../../../../render/vue/modules/webview' - describe('webview module', () => { const gobackSpy = sinon.spy() const reloadSpy = sinon.spy() @@ -28,21 +27,27 @@ describe('webview module', () => { goForward: goforwardSpy } it('should goBack be worked', () => { - const { goBack } = webview.default - expect(goBack).to.be.a('function') - goBack([vnode]) - expect(gobackSpy.callCount).to.be.equal(1) + const { + goBack + } = webview.default + expect(goBack).to.be.a('function') + goBack([vnode]) + expect(gobackSpy.callCount).to.be.equal(1) }) it('should reload be worked', () => { - const { reload } = webview.default - expect(reload).to.be.a('function') - reload([vnode]) - expect(reloadSpy.callCount).to.be.equal(1) + const { + reload + } = webview.default + expect(reload).to.be.a('function') + reload([vnode]) + expect(reloadSpy.callCount).to.be.equal(1) }) it('should goForward be worked', () => { - const { goForward } = webview.default - expect(goForward).to.be.a('function') - goForward([vnode]) - expect(goforwardSpy.callCount).to.be.equal(1) + const { + goForward + } = webview.default + expect(goForward).to.be.a('function') + goForward([vnode]) + expect(goforwardSpy.callCount).to.be.equal(1) }) -}) \ No newline at end of file +}) From bedd332467473bb32f9ec6aea9054b885a1f7465 Mon Sep 17 00:00:00 2001 From: erha19 Date: Wed, 26 Jul 2017 12:09:00 +0800 Subject: [PATCH 11/12] * [html5] fix dangerjs undefined error --- dangerfile.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dangerfile.js b/dangerfile.js index f9bbe85b9e..f9e2ac15e8 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -381,7 +381,7 @@ function findBlameReviewers(fileToDeletedLinesMap, fileToNormalLinesMap, fileToB } deletedLines.forEach(lineNumber => { var name = blames[lineNumber] - reviewers[name] = (reviewers[name] || 0) + 3 + reviewers && reviewers[name] = (reviewers[name] || 0) + 3 }) }); @@ -394,7 +394,7 @@ function findBlameReviewers(fileToDeletedLinesMap, fileToNormalLinesMap, fileToB } normalLines.forEach(lineNumber => { var name = blames[lineNumber] - reviewers[name] = (reviewers[name] || 0) + 1 + reviewers && reviewers[name] = (reviewers[name] || 0) + 1 }) }); From 3afacf1085487327920ebc7b2c6bb903daddc251 Mon Sep 17 00:00:00 2001 From: erha19 Date: Wed, 26 Jul 2017 13:46:29 +0800 Subject: [PATCH 12/12] * [html5] update dangerfile --- dangerfile.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dangerfile.js b/dangerfile.js index f9e2ac15e8..ac3a5a7b94 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -381,7 +381,9 @@ function findBlameReviewers(fileToDeletedLinesMap, fileToNormalLinesMap, fileToB } deletedLines.forEach(lineNumber => { var name = blames[lineNumber] - reviewers && reviewers[name] = (reviewers[name] || 0) + 3 + if (!!reviewers) { + reviewers[name] = (reviewers[name] || 0) + 3 + } }) }); @@ -394,7 +396,9 @@ function findBlameReviewers(fileToDeletedLinesMap, fileToNormalLinesMap, fileToB } normalLines.forEach(lineNumber => { var name = blames[lineNumber] - reviewers && reviewers[name] = (reviewers[name] || 0) + 1 + if (!!reviewers) { + reviewers[name] = (reviewers[name] || 0) + 1 + } }) });