Skip to content

Commit

Permalink
Add test for issue 45393
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Jan 30, 2023
1 parent b0d951b commit 9fe323a
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { createNextDescribe } from 'e2e-utils'

for (const item of ['trailing-slash', 'no-trailing-slash']) {
createNextDescribe(
`html-extension-navigation-bug-${item}`,
{
files: __dirname,
nextConfig: {
trailingSlash: item === 'trailing-slash',
},
},
({ next }) => {
describe('with .html extension', () => {
it('should work when requesting the page directly', async () => {
const $ = await next.render$(
'/product/shirts_and_tops/mens_ua_playoff_polo_2.0/1327037.html'
)
expect($('#text').text()).toBe(
'Param found: shirts_and_tops, mens_ua_playoff_polo_2.0, 1327037.html'
)
})

it('should work using browser', async () => {
const browser = await next.browser(
'/product/shirts_and_tops/mens_ua_playoff_polo_2.0/1327037.html'
)
expect(await browser.elementByCss('#text').text()).toBe(
'Param found: shirts_and_tops, mens_ua_playoff_polo_2.0, 1327037.html'
)
})

it('should work when navigating', async () => {
const browser = await next.browser('/')
await browser.elementByCss('#with-html').click()
expect(await browser.waitForElementByCss('#text').text()).toBe(
'Param found: shirts_and_tops, mens_ua_playoff_polo_2.0, 1327037.html'
)
})
})

describe('without .html extension', () => {
it('should work when requesting the page directly', async () => {
const $ = await next.render$(
'/product/shirts_and_tops/mens_ua_playoff_polo_2.0/1327037'
)
expect($('#text').text()).toBe(
'Param found: shirts_and_tops, mens_ua_playoff_polo_2.0, 1327037'
)
})

it('should work using browser', async () => {
const browser = await next.browser(
'/product/shirts_and_tops/mens_ua_playoff_polo_2.0/1327037'
)
expect(await browser.elementByCss('#text').text()).toBe(
'Param found: shirts_and_tops, mens_ua_playoff_polo_2.0, 1327037'
)
})

it('should work when navigating', async () => {
const browser = await next.browser('/')
await browser.elementByCss('#without-html').click()
expect(await browser.waitForElementByCss('#text').text()).toBe(
'Param found: shirts_and_tops, mens_ua_playoff_polo_2.0, 1327037'
)
})
})
}
)
}
5 changes: 5 additions & 0 deletions test/e2e/html-extension-navigation-bug/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { NextRequest, NextResponse } from 'next/server'

export default async function middleware(req: NextRequest) {
return NextResponse.next()
}
5 changes: 5 additions & 0 deletions test/e2e/html-extension-navigation-bug/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { AppProps } from 'next/app'

export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
13 changes: 13 additions & 0 deletions test/e2e/html-extension-navigation-bug/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Html, Head, Main, NextScript } from 'next/document'

export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
29 changes: 29 additions & 0 deletions test/e2e/html-extension-navigation-bug/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable no-console */
/* eslint-disable no-param-reassign */

import Link from 'next/link'

export default function Test() {
return (
<>
<ul>
<li>
<Link
id="with-html"
href="/product/shirts_and_tops/mens_ua_playoff_polo_2.0/1327037.html"
>
Does not work
</Link>
</li>
<li>
<Link
id="without-html"
href="/product/shirts_and_tops/mens_ua_playoff_polo_2.0/1327037"
>
Works
</Link>
</li>
</ul>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { GetServerSideProps } from 'next'
import React from 'react'

export interface ProductPageProps {
test: string
}

const ProductPage = (params: ProductPageProps) => {
return (
<>
<h1 id="text">Param found: {params.test}</h1>
</>
)
}

export const getServerSideProps: GetServerSideProps = async ({ params }) => {
const joined = Array.isArray(params['product-params'])
? params['product-params'].join(', ')
: params['product-params']
return {
props: {
test: joined ? joined : 'Not Found',
},
}
}

export default ProductPage

0 comments on commit 9fe323a

Please sign in to comment.