|
| 1 | +import {type Page} from '@playwright/test' |
| 2 | +import {test, expect} from '../../support/fixtures' |
| 3 | +import {TaskFactory} from '../../factories/task' |
| 4 | +import {createProjects} from './prepareProjects' |
| 5 | + |
| 6 | +async function selectSortInList(page: Page, optionLabel: string) { |
| 7 | + await page.locator('.filter-container').getByRole('button', {name: 'Sort', exact: true}).click() |
| 8 | + await page.getByLabel('Sort by').selectOption({label: optionLabel}) |
| 9 | + await page.getByRole('button', {name: 'Apply sort'}).click() |
| 10 | +} |
| 11 | + |
| 12 | +async function navigateViaSidebar(page: Page, projectTitle: string) { |
| 13 | + await page.locator('.menu-list .list-menu-link', { |
| 14 | + has: page.locator('.project-menu-title', {hasText: new RegExp(`^${projectTitle}$`)}), |
| 15 | + }).first().click() |
| 16 | +} |
| 17 | + |
| 18 | +test.describe('Sort persistence across sidebar navigation (#2753)', () => { |
| 19 | + test('List view: sort persists after navigating to another project and back', async ({authenticatedPage: page}) => { |
| 20 | + const projects = await createProjects(2) |
| 21 | + const [projectA, projectB] = projects |
| 22 | + await TaskFactory.create(3, { |
| 23 | + id: '{increment}', |
| 24 | + project_id: projectA.id, |
| 25 | + title: 'Task {increment}', |
| 26 | + }) |
| 27 | + |
| 28 | + const listViewA = projectA.views[0].id |
| 29 | + await page.goto(`/projects/${projectA.id}/${listViewA}`) |
| 30 | + await expect(page).not.toHaveURL(/sort=/) |
| 31 | + |
| 32 | + await selectSortInList(page, 'Due date (Earliest first)') |
| 33 | + await expect(page).toHaveURL(/sort=due_date:asc/) |
| 34 | + |
| 35 | + await navigateViaSidebar(page, projectB.title) |
| 36 | + await expect(page).toHaveURL(new RegExp(`/projects/${projectB.id}/`)) |
| 37 | + |
| 38 | + await navigateViaSidebar(page, projectA.title) |
| 39 | + await expect(page).toHaveURL(new RegExp(`/projects/${projectA.id}/`)) |
| 40 | + await expect(page).toHaveURL(/sort=due_date:asc/) |
| 41 | + }) |
| 42 | + |
| 43 | + test('List view: explicit URL sort wins over stored sort', async ({authenticatedPage: page}) => { |
| 44 | + const projects = await createProjects(1) |
| 45 | + const listView = projects[0].views[0].id |
| 46 | + |
| 47 | + // Seed the store with one sort by visiting with it set. |
| 48 | + await page.goto(`/projects/${projects[0].id}/${listView}?sort=due_date:asc`) |
| 49 | + await expect(page).toHaveURL(/sort=due_date:asc/) |
| 50 | + |
| 51 | + // Visit a URL that explicitly sets a different sort — that should win. |
| 52 | + await page.goto(`/projects/${projects[0].id}/${listView}?sort=priority:desc`) |
| 53 | + await expect(page).toHaveURL(/sort=priority:desc/) |
| 54 | + }) |
| 55 | +}) |
0 commit comments