1+ import { Page , test , expect , Request } from '@playwright/test' ;
2+ import { waitForPageToLoadWithTimeout } from '../../src/helpers/waitForPageToLoadWithTimeout' ;
3+ import PageManager from '../../src/pom/PageManager' ;
4+ import { ExampleLinkType } from '../../types/exampleLinkType' ;
5+ import { PROFILE_ROUTE_PATTERN , CONFIG_ROUTE_PATTERN } from '../../src/consts/appletRoutes' ;
6+
7+
8+ export async function testProfileAndConfigAppletUrlsFetch ( page : Page , pomPages : PageManager , link : ExampleLinkType
9+ ) {
10+ const profileRequests : Request [ ] = [ ] ;
11+ const configRequests : Request [ ] = [ ] ;
12+
13+ await test . step ( 'Track profile and config requests' , async ( ) => {
14+ await page . route ( PROFILE_ROUTE_PATTERN , ( route ) => {
15+ profileRequests . push ( route . request ( ) ) ;
16+ return route . continue ( ) ;
17+ } ) ;
18+
19+ await page . route ( CONFIG_ROUTE_PATTERN , ( route ) => {
20+ configRequests . push ( route . request ( ) ) ;
21+ return route . continue ( ) ;
22+ } ) ;
23+ } ) ;
24+
25+ await test . step ( 'Navigate to profiles page' , async ( ) => {
26+ await pomPages . mainPage . clickLinkByName ( link . name ) ;
27+ await waitForPageToLoadWithTimeout ( page , 5000 ) ;
28+ } ) ;
29+
30+ await test . step ( 'Validate profile request URL' , async ( ) => {
31+ expect ( profileRequests . length , 'Expected at least one profile request' ) . toBeGreaterThanOrEqual ( 1 ) ;
32+
33+ const profileUrl = new URL ( profileRequests [ 0 ] . url ( ) ) ;
34+ expect ( profileUrl . pathname ) . toMatch (
35+ / \/ _ a p p l e t _ \/ v i d e o _ s e r v i c e \/ v i d e o _ p l a y e r _ p r o f i l e s \/ [ ^ / ] + \. j s o n $ /
36+ ) ;
37+ } ) ;
38+
39+ await test . step ( 'Validate config request URL' , async ( ) => {
40+ expect ( configRequests . length , 'Expected at least one config request' ) . toBeGreaterThanOrEqual ( 1 ) ;
41+
42+ const configUrl = new URL ( configRequests [ 0 ] . url ( ) ) ;
43+ expect ( configUrl . pathname ) . toMatch (
44+ / \/ _ a p p l e t _ \/ v i d e o _ s e r v i c e \/ v i d e o _ p l a y e r _ c o n f i g \/ v i d e o \/ [ ^ / ] + \/ [ ^ / ] + \. j s o n $ /
45+ ) ;
46+ } ) ;
47+ }
0 commit comments