Skip to content

Commit

Permalink
Merge pull request #2499 from ilandikov/fix-future-menu-names
Browse files Browse the repository at this point in the history
fix: better menu items to postpone future dates
  • Loading branch information
claremacrae authored Dec 12, 2023
2 parents 6027cfb + 34fb408 commit f17c7fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Scripting/Postponer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ export function postponeMenuItemTitle(task: Task, amount: number, timeUnit: unit
function capitalizeFirstLetter(word: string) {
return word.charAt(0).toUpperCase() + word.slice(1);
}

const updatedDateType = getDateFieldToPostpone(task)!;
const dateToUpdate = task[updatedDateType] as Moment;
const updatedDateDisplayText = capitalizeFirstLetter(updatedDateType.replace('Date', ''));

const postponedDate = new TasksDate(dateToUpdate).postpone(timeUnit, amount);
const formattedNewDate = postponedDate.format('ddd Do MMM');

const amountOrArticle = amount > 1 ? amount : 'a';
return `${updatedDateDisplayText} in ${amountOrArticle} ${timeUnit}, on ${formattedNewDate}`;
if (dateToUpdate.isSameOrBefore(window.moment(), 'day')) {
const updatedDateDisplayText = capitalizeFirstLetter(updatedDateType.replace('Date', ''));
return `${updatedDateDisplayText} in ${amountOrArticle} ${timeUnit}, on ${formattedNewDate}`;
} else {
const updatedDateDisplayText = updatedDateType.replace('Date', ' date');
return `Postpone ${updatedDateDisplayText} by ${amountOrArticle} ${timeUnit}, to ${formattedNewDate}`;
}
}
22 changes: 19 additions & 3 deletions tests/Scripting/Postponer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import { TaskBuilder } from '../TestingTools/TaskBuilder';

window.moment = moment;

const yesterday = '2023-12-02';
const today = '2023-12-03';
const tomorrow = '2023-12-04';

beforeEach(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date(today));
Expand Down Expand Up @@ -169,13 +172,26 @@ describe('postpone - UI text', () => {
);
});

it('should include date type and new date in context menu labels', () => {
it('should include date type and new date in context menu labels when due today', () => {
const task = new TaskBuilder().dueDate(today).build();
// TODO This text is misleading if the date is already in the future.
// In that case, it should still be 'Postpone'???

expect(postponeMenuItemTitle(task, 1, 'day')).toEqual('Due in a day, on Mon 4th Dec');
expect(postponeMenuItemTitle(task, 2, 'days')).toEqual('Due in 2 days, on Tue 5th Dec');
});

it('should include date type and new date in context menu labels when overdue', () => {
const task = new TaskBuilder().scheduledDate(yesterday).build();

expect(postponeMenuItemTitle(task, 1, 'day')).toEqual('Scheduled in a day, on Mon 4th Dec');
expect(postponeMenuItemTitle(task, 2, 'days')).toEqual('Scheduled in 2 days, on Tue 5th Dec');
});

it('should include date type and new date in context menu labels when due in future', () => {
const task = new TaskBuilder().startDate(tomorrow).build();

expect(postponeMenuItemTitle(task, 1, 'day')).toEqual('Postpone start date by a day, to Tue 5th Dec');
expect(postponeMenuItemTitle(task, 2, 'days')).toEqual('Postpone start date by 2 days, to Wed 6th Dec');
});
});

describe('postpone - new task creation', () => {
Expand Down

0 comments on commit f17c7fb

Please sign in to comment.