From 9d6822a75f434d97bbb989fdeeac7ced0cf1d46f Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 25 May 2022 23:10:50 +0200 Subject: [PATCH] fix: add tests to make sure tasks are sorted correctly on overview --- .../integration/list/list-view-list.spec.js | 10 ++ cypress/integration/task/overview.spec.js | 102 ++++++++++++++++++ cypress/integration/task/task.spec.js | 4 +- 3 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 cypress/integration/task/overview.spec.js diff --git a/cypress/integration/list/list-view-list.spec.js b/cypress/integration/list/list-view-list.spec.js index e1a4a0f69..631827d78 100644 --- a/cypress/integration/list/list-view-list.spec.js +++ b/cypress/integration/list/list-view-list.spec.js @@ -21,6 +21,16 @@ describe('List View List', () => { .contains('This list is currently empty.') .should('exist') }) + + it('Should create a new task', () => { + const newTaskTitle = 'New task' + + cy.visit('/lists/1') + cy.get('.task-add textarea') + .type(newTaskTitle+'{enter}') + cy.get('.tasks') + .should('contain.text', newTaskTitle) + }) it('Should navigate to the task when the title is clicked', () => { const tasks = TaskFactory.create(5, { diff --git a/cypress/integration/task/overview.spec.js b/cypress/integration/task/overview.spec.js new file mode 100644 index 000000000..c11230024 --- /dev/null +++ b/cypress/integration/task/overview.spec.js @@ -0,0 +1,102 @@ +import {ListFactory} from '../../factories/list' +import {seed} from '../../support/seed' +import {TaskFactory} from '../../factories/task' +import {formatISO} from 'date-fns' +import {UserFactory} from '../../factories/user' +import {NamespaceFactory} from '../../factories/namespace' + +function seedTasks(numberOfTasks = 100) { + UserFactory.create(1) + NamespaceFactory.create(1) + const list = ListFactory.create()[0] + BucketFactory.create(1, { + list_id: list.id, + }) + const tasks = [] + let due_date = new Date() + for (let i = 0; i < numberOfTasks; i++) { + const now = new Date() + due_date = (new Date(due_date.valueOf())).setDate((new Date(due_date.valueOf())).getDate() + 2) + tasks.push({ + id: i + 1, + list_id: list.id, + done: false, + created_by_id: 1, + title: 'Test Task ' + i, + index: i + 1, + due_date: formatISO(due_date), + created: formatISO(now), + updated: formatISO(now), + }) + } + seed(TaskFactory.table, tasks) + return tasks +} + +import '../../support/authenticateUser' +import {BucketFactory} from '../../factories/bucket' + +describe('Home Page Task Overview', () => { + it('Should show tasks with a near due date first on the home page overview', () => { + const tasks = seedTasks() + + cy.visit('/') + cy.get('[data-cy="showTasks"] .card .task') + .each(([task], index) => { + expect(task.innerText).to.contain(tasks[index].title) + }) + }) + + it('Should show a new task with a very soon due date at the top', () => { + const tasks = seedTasks() + const newTaskTitle = 'New Task' + + cy.visit('/') + + TaskFactory.create(1, { + id: 999, + title: newTaskTitle, + due_date: formatISO(new Date()), + }, false) + + cy.visit(`/lists/${tasks[0].list_id}/list`) + cy.get('.tasks .task') + .first() + .should('contain.text', newTaskTitle) + cy.visit('/') + cy.get('[data-cy="showTasks"] .card .task') + .first() + .should('contain.text', newTaskTitle) + }) + + it('Should not show a new task without a date at the bottom when there are > 50 tasks', () => { + // We're not using the api here to create the task in order to verify the flow + const tasks = seedTasks() + const newTaskTitle = 'New Task' + + cy.visit('/') + + cy.visit(`/lists/${tasks[0].list_id}/list`) + cy.get('.task-add textarea') + .type(newTaskTitle+'{enter}') + cy.visit('/') + cy.get('[data-cy="showTasks"] .card .task') + .last() + .should('not.contain.text', newTaskTitle) + }) + + it('Should show a new task without a date at the bottom when there are < 50 tasks', () => { + seedTasks(40) + const newTaskTitle = 'New Task' + TaskFactory.create(1, { + id: 999, + title: newTaskTitle, + }, false) + + cy.visit('/') + cy.get('[data-cy="showTasks"] .card .task') + .last() + .should('contain.text', newTaskTitle) + }) + // Should do the same with adding tasks via quick add magic +}) diff --git a/cypress/integration/task/task.spec.js b/cypress/integration/task/task.spec.js index 29ade1d24..c482c7a78 100644 --- a/cypress/integration/task/task.spec.js +++ b/cypress/integration/task/task.spec.js @@ -6,13 +6,13 @@ import {TaskCommentFactory} from '../../factories/task_comment' import {UserFactory} from '../../factories/user' import {NamespaceFactory} from '../../factories/namespace' import {UserListFactory} from '../../factories/users_list' - -import '../../support/authenticateUser' import {TaskAssigneeFactory} from '../../factories/task_assignee' import {LabelFactory} from '../../factories/labels' import {LabelTaskFactory} from '../../factories/label_task' import {BucketFactory} from '../../factories/bucket' +import '../../support/authenticateUser' + describe('Task', () => { let namespaces let lists