Skip to content

Commit

Permalink
fix: Shorten tooltip on Postpone actions
Browse files Browse the repository at this point in the history
  • Loading branch information
claremacrae committed Dec 11, 2023
1 parent 98f99ad commit c150ace
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/Scripting/Postponer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ export function postponeButtonTitle(task: Task, amount: number, timeUnit: unitOf
}

export function postponeMenuItemTitle(task: Task, amount: number, timeUnit: unitOfTime.DurationConstructor) {
function capitalizeFirstLetter(word: string) {
return word.charAt(0).toUpperCase() + word.slice(1);
}
const updatedDateType = getDateFieldToPostpone(task)!;
const dateToUpdate = task[updatedDateType] as Moment;
const updatedDateDisplayText = updatedDateType.replace('Date', '');
const updatedDateDisplayText = capitalizeFirstLetter(updatedDateType.replace('Date', ''));

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

const amountOrArticle = amount > 1 ? amount : 'a';
return `Postpone ${updatedDateDisplayText} for ${amountOrArticle} ${timeUnit} - to ${formattedNewDate}`;
return `${updatedDateDisplayText} in ${amountOrArticle} ${timeUnit}, on ${formattedNewDate}`;
}
8 changes: 4 additions & 4 deletions tests/Scripting/Postponer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ describe('postpone - UI text', () => {
it('should include date type and new date in button tooltip', () => {
const task = new TaskBuilder().dueDate(today).build();
expect(postponeButtonTitle(task, 1, 'day')).toEqual(
'ℹ️ Postpone due for a day - to Mon 4th Dec, 2023 (right-click for more options)',
'ℹ️ Due in a day, on Mon 4th Dec, 2023 (right-click for more options)',
);
expect(postponeButtonTitle(task, 2, 'days')).toEqual(
'ℹ️ Postpone due for 2 days - to Tue 5th Dec, 2023 (right-click for more options)',
'ℹ️ Due in 2 days, on Tue 5th Dec, 2023 (right-click for more options)',
);
});

it('should include date type and new date in context menu labels', () => {
const task = new TaskBuilder().dueDate(today).build();
expect(postponeMenuItemTitle(task, 1, 'day')).toEqual('Postpone due for a day - to Mon 4th Dec, 2023');
expect(postponeMenuItemTitle(task, 2, 'days')).toEqual('Postpone due for 2 days - to Tue 5th Dec, 2023');
expect(postponeMenuItemTitle(task, 1, 'day')).toEqual('Due in a day, on Mon 4th Dec, 2023');
expect(postponeMenuItemTitle(task, 2, 'days')).toEqual('Due in 2 days, on Tue 5th Dec, 2023');
});
});

Expand Down

0 comments on commit c150ace

Please sign in to comment.