TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.
TypeScript graphviewkanban-boardnodejsproductivityproject-managementself-hostedtasktask-managementtask-managertodoapp
test(web): e2e for calendar drag and resize and date picker times
Daniel Barretoe67ed327fe0f
diff --git a/web/e2e/calendar.spec.ts b/web/e2e/calendar.spec.tsindex f9996c9..6e20174 100644--- a/web/e2e/calendar.spec.ts+++ b/web/e2e/calendar.spec.ts@@ -1,5 +1,5 @@-import { test, expect, type Page } from '@playwright/test'-import { format, getDay, parseISO } from 'date-fns'+import { test, expect, type Locator, type Page } from '@playwright/test'+import { format, getDay, isWeekend, parseISO } from 'date-fns'import {setupAndLogin,cleanupProjects,@@ -14,8 +14,36 @@ async function openCalendar(page: Page, projectId: number, query = '') {await expect(page.getByTestId('calendar-title')).toBeVisible({ timeout: 10000 })}+// The dates shown in the week view, in display order (the first day follows the week-start preference)+async function visibleDates(page: Page) {+ const headers = page.locator('.tv-calendar [role="columnheader"][data-date]')+ return headers.evaluateAll((cells) => cells.map((cell) => (cell as HTMLElement).dataset.date!))+}++const dayHeader = (page: Page, date: string) => page.locator(`.tv-calendar [role="columnheader"][data-date="${date}"]`)++async function box(locator: Locator) {+ const rect = await locator.boundingBox()+ if (!rect) throw new Error('Element is not visible')+ return rect+}++// FullCalendar starts a drag only after the pointer has moved a few pixels with the button held.+// Returns the saved dates.+async function drag(page: Page, from: { x: number; y: number }, toX: number) {+ const saved = page.waitForResponse((response) => response.url().endsWith('/module/tasks') && response.request().method() === 'PATCH')+ await page.mouse.move(from.x, from.y)+ await page.mouse.down()+ await page.mouse.move(toX, from.y, { steps: 15 })+ await page.mouse.up()+ const response = await saved+ expect(response.ok()).toBe(true)+ return JSON.parse(response.request().postData()!)+}+test.describe('Calendar', () => {- test.setTimeout(30_000)+ // Drag and resize tests reload twice and log in through the UI: 30s is tight with parallel workers+ test.setTimeout(60_000)test.beforeEach(async ({ page }) => {await setupAndLogin(page)@@ -60,20 +88,54 @@ test.describe('Calendar', () => {await expect(page.getByTestId('calendar-empty')).toBeVisible()})- test('collapses empty weekend days in the week view', async ({ page }) => {+ // Collapsing only applies when tasks can't be moved: dropping relies on equal-width columns+ test('keeps weekend days full width when tasks can be moved', async ({ page }) => {const projectId = await createProjectViaApi(page, `Calendar ${Date.now()}`)await openCalendar(page, projectId, '?view=week')- // Read the visible week from the headers: its first day depends on the user's week-start preference- const headers = page.locator('.tv-calendar [role="columnheader"][data-date]')- const dates = await headers.evaluateAll((cells) => cells.map((cell) => (cell as HTMLElement).dataset.date!))- const saturday = dates.find((date) => getDay(parseISO(date)) === 6)!- const sunday = dates.find((date) => getDay(parseISO(date)) === 0)!- await createTaskViaApi(page, { goalId: projectId, description: 'Weekend task', startDate: saturday })+ const sunday = (await visibleDates(page)).find((date) => getDay(parseISO(date)) === 0)!+ await expect(dayHeader(page, sunday)).toBeVisible()+ await expect(dayHeader(page, sunday)).not.toHaveClass(/tv-calendar-collapsed/)+ })++ test('moves a task to another day by dragging it', async ({ page }) => {+ const projectId = await createProjectViaApi(page, `Calendar ${Date.now()}`)+ await openCalendar(page, projectId, '?view=week')+ const [from, , to] = (await visibleDates(page)).filter((date) => !isWeekend(parseISO(date)))+ const taskId = await createTaskViaApi(page, { goalId: projectId, description: 'Move me', startDate: from })await page.reload()- const header = (date: string) => page.locator(`.tv-calendar [role="columnheader"][data-date="${date}"]`)- await expect(header(sunday)).toHaveClass(/tv-calendar-collapsed/)- await expect(header(saturday)).not.toHaveClass(/tv-calendar-collapsed/)+ const card = page.getByTestId(`calendar-task-${taskId}`)+ const start = await box(card)+ const target = await box(dayHeader(page, to))+ const patch = await drag(page, { x: start.x + start.width / 2, y: start.y + start.height / 2 }, target.x + target.width / 2)+ expect(patch).toMatchObject({ id: taskId, startDate: to, startTime: null })++ await page.reload()+ const moved = await box(card)+ expect(moved.x).toBeGreaterThanOrEqual(target.x)+ expect(moved.x + moved.width).toBeLessThanOrEqual(target.x + target.width)+ })++ test('stretches a task over more days by resizing it', async ({ page }) => {+ const projectId = await createProjectViaApi(page, `Calendar ${Date.now()}`)+ await openCalendar(page, projectId, '?view=week')+ const [first, , third] = (await visibleDates(page)).filter((date) => !isWeekend(parseISO(date)))+ const taskId = await createTaskViaApi(page, { goalId: projectId, description: 'Stretch me', startDate: first })+ await page.reload()++ // The resize handle sits on the event's end edge and shows on hover+ const card = page.getByTestId(`calendar-task-${taskId}`)+ await card.hover()+ const start = await box(card)+ const target = await box(dayHeader(page, third))+ const patch = await drag(page, { x: start.x + start.width - 2, y: start.y + start.height / 2 }, target.x + target.width / 2)+ expect(patch).toMatchObject({ id: taskId, startDate: first, endDate: third })++ await page.reload()+ const firstDay = await box(dayHeader(page, first))+ const stretched = await box(card)+ expect(stretched.x).toBeLessThan(firstDay.x + firstDay.width)+ expect(stretched.x + stretched.width).toBeGreaterThan(target.x)})})diff --git a/web/e2e/task-date-picker.spec.ts b/web/e2e/task-date-picker.spec.tsnew file mode 100644index 0000000..56d09d1--- /dev/null+++ b/web/e2e/task-date-picker.spec.ts@@ -0,0 +1,110 @@+import { test, expect, type Page } from '@playwright/test'+import { format, setDate } from 'date-fns'+import {+ setupAndLogin,+ cleanupProjects,+ createProjectViaApi,+ createTaskViaApi,+} from './test-helpers'++const today = () => format(new Date(), 'yyyy-MM-dd')++// Opens the task's details from the calendar, then its date picker+async function openDatePicker(page: Page, projectId: number, taskId: number) {+ await page.waitForURL((url) => url.pathname !== '/', { timeout: 10000 })+ const orgSlug = new URL(page.url()).pathname.split('/')[1]+ await page.goto(`/${orgSlug}/${projectId}/calendar?view=week`)+ await page.getByTestId(`calendar-task-${taskId}`).click()+ await page.getByTestId('date-range-trigger').click()+}++test.describe('Task date picker', () => {+ // Opens the task twice through the calendar: 30s is tight with parallel workers+ test.setTimeout(60_000)++ test.beforeEach(async ({ page }) => {+ await setupAndLogin(page)+ })++ test.afterAll(async ({ browser }) => {+ const page = await browser.newPage()+ await cleanupProjects(page)+ await page.close()+ })++ test('opens a task with two dates in range mode', async ({ page }) => {+ const projectId = await createProjectViaApi(page, `Dates ${Date.now()}`)+ const taskId = await createTaskViaApi(page, { goalId: projectId, description: 'Range', startDate: today(), endDate: today() })++ await openDatePicker(page, projectId, taskId)++ await expect(page.getByRole('checkbox', { name: 'Select range' })).toBeChecked()+ })++ test('shows the times of a task that already has them', async ({ page }) => {+ const projectId = await createProjectViaApi(page, `Dates ${Date.now()}`)+ const taskId = await createTaskViaApi(page, {+ goalId: projectId,+ description: 'Meeting',+ startDate: today(),+ startTime: '12:00:00',+ endDate: today(),+ endTime: '13:00:00',+ })++ await openDatePicker(page, projectId, taskId)++ await expect(page.getByRole('checkbox', { name: 'Select time' })).toBeChecked()+ await expect(page.getByTestId('date-range-start-time')).toBeVisible()+ await expect(page.getByTestId('date-range-end-time')).toBeVisible()+ })++ test('adds a time to a date-only task with the checkbox', async ({ page }) => {+ const projectId = await createProjectViaApi(page, `Dates ${Date.now()}`)+ const taskId = await createTaskViaApi(page, { goalId: projectId, description: 'Deadline', endDate: today() })++ await openDatePicker(page, projectId, taskId)+ await expect(page.getByTestId('date-range-end-time')).toBeHidden()++ const saved = page.waitForResponse((response) => response.url().endsWith('/module/tasks') && response.request().method() === 'PATCH')+ await page.getByRole('checkbox', { name: 'Select time' }).click()+ const body = JSON.parse((await saved).request().postData()!)+ expect(body.endTime).toMatch(/^\d{2}:\d{2}:00$/)++ // Load the task again: the times now come from the server+ await openDatePicker(page, projectId, taskId)+ await expect(page.getByTestId('date-range-end-time')).toBeVisible()+ })++ test('saves a new range only once both ends are picked, keeping its times', async ({ page }) => {+ const projectId = await createProjectViaApi(page, `Dates ${Date.now()}`)+ const taskId = await createTaskViaApi(page, {+ goalId: projectId,+ description: 'Workshop',+ startDate: today(),+ startTime: '12:00:00',+ endDate: today(),+ endTime: '13:00:00',+ })+ await openDatePicker(page, projectId, taskId)++ // Days 10 and 12 are always in the month the picker opens on+ const day = (dayOfMonth: number) => page.locator(`[data-reka-calendar-cell-trigger][data-value="${format(setDate(new Date(), dayOfMonth), 'yyyy-MM-dd')}"]`)+ const patches: string[] = []+ page.on('request', (request) => {+ if (request.method() === 'PATCH' && request.url().endsWith('/module/tasks')) patches.push(request.postData()!)+ })++ await day(10).click()+ await page.waitForTimeout(500)+ expect(patches).toHaveLength(0)++ const saved = page.waitForResponse((response) => response.url().endsWith('/module/tasks') && response.request().method() === 'PATCH')+ await day(12).click()+ await saved+ expect(patches).toHaveLength(1)+ const body = JSON.parse(patches[0])+ expect(body.startTime).not.toBeNull()+ expect(body.endTime).not.toBeNull()+ })+})diff --git a/web/e2e/test-helpers.ts b/web/e2e/test-helpers.tsindex f9d23ca..bd6e592 100644--- a/web/e2e/test-helpers.ts+++ b/web/e2e/test-helpers.ts@@ -154,7 +154,7 @@ export async function createProjectViaApi(page: Page, name: string): Promise<num/*** Creates a task through the API, for tests that need fields the quick-add input can't set (e.g. dates).*/-export async function createTaskViaApi(page: Page, task: { goalId: number; description: string; startDate?: string; endDate?: string }): Promise<number> {+export async function createTaskViaApi(page: Page, task: { goalId: number; description: string; startDate?: string; startTime?: string; endDate?: string; endTime?: string }): Promise<number> {const token = await apiToken(page)const response = await page.request.post(`${API_URL}/module/tasks`, {data: task,