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/20 08:30:02 UTC

[32/50] incubator-weex git commit: * [html5] improve lazyload unit test case

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

Branch: refs/heads/0.15-dev
Commit: 30a52ef4f742e7f3dabcfb840c4a3fa3599392a0
Parents: abb4d66
Author: erha19 <fa...@gmail.com>
Authored: Mon Jul 17 20:49:32 2017 +0800
Committer: erha19 <fa...@gmail.com>
Committed: Mon Jul 17 20:49:32 2017 +0800

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


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/30a52ef4/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 7fc25a7..6f574d4 100644
--- a/html5/test/render/vue/utils/lazyload.js
+++ b/html5/test/render/vue/utils/lazyload.js
@@ -23,9 +23,11 @@ describe('utils', function () {
     const validImageBlack = 'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs='
     const invalidImage = 'data:image/jpeg;base64,'
     before(() => {
+      this.weexEmit = sinon.stub(window.weex, 'emit')
       //   this.clock = sinon.useFakeTimers()
     })
     after(() => {
+      this.weexEmit.restore()
       //   this.clock.restore()
     })
     it('fireLazyload', (done) => {
@@ -34,20 +36,24 @@ describe('utils', function () {
       } = lazyload
       const node = document.createElement('figure')
       const urlReg = /http(s)?:\/\/(\S+):(\d+)\//
-      //  const IMG_REC_INDENT = 500
+      const IMG_REC_INDENT = 500
       node.setAttribute('img-src', invalidImage)
       node.setAttribute('img-placeholder', validImageBlack)
       node.style.height = '10px'
-        //  coverage branch if (item._src_loading)
+      //  coverage branch if (item._src_loading)
       node._src_loading = true
-        //  coverage branch if (Array.isArray(el))
+      //  coverage branch if (Array.isArray(el))
       fireLazyload([node])
       node._src_loading = false
       fireLazyload(node, true)
       setTimeout(() => {
         expect(node.style.backgroundImage.replace(urlReg, '')).to.be.equal('url(' + validImageBlack + ')')
-        done()
-        document.body.removeChild(node)
+        setTimeout(() => {
+          expect(this.weexEmit.withArgs('renderfinish').callCount).to.be.equal(1)
+          expect(this.weexEmit.withArgs('firstscreenfinish').callCount).to.be.equal(0)
+          done()
+          document.body.removeChild(node)
+        }, IMG_REC_INDENT)
       }, 100)
     })
     it('getThrottleLazyload', (done) => {
@@ -57,16 +63,21 @@ describe('utils', function () {
       const node = document.createElement('figure')
       const urlReg = /http(s)?:\/\/(\S+):(\d+)\//
       const wait = 100
+      const IMG_REC_INDENT = 500
       node.style.height = '10px'
       node.setAttribute('img-src', validImageTransparent)
       node.setAttribute('img-placeholder', validImageBlack)
       document.body.appendChild(node)
-      window._weex_perf.renderTime.length = 3
+      window._first_screen_detected = false
       getThrottleLazyload(wait, node)()
       setTimeout(() => {
         expect(node.style.backgroundImage.replace(urlReg, '')).to.be.equal('url(' + validImageTransparent + ')')
-        done()
-        document.body.removeChild(node)
+        setTimeout(() => {
+          expect(this.weexEmit.withArgs('renderfinish').callCount).to.be.equal(2)
+          expect(this.weexEmit.withArgs('firstscreenfinish').callCount).to.be.equal(1)
+          done()
+          document.body.removeChild(node)
+        }, IMG_REC_INDENT)
       }, 100)
     })
   })