Skip to content

Commit 604a117

Browse files
authored
test: update environment for correct preview testing (cut) (#710)
1 parent ed85780 commit 604a117

12 files changed

+65
-18
lines changed

demo/components/Playground.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export const Playground = memo<PlaygroundProps>((props) => {
312312
<MarkdownEditorView
313313
autofocus
314314
className={className}
315-
qa="playground-md-editor"
315+
qa="demo-md-editor"
316316
stickyToolbar={Boolean(stickyToolbar)}
317317
toolbarsPreset={toolbarsPreset}
318318
wysiwygToolbarConfig={wysiwygToolbarConfig}

demo/components/SplitModePreview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const SplitModePreview: React.FC<SplitModePreviewProps> = (props) => {
8686

8787
return (
8888
<Preview
89+
qa="demo-md-preview"
8990
ref={divRef}
9091
html={html}
9192
meta={meta}

src/bundle/MarkdownEditorView.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,12 @@ export const MarkdownEditorView = forwardRef<HTMLDivElement, MarkdownEditorViewP
277277
role="button"
278278
tabIndex={0}
279279
>
280-
<div className={b('editor-wrapper')} ref={editorWrapperRef}>
280+
<div
281+
className={b('editor-wrapper')}
282+
ref={editorWrapperRef}
283+
data-qa="g-md-editor-mode"
284+
data-mode={editor.currentMode}
285+
>
281286
{showPreview ? (
282287
<>
283288
<div className={b('preview-wrapper')}>
@@ -300,7 +305,6 @@ export const MarkdownEditorView = forwardRef<HTMLDivElement, MarkdownEditorViewP
300305
toolbarConfig={wysiwygToolbarConfig}
301306
toolbarVisible={editor.toolbarVisible}
302307
hiddenActionsConfig={wysiwygHiddenActionsConfig}
303-
qa="g-md-editor-mode"
304308
className={b('editor', {mode: editorMode})}
305309
toolbarClassName={b('toolbar')}
306310
stickyToolbar={stickyToolbar}
@@ -318,7 +322,6 @@ export const MarkdownEditorView = forwardRef<HTMLDivElement, MarkdownEditorViewP
318322
splitMode={editor.splitMode}
319323
splitModeEnabled={editor.splitModeEnabled}
320324
hiddenActionsConfig={markupHiddenActionsConfig}
321-
qa="g-md-editor-mode"
322325
className={b('editor', {mode: editorMode})}
323326
toolbarClassName={b('toolbar')}
324327
stickyToolbar={stickyToolbar}

src/bundle/MarkupEditorView.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ export const MarkupEditorView = memo<MarkupEditorViewProps>((props) => {
6161
});
6262

6363
return (
64-
<div
65-
className={b({toolbar: toolbarVisible}, [className])}
66-
data-mode={editor.currentMode}
67-
data-qa={qa}
68-
>
64+
<div className={b({toolbar: toolbarVisible}, [className])} data-qa={qa}>
6965
{toolbarVisible ? (
7066
<MarkupToolbarContextProvider
7167
value={{

src/bundle/WysiwygEditorView.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ export const WysiwygEditorView = memo<WysiwygEditorViewProps>((props) => {
5656
});
5757
});
5858
return (
59-
<div
60-
className={b({toolbar: toolbarVisible}, [className])}
61-
data-mode={editor.currentMode}
62-
data-qa={qa}
63-
>
59+
<div className={b({toolbar: toolbarVisible}, [className])} data-qa={qa}>
6460
{toolbarVisible ? (
6561
<ToolbarView
6662
editor={editor}

src/bundle/settings/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export const EditorSettings = memo<EditorSettingsProps>(function EditorSettings(
5454
hotkey="mod+shift+p"
5555
>
5656
<Button
57+
qa="g-md-markup-preview-button"
5758
size="m"
5859
view="flat"
5960
pin="round-round"
@@ -129,7 +130,7 @@ const SettingsContent: React.FC<SettingsContentProps> = function SettingsContent
129130
<div className={bContent(null, [className])} data-qa="g-md-settings-content">
130131
<Menu size="l" className={bContent('mode')}>
131132
<Menu.Item
132-
qa="md-settings-mode-wysiwyg"
133+
qa="g-md-settings-mode-wysiwyg"
133134
active={mode === 'wysiwyg'}
134135
onClick={() => {
135136
onModeChange('wysiwyg');
@@ -140,7 +141,7 @@ const SettingsContent: React.FC<SettingsContentProps> = function SettingsContent
140141
{i18n('settings_wysiwyg')}
141142
</Menu.Item>
142143
<Menu.Item
143-
qa="md-settings-mode-markup"
144+
qa="g-md-settings-mode-markup"
144145
active={mode === 'markup'}
145146
onClick={() => {
146147
onModeChange('markup');

tests/playwright/core/editor.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2531
type PasteData = Partial<Record<DataTransferType, string>>;
2632

33+
type VisibleState = 'attached' | 'detached' | 'visible' | 'hidden' | undefined;
34+
2735
export 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
}
Loading
Loading
Loading

0 commit comments

Comments
 (0)