Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hide postpone button if happens date absent or invalid #2485

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Scripting/Postponer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { Task } from '../Task';
import { TasksDate } from './TasksDate';

export function shouldShowPostponeButton(task: Task) {
return !task.isDone;
const hasAValidHappensDate = task.happensDates.some((date) => {
return !!date?.isValid();
});

return !task.isDone && hasAValidHappensDate;
}

export type HappensDate = keyof Pick<Task, 'startDate' | 'scheduledDate' | 'dueDate'>;
Expand Down
26 changes: 13 additions & 13 deletions tests/Scripting/Postponer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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);
});
});

Expand Down