-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import type { Page, Request } from 'playwright-core'; | ||
|
||
/** | ||
* This function console logs an info message. | ||
* | ||
* @param {string} message | ||
*/ | ||
const log_info = (message: string): void => { | ||
console.log(`(cmp monitoring) info: ${message}`); | ||
}; | ||
|
||
|
||
/** | ||
* This function waits for the page to load | ||
* clicks the accept all button | ||
* | ||
* @param {Page} page | ||
* @param {string} textToPrintToConsole | ||
*/ | ||
export const clickAcceptAllCookies = async (page: Page, textToPrintToConsole: string = "Accept All") => { | ||
Check warning on line 20 in src/testing/common-functions.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
|
||
log_info(`Clicking on "${textToPrintToConsole}" on CMP`); | ||
|
||
const acceptAllButton = page.frameLocator('[id*="sp_message_iframe"]').locator('button.sp_choice_type_ACCEPT_ALL'); | ||
await acceptAllButton.click(); | ||
|
||
log_info(`Clicked on "${textToPrintToConsole}"`); | ||
}; | ||
|
||
/** | ||
* This function checks for interaction with GAM | ||
* Using this after advice from Commercial to check that cookies were accepted as we otherwise do not interact with GAM | ||
* This has to be adjusted if anything in the interaction with GAM changes or we stop using GAM | ||
* | ||
* @param {Page} page | ||
* @return {*} {Promise<void>} | ||
*/ | ||
export const checkTopAdHasLoaded = async (page: Page) => { | ||
log_info(`Waiting for interaction with GAM: Start`); | ||
|
||
const gamUrl = /https:\/\/securepubads.g.doubleclick.net\/gampad\/ads/; | ||
|
||
const getEncodedParamsFromRequest = ( | ||
request: Request, | ||
paramName: string, | ||
): URLSearchParams | null => { | ||
const url = new URL(request.url()); | ||
const param = url.searchParams.get(paramName); | ||
if (!param) return null; | ||
Check warning on line 49 in src/testing/common-functions.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 49 in src/testing/common-functions.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
const paramDecoded = decodeURIComponent(param); | ||
const searchParams = new URLSearchParams(paramDecoded); | ||
return searchParams; | ||
}; | ||
|
||
const assertOnSlotFromRequest = (request: Request, expectedSlot: string) => { | ||
const isURL = request.url().match(gamUrl); | ||
if (!isURL) return false; | ||
Check warning on line 57 in src/testing/common-functions.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 57 in src/testing/common-functions.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
const searchParams = getEncodedParamsFromRequest(request, 'prev_scp'); | ||
if (searchParams === null) return false; | ||
Check warning on line 59 in src/testing/common-functions.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 59 in src/testing/common-functions.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
const slot = searchParams.get('slot'); | ||
if (slot !== expectedSlot) return false; | ||
Check warning on line 61 in src/testing/common-functions.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 61 in src/testing/common-functions.ts GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
|
||
return true; | ||
}; | ||
|
||
const waitForGAMRequestForSlot = (page: Page, slotExpected: string) => { | ||
return page.waitForRequest((request) => | ||
assertOnSlotFromRequest(request, slotExpected), | ||
); | ||
}; | ||
|
||
const gamRequestPromise = waitForGAMRequestForSlot( | ||
page, | ||
'top-above-nav', | ||
); | ||
await gamRequestPromise; | ||
|
||
log_info(`Waiting for interaction with GAM: Complete`); | ||
}; |
b226a3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
328 tests passing in 16 suites.
Report generated by 🧪jest coverage report action from b226a3b