From d36766d3380137682324df9f85b06d746ef9e903 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Sun, 3 Dec 2023 16:26:26 +0600 Subject: [PATCH 1/2] feat: - do not show postpone button for tasks without a happens date --- src/Scripting/Postponer.ts | 6 +++++- tests/Scripting/Postponer.test.ts | 14 +++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index cf44adb4e9..42a0b1b9e7 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -3,7 +3,11 @@ import { Task } from '../Task'; import { TasksDate } from './TasksDate'; export function shouldShowPostponeButton(task: Task) { - return !task.isDone; + const hasHappensDate = task.happensDates.some((date) => { + return date !== null; + }); + + return !task.isDone && hasHappensDate; } export type HappensDate = keyof Pick; diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index ab5a1c1148..5c40c37279 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -73,7 +73,7 @@ describe('postpone - whether to show button', () => { it('should account for status type', () => { function checkPostponeButtonVisibility(statusType: StatusType, expected: boolean) { const status = new Status(new StatusConfiguration('p', 'Test', 'q', true, statusType)); - const task = new TaskBuilder().status(status).build(); + const task = new TaskBuilder().dueDate('2023-10-30').status(status).build(); expect(shouldShowPostponeButton(task)).toEqual(expected); } @@ -87,22 +87,22 @@ describe('postpone - whether to show button', () => { checkPostponeButtonVisibility(StatusType.DONE, false); }); - it('should show button for a task with no dates', () => { + it('should not show button for a task with no dates', () => { const task = new TaskBuilder().build(); - expect(shouldShowPostponeButton(task)).toEqual(true); + expect(shouldShowPostponeButton(task)).toEqual(false); }); - it('should show button for a task with a created date only', () => { + it('should not show button for a task with a created date only', () => { const task = new TaskBuilder().createdDate('2023-11-29').build(); - expect(shouldShowPostponeButton(task)).toEqual(true); + expect(shouldShowPostponeButton(task)).toEqual(false); }); - it('should show button for a task with a done date only', () => { + it('should not show button for a task with a done date only', () => { const task = new TaskBuilder().doneDate('2023-11-30').build(); - expect(shouldShowPostponeButton(task)).toEqual(true); + expect(shouldShowPostponeButton(task)).toEqual(false); }); it('should show button for a task with a start date only', () => { From 968e8612c70c919a73a5344dcaeec7ac83e3d241 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Sun, 3 Dec 2023 16:31:17 +0600 Subject: [PATCH 2/2] feat: - do not show postpone button for tasks with invalid happens dates --- src/Scripting/Postponer.ts | 6 +++--- tests/Scripting/Postponer.test.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Scripting/Postponer.ts b/src/Scripting/Postponer.ts index 42a0b1b9e7..a0c95417e0 100644 --- a/src/Scripting/Postponer.ts +++ b/src/Scripting/Postponer.ts @@ -3,11 +3,11 @@ import { Task } from '../Task'; import { TasksDate } from './TasksDate'; export function shouldShowPostponeButton(task: Task) { - const hasHappensDate = task.happensDates.some((date) => { - return date !== null; + const hasAValidHappensDate = task.happensDates.some((date) => { + return !!date?.isValid(); }); - return !task.isDone && hasHappensDate; + return !task.isDone && hasAValidHappensDate; } export type HappensDate = keyof Pick; diff --git a/tests/Scripting/Postponer.test.ts b/tests/Scripting/Postponer.test.ts index 5c40c37279..35cdd2a595 100644 --- a/tests/Scripting/Postponer.test.ts +++ b/tests/Scripting/Postponer.test.ts @@ -111,10 +111,10 @@ describe('postpone - whether to show button', () => { expect(shouldShowPostponeButton(task)).toEqual(true); }); - it('should show button for a task with an invalid start date', () => { + it('should not show button for a task with an invalid start date', () => { const task = new TaskBuilder().startDate('2023-13-01').build(); - expect(shouldShowPostponeButton(task)).toEqual(true); + expect(shouldShowPostponeButton(task)).toEqual(false); }); it('should show button for a task with a scheduled date only', () => { @@ -123,10 +123,10 @@ describe('postpone - whether to show button', () => { expect(shouldShowPostponeButton(task)).toEqual(true); }); - it('should show button for a task with an invalid scheduled date', () => { + it('should not show button for a task with an invalid scheduled date', () => { const task = new TaskBuilder().scheduledDate('2023-12-36').build(); - expect(shouldShowPostponeButton(task)).toEqual(true); + expect(shouldShowPostponeButton(task)).toEqual(false); }); it('should show button for a task with a due date only', () => { @@ -135,10 +135,10 @@ describe('postpone - whether to show button', () => { expect(shouldShowPostponeButton(task)).toEqual(true); }); - it('should show button for a task with an invalid due date', () => { + it('should not show button for a task with an invalid due date', () => { const task = new TaskBuilder().dueDate('20233-12-03').build(); - expect(shouldShowPostponeButton(task)).toEqual(true); + expect(shouldShowPostponeButton(task)).toEqual(false); }); });