* [html5] fix lazyload 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/1a77685a Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/1a77685a Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/1a77685a Branch: refs/heads/0.15-dev Commit: 1a77685a027d0261ebb8a4f871e380d2a1a66cf0 Parents: f00356a Author: erha19 <faterr...@gmail.com> Authored: Thu Jul 13 22:38:14 2017 +0800 Committer: erha19 <faterr...@gmail.com> Committed: Thu Jul 13 22:38:14 2017 +0800 ---------------------------------------------------------------------- html5/test/render/vue/utils/lazyload.js | 49 ++++++++++++++-------------- 1 file changed, 25 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/1a77685a/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 59c5593..5f5eeaa 100644 --- a/html5/test/render/vue/utils/lazyload.js +++ b/html5/test/render/vue/utils/lazyload.js @@ -19,48 +19,49 @@ 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 invalidImage = 'data:image/jpeg;base64,' before(() => { - this.clock = sinon.useFakeTimers() + // this.clock = sinon.useFakeTimers() }) after(() => { - this.clock.restore() - }) - it('applySrc', () => { - const { - applySrc - } = lazyload - const node = document.createElement('figure') - node.setAttribute('img-src', 'http://via.placeholder.com/1x1') - node.setAttribute('img-placeholder', 'http://via.placeholder.com/2x2') - document.body.appendChild(node) - expect(applySrc(node, '')).to.be.a('undefined') - expect(node.attributes[0].name).to.be.equal('img-src') + // this.clock.restore() }) it('fireLazyload', () => { const { fireLazyload } = lazyload const node = document.createElement('figure') - node.setAttribute('img-src', 'http://via.placeholder.com/1x1') - node.setAttribute('img-placeholder', 'http://via.placeholder.com/2x2') + const urlReg = /http(s)?:\/\/(\S+):(\d+)\// + node.style.height = '10px' + node.setAttribute('img-src', validImage_transparent) + node.setAttribute('img-placeholder', validImage_transparent) document.body.appendChild(node) + 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) fireLazyload(node, true) - expect(node.style.backgroundImage).to.be.equal('url(http://via.placeholder.com/1x1)') + expect(node.style.backgroundImage.replace(urlReg,'')).to.be.equal('url('+validImage_black+')') + document.body.removeChild(node) }) it('getThrottleLazyload', () => { const { getThrottleLazyload } = lazyload const node = document.createElement('figure') - node.setAttribute('img-src', 'http://via.placeholder.com/1x1') - node.setAttribute('img-placeholder', 'http://via.placeholder.com/2x2') + const urlReg = /http(s)?:\/\/(\S+):(\d+)\// + const wait = 100,duration = wait + (wait > 25 ? wait : 25) + node.style.height = '10px' + node.setAttribute('img-src', validImage_transparent) + node.setAttribute('img-placeholder', validImage_transparent) document.body.appendChild(node) - const throttle = getThrottleLazyload(100, node) - expect(throttle).to.be.a('function') - throttle() - // this.clock.tick(100) - // console.log(node.style.backgroundImage) - // expect(node.style.backgroundImage).to.be.equal('url(http://localhost:9876/img-src.jpg)') + getThrottleLazyload(wait, node)() + document.body.removeChild(node) + expect(node.style.backgroundImage.replace(urlReg,'')).to.be.equal('url('+validImage_transparent+')') }) }) })