* [html5] imporve 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/89c66d4e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/89c66d4e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/89c66d4e

Branch: refs/heads/0.15-dev
Commit: 89c66d4e4d0bf67cd0f50273cd9cfbdf946eb02e
Parents: 92bf1d3
Author: erha19 <faterr...@gmail.com>
Authored: Mon Jul 17 17:52:52 2017 +0800
Committer: erha19 <faterr...@gmail.com>
Committed: Mon Jul 17 17:52:52 2017 +0800

----------------------------------------------------------------------
 html5/test/render/vue/utils/lazyload.js | 48 ++++++++++++++++------------
 1 file changed, 27 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/89c66d4e/html5/test/render/vue/utils/lazyload.js
----------------------------------------------------------------------
diff --git a/html5/test/render/vue/utils/lazyload.js 
b/html5/test/render/vue/utils/lazyload.js
index 5f5eeaa..7fc25a7 100644
--- a/html5/test/render/vue/utils/lazyload.js
+++ b/html5/test/render/vue/utils/lazyload.js
@@ -19,49 +19,55 @@
 import * as lazyload from '../../../../render/vue/utils/lazyload'
 describe('utils', function () {
   describe('lazyload', function () {
-    const validImage_transparent = 
'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
-    const validImage_black = 
'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='
+    const validImageTransparent = 
'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
+    const validImageBlack = 
'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='
     const invalidImage = 'data:image/jpeg;base64,'
     before(() => {
-    //   this.clock = sinon.useFakeTimers()
+      //   this.clock = sinon.useFakeTimers()
     })
     after(() => {
-    //   this.clock.restore()
+      //   this.clock.restore()
     })
-    it('fireLazyload', () => {
+    it('fireLazyload', (done) => {
       const {
         fireLazyload
       } = lazyload
       const node = document.createElement('figure')
       const urlReg = /http(s)?:\/\/(\S+):(\d+)\//
+      //  const IMG_REC_INDENT = 500
+      node.setAttribute('img-src', invalidImage)
+      node.setAttribute('img-placeholder', validImageBlack)
       node.style.height = '10px'
-      node.setAttribute('img-src', validImage_transparent)
-      node.setAttribute('img-placeholder', validImage_transparent)
-      document.body.appendChild(node)
+        //  coverage branch if (item._src_loading)
+      node._src_loading = true
+        //  coverage branch if (Array.isArray(el))
       fireLazyload([node])
-      setTimeout(() => {
-          console.log(node)
-      },200)
-      
expect(node.style.backgroundImage.replace(urlReg,'')).to.be.equal('url('+validImage_transparent+')')
-      node.setAttribute('img-src', validImage_black)
+      node._src_loading = false
       fireLazyload(node, true)
-      
expect(node.style.backgroundImage.replace(urlReg,'')).to.be.equal('url('+validImage_black+')')
-      document.body.removeChild(node)
+      setTimeout(() => {
+        expect(node.style.backgroundImage.replace(urlReg, 
'')).to.be.equal('url(' + validImageBlack + ')')
+        done()
+        document.body.removeChild(node)
+      }, 100)
     })
-    it('getThrottleLazyload', () => {
+    it('getThrottleLazyload', (done) => {
       const {
         getThrottleLazyload
       } = lazyload
       const node = document.createElement('figure')
       const urlReg = /http(s)?:\/\/(\S+):(\d+)\//
-      const wait = 100,duration = wait + (wait > 25 ? wait : 25)
+      const wait = 100
       node.style.height = '10px'
-      node.setAttribute('img-src', validImage_transparent)
-      node.setAttribute('img-placeholder', validImage_transparent)
+      node.setAttribute('img-src', validImageTransparent)
+      node.setAttribute('img-placeholder', validImageBlack)
       document.body.appendChild(node)
+      window._weex_perf.renderTime.length = 3
       getThrottleLazyload(wait, node)()
-      document.body.removeChild(node)
-      
expect(node.style.backgroundImage.replace(urlReg,'')).to.be.equal('url('+validImage_transparent+')')
+      setTimeout(() => {
+        expect(node.style.backgroundImage.replace(urlReg, 
'')).to.be.equal('url(' + validImageTransparent + ')')
+        done()
+        document.body.removeChild(node)
+      }, 100)
     })
   })
 })

Reply via email to