Files
baserow/e2e-tests/tests/dashboard/dashboardWidgetGrid.spec.ts
Jonathan Adelineandpeter_baserow a26c5ce6b0 feat: filter dashboard widgets by date or date range (#6954)
* fix: handle calendar boundaries in date comparisons

* feat: add a single-date filter to the dashboard API

* feat: send the viewer timezone with dashboard data requests

* refactor: share dashboard filter controls and target settings

* feat: configure dashboard filter conditions on date fields

* feat: add the Date filter to the dashboard widget picker

Implement the single-date mode of #6886.

* fix: restore dragging dashboard filters by their titles

* feat: persist the dashboard date filter display format

* feat: choose how dashboard filter dates are displayed

* test: align numeric filter checks with shared dashboard controls

* style: format the dashboard date filter component test

* fix: accept fixed UTC offsets in dashboard date filters

* fix: expose dashboard filter dates as ISO strings in formulas

* fix: seed dashboard conditions with compatible operators

* feat: expose date ranges in dashboard formulas and viewer selections

* feat: configure inclusive date range conditions for dashboard targets

* feat: persist and dispatch inclusive dashboard date ranges

* docs: describe date range selections in the dashboard dispatch API

* feat: select and configure dashboard date ranges

* fix: let viewers clear each dashboard date range endpoint

* fix: preserve unfinished dashboard date range bounds on refresh

* fix: refresh public dashboards after a date filter mode change

* test: group dashboard date filter mode transitions

* fix: warn about incompatible date range formula operands

* fix: convert dashboard date defaults from the saved widget

* fix: keep dashboard filter controls aligned when a condition has a warning

* fix: clear incompatible dashboard conditions when switching date modes

* fix: show cleared date conditions without warnings or redundant saves

* fix: ignore empty dashboard date conditions after switching modes

* fix: ignore dashboard date conditions without a single date and simplify mode switch clearing

---------

Co-authored-by: peter_baserow <peter@baserow.io>
2026-12-03 20:40:18 +04:00

921 lines
31 KiB
TypeScript

import type { Locator, Page } from '@playwright/test'
import { getClient } from '../../client'
import type { Dashboard } from '../../fixtures/dashboard/dashboard'
import {
createDashboard,
createSummaryWidget,
getDashboardWidgets,
updateDashboardWidgetLayout,
updateDashboardSharing,
} from '../../fixtures/dashboard/dashboard'
import { baserowConfig } from '../../playwright.config'
import { expect, test } from '../baserowTest'
type GridCoordinates = {
grid_x: number
grid_y: number
grid_width: number
grid_height: number
}
async function goToDashboard(page: Page, dashboard: Dashboard) {
await page.goto(
`${baserowConfig.PUBLIC_WEB_FRONTEND_URL}/dashboard/${dashboard.id}`,
{ waitUntil: 'networkidle' }
)
await expect(page.getByText('Edit mode', { exact: true })).toBeVisible()
}
async function enterEditMode(page: Page) {
await page.getByText('Edit mode', { exact: true }).click()
await expect(page.getByRole('button', { name: 'Done editing' })).toBeVisible()
}
async function dragBy(
page: Page,
source: Locator,
deltaX: number,
deltaY: number
) {
await source.hover()
const box = await source.boundingBox()
if (!box) {
throw new Error('Could not measure the dashboard widget drag source')
}
const x = box.x + box.width / 2
const y = box.y + box.height / 2
await page.mouse.move(x, y)
await page.mouse.down()
await page.mouse.move(x + deltaX, y + deltaY, { steps: 12 })
await page.mouse.up()
}
function waitForWidgetLayoutUpdate(page: Page, dashboard: Dashboard) {
return page.waitForResponse(
(response) =>
response.request().method() === 'PATCH' &&
response.url().includes(`/dashboard/${dashboard.id}/widgets/layout/`)
)
}
async function expectWidgetLayout(
dashboard: Dashboard,
widgetId: number,
expected: Partial<GridCoordinates>
) {
await expect
.poll(async () => {
const widgets = await getDashboardWidgets(dashboard)
return widgets.find((widget) => widget.id === widgetId)
})
.toMatchObject(expected)
}
test.describe('Dashboard widget grid', () => {
test.use({ viewport: { width: 1920, height: 1000 } })
test('keeps widget context menus available in edit mode', async ({
page,
workspacePage,
}) => {
const dashboard = await createDashboard(
'Dashboard widget context menu',
workspacePage.workspace
)
const widget = await createSummaryWidget(dashboard, 'Context widget')
await goToDashboard(page, dashboard)
await expect(
page.getByTestId(`dashboard-widget-grid-item-${widget.id}`)
).toBeVisible()
await enterEditMode(page)
const contextButton = page.getByTestId(
`dashboard-widget-context-${widget.id}`
)
await page.getByTestId(`dashboard-widget-${widget.id}`).hover()
await expect(contextButton).toBeVisible()
await expect(contextButton).toHaveCSS('pointer-events', 'auto')
await contextButton.click()
await expect(page.getByText('Delete', { exact: true })).toBeVisible()
})
for (const filter of [
{ title: 'Order date', type: 'date_filter' },
{ title: 'Customer search', type: 'text_filter', mode: 'input' },
{ title: 'Order status', type: 'text_filter', mode: 'dropdown' },
]) {
test(`moves the ${filter.title} filter by its title`, async ({
page,
workspacePage,
}) => {
const dashboard = await createDashboard(
'Movable dashboard filters',
workspacePage.workspace
)
const { data: widget } = await getClient(workspacePage.user).post(
`dashboard/${dashboard.id}/widgets/`,
filter
)
await goToDashboard(page, dashboard)
await enterEditMode(page)
const item = page.getByTestId(`dashboard-widget-grid-item-${widget.id}`)
const title = item.getByText(filter.title, { exact: true })
await title.hover()
const box = await item.boundingBox()
if (!box) throw new Error('Could not measure the filter widget')
// Move by the widget's width in tracks, including the trailing grid gap.
await dragBy(page, title, box.width + 16, 0)
await expectWidgetLayout(dashboard, widget.id, {
grid_x: widget.grid_x + widget.grid_width,
grid_y: widget.grid_y,
})
})
}
test('finishes loading widgets after reloading a dashboard', async ({
page,
workspacePage,
}) => {
const dashboard = await createDashboard(
'Dashboard widget reload',
workspacePage.workspace
)
const widget = await createSummaryWidget(dashboard, 'Reload widget')
await goToDashboard(page, dashboard)
await expect(
page.getByTestId(`dashboard-widget-grid-item-${widget.id}`)
).toBeVisible()
await page.reload({ waitUntil: 'networkidle' })
const loadingIndicator = page
.getByTestId(`dashboard-widget-grid-item-${widget.id}`)
.locator('.skeleton-loading')
await expect(loadingIndicator).toHaveCount(0, { timeout: 10_000 })
})
for (const interaction of ['dragging', 'resizing']) {
test(`shows a new widget after ${interaction} another back to its original geometry`, async ({
page,
workspacePage,
}) => {
const dashboard = await createDashboard(
`Dashboard unchanged ${interaction}`,
workspacePage.workspace
)
const widget = await createSummaryWidget(dashboard, 'Existing widget')
await goToDashboard(page, dashboard)
await enterEditMode(page)
const handle = page
.getByTestId(`dashboard-widget-grid-item-${widget.id}`)
.locator(
interaction === 'dragging'
? '.widget__header-title'
: '.vgl-item__resizer'
)
await handle.hover()
const box = await handle.boundingBox()
if (!box) {
throw new Error('Could not measure the widget drag handle')
}
const x = box.x + box.width / 2
const y = box.y + box.height / 2
await page.mouse.move(x, y)
await page.mouse.down()
try {
await page.mouse.move(x + 250, y, { steps: 12 })
await page.mouse.move(x, y, { steps: 12 })
} finally {
await page.mouse.up()
}
await expectWidgetLayout(dashboard, widget.id, {
grid_x: 0,
grid_y: 0,
grid_width: 2,
grid_height: 4,
})
await page
.getByRole('button', { name: 'Add widget', exact: true })
.click()
const creationResponse = page.waitForResponse(
(response) =>
response.request().method() === 'POST' &&
response.url().endsWith(`/dashboard/${dashboard.id}/widgets/`)
)
await page
.getByRole('button', { name: 'Summary', exact: true })
.click()
const createdWidget = await (await creationResponse).json()
await expect(
page.getByTestId(`dashboard-widget-${createdWidget.id}`)
).toBeVisible()
})
}
test('resizes in discrete grid tracks without placeholder feedback', async ({
page,
workspacePage,
}) => {
test.setTimeout(60_000)
const dashboard = await createDashboard(
'Dashboard widget grid snap',
workspacePage.workspace
)
const widget = await createSummaryWidget(dashboard, 'Guide widget')
const adjacentWidget = await createSummaryWidget(
dashboard,
'Adjacent widget'
)
await goToDashboard(page, dashboard)
await enterEditMode(page)
const grid = page.getByTestId('dashboard-widget-grid')
await expect(grid).toHaveCSS('--dashboard-widget-grid-columns', '6')
const gridItem = page.getByTestId(`dashboard-widget-grid-item-${widget.id}`)
const dashboardWidget = page.getByTestId(`dashboard-widget-${widget.id}`)
const adjacentItem = page.getByTestId(
`dashboard-widget-grid-item-${adjacentWidget.id}`
)
// Hover waits for the edit sidebar's layout transition to finish.
await adjacentItem.hover()
const layoutBox = await grid.locator('.vgl-layout').boundingBox()
const resizer = gridItem.locator('.vgl-item__resizer')
const resizerBox = await resizer.boundingBox()
const initialWidgetBox = await gridItem.boundingBox()
const initialAdjacentBox = await adjacentItem.boundingBox()
if (!layoutBox || !resizerBox || !initialWidgetBox || !initialAdjacentBox) {
throw new Error('Could not measure the dashboard widget grid resizer')
}
const gridGap = 16
const columnWidth = (layoutBox.width - 7 * gridGap) / 6
const x = resizerBox.x + resizerBox.width / 2
const y = resizerBox.y + resizerBox.height / 2
const gridStep = columnWidth + gridGap
await page.mouse.move(x, y)
await page.mouse.down()
try {
await page.mouse.move(x + gridStep * 0.4, y, { steps: 6 })
await expect(gridItem).toHaveClass(
/dashboard-widget-grid__item--snap-resizing/
)
await expect(dashboardWidget.locator('.widget__header')).toHaveCSS(
'cursor',
'se-resize'
)
await expect(dashboardWidget.locator('.widget__header-title')).toHaveCSS(
'user-select',
'none'
)
await expect(
page
.getByTestId(`dashboard-widget-${adjacentWidget.id}`)
.locator('.widget__header-title')
).toHaveCSS('user-select', 'none')
const intermediateWidgetBox = await gridItem.boundingBox()
if (!intermediateWidgetBox) {
throw new Error('Could not measure the resizing dashboard widget')
}
expect(
Math.abs(intermediateWidgetBox.width - initialWidgetBox.width)
).toBeLessThanOrEqual(1)
await page.mouse.move(x + gridStep, y, { steps: 12 })
await expect(grid).toHaveClass(/dashboard-widget-grid--interacting/)
await expect
.poll(async () => {
const resizedBox = await gridItem.boundingBox()
const adjacentBox = await adjacentItem.boundingBox()
if (!resizedBox || !adjacentBox) return false
return (
Math.abs(resizedBox.y - adjacentBox.y) < 1 &&
adjacentBox.x >= resizedBox.x + resizedBox.width
)
})
.toBe(true)
await page.mouse.move(x, y, { steps: 12 })
await expect
.poll(async () => (await gridItem.boundingBox())?.width)
.toBeCloseTo(initialWidgetBox.width, 0)
await expect
.poll(async () => (await adjacentItem.boundingBox())?.x)
.toBeCloseTo(initialAdjacentBox.x, 0)
await page.mouse.move(x + gridStep, y, { steps: 12 })
} finally {
await page.mouse.up()
}
await expect(
page
.getByTestId(`dashboard-widget-${adjacentWidget.id}`)
.locator('.widget__header-title')
).toHaveCSS('user-select', 'auto')
await expectWidgetLayout(dashboard, widget.id, { grid_width: 3 })
await expectWidgetLayout(dashboard, adjacentWidget.id, {
grid_x: 3,
grid_y: 0,
})
await page.reload({ waitUntil: 'networkidle' })
const resizedBox = await gridItem.boundingBox()
const adjacentBox = await adjacentItem.boundingBox()
if (!resizedBox || !adjacentBox) {
throw new Error('Could not measure the reloaded widgets')
}
expect(adjacentBox.y).toBeCloseTo(resizedBox.y, 0)
expect(adjacentBox.x).toBeGreaterThanOrEqual(
resizedBox.x + resizedBox.width
)
})
test('persists drag and horizontal/vertical resize, then broadcasts the layout', async ({
page,
workspacePage,
}) => {
const dashboard = await createDashboard(
'Dashboard widget grid',
workspacePage.workspace
)
const firstWidget = await createSummaryWidget(dashboard, 'First widget')
const secondWidget = await createSummaryWidget(dashboard, 'Second widget')
await updateDashboardWidgetLayout(dashboard, [
{
id: firstWidget.id,
grid_x: 0,
grid_y: 0,
grid_width: 2,
grid_height: 4,
},
{
id: secondWidget.id,
grid_x: 0,
grid_y: 4,
grid_width: 2,
grid_height: 4,
},
])
await goToDashboard(page, dashboard)
const observerPage = await page.context().newPage()
await goToDashboard(observerPage, dashboard)
// Keep the editor active while the second tab observes layout updates.
await page.bringToFront()
await enterEditMode(page)
const grid = page.getByTestId('dashboard-widget-grid')
await expect(grid).toHaveCSS('--dashboard-widget-grid-columns', '6')
const layoutBox = await grid.locator('.vgl-layout').boundingBox()
if (!layoutBox) {
throw new Error('Could not measure the dashboard widget grid')
}
const columnWidth = (layoutBox.width - 7 * 16) / 6
const rowHeightWithMargin = 24 + 16
const secondWidgetElement = page.getByTestId(
`dashboard-widget-${secondWidget.id}`
)
const secondWidgetHeader = secondWidgetElement.locator('.widget__header')
await secondWidgetHeader.hover()
await expect(secondWidgetHeader).toHaveCSS('cursor', 'move')
const secondWidgetHeaderBox = await secondWidgetHeader.boundingBox()
if (!secondWidgetHeaderBox) {
throw new Error('Could not measure the dashboard widget drag source')
}
const dragStartX = secondWidgetHeaderBox.x + secondWidgetHeaderBox.width / 2
const dragStartY =
secondWidgetHeaderBox.y + secondWidgetHeaderBox.height / 2
const dragResponsePromise = waitForWidgetLayoutUpdate(page, dashboard)
await page.mouse.move(dragStartX, dragStartY)
await page.mouse.down()
try {
await page.mouse.move(
dragStartX + 2 * (columnWidth + 16),
dragStartY - 4 * rowHeightWithMargin,
{ steps: 12 }
)
const dragPlaceholder = grid.locator('.vgl-item--placeholder')
await expect(dragPlaceholder).toBeVisible()
} finally {
await page.mouse.up()
}
const dragResponse = await dragResponsePromise
expect(dragResponse.ok()).toBeTruthy()
await expect(grid).not.toHaveClass(/dashboard-widget-grid--interacting/)
await expectWidgetLayout(dashboard, secondWidget.id, {
grid_x: 2,
grid_y: 0,
})
const resizer = page
.getByTestId(`dashboard-widget-grid-item-${secondWidget.id}`)
.locator('.vgl-item__resizer')
const resizeResponsePromise = waitForWidgetLayoutUpdate(page, dashboard)
await dragBy(page, resizer, 2 * (columnWidth + 16), 2 * rowHeightWithMargin)
const resizeResponse = await resizeResponsePromise
expect(resizeResponse.ok()).toBeTruthy()
await expect(grid).not.toHaveClass(/dashboard-widget-grid--interacting/)
await expectWidgetLayout(dashboard, secondWidget.id, {
grid_x: 2,
grid_y: 0,
grid_width: 4,
grid_height: 6,
})
await page.reload({ waitUntil: 'networkidle' })
await expectWidgetLayout(dashboard, secondWidget.id, {
grid_x: 2,
grid_y: 0,
grid_width: 4,
grid_height: 6,
})
await expect
.poll(async () => {
const box = await observerPage
.getByTestId(`dashboard-widget-grid-item-${secondWidget.id}`)
.boundingBox()
const firstBox = await observerPage
.getByTestId(`dashboard-widget-grid-item-${firstWidget.id}`)
.boundingBox()
return box && firstBox ? Math.round(box.x - firstBox.x) : null
})
.toBeGreaterThan(0)
await observerPage.close()
})
test('refreshes widget and data-source lists once after remote creation', async ({
page,
workspacePage,
}) => {
const dashboard = await createDashboard(
'Dashboard remote creation requests',
workspacePage.workspace
)
await goToDashboard(page, dashboard)
const observer = await page.context().newPage()
await goToDashboard(observer, dashboard)
const requests: string[] = []
observer.on('request', (request) => {
const path = new URL(request.url()).pathname
if (request.method() === 'GET') {
requests.push(path)
}
})
const widget = await createSummaryWidget(dashboard, 'Remote widget')
await expect(
observer.getByTestId(`dashboard-widget-grid-item-${widget.id}`)
).toBeVisible()
await observer.waitForLoadState('networkidle')
for (const collection of ['widgets', 'data-sources']) {
expect(
requests.filter(
(path) => path === `/api/dashboard/${dashboard.id}/${collection}/`
)
).toHaveLength(1)
}
await observer.close()
})
test('keeps a dragged widget below a full-width row after saving and reloading', async ({
page,
workspacePage,
}) => {
const dashboard = await createDashboard(
'Dashboard full-width row',
workspacePage.workspace
)
const first = await createSummaryWidget(dashboard, 'First widget')
const fullWidth = await createSummaryWidget(dashboard, 'Full-width widget')
const moved = await createSummaryWidget(dashboard, 'Moved widget')
await updateDashboardWidgetLayout(dashboard, [
{ id: first.id, grid_x: 0, grid_y: 0, grid_width: 2, grid_height: 4 },
{ id: fullWidth.id, grid_x: 0, grid_y: 4, grid_width: 6, grid_height: 4 },
{ id: moved.id, grid_x: 2, grid_y: 0, grid_width: 2, grid_height: 4 },
])
await goToDashboard(page, dashboard)
await enterEditMode(page)
const response = waitForWidgetLayoutUpdate(page, dashboard)
await dragBy(
page,
page
.getByTestId(`dashboard-widget-${moved.id}`)
.locator('.widget__header'),
0,
8 * (24 + 16)
)
expect((await response).ok()).toBeTruthy()
await expectWidgetLayout(dashboard, moved.id, { grid_x: 2, grid_y: 8 })
await page.reload({ waitUntil: 'networkidle' })
await expect
.poll(async () => {
const movedBox = await page
.getByTestId(`dashboard-widget-grid-item-${moved.id}`)
.boundingBox()
const fullWidthBox = await page
.getByTestId(`dashboard-widget-grid-item-${fullWidth.id}`)
.boundingBox()
return movedBox && fullWidthBox
? movedBox.y - fullWidthBox.y - fullWidthBox.height
: null
})
.toBeGreaterThan(0)
})
test('restores three widgets on one row after another tab occupies the middle position', async ({
page,
workspacePage,
}) => {
test.setTimeout(60_000)
const dashboard = await createDashboard(
'Dashboard collaborative undo',
workspacePage.workspace
)
const first = await createSummaryWidget(dashboard, 'Summary 1')
const deleted = await createSummaryWidget(dashboard, 'Summary 2')
const moved = await createSummaryWidget(dashboard, 'Summary 3')
await goToDashboard(page, dashboard)
await enterEditMode(page)
const observer = await page.context().newPage()
try {
await goToDashboard(observer, dashboard)
await enterEditMode(observer)
const deletedCard = page.getByTestId(`dashboard-widget-${deleted.id}`)
await deletedCard.hover()
await page.getByTestId(`dashboard-widget-context-${deleted.id}`).click()
await page.getByText('Delete', { exact: true }).click()
await expect(deletedCard).toHaveCount(0)
await expect(
observer.getByTestId(`dashboard-widget-${deleted.id}`)
).toHaveCount(0)
const movedHeader = observer
.getByTestId(`dashboard-widget-${moved.id}`)
.locator('.widget__header')
await movedHeader.hover()
const movedBox = await observer
.getByTestId(`dashboard-widget-${moved.id}`)
.boundingBox()
if (!movedBox) throw new Error('Could not measure the moved widget')
const layoutUpdate = waitForWidgetLayoutUpdate(observer, dashboard)
await dragBy(observer, movedHeader, -(movedBox.width + 16), 0)
await layoutUpdate
await expectWidgetLayout(dashboard, moved.id, { grid_x: 2, grid_y: 0 })
for (let cycle = 0; cycle < 2; cycle++) {
const undoResponse = page.waitForResponse((response) =>
response.url().endsWith('/user/undo/')
)
await page.keyboard.press('ControlOrMeta+z')
expect((await undoResponse).ok()).toBe(true)
await expectWidgetLayout(dashboard, deleted.id, {
grid_x: 2,
grid_y: 0,
})
await expectWidgetLayout(dashboard, moved.id, {
grid_x: 4,
grid_y: 0,
})
for (const tab of [page, observer]) {
const restoredCard = tab.getByTestId(`dashboard-widget-${deleted.id}`)
const shiftedCard = tab.getByTestId(`dashboard-widget-${moved.id}`)
await expect(restoredCard.locator('.widget__header')).toBeVisible()
await expect
.poll(async () => {
const firstBox = await tab
.getByTestId(`dashboard-widget-${first.id}`)
.boundingBox()
const restoredBox = await restoredCard.boundingBox()
const shiftedBox = await shiftedCard.boundingBox()
if (!firstBox || !restoredBox || !shiftedBox) return false
return (
Math.abs(firstBox.y - restoredBox.y) < 1 &&
Math.abs(restoredBox.y - shiftedBox.y) < 1 &&
restoredBox.x >= firstBox.x + firstBox.width &&
shiftedBox.x >= restoredBox.x + restoredBox.width
)
})
.toBe(true)
}
const redoResponse = page.waitForResponse((response) =>
response.url().endsWith('/user/redo/')
)
await page.keyboard.press('ControlOrMeta+Shift+z')
expect((await redoResponse).ok()).toBe(true)
await expectWidgetLayout(dashboard, moved.id, { grid_x: 2, grid_y: 0 })
for (const tab of [page, observer]) {
await expect(
tab.getByTestId(`dashboard-widget-${deleted.id}`)
).toHaveCount(0)
}
}
} finally {
await observer.close()
}
})
for (const viewportWidth of [1500, 1100]) {
test(`edits the shared layout in a scrolling canvas at ${viewportWidth}px`, async ({
page,
workspacePage,
}) => {
const dashboard = await createDashboard(
'Dashboard small-screen editing',
workspacePage.workspace
)
const widget = await createSummaryWidget(dashboard, 'Editable widget')
await updateDashboardWidgetLayout(dashboard, [
{
id: widget.id,
grid_x: 4,
grid_y: 0,
grid_width: 2,
grid_height: 4,
},
])
await page.setViewportSize({ width: viewportWidth, height: 1000 })
await goToDashboard(page, dashboard)
await enterEditMode(page)
const grid = page.getByTestId('dashboard-widget-grid')
await expect(grid).toHaveCSS('--dashboard-widget-grid-columns', '6')
const pane = page.locator('.dashboard-app__layout-scrollable')
await expect
.poll(() => pane.evaluate((el) => el.scrollWidth > el.clientWidth))
.toBe(true)
const gridBox = await grid.boundingBox()
if (!gridBox) throw new Error('Could not measure the dashboard grid')
const columnWidth = (gridBox.width + 16) / 6
const item = page.getByTestId(`dashboard-widget-grid-item-${widget.id}`)
const moveResponse = waitForWidgetLayoutUpdate(page, dashboard)
await dragBy(page, item.locator('.widget__header-title'), -columnWidth, 0)
expect((await moveResponse).ok()).toBe(true)
await expectWidgetLayout(dashboard, widget.id, { grid_x: 3, grid_y: 0 })
await expect
.poll(() => pane.evaluate((el) => el.scrollLeft))
.toBeGreaterThan(0)
const resizeResponse = waitForWidgetLayoutUpdate(page, dashboard)
await dragBy(page, item.locator('.vgl-item__resizer'), columnWidth, 40)
expect((await resizeResponse).ok()).toBe(true)
const expectedLayout = {
grid_x: 3,
grid_y: 0,
grid_width: 3,
grid_height: 5,
}
await expectWidgetLayout(dashboard, widget.id, expectedLayout)
await page.getByRole('button', { name: 'Done editing' }).click()
await page.setViewportSize({ width: 1100, height: 1000 })
await expect(grid).toHaveCSS('--dashboard-widget-grid-columns', '1')
await expect(item.locator('.vgl-item__resizer')).toHaveCount(0)
await expect
.poll(() => pane.evaluate((el) => el.scrollWidth > el.clientWidth))
.toBe(false)
await expect
.poll(async () => {
const canvasBox = await grid.boundingBox()
const widgetBox = await item.boundingBox()
if (!canvasBox || !widgetBox) return null
return Math.round(widgetBox.width - canvasBox.width)
})
.toBe(0)
await page.setViewportSize({ width: 1920, height: 1000 })
await page.reload({ waitUntil: 'networkidle' })
await expect(grid).toHaveCSS('--dashboard-widget-grid-columns', '6')
await expectWidgetLayout(dashboard, widget.id, expectedLayout)
})
}
test('adapts viewing rows and public mobile dashboards without saving', async ({
page,
workspacePage,
}) => {
test.setTimeout(60_000)
const dashboard = await createDashboard(
'Responsive dashboard',
workspacePage.workspace
)
const widgets = await Promise.all(
[1, 2, 3, 4, 5].map((index) =>
createSummaryWidget(dashboard, `Summary ${index}`)
)
)
const saved = [
{ grid_x: 0, grid_y: 0, grid_width: 2, grid_height: 4 },
{ grid_x: 2, grid_y: 0, grid_width: 4, grid_height: 6 },
{ grid_x: 0, grid_y: 6, grid_width: 3, grid_height: 4 },
{ grid_x: 3, grid_y: 6, grid_width: 3, grid_height: 6 },
{ grid_x: 0, grid_y: 10, grid_width: 2, grid_height: 4 },
].map((coordinates, index) => ({ id: widgets[index].id, ...coordinates }))
await updateDashboardWidgetLayout(dashboard, saved)
let layoutUpdates = 0
page.on('request', (request) => {
if (
request.method() === 'PATCH' &&
request.url().endsWith('/widgets/layout/')
) {
layoutUpdates += 1
}
})
await goToDashboard(page, dashboard)
const grid = page.getByTestId('dashboard-widget-grid')
const pane = page.locator('.dashboard-app__layout-scrollable')
const desktop = [
[0, 0, 2],
[2, 0, 4],
[0, 6, 3],
[3, 6, 3],
[0, 10, 2],
]
const tablet = [
[0, 0, 1],
[0, 4, 2],
[0, 10, 1],
[1, 10, 1],
[0, 16, 1],
]
const mobile = [
[0, 0, 1],
[0, 4, 1],
[0, 10, 1],
[0, 14, 1],
[0, 20, 1],
]
for (const { width, columns, expected } of [
{ width: 1920, columns: 6, expected: desktop },
{ width: 1200, columns: 2, expected: tablet },
{ width: 900, columns: 1, expected: mobile },
{ width: 1920, columns: 6, expected: desktop },
]) {
await page.setViewportSize({ width, height: 1000 })
await expect(grid).toHaveCSS(
'--dashboard-widget-grid-columns',
String(columns)
)
await expect(grid.locator('.vgl-item__resizer')).toHaveCount(0)
await expect
.poll(() => pane.evaluate((el) => el.scrollWidth > el.clientWidth))
.toBe(false)
for (const [index, [x, y, w]] of expected.entries()) {
const item = page.getByTestId(
`dashboard-widget-grid-item-${widgets[index].id}`
)
await expect
.poll(async () => {
const canvas = await grid.boundingBox()
const box = await item.boundingBox()
if (!canvas || !box) return null
const unit = (canvas.width + 16) / columns
return Math.max(
Math.abs(box.x - canvas.x - x * unit),
Math.abs(box.y - canvas.y - y * 40),
Math.abs(box.width - (w * unit - 16)),
Math.abs(box.height - (saved[index].grid_height * 40 - 16))
)
})
.toBeLessThanOrEqual(1)
}
}
const { slug } = await updateDashboardSharing(dashboard, { public: true })
await page.goto(
`${baserowConfig.PUBLIC_WEB_FRONTEND_URL}/public/dashboard/${slug}`
)
for (const width of [375, 320]) {
await page.setViewportSize({ width, height: 1000 })
await expect(grid).toHaveCSS('--dashboard-widget-grid-columns', '1')
await expect
.poll(() =>
page.evaluate(
() => document.documentElement.scrollWidth <= window.innerWidth
)
)
.toBe(true)
for (const widget of widgets) {
const item = page.getByTestId(`dashboard-widget-grid-item-${widget.id}`)
await expect
.poll(async () => {
const canvas = await grid.boundingBox()
const box = await item.boundingBox()
if (!canvas || !box) return null
return Math.round(box.width - canvas.width)
})
.toBe(0)
}
}
expect(layoutUpdates).toBe(0)
const persisted = await getDashboardWidgets(dashboard)
for (const coordinates of saved) {
expect(
persisted.find((widget) => widget.id === coordinates.id)
).toMatchObject(coordinates)
}
})
test('keeps the canonical desktop layout when deleting on a small screen', async ({
page,
workspacePage,
}) => {
const dashboard = await createDashboard(
'Dashboard tablet widget deletion',
workspacePage.workspace
)
const firstWidget = await createSummaryWidget(dashboard, 'First widget')
const secondWidget = await createSummaryWidget(dashboard, 'Second widget')
await updateDashboardWidgetLayout(dashboard, [
{
id: firstWidget.id,
grid_x: 0,
grid_y: 0,
grid_width: 2,
grid_height: 4,
},
{
id: secondWidget.id,
grid_x: 2,
grid_y: 0,
grid_width: 4,
grid_height: 4,
},
])
await page.setViewportSize({ width: 1100, height: 1000 })
await goToDashboard(page, dashboard)
await expect(page.getByTestId('dashboard-widget-grid')).toHaveCSS(
'--dashboard-widget-grid-columns',
'1'
)
const firstWidgetItem = page.getByTestId(
`dashboard-widget-grid-item-${firstWidget.id}`
)
const secondWidgetItem = page.getByTestId(
`dashboard-widget-grid-item-${secondWidget.id}`
)
await expect
.poll(async () => {
const firstBox = await firstWidgetItem.boundingBox()
const secondBox = await secondWidgetItem.boundingBox()
if (!firstBox || !secondBox) {
return null
}
return (firstBox.width + 16) / (secondBox.width + 16)
})
.toBeCloseTo(1, 1)
await enterEditMode(page)
await expect(page.getByTestId('dashboard-widget-grid')).toHaveCSS(
'--dashboard-widget-grid-columns',
'6'
)
await page.getByTestId(`dashboard-widget-${firstWidget.id}`).hover()
const contextButton = page.getByTestId(
`dashboard-widget-context-${firstWidget.id}`
)
await expect(contextButton).toHaveCSS('pointer-events', 'auto')
await contextButton.click()
await page.getByText('Delete', { exact: true }).click()
await expectWidgetLayout(dashboard, secondWidget.id, {
grid_x: 2,
grid_y: 0,
grid_width: 4,
grid_height: 4,
})
})
})