From ecac075bef94c906458c006376e6ec2bd08dc57e Mon Sep 17 00:00:00 2001 From: pangxie1991 Date: Mon, 17 Apr 2017 11:03:13 +0800 Subject: [PATCH] waterfall specs --- test/unit/components/waterfall.vue | 49 ++++++++++++++++++++ test/unit/get-webpack-conf.js | 4 ++ test/unit/specs/search.spec.js | 2 +- test/unit/specs/waterfall.spec.js | 72 ++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 test/unit/components/waterfall.vue create mode 100644 test/unit/specs/waterfall.spec.js diff --git a/test/unit/components/waterfall.vue b/test/unit/components/waterfall.vue new file mode 100644 index 000000000..b60910883 --- /dev/null +++ b/test/unit/components/waterfall.vue @@ -0,0 +1,49 @@ + + + diff --git a/test/unit/get-webpack-conf.js b/test/unit/get-webpack-conf.js index 73ecfcb6e..2f1d20772 100644 --- a/test/unit/get-webpack-conf.js +++ b/test/unit/get-webpack-conf.js @@ -16,6 +16,10 @@ const webpackConfig = { ], postcss: getPostcssPlugin, resolve: { + modules: [ + path.resolve(process.cwd(), 'node_modules'), + 'node_modules' + ], extensions: [ '', '.js', diff --git a/test/unit/specs/search.spec.js b/test/unit/specs/search.spec.js index f2bae3644..0f6da1e38 100644 --- a/test/unit/specs/search.spec.js +++ b/test/unit/specs/search.spec.js @@ -36,6 +36,6 @@ describe('Search', () => { expect(eventStub.calledOnce).to.be.true; expect(eventStub.calledWith('change')); done(); - }) + }); }); }); diff --git a/test/unit/specs/waterfall.spec.js b/test/unit/specs/waterfall.spec.js new file mode 100644 index 000000000..dab152e82 --- /dev/null +++ b/test/unit/specs/waterfall.spec.js @@ -0,0 +1,72 @@ +import Waterfall from '../components/waterfall'; +import { mount } from 'avoriaz'; + +describe('Waterfall', () => { + let wrapper; + afterEach(() => { + wrapper && wrapper.destroy(); + }); + + it('create', (done) => { + const waterfallLowerSpy = sinon.spy(); + wrapper = mount(Waterfall, { + attachToDocument: true, + propsData: { + disabled: false, + list: [], + onWaterfallLower: waterfallLowerSpy + } + }); + + setTimeout(() => { + expect(waterfallLowerSpy.called).to.be.true; + done(); + }, 500); + }); + + it('test waterfall lower function', (done) => { + const waterfallLowerSpy = sinon.spy(function() { + wrapper.vm.list = wrapper.vm.list.concat([{ id: 1 }, { id: 2 }, { id: 3 }]); + wrapper.vm.disabled = true; + }); + wrapper = mount(Waterfall, { + attachToDocument: true, + propsData: { + disabled: false, + list: [{ id: 10 }], + onWaterfallLower: waterfallLowerSpy + } + }); + + setTimeout(() => { + const item = wrapper.find('.waterfall-item'); + expect(waterfallLowerSpy.calledOnce).to.be.true; + expect(item.length).to.equal(4); + expect(item[item.length - 1].text()).to.equal('3'); + done(); + }, 500); + }); + + it('test waterfall upper function', (done) => { + const waterfallUpperSpy = sinon.spy(function() { + wrapper.vm.list.unshift({ id: 1 }, { id: 2 }, { id: 3 }); + wrapper.vm.disabled = true; + }); + wrapper = mount(Waterfall, { + attachToDocument: true, + propsData: { + disabled: false, + list: [{ id: 10 }], + onWaterfallUpper: waterfallUpperSpy + } + }); + + setTimeout(() => { + const item = wrapper.find('.waterfall-item'); + expect(waterfallUpperSpy.calledOnce).to.be.true; + expect(item.length).to.equal(4); + expect(item[0].text()).to.equal('1'); + done(); + }, 500); + }); +});