浏览代码

test(price,backtop,range,infiniteloading): optimization test (#1123)

Drjingfubo 3 年之前
父节点
当前提交
0c7fb63fe3

+ 12 - 3
src/packages/__VUE/backtop/__tests__/backtop.spec.ts

@@ -1,7 +1,9 @@
 import { mount, config } from '@vue/test-utils';
 import BackTop from '../index.vue';
+import { mockScrollTop } from './../../../utils/unit';
 
 import NutIcon from '../../icon/index.vue';
+import { nextTick } from 'vue';
 
 beforeAll(() => {
   config.global.components = {
@@ -35,22 +37,29 @@ test('backtop style', () => {
   expect(backtop.element.style.bottom).toBe('50px');
 });
 
-test('backtop style', () => {
+test('backtop style,backtop show', async () => {
   const wrapper = mount(BackTop, {
     props: {
       right: 40
     }
   });
+  await mockScrollTop(1000);
+  const show: any = wrapper.find('.show');
+  expect(show.exists()).toBe(true);
   const backtop: any = wrapper.find('.nut-backtop');
   expect(backtop.element.style.right).toBe('40px');
 });
 
-test('backtop style', () => {
+test('backtop style', async () => {
   const wrapper = mount(BackTop, {
     props: {
-      zIndex: 100
+      zIndex: 100,
+      distance: 0
     }
   });
+  await nextTick();
   const backtop: any = wrapper.find('.nut-backtop');
+  const show: any = wrapper.find('.show');
   expect(backtop.element.style.zIndex).toBe('100');
+  expect(show.exists()).toBe(true);
 });

+ 4 - 0
src/packages/__VUE/backtop/index.vue

@@ -130,11 +130,15 @@ export default create({
       if (props.elId && document.getElementById(props.elId)) {
         state.scrollEl = document.getElementById(props.elId) as HTMLElement | Window;
       }
+
       addEventListener();
       initCancelAniFrame();
     }
 
     onMounted(() => {
+      if (props.distance == 0) {
+        state.backTop = true;
+      }
       init();
     });
 

+ 32 - 0
src/packages/__VUE/badge/__test__/__snapshots__/badge.spec.ts.snap

@@ -0,0 +1,32 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should change dot position when using offset prop: -2px 1`] = `""`;
+
+exports[`should change dot position when using offset prop: 4px 1`] = `""`;
+
+exports[`should render content slot correctly 1`] = `
+"<view class=\\"nut-badge\\">
+  <view class=\\"slot-icons\\"></view>Custom Content<view class=\\"nut-badge__content sup\\" style=\\"top: 0px; right: 0px; z-index: 9; display: none;\\"></view>
+</view>"
+`;
+
+exports[`should render nothing when content is empty string 1`] = `
+"<view class=\\"nut-badge\\">
+  <view class=\\"slot-icons\\"></view>
+  <view class=\\"nut-badge__content sup\\" style=\\"top: 0px; right: 0px; z-index: 9; display: none;\\"></view>
+</view>"
+`;
+
+exports[`should render nothing when content is undefined 1`] = `
+"<view class=\\"nut-badge\\">
+  <view class=\\"slot-icons\\"></view>
+  <view class=\\"nut-badge__content sup\\" style=\\"top: 0px; right: 0px; z-index: 9; display: none;\\"></view>
+</view>"
+`;
+
+exports[`should render nothing when content is zero 1`] = `
+"<view class=\\"nut-badge\\">
+  <view class=\\"slot-icons\\"></view>
+  <view class=\\"nut-badge__content sup\\" style=\\"top: 0px; right: 0px; z-index: 9; display: none;\\">0</view>
+</view>"
+`;

+ 3 - 1
src/packages/__VUE/infiniteloading/__tests__/infiniteloading.spec.ts

@@ -23,7 +23,8 @@ afterAll(() => {
 test('pull base', async () => {
   const wrapper = mount(InfiniteLoading, {
     props: {
-      isOpenRefresh: true
+      isOpenRefresh: true,
+      loadMoreTxt: '没有更多'
     }
   });
   const track = wrapper.find('.nut-infiniteloading');
@@ -51,6 +52,7 @@ test('infiniteloading base', async () => {
     template: `
     <nut-infiniteloading
       :has-more="hasMore"
+      load-more-txt="没有啦~"
       @load-more="loadMore">
         <li class="infiniteLi" v-for="(item, index) in defultList" :key="index">{{item}}</li>
     </nut-infiniteloading>

+ 9 - 23
src/packages/__VUE/price/__tests__/price.spec.ts

@@ -19,22 +19,9 @@ test('base price', () => {
     }
   });
   const price: any = wrapper.find('.nut-price');
-  console.log('price', price.text());
   expect(price.text()).toBe('¥199.99');
 });
 
-// test('base price', () => {
-//   const wrapper = mount(Price, {
-//     props: {
-//       price: '199.999',
-//       decimalDigits: '2'
-//     }
-//   });
-//   const price: any = wrapper.find('.nut-price');
-//   console.log('price', price.text())
-//   expect(price.text()).toBe('¥199.99');
-// });
-
 test('decimalDigits price', () => {
   const wrapper = mount(Price, {
     props: {
@@ -43,7 +30,6 @@ test('decimalDigits price', () => {
     }
   });
   const price: any = wrapper.find('.nut-price');
-  console.log('price', price.text());
   expect(price.text()).toBe('¥299.9');
 });
 
@@ -52,15 +38,15 @@ test('default needSymbol props', () => {
   const price: any = wrapper.find('.nut-price');
   expect(price.find('.nut-price--symbol').text()).toBe('¥');
 });
-// test('needSymbol props', () => {
-//   const wrapper = mount(Price, {
-//     props: {
-//       needSymbol: false
-//     }
-//   });
-//   const price: any = wrapper.find('.nut-price');
-//   expect(price.find('.nut-price--symbol')).toBeNull();
-// });
+test('needSymbol props', () => {
+  const wrapper = mount(Price, {
+    props: {
+      needSymbol: false
+    }
+  });
+  const price: any = wrapper.find('.nut-price');
+  expect(price.find('.nut-price--symbol').exists()).toBe(false);
+});
 test('symbol props', () => {
   const wrapper = mount(Price, {
     props: {

+ 4 - 2
src/packages/__VUE/range/__test__/range.spec.ts

@@ -31,15 +31,17 @@ test('should set min and max when use min and max props', async () => {
     props: {
       modelValue: 0,
       max: 10,
-      min: -10
+      min: -10,
+      range: true
     }
   });
+
   let min = wrapper.find<HTMLElement>('.min');
   let max = wrapper.find<HTMLElement>('.max');
   let btn = wrapper.find<HTMLElement>('.nut-range-button-wrapper-left .number');
   expect(min.text()).toBe('-10');
   expect(max.text()).toBe('10');
-  expect(btn.text()).toBe('0');
+  expect(btn.text()).toBe('');
 });
 
 test('should change color template when use color props', async () => {