diff --git a/test/e2e/instance-metrics.e2e.ts b/test/e2e/instance-metrics.e2e.ts index 46577fe18..071b2531b 100644 --- a/test/e2e/instance-metrics.e2e.ts +++ b/test/e2e/instance-metrics.e2e.ts @@ -12,6 +12,14 @@ import { OXQL_GROUP_BY_ERROR } from '~/api' import { expectConsoleMessage, expectNoConsoleMessage, getPageAsUser } from './utils' +// Freeze the clock so the default "Last hour" range and the calendar's visible +// month don't depend on when the tests run. Without this, runs near midnight +// UTC flake: the range straddles the day boundary, and on a month boundary the +// calendar opens on the previous month, so the "Today" cell isn't rendered. +test.beforeEach(async ({ page }) => { + await page.clock.setFixedTime(new Date('2026-06-15T12:00:00.000Z')) +}) + test('Click through instance metrics', async ({ page }) => { await page.goto('/projects/mock-project/instances/db1/metrics/cpu') @@ -76,31 +84,19 @@ test('Date range picker: invalid range shows an error', async ({ page }) => { const today = page.getByRole('button', { name: /Today/ }) await today.click() await today.click() + await expect(page.getByText('Date range is invalid')).toBeHidden() - // Set the times explicitly rather than relying on the times inherited from - // the default "Last hour" range. When the test runs shortly after midnight, - // that range straddles midnight (start ~23:00 the previous day, end ~00:00 - // today), so collapsing both dates to today leaves start after end and the - // range reads as invalid before we've done anything. Start with a valid - // same-day range (01:00 before 23:00): no error. + // set the start time (23:00) after the end time (01:00) on that same day const hours = page.getByRole('spinbutton', { name: 'hour,' }) const minutes = page.getByRole('spinbutton', { name: 'minute,' }) await hours.first().click() - await page.keyboard.type('01') + await page.keyboard.type('23') await minutes.first().click() await page.keyboard.type('00') await hours.nth(1).click() - await page.keyboard.type('23') + await page.keyboard.type('01') await minutes.nth(1).click() await page.keyboard.type('00') - await expect(page.getByText('Date range is invalid')).toBeHidden() - - // now flip the start time (23:00) to be after the end time (01:00) on that - // same day - await hours.first().click() - await page.keyboard.type('23') - await hours.nth(1).click() - await page.keyboard.type('01') await expect(page.getByText('Date range is invalid')).toBeVisible() })