@@ -10,9 +10,15 @@ class MarkdownEditorLocators {
1010 readonly settingsContent ;
1111
1212 readonly contenteditable ;
13+ readonly previewContent ;
14+
15+ readonly previewButton ;
1316
1417 constructor ( page : Page ) {
15- this . component = page . getByTestId ( 'playground-md-editor' ) ;
18+ this . component = page . getByTestId ( 'demo-md-editor' ) ;
19+ this . previewContent = page . getByTestId ( 'demo-md-preview' ) ;
20+ this . previewButton = page . getByTestId ( 'g-md-markup-preview-button' ) ;
21+
1622 this . editor = page . getByTestId ( 'g-md-editor-mode' ) ;
1723
1824 this . settingsButton = page . getByTestId ( 'g-md-settings-button' ) ;
@@ -24,6 +30,8 @@ class MarkdownEditorLocators {
2430
2531type PasteData = Partial < Record < DataTransferType , string > > ;
2632
33+ type VisibleState = 'attached' | 'detached' | 'visible' | 'hidden' | undefined ;
34+
2735export class MarkdownEditorPage {
2836 protected readonly page : Page ;
2937 protected readonly expect : Expect ;
@@ -54,10 +62,40 @@ export class MarkdownEditorPage {
5462 if ( ( await this . getMode ( ) ) === mode ) return ;
5563
5664 await this . openSettingsPopup ( ) ;
57- await this . locators . settingsContent . getByTestId ( `md-settings-mode-${ mode } ` ) . click ( ) ;
65+ await this . locators . settingsContent . getByTestId ( `g- md-settings-mode-${ mode } ` ) . click ( ) ;
5866 await this . assertMode ( mode ) ;
5967 }
6068
69+ async getPreview ( ) : Promise < VisibleState > {
70+ const previewContent = await this . locators . previewContent ;
71+ if ( await previewContent . isVisible ( ) ) {
72+ return 'visible' ;
73+ }
74+
75+ const previewButton = await this . locators . previewButton ;
76+ if ( await previewButton . isVisible ( ) ) {
77+ return 'hidden' ;
78+ }
79+ return undefined ;
80+ }
81+
82+ async switchPreview ( state ?: VisibleState ) {
83+ const currentState = await this . getPreview ( ) ;
84+ const revertState = currentState === 'visible' ? 'hidden' : 'visible' ;
85+ const targetState = state === undefined ? revertState : state ;
86+
87+ if ( currentState === targetState ) {
88+ return ;
89+ }
90+
91+ await this . switchMode ( 'markup' ) ;
92+ await this . locators . previewButton . click ( ) ;
93+
94+ await this . locators . previewContent . waitFor ( {
95+ state : targetState ,
96+ } ) ;
97+ }
98+
6199 async assertMode ( mode : MarkdownEditorMode ) {
62100 await this . expect . poll ( ( ) => this . getMode ( ) ) . toBe ( mode ) ;
63101 }
0 commit comments