Files
next.js/test/e2e/app-dir/use-selected-layout-segment-s/use-selected-layout-segment-s.test.ts
Tim NeutkensandGitHub e860cec656 test: migrate webdriver callers to next.browser (#93941)
### What?

Migrate remaining direct `next-webdriver` test callers that have a
`NextInstance` to `next.browser()`, and expose the shared `Playwright`
browser type from `e2e-utils`.

### Why?

`NextInstance.browser` should be the supported browser-opening interface
for test fixtures, with `next-webdriver` kept as the private
implementation detail.

### How?

Updated affected development, e2e, and production tests to call
`next.browser()` directly, passing `baseUrl` where tests intentionally
target a manually spawned or proxied server. Shared helpers now receive
browser callbacks from the test context, and browser types import
`Playwright` from `e2e-utils` instead of deriving from `next.browser` or
importing from private paths.

<!-- NEXT_JS_LLM_PR -->
2026-05-22 14:01:58 +02:00

135 lines
4.3 KiB
TypeScript

import { FileRef, nextTestSetup, type Playwright } from 'e2e-utils'
import { check } from 'next-test-utils'
describe('useSelectedLayoutSegment(s)', () => {
const { next } = nextTestSetup({
files: new FileRef(__dirname),
})
let browser: Playwright
beforeEach(async () => {
browser = await next.browser(
'/segment-name/value1/segment-name2/value2/value3/value4'
)
})
it('should return correct values for root layout', async () => {
expect(
await browser.elementByCss('#root > .segments').text()
).toMatchInlineSnapshot(
`"["segment-name","value1","segment-name2","value2","value3/value4"]"`
)
expect(
await browser.elementByCss('#root > .segment').text()
).toMatchInlineSnapshot(`""segment-name""`)
})
it('should return correct values in layout before static segment', async () => {
expect(
await browser.elementByCss('#before-static > .segments').text()
).toMatchInlineSnapshot(`"["segment-name2","value2","value3/value4"]"`)
expect(
await browser.elementByCss('#before-static > .segment').text()
).toMatchInlineSnapshot(`""segment-name2""`)
})
it('should return correct values in layout before param segment', async () => {
expect(
await browser.elementByCss('#before-param > .segments').text()
).toMatchInlineSnapshot(`"["value2","value3/value4"]"`)
expect(
await browser.elementByCss('#before-param > .segment').text()
).toMatchInlineSnapshot(`""value2""`)
})
it('should return correct values in layout before catchall segment', async () => {
expect(
await browser.elementByCss('#before-catchall > .segments').text()
).toMatchInlineSnapshot(`"["value3/value4"]"`)
expect(
await browser.elementByCss('#before-catchall > .segment').text()
).toMatchInlineSnapshot(`""value3/value4""`)
})
it('should return correct values in layout after last segment', async () => {
expect(
await browser.elementByCss('#final > .segments').text()
).toMatchInlineSnapshot(`"[]"`)
expect(
await browser.elementByCss('#final > .segment').text()
).toMatchInlineSnapshot(`"null"`)
})
it('should correctly update when changing static segment', async () => {
browser.elementById('change-static').click()
await check(
() => browser.eval('window.location.pathname'),
'/segment-name/param1/different-segment'
)
expect(
await browser.elementByCss('#root > .segments').text()
).toMatchInlineSnapshot(`"["segment-name","param1","different-segment"]"`)
expect(
await browser.elementByCss('#before-static > .segments').text()
).toMatchInlineSnapshot(`"["different-segment"]"`)
expect(
await browser.elementByCss('#before-static > .segment').text()
).toMatchInlineSnapshot(`""different-segment""`)
})
it('should correctly update when changing param segment', async () => {
browser.elementById('change-param').click()
await check(
() => browser.eval('window.location.pathname'),
'/segment-name/param1/segment-name2/different-value/value3/value4'
)
expect(
await browser.elementByCss('#root > .segments').text()
).toMatchInlineSnapshot(
`"["segment-name","param1","segment-name2","different-value","value3/value4"]"`
)
expect(
await browser.elementByCss('#before-param > .segments').text()
).toMatchInlineSnapshot(`"["different-value","value3/value4"]"`)
expect(
await browser.elementByCss('#before-param > .segment').text()
).toMatchInlineSnapshot(`""different-value""`)
})
it('should correctly update when changing catchall segment', async () => {
browser.elementById('change-catchall').click()
await check(
() => browser.eval('window.location.pathname'),
'/segment-name/param1/segment-name2/value2/different/random/paths'
)
expect(
await browser.elementByCss('#root > .segments').text()
).toMatchInlineSnapshot(
`"["segment-name","param1","segment-name2","value2","different/random/paths"]"`
)
expect(
await browser.elementByCss('#before-catchall > .segments').text()
).toMatchInlineSnapshot(`"["different/random/paths"]"`)
expect(
await browser.elementByCss('#before-catchall > .segment').text()
).toMatchInlineSnapshot(`""different/random/paths""`)
})
})