@whitewizard/countdown 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/countdown.vue +1 -1
- package/package.json +2 -5
- package/test/Countdown.test.js +86 -79
package/countdown.vue
CHANGED
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
},
|
|
73
73
|
methods: {
|
|
74
74
|
getDatePart(i) {
|
|
75
|
-
return this.getDiffArray[i].padStart(2, '0');
|
|
75
|
+
return this.getDiffArray && this.getDiffArray[i] && this.getDiffArray[i].toString() && this.getDiffArray[i].toString().padStart(2, '0') || '00';
|
|
76
76
|
},
|
|
77
77
|
getSeparator(i) {
|
|
78
78
|
if (typeof this.separators !== 'string' && this.separators.length === 2) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whitewizard/countdown",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Universal countdown Vue component",
|
|
5
5
|
"main": "countdown.vue",
|
|
6
6
|
"scripts": {
|
|
@@ -27,8 +27,5 @@
|
|
|
27
27
|
"vue-loader": "^13.3.0",
|
|
28
28
|
"vue-template-compiler": "^2.5.2",
|
|
29
29
|
"webpack": "^3.8.1"
|
|
30
|
-
}
|
|
31
|
-
"pre-commit": [
|
|
32
|
-
"test"
|
|
33
|
-
]
|
|
30
|
+
}
|
|
34
31
|
}
|
package/test/Countdown.test.js
CHANGED
|
@@ -6,89 +6,96 @@ import moment from 'moment';
|
|
|
6
6
|
Vue.config.productionTip = false;
|
|
7
7
|
Vue.config.devtools = false;
|
|
8
8
|
|
|
9
|
-
function getViewModel
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
function getViewModel(Component, propsData) {
|
|
10
|
+
const Constructor = Vue.extend(Component);
|
|
11
|
+
return new Constructor({propsData}).$mount();
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
describe('Countdown component: ', () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('methods: ', () => {
|
|
57
|
-
it('getDatePart result is correctly padded', () => {
|
|
58
|
-
const getDatePart = diffArray => Countdown.methods.getDatePart.call({getDiffArray: diffArray}, 1);
|
|
59
|
-
|
|
60
|
-
assert.equal(getDatePart([0, 1, 2]), '01');
|
|
61
|
-
assert.equal(getDatePart([0, 123, 2]), '123')
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('getSeparator returns correct separator', () => {
|
|
65
|
-
const separators = ['h', 'm', 's'],
|
|
66
|
-
res = Countdown.methods.getSeparator.call({separators, getSeparators: separators }, 1);
|
|
67
|
-
|
|
68
|
-
assert.equal(res, 'm');
|
|
15
|
+
describe('computed properties: ', () => {
|
|
16
|
+
|
|
17
|
+
it('getDateDataParts returns correct array of dateparts', () => {
|
|
18
|
+
const format = ['h', 'm', 's'];
|
|
19
|
+
|
|
20
|
+
let res = Countdown.computed.getDateDataParts.call({format: format.join(':')});
|
|
21
|
+
assert.deepEqual(res, format);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('getSeparators returns correct array of separators', () => {
|
|
25
|
+
const separators = ['h', 'min', 'sekundit'];
|
|
26
|
+
|
|
27
|
+
let res = Countdown.computed.getSeparators.call({separators: separators.join(':')});
|
|
28
|
+
assert.deepEqual(res, separators);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('hasCountDownEnded returns true if timeDiff is < 1000', (done) => {
|
|
32
|
+
const hasCountDownEnded = (timeDiff) => Countdown.computed.hasCountDownEnded.call({timeDiff});
|
|
33
|
+
|
|
34
|
+
assert.isTrue(hasCountDownEnded(0));
|
|
35
|
+
assert.isTrue(hasCountDownEnded(-2000));
|
|
36
|
+
assert.isTrue(hasCountDownEnded(999));
|
|
37
|
+
assert.isFalse(hasCountDownEnded(1000));
|
|
38
|
+
assert.isFalse(hasCountDownEnded(1001));
|
|
39
|
+
assert.isFalse(hasCountDownEnded(5000));
|
|
40
|
+
done();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('getDiffArray returns correct array', () => {
|
|
44
|
+
const format = ['minutes', 'seconds'];
|
|
45
|
+
const getDiffArray = (timeDiff) => Countdown.computed.getDiffArray.call({
|
|
46
|
+
timeDiff,
|
|
47
|
+
getDateDataParts: format
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
assert.lengthOf(getDiffArray(0), 0, 'returns empty array if timeDiff is 0');
|
|
51
|
+
assert.lengthOf(getDiffArray(12345), format.length, 'array has same length as format');
|
|
52
|
+
assert.deepEqual(getDiffArray(1000 * 60 * 60 * 2 + 1000 * 60 + 1000 * 4), [121, 4], 'calculates array members correctly')
|
|
53
|
+
});
|
|
69
54
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
55
|
+
|
|
56
|
+
describe('methods: ', () => {
|
|
57
|
+
it('getDatePart result is correctly padded', () => {
|
|
58
|
+
const getDatePart = diffArray => Countdown.methods.getDatePart.call({getDiffArray: diffArray}, 1);
|
|
59
|
+
|
|
60
|
+
assert.equal(getDatePart([0, 1, 2]), '01');
|
|
61
|
+
assert.equal(getDatePart([0, 123, 2]), '123')
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('getSeparator returns correct separator', () => {
|
|
65
|
+
const getDatePart = (a) => Countdown.methods.getDatePart.call({getDiffArray: [0, 1, 2]}, a),
|
|
66
|
+
res = Countdown.methods.getSeparator.call({
|
|
67
|
+
separators: [
|
|
68
|
+
'päeva:tundi:minutit:sekundit',
|
|
69
|
+
'päev:tund:minut:sekund',
|
|
70
|
+
],
|
|
71
|
+
getSeparators: ['h', 'm', 's'],
|
|
72
|
+
getDatePart
|
|
73
|
+
}, 1);
|
|
74
|
+
|
|
75
|
+
assert.equal(res, 'tund');
|
|
76
|
+
});
|
|
81
77
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
|
|
79
|
+
describe('Countdown functionality: ', () => {
|
|
80
|
+
it('emits countDownEnd event if timeDiff is < 1000', (done) => {
|
|
81
|
+
let vm = getViewModel(Countdown, {
|
|
82
|
+
end: moment().add(50, 'milliseconds').format()
|
|
83
|
+
}).$mount();
|
|
84
|
+
|
|
85
|
+
vm.$on('countDownEnd', () => {
|
|
86
|
+
done();
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('root element has countdown-ended class if timeDiff is < 1000', (done) => {
|
|
91
|
+
let vm = getViewModel(Countdown, {
|
|
92
|
+
end: moment().add(100, 'milliseconds').format()
|
|
93
|
+
}).$mount();
|
|
94
|
+
|
|
95
|
+
vm.$nextTick(() => {
|
|
96
|
+
assert.isTrue(vm.$el.className.includes('countdown-ended'));
|
|
97
|
+
done();
|
|
98
|
+
})
|
|
99
|
+
})
|
|
92
100
|
})
|
|
93
|
-
})
|
|
94
101
|
});
|