NoticeBar: add test cases

This commit is contained in:
陈嘉涵 2017-08-28 14:20:34 +08:00
parent a1aededecb
commit c357dd4e71
4 changed files with 68 additions and 7 deletions

View File

@ -21,9 +21,7 @@ Vue.component(NoticeBar.name, NoticeBar);
:::demo 基础用法 :::demo 基础用法
```html ```html
<van-notice-bar> <van-notice-bar text="足协杯战线连续第2年上演广州德比战上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。">
足协杯战线连续第2年上演广州德比战上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。
</van-notice-bar>
``` ```
::: :::

View File

@ -2,7 +2,7 @@
<div v-show="showNoticeBar" @click="$emit('click')" :class="['van-notice-bar', { 'van-notice-bar--withicon': mode }]"> <div v-show="showNoticeBar" @click="$emit('click')" :class="['van-notice-bar', { 'van-notice-bar--withicon': mode }]">
<div class="van-notice-bar__content-wrap" ref="contentWrap"> <div class="van-notice-bar__content-wrap" ref="contentWrap">
<div class="van-notice-bar__content" ref="content" :style="contentStyle" @transitionend="onTransitionEnd"> <div class="van-notice-bar__content" ref="content" :style="contentStyle" @transitionend="onTransitionEnd">
<slot></slot> <slot>{{ text }}</slot>
</div> </div>
</div> </div>
<van-icon class="van-notice-bar__icon" :name="iconName" v-if="iconName" @click="onClickIcon" /> <van-icon class="van-notice-bar__icon" :name="iconName" v-if="iconName" @click="onClickIcon" />
@ -22,6 +22,7 @@ export default {
}, },
props: { props: {
text: String,
mode: { mode: {
type: String, type: String,
default: '', default: '',

View File

@ -7,14 +7,14 @@ const defaultProps = {
leftWidth: 100, leftWidth: 100,
rightWidth: 100 rightWidth: 100
} }
} };
describe('CellSwipe', () => { describe('CellSwipe', () => {
let wrapper; let wrapper;
afterEach(() => { afterEach(() => {
wrapper && wrapper.destroy(); wrapper && wrapper.destroy();
}); });
it('render left or right part when has width', () => { it('render left or right part when has width', () => {
wrapper = mount(CellSwipe, defaultProps); wrapper = mount(CellSwipe, defaultProps);
expect(wrapper.find('.van-cell-swipe__left').length).to.equal(1); expect(wrapper.find('.van-cell-swipe__left').length).to.equal(1);
@ -97,7 +97,7 @@ describe('CellSwipe', () => {
triggerTouch(wrapper, 'touchstart', 0, 0); triggerTouch(wrapper, 'touchstart', 0, 0);
triggerTouch(wrapper, 'touchmove', 1, 0); triggerTouch(wrapper, 'touchmove', 1, 0);
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
expect(wrapper.vm.offset).to.equal(0); expect(wrapper.vm.offset).to.equal(0);
expect(wrapper.vm.opened).to.be.false; expect(wrapper.vm.opened).to.be.false;

View File

@ -0,0 +1,62 @@
import NoticeBar from 'packages/notice-bar';
import { mount } from 'avoriaz';
describe('NoticeBar', () => {
let wrapper;
afterEach(() => {
wrapper && wrapper.destroy();
});
it('create a notice-bar', () => {
wrapper = mount(NoticeBar, {
propsData: {},
attachToDocument: true
});
expect(wrapper.hasClass('van-notice-bar')).to.be.true;
});
it('mode closeable', () => {
wrapper = mount(NoticeBar, {
propsData: {
mode: 'closeable'
},
attachToDocument: true
});
const icon = wrapper.find('.van-icon-close');
expect(icon.length).to.equal(1);
icon[0].trigger('click');
expect(wrapper.hasStyle('display', 'none'));
});
it('mode link', () => {
wrapper = mount(NoticeBar, {
propsData: {
mode: 'link'
},
attachToDocument: true
});
expect(wrapper.find('.van-icon-arrow').length).to.equal(1);
});
it('notice-bar transitionend', (done) => {
wrapper = mount(NoticeBar, {
propsData: {
text: '足协杯战线连续第2年上演广州德比战上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。足协杯战线连续第2年上演广州德比战上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。足协杯战线连续第2年上演广州德比战上赛季半决赛上恒大以两回合5-3的总比分淘汰富力。',
speed: 10000,
delay: 0
},
attachToDocument: true
});
const content = wrapper.find('.van-notice-bar__content')[0];
setTimeout(() => {
expect(content.hasStyle('transition-delay', '0s')).to.be.true;
done();
}, 1500);
});
});