Skip to content

Commit

Permalink
Added support for complete and uncomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
karelklima committed Jan 6, 2025
1 parent a12c0b6 commit f61a75a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,31 @@ export class List {
return this;
}

/**
* Completes the list
* @returns {List} this
*/
public setCompleted(complete = true): List {
if (complete === this.isCompleted) {
return this;
}

this.#companion.addOperation(this.data.treeId, {
type: complete ? "complete" : "uncomplete",
data: {
projectid: this.data.id,
},
undo_data: {
previous_last_modified: this.data.lastModified,
previous_last_modified_by: null,
previous_completed: this.data.completed ?? false,
},
});

this.data.completed = complete ? this.#companion.getNow() : undefined;
return this;
}

/**
* Moves this list to a different list
*
Expand Down
44 changes: 44 additions & 0 deletions tests/document_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,50 @@ Deno.test("WorkFlowy Document / Edit mirror", () => {
});
});

Deno.test("WorkFlowy Document / Complete list", () => {
const document = mockDocument();

const list = document.root.items[1];

list.setCompleted().setCompleted();

assertEquals(document.root.items[1].isCompleted, true);

const ops = document.getPendingOperations()[ROOT];
assertEquals(ops.length, 1);
assertObjectMatch(ops[0], {
type: "complete",
data: {
projectid: list.id,
},
undo_data: {
previous_completed: false,
},
});
});

Deno.test("WorkFlowy Document / Uncomplete list", () => {
const document = mockDocument();

const list = document.root.items[2];

list.setCompleted(false).setCompleted(false);

assertEquals(document.root.items[2].isCompleted, false);

const ops = document.getPendingOperations()[ROOT];
assertEquals(ops.length, 1);
assertObjectMatch(ops[0], {
type: "uncomplete",
data: {
projectid: list.id,
},
undo_data: {
previous_completed: 199,
},
});
});

Deno.test("WorkFlowy Document / Move list", () => {
const document = mockDocument();

Expand Down

0 comments on commit f61a75a

Please sign in to comment.