Skip to content

Commit

Permalink
add test for route params
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Oct 19, 2023
1 parent cbf51b7 commit 437dceb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
6 changes: 2 additions & 4 deletions e2e/react/src/api/users.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { sleep } from '~/utils/sleep'

import { builder } from './builder'
import { connectionFromArray } from './utils'

export type User = {
id: string
Expand Down Expand Up @@ -138,6 +139,3 @@ function getUserSnapshot(snapshot: string) {

return userSnapshots[snapshot]
}
export async function sleep(duration: number) {
return new Promise((resolve) => setTimeout(resolve, duration))
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect, test } from '@playwright/test'
import { routes } from '~/utils/routes'
import { goto } from '~/utils/testsHelper.js'

test('Component fields with correct argument value', async ({ page }) => {
await goto(page, '/component_fields/arguments')
await goto(page, routes.componentFields_arguments)

// find all of the images
const images = await page.locator('img').all()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect, test } from '@playwright/test'
import { routes } from '~/utils/routes'
import { goto } from '~/utils/testsHelper.js'

test('Component field happy path', async ({ page }) => {
await goto(page, '/component_fields/simple')
await goto(page, routes.componentFields_simple)

// find all of the images
const images = await page.locator('img').all()
Expand Down
9 changes: 6 additions & 3 deletions e2e/react/src/routes/route_params/+layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ export default ({ children }: LayoutProps) => {
return (
<div>
<div className="flex flex-row gap-12">
<a href="/route_params/1">user 1</a>
<a href="/route_params/2">user 2</a>
<a href="/route_params/3">user 3</a>
<a id="user-link-1" href="/route_params/1">
user 1
</a>
<a id="user-link-2" href="/route_params/2">
user 2
</a>
</div>
{children}
</div>
Expand Down
20 changes: 20 additions & 0 deletions e2e/react/src/routes/route_params/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { test } from '@playwright/test'
import { routes } from '~/utils/routes'
import { sleep } from '~/utils/sleep'
import { expect_to_be, goto } from '~/utils/testsHelper'

test('Component fields with correct argument value', async ({ page }) => {
await goto(page, routes.route_params)

// be default we see user 1
await expect_to_be(page, 'Bruce Willis')

// click on the link 2
await page.click('user-link-2')

// wait some time
await sleep(100)

// make sure we loaded the second user's information
await expect_to_be(page, 'Samuel Jackson')
})
3 changes: 3 additions & 0 deletions e2e/react/src/utils/sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function sleep(duration: number) {
return new Promise((resolve) => setTimeout(resolve, duration))
}

0 comments on commit 437dceb

Please sign in to comment.