15
15
*/
16
16
17
17
import { test , expect } from '@playwright/test' ;
18
-
19
- const BASE_URL = 'http://localhost:5555' ;
18
+ import { BASE_URL , expect404PageButtons , goTo404Page } from './utils' ;
20
19
21
20
test ( 'Bad URL redirection to 404 page' , async ( { page} ) => {
22
21
const badUrls = [
@@ -52,35 +51,14 @@ test('Bad URL redirection to 404 page', async ({page}) => {
52
51
}
53
52
} ) ;
54
53
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
-
76
54
test ( 'shows similar features and all buttons when results exist' , async ( {
77
55
page,
78
56
} ) => {
79
57
const query = 'g' ;
80
58
await goTo404Page ( page , query ) ;
81
59
82
60
await expect ( page . locator ( '.similar-features-container' ) ) . toBeVisible ( ) ;
83
- await expectButtons ( page , { hasSearch : true } ) ;
61
+ await expect404PageButtons ( page , { hasSearch : true } ) ;
84
62
85
63
const similarContainerButton = page . locator ( '#error-action-search-btn' ) ;
86
64
const pageContainer = page . locator ( '.page-container' ) ;
@@ -102,7 +80,7 @@ test('shows only home and report buttons when no similar features found', async
102
80
await goTo404Page ( page , query ) ;
103
81
104
82
await expect ( page . locator ( '.similar-features-container' ) ) . toHaveCount ( 0 ) ;
105
- await expectButtons ( page , { hasSearch : false } ) ;
83
+ await expect404PageButtons ( page , { hasSearch : false } ) ;
106
84
107
85
await expect ( page . locator ( '#error-detailed-message' ) ) . toContainText (
108
86
`We could not find Feature ID: ${ query } ` ,
0 commit comments