fix(task) - 11139 use start-from hours in due date calculation (#12609)

* fix(task) - 11139 use start-from hours in due date calculation

* fix(task) - 11139 - Initial setup of Task unit test

* Add more unit tests for formatDueDate
This commit is contained in:
Bart Enkelaar
2020-10-05 16:19:47 +02:00
committed by GitHub
parent 221c95eb14
commit 12bd10a095
2 changed files with 91 additions and 4 deletions

View File

@@ -1071,7 +1071,7 @@ export default {
this.scoreChecklistItem({ taskId: this.task._id, itemId: item.id }); this.scoreChecklistItem({ taskId: this.task._id, itemId: item.id });
}, },
calculateTimeTillDue () { calculateTimeTillDue () {
const endOfToday = moment().endOf('day'); const endOfToday = moment().subtract(this.user.preferences.dayStart, 'hours').endOf('day');
const endOfDueDate = moment(this.task.date).endOf('day'); const endOfDueDate = moment(this.task.date).endOf('day');
return moment.duration(endOfDueDate.diff(endOfToday)); return moment.duration(endOfDueDate.diff(endOfToday));
@@ -1080,9 +1080,8 @@ export default {
return this.calculateTimeTillDue().asDays() <= 0; return this.calculateTimeTillDue().asDays() <= 0;
}, },
formatDueDate () { formatDueDate () {
const dueIn = this.calculateTimeTillDue().asDays() === 0 const timeTillDue = this.calculateTimeTillDue();
? this.$t('today') const dueIn = timeTillDue.asDays() === 0 ? this.$t('today') : timeTillDue.humanize(true);
: this.calculateTimeTillDue().humanize(true);
return this.task.date && this.$t('dueIn', { dueIn }); return this.task.date && this.$t('dueIn', { dueIn });
}, },

View File

@@ -0,0 +1,88 @@
import { shallowMount, createLocalVue } from '@vue/test-utils';
import moment from 'moment';
import Task from '@/components/tasks/task.vue';
import Store from '@/libs/store';
const localVue = createLocalVue();
localVue.use(Store);
describe('Task', () => {
let wrapper;
function makeWrapper (additionalTaskData = {}, additionalUserData = {}) {
return shallowMount(Task, {
propsData: {
task: {
group: {},
...additionalTaskData,
},
},
store: {
state: {
user: {
data: {
preferences: {},
...additionalUserData,
},
},
},
getters: {
'tasks:getTaskClasses': () => ({}),
'tasks:canEdit': () => ({}),
'tasks:canDelete': () => ({}),
},
},
mocks: { $t: (key, params) => key + (params ? JSON.stringify(params) : '') },
directives: { 'b-tooltip': {} },
localVue,
});
}
it('returns a vue instance', () => {
wrapper = makeWrapper();
expect(wrapper.isVueInstance()).to.be.true;
});
describe('Due date calculation', () => {
let clock;
function setClockTo (time) {
const now = moment(time);
clock = sinon.useFakeTimers(now.toDate());
return now;
}
afterEach(() => {
clock.restore();
});
it('formats due date to today if due today', () => {
const now = setClockTo('2019-09-17T17:57:00+02:00');
wrapper = makeWrapper({ date: now });
expect(wrapper.vm.formatDueDate()).to.equal('dueIn{"dueIn":"today"}');
});
it('formats due date to tomorrow if due tomorrow', () => {
const now = setClockTo('2012-06-12T14:17:28Z');
wrapper = makeWrapper({ date: now.add(1, 'day') });
expect(wrapper.vm.formatDueDate()).to.equal('dueIn{"dueIn":"in a day"}');
});
it('formats due date to 5 days if due in 5 days', () => {
const now = setClockTo();
wrapper = makeWrapper({ date: now.add(5, 'days') });
expect(wrapper.vm.formatDueDate()).to.equal('dueIn{"dueIn":"in 5 days"}');
});
it('formats due date to tomorrow if today but before dayStart', () => {
const now = setClockTo('2019-06-12T04:23:37+02:00');
wrapper = makeWrapper({ date: now.add(8, 'hours') }, { preferences: { dayStart: 7 } });
expect(wrapper.vm.formatDueDate()).to.equal('dueIn{"dueIn":"in a day"}');
});
});
});