From 261ec64bd2f651d4fd4a4daeab238909f9e383b5 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 19:46:36 +0000 Subject: [PATCH 01/17] refactor: Extract method postponeMenuItemTitle() --- src/QueryRenderer.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index d825635c6e..296a6bcac0 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -51,6 +51,12 @@ export class QueryRenderer { } } +function postponeMenuItemTitle(amount: number, timeUnit: unitOfTime.DurationConstructor) { + const commonTitle = 'Postpone for'; + const amountOrArticle = amount > 1 ? amount : 'a'; + return `${commonTitle} ${amountOrArticle} ${timeUnit}`; +} + class QueryRenderChild extends MarkdownRenderChild { private readonly app: App; private readonly events: TasksEvents; @@ -422,13 +428,10 @@ class QueryRenderChild extends MarkdownRenderChild { */ button.addEventListener('contextmenu', async (ev: MouseEvent) => { const menu = new Menu(); - const commonTitle = 'Postpone for'; const postponeMenuItemCallback = (item: MenuItem, timeUnit: unitOfTime.DurationConstructor, amount = 1) => { - const amountOrArticle = amount > 1 ? amount : 'a'; - item.setTitle(`${commonTitle} ${amountOrArticle} ${timeUnit}`).onClick(() => - this.postponeOnClickCallback(button, task, amount, timeUnit), - ); + const title = postponeMenuItemTitle(amount, timeUnit); + item.setTitle(title).onClick(() => this.postponeOnClickCallback(button, task, amount, timeUnit)); }; menu.addItem((item) => postponeMenuItemCallback(item, 'days', 2)); From c8bf8d1b3c9bfec7b823b0bc39621e03f585742d Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 19:48:20 +0000 Subject: [PATCH 02/17] refactor: Move postponeMenuItemTitle() to Postponer.ts --- src/QueryRenderer.ts | 7 +------ src/Scripting/Postponer.ts | 6 ++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index 296a6bcac0..8798cb8abf 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -16,6 +16,7 @@ import { type HappensDate, createPostponedTask, getDateFieldToPostpone, + postponeMenuItemTitle, postponementSuccessMessage, shouldShowPostponeButton, } from './Scripting/Postponer'; @@ -51,12 +52,6 @@ export class QueryRenderer { } } -function postponeMenuItemTitle(amount: number, timeUnit: unitOfTime.DurationConstructor) { - const commonTitle = 'Postpone for'; - const amountOrArticle = amount > 1 ? amount : 'a'; - return `${commonTitle} ${amountOrArticle} ${timeUnit}`; -} - class QueryRenderChild extends MarkdownRenderChild { private readonly app: App; private readonly events: TasksEvents; diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index 4c3c4ec8a9..92971e941c 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -51,3 +51,9 @@ export function postponementSuccessMessage(postponedDate: Moment, dateFieldToPos const postponedDateString = postponedDate?.format('DD MMM YYYY'); return `Task's ${dateFieldToPostpone} postponed until ${postponedDateString}`; } + +export function postponeMenuItemTitle(amount: number, timeUnit: unitOfTime.DurationConstructor) { + const commonTitle = 'Postpone for'; + const amountOrArticle = amount > 1 ? amount : 'a'; + return `${commonTitle} ${amountOrArticle} ${timeUnit}`; +} From 050885a0e32423f33ac70c6a6a64d53f402b1d0f Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 19:50:51 +0000 Subject: [PATCH 03/17] test: Add first tests of postponement menu item label --- tests/Scripting/Postponer.test.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index 3172a37f44..889049d0fc 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -7,6 +7,7 @@ import { type HappensDate, createPostponedTask, getDateFieldToPostpone, + postponeMenuItemTitle, postponementSuccessMessage, shouldShowPostponeButton, } from '../../src/Scripting/Postponer'; @@ -16,6 +17,16 @@ import { TaskBuilder } from '../TestingTools/TaskBuilder'; window.moment = moment; +const today = '2023-12-03'; +beforeEach(() => { + jest.useFakeTimers(); + jest.setSystemTime(new Date(today)); +}); + +afterEach(() => { + jest.useRealTimers(); +}); + describe('postpone - date field choice', () => { function checkPostponeField(taskBuilder: TaskBuilder, expected: HappensDate | null) { const task = taskBuilder.build(); @@ -146,16 +157,17 @@ describe('postpone - whether to show button', () => { }); }); -describe('postpone - new task creation', () => { - beforeEach(() => { - jest.useFakeTimers(); - jest.setSystemTime(new Date('2023-12-03')); - }); - - afterEach(() => { - jest.useRealTimers(); +describe('postpone - name context menu option', () => { + it('rename me', () => { + // Create a task with a due date + // Set amount and timeUnit + // Create the text used to label its menu item to postpone it by the given units + expect(postponeMenuItemTitle(1, 'day')).toEqual('Postpone for a day'); + expect(postponeMenuItemTitle(2, 'days')).toEqual('Postpone for 2 days'); }); +}); +describe('postpone - new task creation', () => { function testPostponedTaskAndDate(task: Task, expectedDateField: HappensDate, expectedPostponedDate: string) { const { postponedDate, postponedTask } = createPostponedTask(task, expectedDateField, 'day', 1); expect(postponedDate.format('YYYY-MM-DD')).toEqual(expectedPostponedDate); From ddb4494127c61f981d90078acee52662427da437 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 19:58:53 +0000 Subject: [PATCH 04/17] feat: Put the type of date that will be updated in to context menu labels --- src/QueryRenderer.ts | 2 +- src/Scripting/Postponer.ts | 5 +++-- tests/Scripting/Postponer.test.ts | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index 8798cb8abf..29d1f37b96 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -425,7 +425,7 @@ class QueryRenderChild extends MarkdownRenderChild { const menu = new Menu(); const postponeMenuItemCallback = (item: MenuItem, timeUnit: unitOfTime.DurationConstructor, amount = 1) => { - const title = postponeMenuItemTitle(amount, timeUnit); + const title = postponeMenuItemTitle(task, amount, timeUnit); item.setTitle(title).onClick(() => this.postponeOnClickCallback(button, task, amount, timeUnit)); }; diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index 92971e941c..36855c5d2e 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -52,8 +52,9 @@ export function postponementSuccessMessage(postponedDate: Moment, dateFieldToPos return `Task's ${dateFieldToPostpone} postponed until ${postponedDateString}`; } -export function postponeMenuItemTitle(amount: number, timeUnit: unitOfTime.DurationConstructor) { - const commonTitle = 'Postpone for'; +export function postponeMenuItemTitle(task: Task, amount: number, timeUnit: unitOfTime.DurationConstructor) { + const updatedDateType = getDateFieldToPostpone(task)!; + const commonTitle = `Postpone ${updatedDateType} for`; const amountOrArticle = amount > 1 ? amount : 'a'; return `${commonTitle} ${amountOrArticle} ${timeUnit}`; } diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index 889049d0fc..1aa4f576a2 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -160,10 +160,10 @@ describe('postpone - whether to show button', () => { describe('postpone - name context menu option', () => { it('rename me', () => { // Create a task with a due date - // Set amount and timeUnit + const task = new TaskBuilder().dueDate(today).build(); // Create the text used to label its menu item to postpone it by the given units - expect(postponeMenuItemTitle(1, 'day')).toEqual('Postpone for a day'); - expect(postponeMenuItemTitle(2, 'days')).toEqual('Postpone for 2 days'); + expect(postponeMenuItemTitle(task, 1, 'day')).toEqual('Postpone dueDate for a day'); + expect(postponeMenuItemTitle(task, 2, 'days')).toEqual('Postpone dueDate for 2 days'); }); }); From ec017923bc4fcb44efc51755714774603225dbd6 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 20:08:24 +0000 Subject: [PATCH 05/17] feat: Put the new date in to context menu labels --- src/Scripting/Postponer.ts | 7 ++++++- tests/Scripting/Postponer.test.ts | 12 +++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index 36855c5d2e..c9bd1e1d67 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -54,7 +54,12 @@ export function postponementSuccessMessage(postponedDate: Moment, dateFieldToPos export function postponeMenuItemTitle(task: Task, amount: number, timeUnit: unitOfTime.DurationConstructor) { const updatedDateType = getDateFieldToPostpone(task)!; + + const dateToUpdate = task[updatedDateType] as Moment; + const postponedDate = new TasksDate(dateToUpdate).postpone(timeUnit, amount); + const formattedNewDate = postponedDate.format('dddd Do MMMM YYYY'); + const commonTitle = `Postpone ${updatedDateType} for`; const amountOrArticle = amount > 1 ? amount : 'a'; - return `${commonTitle} ${amountOrArticle} ${timeUnit}`; + return `${commonTitle} ${amountOrArticle} ${timeUnit} - to ${formattedNewDate}`; } diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index 1aa4f576a2..99b08bcb99 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -158,12 +158,14 @@ describe('postpone - whether to show button', () => { }); describe('postpone - name context menu option', () => { - it('rename me', () => { - // Create a task with a due date + it('should include date type and new date in context menu labels', () => { const task = new TaskBuilder().dueDate(today).build(); - // Create the text used to label its menu item to postpone it by the given units - expect(postponeMenuItemTitle(task, 1, 'day')).toEqual('Postpone dueDate for a day'); - expect(postponeMenuItemTitle(task, 2, 'days')).toEqual('Postpone dueDate for 2 days'); + expect(postponeMenuItemTitle(task, 1, 'day')).toEqual( + 'Postpone dueDate for a day - to Monday 4th December 2023', + ); + expect(postponeMenuItemTitle(task, 2, 'days')).toEqual( + 'Postpone dueDate for 2 days - to Tuesday 5th December 2023', + ); }); }); From e59dae6a9b1a534ac7822bf674d567f7a8356a84 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 20:10:09 +0000 Subject: [PATCH 06/17] feat: Put shorter date date in to context menu labels --- src/Scripting/Postponer.ts | 2 +- tests/Scripting/Postponer.test.ts | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index c9bd1e1d67..1fc4c9db7d 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -57,7 +57,7 @@ export function postponeMenuItemTitle(task: Task, amount: number, timeUnit: unit const dateToUpdate = task[updatedDateType] as Moment; const postponedDate = new TasksDate(dateToUpdate).postpone(timeUnit, amount); - const formattedNewDate = postponedDate.format('dddd Do MMMM YYYY'); + const formattedNewDate = postponedDate.format('ddd Do MMM, YYYY'); const commonTitle = `Postpone ${updatedDateType} for`; const amountOrArticle = amount > 1 ? amount : 'a'; diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index 99b08bcb99..4f4424c848 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -160,12 +160,8 @@ describe('postpone - whether to show button', () => { describe('postpone - name context menu option', () => { 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 dueDate for a day - to Monday 4th December 2023', - ); - expect(postponeMenuItemTitle(task, 2, 'days')).toEqual( - 'Postpone dueDate for 2 days - to Tuesday 5th December 2023', - ); + expect(postponeMenuItemTitle(task, 1, 'day')).toEqual('Postpone dueDate for a day - to Mon 4th Dec, 2023'); + expect(postponeMenuItemTitle(task, 2, 'days')).toEqual('Postpone dueDate for 2 days - to Tue 5th Dec, 2023'); }); }); From 0ae0a569d1f156778c3ff47ed5e9892426aa9480 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 20:17:08 +0000 Subject: [PATCH 07/17] feat: Tooltip on postpone button now shows new date type and value --- src/QueryRenderer.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index 29d1f37b96..891ba8c8c3 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -405,10 +405,13 @@ class QueryRenderChild extends MarkdownRenderChild { } private addPostponeButton(listItem: HTMLElement, task: Task, shortMode: boolean) { + const amount = 1; + const timeUnit = 'day'; + const buttonText = postponeMenuItemTitle(task, amount, timeUnit); const button = listItem.createEl('button', { attr: { id: 'postpone-button', - title: 'ℹ️ Postpone the task (right-click for more options)', + title: `ℹ️ ${buttonText} (right-click for more options)`, }, }); @@ -416,7 +419,7 @@ class QueryRenderChild extends MarkdownRenderChild { button.addClasses(classNames); button.setText(' ⏩'); - button.addEventListener('click', () => this.postponeOnClickCallback(button, task, 1, 'days')); + button.addEventListener('click', () => this.postponeOnClickCallback(button, task, amount, timeUnit)); /** Open a context menu on right-click. * Give a choice of postponing for a week, month, or quarter. From b3188175ee7fe534e38183d885d25d42adeca094 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 20:18:19 +0000 Subject: [PATCH 08/17] refactor: . Extract variable buttonTooltipText --- src/QueryRenderer.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index 891ba8c8c3..465d1cd346 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -408,10 +408,11 @@ class QueryRenderChild extends MarkdownRenderChild { const amount = 1; const timeUnit = 'day'; const buttonText = postponeMenuItemTitle(task, amount, timeUnit); + const buttonTooltipText = `ℹ️ ${buttonText} (right-click for more options)`; const button = listItem.createEl('button', { attr: { id: 'postpone-button', - title: `ℹ️ ${buttonText} (right-click for more options)`, + title: buttonTooltipText, }, }); From 047c231d220990a71bda08864abdf5c88761abed Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 20:19:54 +0000 Subject: [PATCH 09/17] refactor: . Extract method postponeButtonTitle() --- src/QueryRenderer.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index 465d1cd346..d9ccafc3db 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -52,6 +52,11 @@ export class QueryRenderer { } } +function postponeButtonTitle(task: Task, amount: number, timeUnit: unitOfTime.DurationConstructor) { + const buttonText = postponeMenuItemTitle(task, amount, timeUnit); + return `ℹ️ ${buttonText} (right-click for more options)`; +} + class QueryRenderChild extends MarkdownRenderChild { private readonly app: App; private readonly events: TasksEvents; @@ -407,8 +412,7 @@ class QueryRenderChild extends MarkdownRenderChild { private addPostponeButton(listItem: HTMLElement, task: Task, shortMode: boolean) { const amount = 1; const timeUnit = 'day'; - const buttonText = postponeMenuItemTitle(task, amount, timeUnit); - const buttonTooltipText = `ℹ️ ${buttonText} (right-click for more options)`; + const buttonTooltipText = postponeButtonTitle(task, amount, timeUnit); const button = listItem.createEl('button', { attr: { id: 'postpone-button', From 1586f9e3097ccdbab6484eb17ed4735fb4aa43d2 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 20:21:10 +0000 Subject: [PATCH 10/17] refactor: . Move postponeButtonTitle() to Postponer.ts --- src/QueryRenderer.ts | 6 +----- src/Scripting/Postponer.ts | 5 +++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index d9ccafc3db..2eecb43701 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -16,6 +16,7 @@ import { type HappensDate, createPostponedTask, getDateFieldToPostpone, + postponeButtonTitle, postponeMenuItemTitle, postponementSuccessMessage, shouldShowPostponeButton, @@ -52,11 +53,6 @@ export class QueryRenderer { } } -function postponeButtonTitle(task: Task, amount: number, timeUnit: unitOfTime.DurationConstructor) { - const buttonText = postponeMenuItemTitle(task, amount, timeUnit); - return `ℹ️ ${buttonText} (right-click for more options)`; -} - class QueryRenderChild extends MarkdownRenderChild { private readonly app: App; private readonly events: TasksEvents; diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index 1fc4c9db7d..93009ece22 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -52,6 +52,11 @@ export function postponementSuccessMessage(postponedDate: Moment, dateFieldToPos return `Task's ${dateFieldToPostpone} postponed until ${postponedDateString}`; } +export function postponeButtonTitle(task: Task, amount: number, timeUnit: unitOfTime.DurationConstructor) { + const buttonText = postponeMenuItemTitle(task, amount, timeUnit); + return `ℹ️ ${buttonText} (right-click for more options)`; +} + export function postponeMenuItemTitle(task: Task, amount: number, timeUnit: unitOfTime.DurationConstructor) { const updatedDateType = getDateFieldToPostpone(task)!; From 72302040afd4353276e18e5764aaad4d53f91cee Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 20:24:15 +0000 Subject: [PATCH 11/17] test: Check the tooltips used for postpone buttons --- tests/Scripting/Postponer.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index 4f4424c848..5db7f78dcf 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -7,6 +7,7 @@ import { type HappensDate, createPostponedTask, getDateFieldToPostpone, + postponeButtonTitle, postponeMenuItemTitle, postponementSuccessMessage, shouldShowPostponeButton, @@ -157,7 +158,17 @@ describe('postpone - whether to show button', () => { }); }); -describe('postpone - name context menu option', () => { +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 dueDate for a day - to Mon 4th Dec, 2023 (right-click for more options)', + ); + expect(postponeButtonTitle(task, 2, 'days')).toEqual( + 'ℹ️ Postpone dueDate for 2 days - to 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 dueDate for a day - to Mon 4th Dec, 2023'); From 88272d12beb6a3ee75d4c359ef7523637fc60716 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Thu, 7 Dec 2023 20:27:24 +0000 Subject: [PATCH 12/17] feat: Add more dates to the postpone button context menu --- src/QueryRenderer.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/QueryRenderer.ts b/src/QueryRenderer.ts index 2eecb43701..583b61b8a1 100644 --- a/src/QueryRenderer.ts +++ b/src/QueryRenderer.ts @@ -435,8 +435,13 @@ class QueryRenderChild extends MarkdownRenderChild { menu.addItem((item) => postponeMenuItemCallback(item, 'days', 2)); menu.addItem((item) => postponeMenuItemCallback(item, 'days', 3)); + menu.addItem((item) => postponeMenuItemCallback(item, 'days', 4)); + menu.addItem((item) => postponeMenuItemCallback(item, 'days', 5)); + menu.addItem((item) => postponeMenuItemCallback(item, 'days', 6)); + menu.addSeparator(); menu.addItem((item) => postponeMenuItemCallback(item, 'week')); menu.addItem((item) => postponeMenuItemCallback(item, 'weeks', 2)); + menu.addItem((item) => postponeMenuItemCallback(item, 'weeks', 3)); menu.addItem((item) => postponeMenuItemCallback(item, 'month')); menu.showAtPosition({ x: ev.clientX, y: ev.clientY }); From 6861625dcf4d296bfcceb196347ad76d6238e8bf Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Fri, 8 Dec 2023 19:37:01 +0000 Subject: [PATCH 13/17] refactor: . Inline commonTitle variable --- src/Scripting/Postponer.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index 93009ece22..c6664cf2c4 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -64,7 +64,6 @@ export function postponeMenuItemTitle(task: Task, amount: number, timeUnit: unit const postponedDate = new TasksDate(dateToUpdate).postpone(timeUnit, amount); const formattedNewDate = postponedDate.format('ddd Do MMM, YYYY'); - const commonTitle = `Postpone ${updatedDateType} for`; const amountOrArticle = amount > 1 ? amount : 'a'; - return `${commonTitle} ${amountOrArticle} ${timeUnit} - to ${formattedNewDate}`; + return `Postpone ${updatedDateType} for ${amountOrArticle} ${timeUnit} - to ${formattedNewDate}`; } From 98f99ada9be59fddec6f6959c139685314c2eb19 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Fri, 8 Dec 2023 19:44:48 +0000 Subject: [PATCH 14/17] fix: Remove variable name from description of postponed field --- src/Scripting/Postponer.ts | 5 +++-- tests/Scripting/Postponer.test.ts | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index c6664cf2c4..9f9cd9b2dc 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -59,11 +59,12 @@ export function postponeButtonTitle(task: Task, amount: number, timeUnit: unitOf export function postponeMenuItemTitle(task: Task, amount: number, timeUnit: unitOfTime.DurationConstructor) { const updatedDateType = getDateFieldToPostpone(task)!; - const dateToUpdate = task[updatedDateType] as Moment; + const updatedDateDisplayText = 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 ${updatedDateType} for ${amountOrArticle} ${timeUnit} - to ${formattedNewDate}`; + return `Postpone ${updatedDateDisplayText} for ${amountOrArticle} ${timeUnit} - to ${formattedNewDate}`; } diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index 5db7f78dcf..bf45c4ab8c 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -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 dueDate for a day - to Mon 4th Dec, 2023 (right-click for more options)', + 'ℹ️ Postpone due for a day - to Mon 4th Dec, 2023 (right-click for more options)', ); expect(postponeButtonTitle(task, 2, 'days')).toEqual( - 'ℹ️ Postpone dueDate for 2 days - to Tue 5th Dec, 2023 (right-click for more options)', + 'ℹ️ Postpone due for 2 days - to 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 dueDate for a day - to Mon 4th Dec, 2023'); - expect(postponeMenuItemTitle(task, 2, 'days')).toEqual('Postpone dueDate for 2 days - to Tue 5th Dec, 2023'); + 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'); }); }); From c150ace6793833ceca9c427bc36661388848a8c4 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Fri, 8 Dec 2023 19:49:59 +0000 Subject: [PATCH 15/17] fix: Shorten tooltip on Postpone actions --- src/Scripting/Postponer.ts | 7 +++++-- tests/Scripting/Postponer.test.ts | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index 9f9cd9b2dc..3990842c42 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -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}`; } diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index bf45c4ab8c..d27d656cb6 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -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'); }); }); From 4bf73ff314d1be10b9f4e837595081c9cf8e6de8 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Fri, 8 Dec 2023 19:51:05 +0000 Subject: [PATCH 16/17] fix: Shorten tooltip text by removing year - it's obvious from context --- src/Scripting/Postponer.ts | 2 +- tests/Scripting/Postponer.test.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index 3990842c42..9c6daa55ef 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -66,7 +66,7 @@ export function postponeMenuItemTitle(task: Task, amount: number, timeUnit: unit const updatedDateDisplayText = capitalizeFirstLetter(updatedDateType.replace('Date', '')); const postponedDate = new TasksDate(dateToUpdate).postpone(timeUnit, amount); - const formattedNewDate = postponedDate.format('ddd Do MMM, YYYY'); + const formattedNewDate = postponedDate.format('ddd Do MMM'); const amountOrArticle = amount > 1 ? amount : 'a'; return `${updatedDateDisplayText} in ${amountOrArticle} ${timeUnit}, on ${formattedNewDate}`; diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index d27d656cb6..4fbc3856c2 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -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( - 'ℹ️ Due in a day, on Mon 4th Dec, 2023 (right-click for more options)', + 'ℹ️ Due in a day, on Mon 4th Dec (right-click for more options)', ); expect(postponeButtonTitle(task, 2, 'days')).toEqual( - 'ℹ️ Due in 2 days, on Tue 5th Dec, 2023 (right-click for more options)', + 'ℹ️ Due in 2 days, on Tue 5th Dec (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('Due in a day, on Mon 4th Dec, 2023'); - expect(postponeMenuItemTitle(task, 2, 'days')).toEqual('Due in 2 days, on Tue 5th Dec, 2023'); + 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'); }); }); From ad0c9bd5987d483aec891a1ce76534397fbe98ab Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Fri, 8 Dec 2023 19:59:33 +0000 Subject: [PATCH 17/17] comment: Add a TODO to Postponer.test.ts --- tests/Scripting/Postponer.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index 4fbc3856c2..16fc7a7045 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -171,6 +171,8 @@ describe('postpone - UI text', () => { it('should include date type and new date in context menu labels', () => { 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'); });