1515 */
1616
1717import { test , expect } from '@playwright/test' ;
18-
19- const BASE_URL = 'http://localhost:5555' ;
18+ import { BASE_URL , expect404PageButtons , goTo404Page } from './utils' ;
2019
2120test ( 'Bad URL redirection to 404 page' , async ( { page} ) => {
2221 const badUrls = [
@@ -52,35 +51,14 @@ test('Bad URL redirection to 404 page', async ({page}) => {
5251 }
5352} ) ;
5453
55- async function goTo404Page ( page , query : string ) : Promise < void > {
56- await page . goto ( `${ BASE_URL } /features/${ query } ` ) ;
57- await expect ( page ) . toHaveURL (
58- `${ BASE_URL } /errors-404/feature-not-found?q=${ query } ` ,
59- ) ;
60-
61- const response = await page . context ( ) . request . fetch ( page . url ( ) ) ;
62- expect ( response . status ( ) ) . toBe ( 404 ) ;
63- }
64-
65- async function expectButtons ( page , { hasSearch} : { hasSearch : boolean } ) {
66- await expect ( page . locator ( '#error-action-home-btn' ) ) . toBeVisible ( ) ;
67- await expect ( page . locator ( '#error-action-report' ) ) . toBeVisible ( ) ;
68-
69- if ( hasSearch ) {
70- await expect ( page . locator ( '#error-action-search-btn' ) ) . toBeVisible ( ) ;
71- } else {
72- await expect ( page . locator ( '#error-action-search-btn' ) ) . toHaveCount ( 0 ) ;
73- }
74- }
75-
7654test ( 'shows similar features and all buttons when results exist' , async ( {
7755 page,
7856} ) => {
7957 const query = 'g' ;
8058 await goTo404Page ( page , query ) ;
8159
8260 await expect ( page . locator ( '.similar-features-container' ) ) . toBeVisible ( ) ;
83- await expectButtons ( page , { hasSearch : true } ) ;
61+ await expect404PageButtons ( page , { hasSearch : true } ) ;
8462
8563 const similarContainerButton = page . locator ( '#error-action-search-btn' ) ;
8664 const pageContainer = page . locator ( '.page-container' ) ;
@@ -102,7 +80,7 @@ test('shows only home and report buttons when no similar features found', async
10280 await goTo404Page ( page , query ) ;
10381
10482 await expect ( page . locator ( '.similar-features-container' ) ) . toHaveCount ( 0 ) ;
105- await expectButtons ( page , { hasSearch : false } ) ;
83+ await expect404PageButtons ( page , { hasSearch : false } ) ;
10684
10785 await expect ( page . locator ( '#error-detailed-message' ) ) . toContainText (
10886 `We could not find Feature ID: ${ query } ` ,
0 commit comments