File size: 2,119 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import { Page } from 'playwright';
import { EditorComponent } from './editor-component';
/**
* Represents the welcome tour that shows in a popover when the editor loads.
*/
export class EditorWelcomeTourComponent {
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;
}
/**
* Force shows or dismisses the welcome tour using Redux state/actions.
*
* @see {@link https://github.com/Automattic/wp-calypso/issues/57660}
*/
async forceToggleWelcomeTour( show = true ): Promise< void > {
const editorParent = await this.editor.parent();
const editorFrame = await ( await editorParent.elementHandle() )?.ownerFrame();
if ( ! editorFrame ) {
return;
}
await editorFrame.waitForFunction( async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const welcomeGuide = ( window as any )?.wp?.data?.select( 'automattic/wpcom-welcome-guide' );
if ( typeof welcomeGuide?.isWelcomeGuideStatusLoaded !== 'function' ) {
return false;
}
return await welcomeGuide.isWelcomeGuideStatusLoaded();
} );
await editorFrame.waitForFunction( async ( show ) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const welcomeGuide = ( window as any )?.wp?.data?.dispatch(
'automattic/wpcom-welcome-guide'
);
if ( typeof welcomeGuide?.setShowWelcomeGuide !== 'function' ) {
return false;
}
const actionPayload = await welcomeGuide.setShowWelcomeGuide( show );
return actionPayload.show === show;
}, show );
}
/**
* Force shows the welcome tour using Redux state/actions.
*/
async forceShowWelcomeTour(): Promise< void > {
await this.forceToggleWelcomeTour( true );
}
/**
* Force dismisses the welcome tour using Redux state/actions.
*/
async forceDismissWelcomeTour(): Promise< void > {
await this.forceToggleWelcomeTour( false );
}
}
|