react-code-dataset / wp-calypso /packages /calypso-e2e /src /lib /components /cookie-banner-component.ts
react-code-dataset / wp-calypso /packages /calypso-e2e /src /lib /components /cookie-banner-component.ts
Download wp-calypso/packages/calypso-e2e/src/lib/components/cookie-banner-component.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/calypso-e2e/src/lib/components/cookie-banner-component.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/calypso-e2e/src/lib/components/cookie-banner-component.ts
-
curl -L -o cookie-banner-component.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/calypso-e2e/src/lib/components/cookie-banner-component.ts
1.21 kB
| import { Page } from 'playwright'; | |
| import { EditorComponent } from './editor-component'; | |
| const selectors = { | |
| acceptCookie: '.a8c-cookie-banner__ok-button, .a8c-cookie-banner__accept-all-button', | |
| }; | |
| /** | |
| * Represents the cookie banner shown on pages when not logged in. | |
| */ | |
| export class CookieBannerComponent { | |
| private page: Page; | |
| private editor: EditorComponent; | |
| /** | |
| * Constructs an instance of the component. | |
| * | |
| * @param {Page} page The underlying page. | |
| * @param {EditorComponent} editor The EditorComponent instance. | |
| */ | |
| constructor( page: Page, editor: EditorComponent ) { | |
| this.page = page; | |
| this.editor = editor; | |
| } | |
| /** | |
| * Accept and clear the cookie notice. | |
| */ | |
| async acceptCookie(): Promise< void > { | |
| const editorParent = await this.editor.parent(); | |
| const locator = editorParent.locator( selectors.acceptCookie ); | |
| // Whether the cookie banner appears is not deterministic. | |
| // If it is not present, exit early. | |
| try { | |
| await locator.waitFor( { timeout: 100 } ); | |
| } catch ( e ) { | |
| // Probably doesn't exist. That's ok. | |
| } | |
| if ( ( await locator.count() ) === 0 ) { | |
| return; | |
| } | |
| if ( await locator.isVisible() ) { | |
| await locator.dispatchEvent( 'click' ); | |
| } | |
| } | |
| } | |