You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by da...@apache.org on 2017/07/26 06:46:08 UTC
[05/12] incubator-weex git commit: + [html5] add dom unit test case
+ [html5] add dom unit test case
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/01ada82e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/01ada82e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/01ada82e
Branch: refs/heads/0.16-dev
Commit: 01ada82ea84eb438f739c2c973f27a8d67af203f
Parents: e5e6445
Author: erha19 <fa...@gmail.com>
Authored: Tue Jul 25 21:11:31 2017 +0800
Committer: erha19 <fa...@gmail.com>
Committed: Tue Jul 25 21:11:31 2017 +0800
----------------------------------------------------------------------
html5/test/render/vue/modules/dom.js | 90 +++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/01ada82e/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 0000000..4c561c2
--- /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