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

fix: Cycle through statuses until TODO is found when marking recurring tasks as DONE #2516

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,11 @@ export class Task {
if (setCreatedDate) {
createdDate = window.moment();
}
const nextStatus = StatusRegistry.getInstance().getNextStatusOrCreate(newStatus);
const statusRegistry = StatusRegistry.getInstance();
let nextStatus = statusRegistry.getNextStatusOrCreate(newStatus);
while (nextStatus.type !== StatusType.TODO) {
nextStatus = statusRegistry.getNextStatusOrCreate(nextStatus);
}
asokawotulo marked this conversation as resolved.
Show resolved Hide resolved
const nextTask = new Task({
...this,
...nextOccurrence,
Expand Down Expand Up @@ -467,7 +471,6 @@ export class Task {
*/
public toggleWithRecurrenceInUsersOrder(): Task[] {
const newTasks = this.toggle();

const { recurrenceOnNextLine: recurrenceOnNextLine } = getSettings();
return recurrenceOnNextLine ? newTasks.reverse() : newTasks;
}
Expand Down
18 changes: 17 additions & 1 deletion tests/Commands/ToggleDone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getNewCursorPosition, toggleLine } from '../../src/Commands/ToggleDone'
import { GlobalFilter } from '../../src/Config/GlobalFilter';
import { StatusRegistry } from '../../src/StatusRegistry';
import { Status } from '../../src/Status';
import { StatusConfiguration } from '../../src/StatusConfiguration';
import { StatusConfiguration, StatusType } from '../../src/StatusConfiguration';

window.moment = moment;

Expand Down Expand Up @@ -227,5 +227,21 @@ describe('ToggleDone', () => {
});
});

it('should proceed through the statuses until a TODO status is reached when a task is completed', () => {
// Arrange
asokawotulo marked this conversation as resolved.
Show resolved Hide resolved
const statusRegistry = StatusRegistry.getInstance();
statusRegistry.resetToDefaultStatuses();
statusRegistry.set([
new Status(new StatusConfiguration('x', 'Done', '-', false, StatusType.DONE)),
...statusRegistry.registeredStatuses,
]);

testToggleLine(
'- [ ] Recurring task should start with TODO| 🔁 every day 📅 2022-09-04 ',
`- [ ] Recurring task should start with TODO 🔁 every day 📅 2022-09-05
- [x] Recurring task should start with TODO| 🔁 every day 📅 2022-09-04 ✅ 2022-09-04`,
);
});

todaySpy.mockClear();
});