Chore: Harden panel-layouts test by wrapping synchronous checks in `.toPass()` (#108849)

harden panel layouts test by wrapping synchronous checks in .toPass()
This commit is contained in:
Ashley Harrison 2025-07-30 13:59:32 +01:00 committed by GitHub
parent 599fe5a400
commit f92752c2f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 56 additions and 31 deletions

View File

@ -69,11 +69,14 @@ test.describe(
// Get initial positions - standard width should have panels on different rows // Get initial positions - standard width should have panels on different rows
const firstPanelTop = await getPanelTop(dashboardPage, selectors); const firstPanelTop = await getPanelTop(dashboardPage, selectors);
const lastPanel = dashboardPage.getByGrafanaSelector(selectors.components.Panels.Panel.title('New panel')).last(); const lastPanel = dashboardPage.getByGrafanaSelector(selectors.components.Panels.Panel.title('New panel')).last();
expect(async () => {
const lastPanelBox = await lastPanel.boundingBox(); const lastPanelBox = await lastPanel.boundingBox();
const lastPanelTop = lastPanelBox?.y || 0; const lastPanelTop = lastPanelBox?.y || 0;
// Verify standard layout has panels on different rows // Verify standard layout has panels on different rows
expect(lastPanelTop).toBeGreaterThan(firstPanelTop); expect(lastPanelTop).toBeGreaterThan(firstPanelTop);
}).toPass();
// Change to narrow min column width // Change to narrow min column width
await dashboardPage await dashboardPage
@ -82,11 +85,13 @@ test.describe(
await page.getByRole('option', { name: 'Narrow' }).click(); await page.getByRole('option', { name: 'Narrow' }).click();
// Verify narrow layout has all panels on same row // Verify narrow layout has all panels on same row
expect(async () => {
const firstPanelTopNarrow = await getPanelTop(dashboardPage, selectors); const firstPanelTopNarrow = await getPanelTop(dashboardPage, selectors);
const lastPanelBoxNarrow = await lastPanel.boundingBox(); const lastPanelBoxNarrow = await lastPanel.boundingBox();
const lastPanelTopNarrow = lastPanelBoxNarrow?.y || 0; const lastPanelTopNarrow = lastPanelBoxNarrow?.y || 0;
expect(lastPanelTopNarrow).toBe(firstPanelTopNarrow); expect(lastPanelTopNarrow).toBe(firstPanelTopNarrow);
}).toPass();
await saveDashboard(dashboardPage, selectors); await saveDashboard(dashboardPage, selectors);
await page.reload(); await page.reload();
@ -99,11 +104,13 @@ test.describe(
) )
).toHaveValue('Narrow'); ).toHaveValue('Narrow');
expect(async () => {
const firstPanelTopReload = await getPanelTop(dashboardPage, selectors); const firstPanelTopReload = await getPanelTop(dashboardPage, selectors);
const lastPanelBoxReload = await lastPanel.boundingBox(); const lastPanelBoxReload = await lastPanel.boundingBox();
const lastPanelTopReload = lastPanelBoxReload?.y || 0; const lastPanelTopReload = lastPanelBoxReload?.y || 0;
expect(lastPanelTopReload).toBe(firstPanelTopReload); expect(lastPanelTopReload).toBe(firstPanelTopReload);
}).toPass();
}); });
test('can change to custom min column width in auto grid layout', async ({ dashboardPage, selectors, page }) => { test('can change to custom min column width in auto grid layout', async ({ dashboardPage, selectors, page }) => {
@ -220,22 +227,28 @@ test.describe(
.click(); .click();
await page.getByRole('option', { name: 'Short' }).click(); await page.getByRole('option', { name: 'Short' }).click();
await expect(async () => {
const shortHeight = await getPanelHeight(dashboardPage, selectors); const shortHeight = await getPanelHeight(dashboardPage, selectors);
expect(shortHeight).toBeLessThan(regularRowHeight); expect(shortHeight).toBeLessThan(regularRowHeight);
}).toPass();
await dashboardPage await dashboardPage
.getByGrafanaSelector(selectors.components.PanelEditor.ElementEditPane.AutoGridLayout.rowHeight) .getByGrafanaSelector(selectors.components.PanelEditor.ElementEditPane.AutoGridLayout.rowHeight)
.click(); .click();
await page.getByRole('option', { name: 'Tall' }).click(); await page.getByRole('option', { name: 'Tall' }).click();
await expect(async () => {
const tallHeight = await getPanelHeight(dashboardPage, selectors); const tallHeight = await getPanelHeight(dashboardPage, selectors);
expect(tallHeight).toBeGreaterThan(regularRowHeight); expect(tallHeight).toBeGreaterThan(regularRowHeight);
}).toPass();
await saveDashboard(dashboardPage, selectors); await saveDashboard(dashboardPage, selectors);
await page.reload(); await page.reload();
await expect(async () => {
const tallHeightAfterReload = await getPanelHeight(dashboardPage, selectors); const tallHeightAfterReload = await getPanelHeight(dashboardPage, selectors);
expect(tallHeightAfterReload).toBeGreaterThan(regularRowHeight); expect(tallHeightAfterReload).toBeGreaterThan(regularRowHeight);
}).toPass();
await dashboardPage.getByGrafanaSelector(selectors.components.NavToolbar.editDashboard.editButton).click(); await dashboardPage.getByGrafanaSelector(selectors.components.NavToolbar.editDashboard.editButton).click();
@ -243,8 +256,10 @@ test.describe(
dashboardPage.getByGrafanaSelector(selectors.components.PanelEditor.ElementEditPane.AutoGridLayout.rowHeight) dashboardPage.getByGrafanaSelector(selectors.components.PanelEditor.ElementEditPane.AutoGridLayout.rowHeight)
).toHaveValue('Tall'); ).toHaveValue('Tall');
await expect(async () => {
const tallHeightAfterEdit = await getPanelHeight(dashboardPage, selectors); const tallHeightAfterEdit = await getPanelHeight(dashboardPage, selectors);
expect(tallHeightAfterEdit).toBeGreaterThan(regularRowHeight); expect(tallHeightAfterEdit).toBeGreaterThan(regularRowHeight);
}).toPass();
}); });
test('can change to custom row height in auto grid layout', async ({ dashboardPage, selectors, page }) => { test('can change to custom row height in auto grid layout', async ({ dashboardPage, selectors, page }) => {
@ -276,15 +291,19 @@ test.describe(
.getByGrafanaSelector(selectors.components.PanelEditor.ElementEditPane.AutoGridLayout.customRowHeight) .getByGrafanaSelector(selectors.components.PanelEditor.ElementEditPane.AutoGridLayout.customRowHeight)
.blur(); .blur();
await expect(async () => {
const customHeight = await getPanelHeight(dashboardPage, selectors); const customHeight = await getPanelHeight(dashboardPage, selectors);
expect(customHeight).toBeCloseTo(800, 5); // Allow some tolerance for rendering differences expect(customHeight).toBeCloseTo(800, 5); // Allow some tolerance for rendering differences
expect(customHeight).toBeGreaterThan(regularRowHeight); expect(customHeight).toBeGreaterThan(regularRowHeight);
}).toPass();
await saveDashboard(dashboardPage, selectors); await saveDashboard(dashboardPage, selectors);
await page.reload(); await page.reload();
await expect(async () => {
const customHeightAfterReload = await getPanelHeight(dashboardPage, selectors); const customHeightAfterReload = await getPanelHeight(dashboardPage, selectors);
expect(customHeightAfterReload).toBeCloseTo(800, 5); expect(customHeightAfterReload).toBeCloseTo(800, 5);
}).toPass();
await dashboardPage.getByGrafanaSelector(selectors.components.NavToolbar.editDashboard.editButton).click(); await dashboardPage.getByGrafanaSelector(selectors.components.NavToolbar.editDashboard.editButton).click();
@ -329,14 +348,18 @@ test.describe(
.getByGrafanaSelector(selectors.components.PanelEditor.ElementEditPane.AutoGridLayout.fillScreen) .getByGrafanaSelector(selectors.components.PanelEditor.ElementEditPane.AutoGridLayout.fillScreen)
.click({ force: true }); .click({ force: true });
await expect(async () => {
const fillScreenHeight = await getPanelHeight(dashboardPage, selectors); const fillScreenHeight = await getPanelHeight(dashboardPage, selectors);
expect(fillScreenHeight).toBeGreaterThan(initialHeight); expect(fillScreenHeight).toBeGreaterThan(initialHeight);
}).toPass();
await saveDashboard(dashboardPage, selectors); await saveDashboard(dashboardPage, selectors);
await page.reload(); await page.reload();
await expect(async () => {
const fillScreenHeightAfterReload = await getPanelHeight(dashboardPage, selectors); const fillScreenHeightAfterReload = await getPanelHeight(dashboardPage, selectors);
expect(fillScreenHeightAfterReload).toBeGreaterThan(initialHeight); expect(fillScreenHeightAfterReload).toBeGreaterThan(initialHeight);
}).toPass();
await dashboardPage.getByGrafanaSelector(selectors.components.NavToolbar.editDashboard.editButton).click(); await dashboardPage.getByGrafanaSelector(selectors.components.NavToolbar.editDashboard.editButton).click();
@ -344,8 +367,10 @@ test.describe(
dashboardPage.getByGrafanaSelector(selectors.components.PanelEditor.ElementEditPane.AutoGridLayout.fillScreen) dashboardPage.getByGrafanaSelector(selectors.components.PanelEditor.ElementEditPane.AutoGridLayout.fillScreen)
).toBeChecked(); ).toBeChecked();
await expect(async () => {
const fillScreenHeightAfterEdit = await getPanelHeight(dashboardPage, selectors); const fillScreenHeightAfterEdit = await getPanelHeight(dashboardPage, selectors);
expect(fillScreenHeightAfterEdit).toBeGreaterThan(initialHeight); expect(fillScreenHeightAfterEdit).toBeGreaterThan(initialHeight);
}).toPass();
}); });
} }
); );