From 05ccfc546911b28d8e1e8f5bb1db40d763f4cbdc Mon Sep 17 00:00:00 2001 From: Jamie Brynes Date: Mon, 8 Jan 2024 23:09:52 +0000 Subject: [PATCH] Remove old tests (#270) --- tests_old/projects.test.ts | 173 ------------------ tests_old/task.test.ts | 359 ------------------------------------- 2 files changed, 532 deletions(-) delete mode 100644 tests_old/projects.test.ts delete mode 100644 tests_old/task.test.ts diff --git a/tests_old/projects.test.ts b/tests_old/projects.test.ts deleted file mode 100644 index c65c172..0000000 --- a/tests_old/projects.test.ts +++ /dev/null @@ -1,173 +0,0 @@ -import "mocha"; -import { assert } from "chai"; -import type { LabelID, ProjectID, SectionID } from "./models"; -import { Project } from "./models"; -import type { ITaskRaw, IProjectRaw, ISectionRaw } from "./raw_models"; -import type { ITodoistMetadata } from "./api"; -import { ExtendedMap } from "../utils"; - -describe("Project tree parsing", () => { - it("Projects are parented correctly", () => { - const rawTasks: ITaskRaw[] = [ - { - id: "1", - project_id: "1", - section_id: null, - labels: [], - content: "", - description: "", - priority: 1, - order: 1, - }, - { - id: "2", - project_id: "2", - section_id: null, - labels: [], - content: "", - description: "", - priority: 1, - order: 2, - }, - ]; - - const metadata = createMetadata({ - projects: [ - { - id: "1", - order: 1, - name: "Parent", - }, - { - id: "2", - order: 2, - parent_id: "1", - name: "Child", - }, - ], - }); - - const projectTree = Project.buildProjectTree(rawTasks, metadata); - assert.lengthOf(projectTree, 1, "Resulting tree has one parent node"); - - const parent = projectTree[0]; - assert.lengthOf( - parent.subProjects, - 1, - "Parent project has one sub-project" - ); - - assert.equal(parent.projectID, "1"); - assert.lengthOf(parent.tasks, 1, "Parent has one task"); - assert.equal(parent.tasks[0].id, "1", "Parent has correct task"); - - const child = parent.subProjects[0]; - assert.equal(child.projectID, "2"); - assert.lengthOf(child.tasks, 1, "Child has one task"); - assert.equal(child.tasks[0].id, "2", "Child has correct task"); - }); - - it("Sections are parented correctly", () => { - const rawTask: ITaskRaw[] = [ - { - id: "1", - project_id: "1", - section_id: "1", - labels: [], - content: "", - description: "", - priority: 1, - order: 1, - }, - ]; - - const metadata = createMetadata({ - projects: [ - { - id: "1", - order: 1, - name: "Parent", - }, - ], - sections: [ - { - id: "1", - project_id: "1", - order: 0, - name: "Section", - }, - ], - }); - - const projects = Project.buildProjectTree(rawTask, metadata); - assert.lengthOf(projects, 1, "Resulting tree has one parent node."); - - const parent = projects[0]; - assert.lengthOf(parent.sections, 1, "Parent has one section"); - assert.lengthOf(parent.tasks, 0, "Parent has no tasks"); - - const section = parent.sections[0]; - assert.equal(section.sectionID, "1"); - assert.lengthOf(section.tasks, 1, "Section has one task"); - }); - - it("Unknown project or sections are marked as such", () => { - const tasks: ITaskRaw[] = [ - { - id: "1", - project_id: "1", - section_id: null, - labels: [], - content: "", - description: "", - priority: 1, - order: 1, - }, - { - id: "2", - project_id: "2", - section_id: "1", - labels: [], - content: "", - description: "", - priority: 1, - order: 2, - }, - ]; - - const projects = Project.buildProjectTree(tasks, createMetadata({})); - assert.lengthOf(projects, 1, "Only one project is returned"); - - const parent = projects[0]; - assert.equal(parent.projectID, "-1", "Unknown project ID"); - assert.lengthOf(parent.tasks, 1, "Parent has one task"); - assert.equal(parent.tasks[0].id, "1", "Parent has 'correct' task"); - - assert.lengthOf(parent.sections, 1, "Parent has one section"); - const section = parent.sections[0]; - assert.equal(section.sectionID, "-1", "Unknown section ID"); - assert.lengthOf(section.tasks, 1, "Parent has one task"); - assert.equal(section.tasks[0].id, "2", "Parent has 'correct' task"); - }); -}); - -function createMetadata(options: { - projects?: IProjectRaw[]; - sections?: ISectionRaw[]; -}): ITodoistMetadata { - const metadata: ITodoistMetadata = { - projects: new ExtendedMap(), - sections: new ExtendedMap(), - labels: new ExtendedMap(), - }; - - if (options.projects) { - options.projects.forEach((prj) => metadata.projects.set(prj.id, prj)); - } - - if (options.sections) { - options.sections.forEach((sect) => metadata.sections.set(sect.id, sect)); - } - - return metadata; -} diff --git a/tests_old/task.test.ts b/tests_old/task.test.ts deleted file mode 100644 index 12a5a37..0000000 --- a/tests_old/task.test.ts +++ /dev/null @@ -1,359 +0,0 @@ -import "mocha"; -import { assert } from "chai"; -import { Task } from "./models"; -import type { ITaskRaw } from "./raw_models"; - -describe("Task tree parsing", () => { - it("Tree matches parents and subtasks", () => { - const apiTasks: ITaskRaw[] = [ - { - id: "1", - priority: 1, - order: 0, - content: "Parent task", - description: "", - project_id: "123", - section_id: null, - labels: [], - }, - { - id: "2", - priority: 2, - order: 1, - content: "Subtask", - description: "", - parent_id: "1", - project_id: "123", - section_id: null, - labels: [], - }, - ]; - - const tasks = Task.buildTree(apiTasks); - assert.lengthOf(tasks, 1, "Resulting tree has one parent node."); - - const parent = tasks[0]; - assert.lengthOf(parent.children, 1, "Parent task has one subtask"); - - const child = parent.children[0]; - assert.equal(child.id, "2", "Parent has expected subtask"); - assert.equal(child.parent, parent, "Subtask has expected parent."); - }); - - it("Subtask without parent in scope is a top-level node", () => { - const apiTasks: ITaskRaw[] = [ - { - id: "2", - priority: 2, - order: 1, - content: "Subtask", - description: "", - parent_id: "1", - project_id: "123", - section_id: null, - labels: [], - }, - ]; - - const tasks = Task.buildTree(apiTasks); - assert.lengthOf(tasks, 1, "Resulting tree has one parent node."); - }); -}); - -describe("Task date parsing", () => { - it("Tasks with dates only have no time", () => { - const apiTask: ITaskRaw = { - id: "1", - priority: 1, - order: 1, - content: "Task", - description: "", - due: { - date: "2019-09-12", - datetime: null, - recurring: false, - }, - project_id: "123", - section_id: null, - labels: [], - }; - - const task = new Task(apiTask); - - assert.isFalse(task.hasTime); - }); - - it("Tasks with time have time", () => { - const apiTask: ITaskRaw = { - id: "1", - priority: 1, - order: 1, - content: "Task", - description: "", - due: { - date: null, - datetime: "2019-09-12T02:30:00Z", - recurring: false, - }, - project_id: "123", - section_id: null, - labels: [], - }; - - const task = new Task(apiTask); - - assert.isTrue(task.hasTime); - }); -}); - -describe("Task comparisons", () => { - it("Tasks use Todoist order if no ordering provided", () => { - const first = new Task({ - id: "1", - priority: 1, - order: 0, - content: "Parent task", - description: "", - project_id: "123", - section_id: null, - labels: [], - }); - - const second = new Task({ - id: "2", - priority: 2, - order: 1, - content: "Subtask", - description: "", - project_id: "123", - section_id: null, - labels: [], - }); - - assert.isBelow(first.compareTo(second, []), 0); - assert.isAbove(second.compareTo(first, []), 0); - }); - - it("Tasks are sorted by priority (high to low)", () => { - const lowPriority = new Task({ - id: "1", - priority: 1, - order: 0, - content: "Parent task", - description: "", - project_id: "123", - section_id: null, - labels: [], - }); - - const highPriority = new Task({ - id: "2", - priority: 2, - order: 1, - content: "Subtask", - description: "", - project_id: "123", - section_id: null, - labels: [], - }); - - assert.isBelow(highPriority.compareTo(lowPriority, ["priority"]), 0); - assert.isAbove(lowPriority.compareTo(highPriority, ["priority"]), 0); - }); - - it("Tasks fallback to Todoist ordering if priority is the same", () => { - const first = new Task({ - id: "1", - priority: 2, - order: 0, - content: "Parent task", - description: "", - project_id: "123", - section_id: null, - labels: [], - }); - - const second = new Task({ - id: "2", - priority: 2, - order: 1, - content: "Subtask", - description: "", - project_id: "123", - section_id: null, - labels: [], - }); - - assert.isBelow(first.compareTo(second, []), 0); - assert.isAbove(second.compareTo(first, []), 0); - }); - - it("Tasks are sorted by date (earliest -> latest).", () => { - const first = new Task({ - id: "1", - priority: 2, - order: 0, - content: "Parent task", - description: "", - due: { - recurring: false, - date: "2019-09-01", - datetime: null, - }, - project_id: "123", - section_id: null, - labels: [], - }); - - const second = new Task({ - id: "2", - priority: 2, - order: 1, - content: "Subtask", - description: "", - due: { - recurring: false, - date: "2019-09-07", - datetime: null, - }, - project_id: "123", - section_id: null, - labels: [], - }); - - assert.isBelow(first.compareTo(second, ["date"]), 0); - assert.isAbove(second.compareTo(first, ["date"]), 0); - }); - - it("Tasks on the same day are sorted in time order (earliest -> latest -> no time)", () => { - const first = new Task({ - id: "1", - priority: 2, - order: 0, - content: "Parent task", - description: "", - due: { - recurring: false, - date: null, - datetime: "2019-08-01T02:30:00Z", - }, - project_id: "123", - section_id: null, - labels: [], - }); - - const second = new Task({ - id: "2", - priority: 2, - order: 1, - content: "Subtask", - description: "", - due: { - recurring: false, - date: null, - datetime: "2019-08-01T03:30:00Z", - }, - project_id: "123", - section_id: null, - labels: [], - }); - - const third = new Task({ - id: "2", - priority: 2, - order: 1, - content: "Subtask", - description: "", - due: { - recurring: false, - date: "2019-08-01", - datetime: null, - }, - project_id: "123", - section_id: null, - labels: [], - }); - - assert.isBelow(first.compareTo(second, ["date"]), 0); - assert.isBelow(first.compareTo(third, ["date"]), 0); - assert.isBelow(second.compareTo(third, ["date"]), 0); - - assert.isAbove(second.compareTo(first, ["date"]), 0); - assert.isAbove(third.compareTo(first, ["date"]), 0); - assert.isAbove(third.compareTo(second, ["date"]), 0); - }); - - it("Task ordered by priority falls to the next if equal", () => { - const first = new Task({ - id: "1", - priority: 1, - order: 1, - content: "Task", - description: "", - due: { - recurring: false, - date: "2019-08-02", - datetime: null, - }, - project_id: "123", - section_id: null, - labels: [], - }); - - const second = new Task({ - id: "1", - priority: 1, - order: 1, - content: "Task", - description: "", - due: { - recurring: false, - date: "2019-08-03", - datetime: null, - }, - project_id: "123", - section_id: null, - labels: [], - }); - - assert.isBelow(first.compareTo(second, ["priority", "date"]), 0); - assert.isAbove(second.compareTo(first, ["priority", "date"]), 0); - }); - - it("Task ordered by date falls to the next if equal", () => { - const first = new Task({ - id: "1", - priority: 2, - order: 1, - content: "Task", - description: "", - due: { - recurring: false, - date: "2019-08-03", - datetime: null, - }, - project_id: "123", - section_id: null, - labels: [], - }); - - const second = new Task({ - id: "1", - priority: 1, - order: 1, - content: "Task", - description: "", - due: { - recurring: false, - date: "2019-08-03", - datetime: null, - }, - project_id: "123", - section_id: null, - labels: [], - }); - - assert.isBelow(first.compareTo(second, ["date", "priority"]), 0); - assert.isAbove(second.compareTo(first, ["date", "priority"]), 0); - }); -});