Browse Source

Merge branch 'v2' of https://github.com/jdf2e/nutui into v2

Frans 6 years ago
parent
commit
ae8d24f7fd

+ 3 - 3
src/packages/countdown/__test__/countdown.spec.js

@@ -1,5 +1,5 @@
 import {shallowMount} from '@vue/test-utils';
-import CountDown, {restTime} from '../countdown.vue';
+import CountDown, {restTime, fill2} from '../countdown.vue';
 
 describe('CountDown.vue', () => {
     const end = 1559334689373;
@@ -10,9 +10,9 @@ describe('CountDown.vue', () => {
     });
     it('默认显示时分秒', () => {
         const rest = restTime(end - Date.now());
-        const h = Number(rest.d) * 24 + Number(rest.h);
+        const h = fill2(Number(rest.d) * 24 + Number(rest.h));
         const text_h = wrapper.findAll('.nut-cd-block').at(0).text();
-        expect(h).toBe(Number(text_h));
+        expect(h).toBe(text_h);
         expect(h).toBe(wrapper.vm.resttime.h);
     });
 

+ 4 - 3
src/packages/countdown/countdown.vue

@@ -4,7 +4,7 @@
       <span class="nut-cd-block">{{plainText}}</span>
     </template>
     <template v-else>
-      <template v-if="resttime.d > 0 && showDays">
+      <template v-if="resttime.d >= 0 && showDays">
         <span class="nut-cd-block">{{resttime.d}}</span>
         <span class="nut-cd-dot">天</span>
       </template>
@@ -99,7 +99,7 @@ const countdownTimer = {
       const rest = restTime(this.restTime);
       const {d, h, m, s} = rest;
       if(!this.showDays && d > 0) {
-        rest.h = Number(rest.h) + d * 24;
+        rest.h = fill2(Number(rest.h) + d * 24);
         rest.d = 0;
       }
       return rest;
@@ -154,7 +154,8 @@ const countdownTimer = {
 }
 countdownTimer.restTime = restTime;
 
-export {restTime};
+// export fill2 for test
+export {restTime, fill2};
 export default countdownTimer; 
 </script>