Skip to content

Commit 1e177f0

Browse files
committed
updated and fixed tests
1 parent 4b06939 commit 1e177f0

12 files changed

+8308
-1477
lines changed

demo/demo.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<h1> Classic version, all default</h1>
88
<noyear></noyear>
99
<h1> Custom version with 18 complete months </h1>
10-
<noyearcustom :days=2 :months=18 :fullMonths=true></noyearcustom>
10+
<noyearcustom :days=2 :months=18 :fullMonths=true accent-color="#dbde1b"></noyearcustom>
1111
<h1> With years version, with 5 years</h1>
12-
<year :years=5></year>
12+
<year :years=5 accent-color="#f44336"></year>
1313
</div>
1414

1515
<script>

dist/draggableCal.common.js

+53-47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/draggableCal.common.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/draggableCal.umd.js

+53-47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/draggableCal.umd.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/draggableCal.umd.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/draggableCal.umd.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.vue

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
</div>
1111
</div>
1212
</div>
13-
<div class="arrow top left" @click="goLeft($event, 'yearly')" :style="{visibility: yearly.realOffset === 0 ? 'hidden' : 'visible'}">
13+
<div v-if="NUMBER_OF_YEARS" class="arrow top left" @click="goLeft($event, 'yearly')" :style="{visibility: yearly.realOffset === 0 ? 'hidden' : 'visible'}">
1414
</div>
15-
<div class="arrow top right" @click="goRight($event, 'yearly')" :style="{visibility: yearly.realOffset <= yearly.maxOffset ? 'hidden' : 'visible'}">
15+
<div v-if="NUMBER_OF_YEARS" class="arrow top right" @click="goRight($event, 'yearly')" :style="{visibility: yearly.realOffset <= yearly.maxOffset ? 'hidden' : 'visible'}">
1616
</div>
1717
<div :class="monthly.maxOffset < 0 ? 'wrapper' : 'wrapper-flex'">
1818
<div ref="monthly" state="monthly" class="months ui-draggable" style="left: 0px;" @mousedown="handleDrag($event)" @touchstart="handleDrag($event)" :style="monthly.phase === 'dragging' ? {pointerEvents: 'none', transition: 'none', cursor:'-webkit-grab'} : {} ">
@@ -157,6 +157,7 @@ export default {
157157
this.$refs[state].style.left = `${this[state].realOffset}px`;
158158
},
159159
goRight(e, state) {
160+
console.log(state);
160161
let elem = e.target.parentNode.querySelector(`[state="${state}"`);
161162
let cell = elem.firstChild;
162163
this[state].realOffset =
@@ -287,6 +288,10 @@ export default {
287288
let m = this.calendar.months;
288289
let d = this.calendar.days;
289290
year = Number(year);
291+
if (this.selectedDate.day) {
292+
this.selectedDate = {};
293+
this.$emit('dateCleared');
294+
}
290295
this.monthly.realOffset = 0;
291296
this.daily.realOffset = 0;
292297
m.splice(0, 14);

src/utils/buildCalendar.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ function splitDate(date) {
1212
};
1313
}
1414

15-
function computeMonthFromDays(NUMBER_OF_DAYS) {
15+
export function computeMonthsFromDays(NUMBER_OF_DAYS) {
1616
const date = new Date(gYear(TODAY), gMonth(TODAY), gDay(TODAY) + NUMBER_OF_DAYS);
1717
const NUMBER_OF_MONTHS = (gYear(date) - gYear(TODAY)) * 12 + gMonth(date) - gMonth(TODAY);
1818
return NUMBER_OF_MONTHS;
1919
}
20-
function computeDaysFromMonths(NUMBER_OF_MONTH) {
20+
export function computeDaysFromMonths(NUMBER_OF_MONTH) {
2121
const NUMBER_OF_DAYS =
2222
(Date.UTC(gYear(TODAY), gMonth(TODAY) + NUMBER_OF_MONTH) -
2323
Date.UTC(gYear(TODAY), gMonth(TODAY))) /
2424
(1000 * 60 * 60 * 24);
2525
return NUMBER_OF_DAYS;
2626
}
2727

28-
function createDaysArray(NUMBER_OF_DAYS, fullMonths) {
28+
export function createDaysArray(NUMBER_OF_DAYS, fullMonths) {
2929
if (NUMBER_OF_DAYS <= 0) return [];
3030
let currentConstructorDate = new Date();
3131
const days = [];
@@ -47,7 +47,7 @@ function createDaysArray(NUMBER_OF_DAYS, fullMonths) {
4747
return days;
4848
}
4949

50-
function createMonthsArray(NUMBER_OF_MONTHS) {
50+
export function createMonthsArray(NUMBER_OF_MONTHS) {
5151
if (NUMBER_OF_MONTHS <= 0) return [];
5252
let currentConstructorMonth = new Date();
5353
const months = [];
@@ -67,7 +67,7 @@ function createMonthsArray(NUMBER_OF_MONTHS) {
6767
return months;
6868
}
6969

70-
function createPrependArray(PREPEND_MONTHS) {
70+
export function createPrependArray(PREPEND_MONTHS) {
7171
const prepended = [{fullYear: gYear(TODAY), monthNumber: gMonth(TODAY)}];
7272
for (let i = 0; i < PREPEND_MONTHS; i++) {
7373
let year = prepended[0].fullYear;
@@ -82,7 +82,7 @@ function createPrependArray(PREPEND_MONTHS) {
8282
return prepended;
8383
}
8484

85-
function buildYear(year) {
85+
export function buildYear(year) {
8686
let currentConstructorDate = new Date(Date.UTC(year, 0, 1));
8787
const isLeap = year % 4 === 0 ? 1 : 0;
8888
const entireYear = {
@@ -113,7 +113,7 @@ export function buildEntireCalendar(NUMBER_OF_YEARS) {
113113
}
114114
export function buildCalendar(NUMBER_OF_DAYS, NUMBER_OF_MONTHS, PREPEND_MONTHS, fullMonths) {
115115
if (NUMBER_OF_MONTHS !== 12) NUMBER_OF_DAYS = computeDaysFromMonths(NUMBER_OF_MONTHS);
116-
else if (NUMBER_OF_DAYS !== 365) NUMBER_OF_MONTHS = computeMonthFromDays(NUMBER_OF_DAYS);
116+
else if (NUMBER_OF_DAYS !== 365) NUMBER_OF_MONTHS = computeMonthsFromDays(NUMBER_OF_DAYS);
117117

118118
const calendar = {
119119
days: createDaysArray(NUMBER_OF_DAYS, fullMonths),

tests/unit/App.spec.js

+64-11
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,32 @@ describe('VueCal', () => {
88
expect(wrapper.vm.calendar.days.length).toEqual(365);
99
expect(wrapper.vm.calendar.months.length).toEqual(14);
1010
});
11+
1112
it('should build with custom days', () => {
1213
const wrapper = shallowMount(App, {
1314
propsData: {days: 900},
1415
sync: false,
1516
});
1617
expect(wrapper.vm.calendar.days.length).toEqual(900);
1718
});
19+
1820
it('should discard days if months is set', () => {
1921
const wrapper = shallowMount(App, {
2022
propsData: {days: 900, months: 6},
2123
sync: false,
2224
});
2325
expect(wrapper.vm.calendar.months.length).toEqual(8);
2426
});
27+
2528
it('should change the language', () => {
2629
const wrapper = shallowMount(App, {
2730
propsData: {lang: 'FR'},
2831
sync: false,
2932
});
3033
expect(wrapper.vm.MONTHS[0]).toMatch('JANVIER');
3134
});
32-
const wrapper = mount(App, {
35+
36+
const noyear = mount(App, {
3337
sync: false,
3438
attachToDocument: true,
3539
propsData: {
@@ -41,15 +45,64 @@ describe('VueCal', () => {
4145
},
4246
},
4347
});
44-
it('should', async () => {
45-
wrapper.element.querySelector('.arrow.bottom.left').click();
46-
wrapper.element.querySelector('.arrow.bottom.right').click();
47-
wrapper.vm.$refs.monthly.childNodes[2].click();
48-
wrapper.vm.$refs.daily.childNodes[5].click();
49-
expect(wrapper.vm.selectedDate).not.toBe(null);
50-
expect(wrapper.element).toMatchSnapshot();
51-
wrapper.vm.$refs.daily.childNodes[5].click();
52-
expect(wrapper.vm.selectedDate).toBe(null);
53-
wrapper.vm.$destroy();
48+
49+
const years = mount(App, {
50+
sync: false,
51+
attachToDocument: true,
52+
propsData: {
53+
years: 10,
54+
},
55+
});
56+
57+
it('should build noyear', async () => {
58+
noyear.element.querySelector('.arrow.top.right').click();
59+
noyear.vm.$nextTick(() => expect(Number(noyear.vm.monthly.realOffset)).toBeLessThan(0));
60+
61+
noyear.element.querySelector('.arrow.bottom.right').click();
62+
noyear.vm.$nextTick(() => expect(Number(noyear.vm.daily.realOffset)).toBeLessThan(0));
63+
64+
noyear.vm.$refs.monthly.childNodes[2].click();
65+
noyear.vm.$nextTick(() =>
66+
expect(noyear.vm.$refs.monthly.childNodes[2].getAttribute('selected')).toBe('selected')
67+
);
68+
69+
noyear.vm.$refs.daily.childNodes[5].click();
70+
expect(noyear.vm.selectedDate).not.toBe(null);
71+
72+
noyear.vm.$refs.daily.childNodes[5].click();
73+
noyear.vm.$nextTick(() => expect(noyear.vm.selectedDate).toBe({}));
74+
75+
expect(noyear.element).toMatchSnapshot();
76+
noyear.vm.$destroy();
77+
});
78+
79+
it('should build year', async () => {
80+
years.vm.$refs.yearly.childNodes[2].click();
81+
noyear.vm.$nextTick(() =>
82+
expect(years.vm.$refs.yearly.childNodes[2].getAttribute('selected')).toBe('selected')
83+
);
84+
85+
years.element.querySelector('.arrow.top.right').click();
86+
noyear.vm.$nextTick(() => expect(Number(years.vm.yearly.realOffset)).toBeLessThan(0));
87+
88+
years.element.querySelector('.arrow.middle.right').click();
89+
noyear.vm.$nextTick(() => expect(Number(years.vm.monthly.realOffset)).toBeLessThan(0));
90+
91+
years.element.querySelector('.arrow.bottom.right').click();
92+
noyear.vm.$nextTick(() => expect(Number(years.vm.daily.realOffset)).toBeLessThan(0));
93+
94+
years.vm.$refs.monthly.childNodes[2].click();
95+
noyear.vm.$nextTick(() =>
96+
expect(years.vm.$refs.monthly.childNodes[2].getAttribute('selected')).toBe('selected')
97+
);
98+
99+
years.vm.$refs.daily.childNodes[5].click();
100+
years.vm.$nextTick(() => expect(years.vm.selectedDate).not.toBe({}));
101+
102+
years.vm.$refs.daily.childNodes[5].click();
103+
years.vm.$nextTick(() => expect(years.vm.selectedDate).toBe({}));
104+
105+
expect(years.element).toMatchSnapshot();
106+
years.vm.$destroy();
54107
});
55108
});

0 commit comments

Comments
 (0)