1
1
mirror of https://github.com/theoludwig/theoludwig.git synced 2024-12-08 00:44:30 +01:00

test: fix e2e tests + 500 error page

This commit is contained in:
Théo LUDWIG 2023-08-01 18:18:16 +02:00
parent 56520830e9
commit e51e3bdc19
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
6 changed files with 43 additions and 61 deletions

View File

@ -1,8 +1,4 @@
{ {
"urls": [ "urls": ["http://127.0.0.1:3000/", "http://127.0.0.1:3000/blog"],
"http://127.0.0.1:3000/",
"http://127.0.0.1:3000/blog",
"http://127.0.0.1:3000/blog/hello-world"
],
"files": ["./public/curriculum-vitae/index.html"] "files": ["./public/curriculum-vitae/index.html"]
} }

View File

@ -2,8 +2,6 @@
import { useEffect } from 'react' import { useEffect } from 'react'
import { ErrorPage } from '@/components/ErrorPage'
export interface ErrorHandlingProps { export interface ErrorHandlingProps {
error: Error error: Error
} }
@ -15,7 +13,20 @@ const ErrorHandling = (props: ErrorHandlingProps): JSX.Element => {
console.error(error) console.error(error)
}, [error]) }, [error])
return <ErrorPage statusCode={500} message='Server error' /> return (
<main className='flex flex-col flex-1 items-center justify-center'>
<h1 className='my-6 text-4xl font-semibold'>
Error{' '}
<span
className='text-yellow dark:text-yellow-dark'
data-cy='status-code'
>
500
</span>
</h1>
<p className='text-center text-lg'>Server error</p>
</main>
)
} }
export default ErrorHandling export default ErrorHandling

View File

@ -1,11 +1,31 @@
import Link from 'next/link'
import { getI18n } from '@/i18n/i18n.server' import { getI18n } from '@/i18n/i18n.server'
import { ErrorPage } from '@/components/ErrorPage'
const NotFound = (): JSX.Element => { const NotFound = (): JSX.Element => {
const i18n = getI18n() const i18n = getI18n()
return ( return (
<ErrorPage statusCode={404} message={i18n.translate('errors.not-found')} /> <main className='flex flex-col flex-1 items-center justify-center'>
<h1 className='my-6 text-4xl font-semibold'>
{i18n.translate('errors.error')}{' '}
<span
className='text-yellow dark:text-yellow-dark'
data-cy='status-code'
>
404
</span>
</h1>
<p className='text-center text-lg'>
{i18n.translate('errors.not-found')}{' '}
<Link
href='/'
className='text-yellow hover:underline dark:text-yellow-dark'
>
{i18n.translate('errors.return-to-home-page')}
</Link>
</p>
</main>
) )
} }

View File

@ -1,36 +0,0 @@
import Link from 'next/link'
import { getI18n } from '@/i18n/i18n.server'
export interface ErrorPageProps {
statusCode: number
message: string
}
export const ErrorPage = (props: ErrorPageProps): JSX.Element => {
const { message, statusCode } = props
const i18n = getI18n()
return (
<main className='flex flex-col flex-1 items-center justify-center'>
<h1 className='my-6 text-4xl font-semibold'>
{i18n.translate('errors.error')}{' '}
<span
className='text-yellow dark:text-yellow-dark'
data-cy='status-code'
>
{statusCode}
</span>
</h1>
<p className='text-center text-lg'>
{message}{' '}
<Link
href='/'
className='text-yellow hover:underline dark:text-yellow-dark'
>
{i18n.translate('errors.return-to-home-page')}
</Link>
</p>
</main>
)
}

View File

@ -37,15 +37,17 @@ describe('Common > Header', () => {
}) })
describe('Switch Language', () => { describe('Switch Language', () => {
it('should switch locale from EN (default) to FR', () => { it('should switch locale from English (default) to French', () => {
cy.get('h1').contains('Théo LUDWIG') cy.get('h1').contains('Théo LUDWIG')
cy.get('[data-cy=locale-flag-text]').contains('EN') cy.get('[data-cy=locale-flag-text]').contains('English')
cy.get('[data-cy=locales-list]').should('not.be.visible') cy.get('[data-cy=locales-list]').should('not.be.visible')
cy.get('[data-cy=locale-click]').click() cy.get('[data-cy=locale-click]').click()
cy.get('[data-cy=locales-list]').should('be.visible') cy.get('[data-cy=locales-list]').should('be.visible')
cy.get('[data-cy=locales-list] > li:first-child').contains('FR').click() cy.get('[data-cy=locales-list] > li:first-child')
.contains('French')
.click()
cy.get('[data-cy=locales-list]').should('not.be.visible') cy.get('[data-cy=locales-list]').should('not.be.visible')
cy.get('[data-cy=locale-flag-text]').contains('FR') cy.get('[data-cy=locale-flag-text]').contains('French')
cy.get('h1').contains('Théo LUDWIG') cy.get('h1').contains('Théo LUDWIG')
}) })

View File

@ -1,11 +0,0 @@
describe('Page /500', () => {
beforeEach(() => {
return cy.visit('/500', { failOnStatusCode: false })
})
it('should display the statusCode of 500', () => {
cy.get('[data-cy=status-code]').contains('500')
})
})
export {}