Skip to content

Commit 55791ec

Browse files
fix: countdown/picker/imagepreview/dialog 组件单元测试修改 (#1886)
* fix: 修复 ImagePreview 在Taro编译成H5后报错的问题 * fix: 地址关闭时, Close 事件触发两次问题解决 * feat: 组件DatePicker 添加双向绑定 * docs: 组件Picker文档修改 * feat: 组件Picker与DatePicker新增属性safe-area-inset-bottom * feat: imagepreview * fix: 组件imagepreview点击视频遮罩关闭(#1729) * fix: 解决 Picker 在微信小程序中无法使用问题 (#1774) * fix: 修改 Picker 组件 v-model 失效问题 * fix: 组件NoticeBar修改height之后,垂直轮播会卡顿 * fix: 删除Datepicker Demo演示多余内容 * fix: 组件Picker在JD小程序上适配 * fix: 组件Address京东小程序适配 * feat: 京东小程序适配 * fix: 删除空格 * feat: 删除console * fix: 京东小程序imagepreview适配 * fix: 修复 imagepreview 动态设置 initNo 显示不正确问题 * fix: 组件 InfiniteLoading 某些情况下会错误触发下拉刷新#1819 * fix: 删除pullrefresh * feat: 组件 imagepreview瘦身 * feat: 组件Picker 瘦身 * fix: address线上问题修改 * fix: 完善imagepreview * feat: 公共函数提取 * feat: 函数式改用 createComponent * fix: 文件回撤 * feat: 单元测试修改
1 parent d8cac09 commit 55791ec

File tree

6 files changed

+47
-142
lines changed

6 files changed

+47
-142
lines changed

src/packages/__VUE/countdown/__tests__/countdown.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('endTime props', async () => {
2020
}
2121
});
2222
expect(wrapper.emitted('on-end')).toBeFalsy();
23-
await sleep(1000);
23+
await sleep(1100);
2424
expect(wrapper.emitted('on-end')).toBeTruthy();
2525
});
2626

src/packages/__VUE/datepicker/__tests__/datepicker.spec.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import NutRange from '../../range/index.vue';
55
import NutPicker from '../../picker/index.vue';
66
import NutPopup from '../../popup/index.vue';
77
import NutPickerColumn from '../../picker/Column.vue';
8+
import NutOverlay from '../../overlay/index.vue';
89
import DatePicker from '../../datepicker/index.vue';
910

1011
function sleep(delay = 0): Promise<void> {
@@ -19,7 +20,8 @@ beforeAll(() => {
1920
NutRange,
2021
NutPicker,
2122
NutPopup,
22-
NutPickerColumn
23+
NutPickerColumn,
24+
NutOverlay
2325
};
2426
});
2527

@@ -38,8 +40,8 @@ test('Do not display Chinese', async () => {
3840
}
3941
});
4042
await nextTick();
41-
expect(wrapper.find('.nut-picker__confirm').exists()).toBeTruthy();
42-
const confirm = wrapper.find('.nut-picker__confirm');
43+
expect(wrapper.find('.nut-picker__right').exists()).toBeTruthy();
44+
const confirm = wrapper.find('.nut-picker__right');
4345
confirm.trigger('click');
4446
expect(wrapper.emitted().confirm[0]).toEqual([
4547
{

src/packages/__VUE/dialog/__tests__/function.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ describe('function Dialog', () => {
115115
cancelText: '取消文案自定义',
116116
okText: '确定文案自定义'
117117
});
118-
await sleep(500);
118+
await sleep(1000);
119119
let cancelText = document.querySelector(
120-
`#dialog-${dialog.options.id} .nut-dialog .nut-dialog__footer-cancel > view > view`
120+
`#dialog-${dialog.options.id} .nut-dialog .nut-dialog__footer-cancel `
121121
) as HTMLDivElement;
122122
expect(cancelText.innerHTML).toEqual('取消文案自定义');
123123
let okText = document.querySelector(
124-
`#dialog-${dialog.options.id} .nut-dialog .nut-dialog__footer-ok > view > view`
124+
`#dialog-${dialog.options.id} .nut-dialog .nut-dialog__footer-ok`
125125
) as HTMLDivElement;
126126
expect(okText.innerHTML).toEqual('确定文案自定义');
127127
});

src/packages/__VUE/imagepreview/__tests__/__snapshots__/imagepreview.spec.ts.snap

-97
This file was deleted.

src/packages/__VUE/imagepreview/__tests__/imagepreview.spec.ts

+29-30
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1-
import { mount } from '@vue/test-utils';
1+
import { mount, config } from '@vue/test-utils';
22
import ImagePreview from '../index.vue';
33
import { nextTick, reactive, toRefs } from 'vue';
4-
// import { trigger } from '@/packages/utils/unit';
4+
import NutOverlay from '../../overlay/index.vue';
5+
import NutIcon from '../../icon/index.vue';
6+
import NutPopup from '../../popup/index.vue';
7+
import NutSwiper from '../../swiper/index.vue';
8+
import NutSwiperItem from '../../swiperitem/index.vue';
9+
import NutVideo from '../../video/index.vue';
10+
11+
beforeAll(() => {
12+
config.global.components = {
13+
NutOverlay,
14+
NutIcon,
15+
NutPopup,
16+
NutSwiper,
17+
NutSwiperItem,
18+
NutVideo
19+
};
20+
});
21+
22+
afterAll(() => {
23+
config.global.components = {};
24+
});
525

626
const images = [
727
{
@@ -25,18 +45,9 @@ const videos = [
2545
type: 'video/mp4'
2646
},
2747
options: {
28-
muted: true,
29-
controls: true
30-
}
31-
},
32-
{
33-
source: {
34-
src: 'https://storage.jd.com/about/big-final.mp4?Expires=3730193075&AccessKey=3LoYX1dQWa6ZXzQl&Signature=ViMFjz%2BOkBxS%2FY1rjtUVqbopbJI%3D',
35-
type: 'video/mp4'
36-
},
37-
options: {
38-
muted: true,
39-
controls: true
48+
autoplay: false,
49+
muted: false,
50+
controls: false
4051
}
4152
}
4253
];
@@ -49,7 +60,7 @@ test('basic usage test', async () => {
4960
}
5061
});
5162
await nextTick();
52-
expect((wrapper.find('.custom-pop').element as any).style.display).toEqual('');
63+
expect((wrapper.find('.nut-imagepreview-custom-pop').element as any).style.display).toEqual('');
5364
});
5465

