Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

app.spec.ts

46 lines1.4 KB

1import { expect, test } from '@playwright/test'
2​
3test('Smoke - Renders home', async ({ page }) => {
4 await page.goto('/')
5 await expect(
6 page.getByRole('heading', { name: 'Welcome Home!' }),
7 ).toBeVisible()
8})
9​
10// Test for scroll related stuff
11;[
12 { to: '/normal-page' },
13 { to: '/with-loader' },
14 { to: '/with-search', search: { where: 'footer' } },
15].forEach((options) => {
16 test(`On navigate to ${options.to} (from the header), scroll should be at top`, async ({
17 page,
18 }) => {
19 await page.goto('/')
20 await page.getByRole('link', { name: `Head-${options.to}` }).click()
21 await expect(page.getByTestId('at-the-top')).toBeInViewport()
22 })
23​
24 // scroll should be at the bottom on navigation after the page is loaded
25 test(`On navigate via index page tests to ${options.to}, scroll should resolve at the bottom`, async ({
26 page,
27 }) => {
28 await page.goto('/')
29 await page
30 .getByRole('link', { name: `${options.to}#at-the-bottom` })
31 .click()
32 await expect(page.getByTestId('at-the-bottom')).toBeInViewport()
33 })
34​
35 // scroll should be at the bottom on first load
36 test(`On first load of ${options.to}, scroll should resolve resolve at the bottom`, async ({
37 page,
38 }) => {
39 let url: string = options.to
40 if ('search' in options) {
41 url = `${url}?where=${options.search}`
42 }
43 await page.goto(`${url}#at-the-bottom`)
44 await expect(page.getByTestId('at-the-bottom')).toBeInViewport()
45 })
46})