File size: 6,701 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
import { nextTestSetup } from 'e2e-utils'
import {
getSegmentExplorerContent,
getSegmentExplorerRoute,
retry,
} from 'next-test-utils'
describe('segment-explorer', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should render the segment explorer for parallel routes', async () => {
const browser = await next.browser('/parallel-routes')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
parallel-routes/ [layout.tsx, page.tsx]
@bar/ [layout.tsx, page.tsx]
@foo/ [layout.tsx, page.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe('/parallel-routes')
})
it('should render the segment explorer for parallel routes in edge runtime', async () => {
const browser = await next.browser('/parallel-routes-edge')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
parallel-routes-edge/ [layout.tsx, page.tsx]
@bar/ [layout.tsx, page.tsx]
@foo/ [layout.tsx, page.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe('/parallel-routes-edge')
})
it('should render the segment explorer for nested routes', async () => {
const browser = await next.browser('/blog/~/grid')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
(v2)/ [layout.tsx]
blog / (team)/ [layout.tsx, template.tsx]
~ / (overview)/ [layout.tsx]
grid/ [page.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe('/blog/~/grid')
})
it('should cleanup on soft navigation', async () => {
const browser = await next.browser('/soft-navigation/a')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
soft-navigation / a/ [page.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe('/soft-navigation/a')
await browser.elementByCss('[href="/soft-navigation/b"]').click()
await retry(async () => {
expect(await browser.elementByCss('body').text()).toContain('Page B')
})
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
soft-navigation / b/ [page.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe('/soft-navigation/b')
})
it('should handle show file segments in order', async () => {
const browser = await next.browser('/file-segments')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
(all) / file-segments/ [layout.tsx, template.tsx, page.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe('/file-segments')
})
it('should not have route info panel for pages router', async () => {
const browser = await next.browser('/pages-router')
expect(await browser.hasElementByCss('[data-segment-explorer]')).toBe(false)
})
it('should handle special built-in not-found segments', async () => {
const browser = await next.browser('/404')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(
`"app/ [layout.tsx, not-found.js]"`
)
expect(await getSegmentExplorerRoute(browser)).toBe('/404')
})
it('should show global-error segment', async () => {
const browser = await next.browser('/runtime-error')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(
`"app/ [global-error.js]"`
)
// FIXME: handle preserve the url when hitting global-error
expect(await getSegmentExplorerRoute(browser)).toBe('')
})
it('should show navigation boundaries of the segment', async () => {
const browser = await next.browser('/boundary?name=not-found')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
boundary/ [layout.tsx, not-found.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe(
'/boundary?name=not-found'
)
await browser.loadPage(`${next.url}/boundary?name=forbidden`)
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
boundary/ [layout.tsx, forbidden.tsx]"
`)
await browser.loadPage(`${next.url}/boundary?name=unauthorized`)
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
boundary/ [layout.tsx, unauthorized.tsx]"
`)
})
it('should show the loading boundary when it is present', async () => {
const browser = await next.browser('/search')
const input = await browser.elementByCss('input[name="q"]')
await input.fill('abc')
await browser.elementByCss('button').click() // submit the form
await retry(async () => {
expect(await browser.elementByCss('#loading').text()).toBe('Loading...')
})
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
search/ [layout.tsx, loading.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe('/search?q=abc')
})
it('should show the custom error boundary when present', async () => {
const browser = await next.browser('/runtime-error/boundary')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
runtime-error / boundary/ [error.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe(
'/runtime-error/boundary'
)
})
it('should display parallel routes default page when present', async () => {
const browser = await next.browser('/parallel-default/subroute')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
parallel-default/ [layout.tsx, default.tsx]
@bar/ [layout.tsx]
subroute/ [page.tsx]
@foo/ [default.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe(
'/parallel-default/subroute'
)
})
it('should display boundary selector when a segment has only boundary files', async () => {
const browser = await next.browser('/no-layout/framework/blog')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(`
"app/ [layout.tsx]
no-layout/ []
framework/ [layout.tsx]
blog/ [layout.tsx, page.tsx]"
`)
expect(await getSegmentExplorerRoute(browser)).toBe(
'/no-layout/framework/blog'
)
})
it('should render route for index page', async () => {
const browser = await next.browser('/')
expect(await getSegmentExplorerContent(browser)).toMatchInlineSnapshot(
`"app/ [layout.tsx, page.tsx]"`
)
expect(await getSegmentExplorerRoute(browser)).toBe('/')
})
})
|