5566
test('test autoplay', async () => {
@@ -63,10 +74,10 @@ test('test autoplay', async () => {
6374

6475
await nextTick();
6576

66-
expect(wrapper.vm.active).toBe(1);
77+
expect(wrapper.vm.active).toBe(0);
6778

6879
setTimeout(() => {
69-
expect(wrapper.vm.active).toBe(2);
80+
expect(wrapper.vm.active).toBe(1);
7081
}, 3000);
7182
});
7283

@@ -79,7 +90,7 @@ test('init page No.', async () => {
7990
}
8091
});
8192
await nextTick();
82-
expect(wrapper.find('.nut-imagepreview-index').html()).toMatchSnapshot();
93+
expect(wrapper.find('.nut-imagepreview-index').text()).toEqual('4 / 4');
8394
});
8495

8596
test('customize pagination and color', async () => {
@@ -97,18 +108,6 @@ test('customize pagination and color', async () => {
97108
expect(swiperPagination.findAll('i')[0].element.style.backgroundColor).toEqual('red');
98109
});
99110

100-
test('video surported in H5 env', async () => {
101-
const wrapper = mount(ImagePreview, {
102-
props: {
103-
show: true,
104-
images,
105-
videos
106-
}
107-
});
108-
await nextTick();
109-
expect(wrapper.find('.custom-pop').html()).toMatchSnapshot();
110-
});
111-
112111
function sleep(delay = 0): Promise<void> {
113112
return new Promise((resolve) => {
114113
setTimeout(resolve, delay);

src/packages/__VUE/picker/__tests__/picker.spec.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { config, mount } from '@vue/test-utils';
22
import Picker from '../index.vue';
33
import NutIcon from '../../icon/index.vue';
44
import NutPupup from '../../popup/index.vue';
5+
import NutOverlay from '../../overlay/index.vue';
56
import NutPickerColumn from '../Column.vue';
6-
import { nextTick, toRefs, reactive, ref, onMounted } from 'vue';
7-
import { triggerDrag } from '../../../utils/test/event';
7+
import { nextTick } from 'vue';
88

99
beforeAll(() => {
1010
config.global.components = {
1111
NutIcon,
1212
NutPupup,
13-
NutPickerColumn
13+
NutPickerColumn,
14+
NutOverlay
1415
};
1516
});
1617

@@ -96,8 +97,8 @@ test('first render', async () => {
9697
}
9798
});
9899
await nextTick();
99-
expect(wrapper.find('.nut-picker__cancel').exists()).toBeTruthy();
100-
expect(wrapper.find('.nut-picker__confirm').exists()).toBeTruthy();
100+
expect(wrapper.find('.nut-picker__left').exists()).toBeTruthy();
101+
expect(wrapper.find('.nut-picker__right').exists()).toBeTruthy();
101102
});
102103

103104
test('simple list-data confirm & close event', async () => {
@@ -109,8 +110,8 @@ test('simple list-data confirm & close event', async () => {
109110
}
110111
});
111112
await nextTick();
112-
wrapper.find('.nut-picker__cancel').trigger('click');
113-
wrapper.find('.nut-picker__confirm').trigger('click');
113+
wrapper.find('.nut-picker__left').trigger('click');
114+
wrapper.find('.nut-picker__right').trigger('click');
114115
expect(wrapper.emitted('confirm')![0]).toEqual([
115116
{
116117
selectedOptions: [{ text: '南京市', value: 'NanJing' }],
@@ -129,7 +130,7 @@ test('simple columns default checked item', async () => {
129130
}
130131
});
131132
await nextTick();
132-
wrapper.find('.nut-picker__confirm').trigger('click');
133+
wrapper.find('.nut-picker__right').trigger('click');
133134
expect(wrapper.emitted('confirm')![0]).toEqual([
134135
{
135136
selectedOptions: [{ text: '无锡市', value: 'WuXi' }],

0 commit comments

Comments
 (0)