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

app.spec.ts

47 lines1.5 KB

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