Skip to content

Commit

Permalink
make scroll restore test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Dec 17, 2024
1 parent db8e52d commit 35014f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 1 addition & 5 deletions app/forms/vpc-router-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
* Copyright Oxide Computer Company
*/
import { useForm } from 'react-hook-form'
import {
useNavigate,
type LoaderFunctionArgs,
type NavigateFunction,
} from 'react-router'
import { useNavigate, type LoaderFunctionArgs, type NavigateFunction } from 'react-router'

import {
apiq,
Expand Down
13 changes: 12 additions & 1 deletion test/e2e/scroll-restore.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { expect, test } from '@playwright/test'

import { expectScrollTop, scrollTo } from './utils'
import { expectScrollTop, scrollTo, sleep } from './utils'

test('scroll restore', async ({ page }) => {
// open small window to make scrolling easier
Expand All @@ -26,14 +26,24 @@ test('scroll restore', async ({ page }) => {
await page.goBack()
await expect(page).toHaveURL('/projects/mock-project/disks')
await expectScrollTop(page, 143)

// sleep required to get the scroll position to stick
await sleep(1000)
await scrollTo(page, 190)
await sleep(1000)

// go forward to snapshots, now scroll it
await page.goForward()
await expect(page).toHaveURL('/projects/mock-project/snapshots')
await expectScrollTop(page, 0)
await scrollTo(page, 30)

// Oddly, this is required here in order for the page to have time to
// catch the 30 scroll position. This became necessary with RR v7's use of
// startTransition. Extra oddly, with a value of 500 it passes rarely, but
// with 1000 it passes every time.
await sleep(1000)

// new nav to disks
await page.getByRole('link', { name: 'Disks' }).click()
await expectScrollTop(page, 0)
Expand All @@ -53,6 +63,7 @@ test('scroll restore', async ({ page }) => {
// back again to disks, newer scroll value is restored
await page.goBack()
await expect(page).toHaveURL('/projects/mock-project/disks')
await sleep(1000)
await expectScrollTop(page, 190)

// forward again to newest disks history entry, scroll remains 0
Expand Down

0 comments on commit 35014f0

Please sign in to comment.