Skip to content

Commit 3a340f3

Browse files
authored
test: updated visual tests for cut block (#735)
1 parent ccdf761 commit 3a340f3

19 files changed

+288
-112
lines changed

scripts/generate-playwright-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const ALIASES = {
88
};
99
const TEMPLATE_DIR = 'tests/playwright/templates';
1010
const DEFAULT_OUTPUT_DIR = 'tests/visual-tests/playground';
11-
const templatePath = path.join(TEMPLATE_DIR, 'Extension.template.test.tsx');
11+
const templatePath = path.join(TEMPLATE_DIR, 'Extension.template.tsx');
1212

1313
if (!fs.existsSync(templatePath)) {
1414
console.error(`❌ Template file not found at ${templatePath}`);

tests/playwright/core/editor.ts

Lines changed: 119 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,57 +47,70 @@ export class MarkdownEditorPage {
4747
this.locators = new MarkdownEditorLocators(page);
4848
}
4949

50-
/** Returns the current editor mode */
50+
/**
51+
* Checks that the current editor mode matches the expected one
52+
*/
53+
async assertMode(mode: MarkdownEditorMode) {
54+
await this.expect.poll(() => this.getMode()).toBe(mode);
55+
}
56+
57+
/**
58+
* Asserts that the toolbar button is disabled
59+
*/
60+
async assertToolbarButtonDisabled(label: string) {
61+
const button = this.getToolbarButton(label);
62+
await this.expect(button).toHaveClass(/disabled/);
63+
}
64+
65+
/**
66+
* Asserts that the toolbar button is enabled
67+
*/
68+
async assertToolbarButtonEnabled(label: string) {
69+
const button = this.getToolbarButton(label);
70+
await this.expect(button).not.toHaveClass(/disabled/);
71+
}
72+
73+
/**
74+
* Returns the current editor mode
75+
*/
5176
async getMode(): Promise<MarkdownEditorMode> {
5277
const value = await this.locators.editor.getAttribute('data-mode');
5378
const mode = value as MarkdownEditorMode | null;
5479
if (mode === 'wysiwyg' || mode === 'markup') return mode;
5580
throw new Error(`MarkdownEditorPage.getMode(): unknown editor mode "${mode}"`);
5681
}
5782

58-
/** Finds a command menu item by text */
83+
/**
84+
* Finds an element in the command menu by its text
85+
*/
5986
getByTextInCommandMenu(text: string): Locator {
6087
return this.locators.commandMenu.getByText(text);
6188
}
6289

63-
/** Finds an element inside the editable area by selector */
90+
/**
91+
* Finds an element by selector within the contenteditable area
92+
*/
6493
getBySelectorInContenteditable(selector: string): Locator {
6594
return this.locators.contenteditable.locator(selector);
6695
}
6796

68-
/** Finds a command menu item by text */
97+
/**
98+
* Finds an element by text within the contenteditable area
99+
*/
69100
getByTextInContenteditable(text: string): Locator {
70101
return this.locators.contenteditable.getByText(text);
71102
}
72103

73-
/** Opens the settings popup if it's not already open */
74-
async openSettingsPopup() {
75-
if (await this.locators.settingsContent.isVisible()) return;
76-
77-
await this.locators.settingsButton.click();
78-
await this.locators.settingsContent.waitFor({state: 'visible'});
79-
}
80-
81-
/** Asserts that the current mode matches the expected one */
82-
async assertMode(mode: MarkdownEditorMode) {
83-
await this.expect.poll(() => this.getMode()).toBe(mode);
84-
}
85-
86-
/** Clicks the toolbar "more actions" button. */
87-
async clickToolbarMoreActionButton() {
88-
await this.locators.toolbarMoreActionButton.click();
104+
/**
105+
* Returns a locator for the toolbar button by its aria-label
106+
*/
107+
getToolbarButton(label: string): Locator {
108+
return this.page.getByLabel(label);
89109
}
90110

91-
/** Switches the editor to the specified mode */
92-
async switchMode(mode: MarkdownEditorMode) {
93-
if ((await this.getMode()) === mode) return;
94-
95-
await this.openSettingsPopup();
96-
await this.locators.settingsContent.getByTestId(`g-md-settings-mode-${mode}`).click();
97-
await this.assertMode(mode);
98-
}
99-
100-
/** Returns the current preview visibility state */
111+
/**
112+
* Returns the current visibility state of the preview
113+
*/
101114
async getPreview(): Promise<VisibleState> {
102115
const previewContent = await this.locators.previewContent;
103116
if (await previewContent.isVisible()) {
@@ -111,7 +124,20 @@ export class MarkdownEditorPage {
111124
return undefined;
112125
}
113126

114-
/** Toggles or sets the preview visibility state */
127+
/**
128+
* Switches the editor to the specified mode
129+
*/
130+
async switchMode(mode: MarkdownEditorMode) {
131+
if ((await this.getMode()) === mode) return;
132+
133+
await this.openSettingsPopup();
134+
await this.locators.settingsContent.getByTestId(`g-md-settings-mode-${mode}`).click();
135+
await this.assertMode(mode);
136+
}
137+
138+
/**
139+
* Toggles or sets the preview visibility state
140+
*/
115141
async switchPreview(state?: VisibleState) {
116142
const currentState = await this.getPreview();
117143
const revertState = currentState === 'visible' ? 'hidden' : 'visible';
@@ -129,28 +155,76 @@ export class MarkdownEditorPage {
129155
});
130156
}
131157

132-
/** Removes focus from the editable area */
158+
/**
159+
* Opens the settings popup if it is not already open
160+
*/
161+
async openSettingsPopup() {
162+
if (await this.locators.settingsContent.isVisible()) return;
163+
164+
await this.locators.settingsButton.click();
165+
await this.locators.settingsContent.waitFor({state: 'visible'});
166+
}
167+
168+
/**
169+
* Clicks the "more actions" button on the toolbar
170+
*/
171+
async clickToolbarMoreActionButton() {
172+
await this.locators.toolbarMoreActionButton.click();
173+
}
174+
175+
/**
176+
* Clicks a toolbar button using its aria-label
177+
*/
178+
async clickToolbarButton(label: string) {
179+
const button = this.getToolbarButton(label);
180+
181+
await this.expect(button).toBeEnabled();
182+
await button.click();
183+
}
184+
185+
/**
186+
* Clears all content from the contenteditable area
187+
*/
188+
async clearContent() {
189+
await this.press('ControlOrMeta+A');
190+
await this.press('Backspace');
191+
}
192+
193+
/**
194+
* Removes focus from the contenteditable area
195+
*/
133196
async blur() {
134197
await this.locators.contenteditable.blur();
135198
}
136199

137-
/** Presses a key in the editable area */
200+
/**
201+
* Presses a key within the contenteditable area
202+
*/
138203
async press(key: string) {
139204
await this.locators.contenteditable.press(key);
140205
}
141206

142-
/** Presses each character in sequence in the editable area */
207+
/**
208+
* Presses each character sequentially in the contenteditable area
209+
*/
143210
async pressSequentially(key: string) {
144211
await this.locators.contenteditable.pressSequentially(key);
145212
}
146213

147-
/** Clears all content from the editable area */
148-
async clearContent() {
149-
await this.press('ControlOrMeta+A');
150-
await this.press('Backspace');
214+
/**
215+
* Simulates input rule behavior by typing a sequence in WYSIWYG mode.
216+
* Clears the editor and types each character
217+
*/
218+
async inputRule(sequence: string) {
219+
await this.switchMode('wysiwyg');
220+
await this.clearContent();
221+
await this.pressSequentially(sequence);
222+
await this.press('Space');
151223
}
152224

153-
/** Pastes data into the editable area */
225+
/**
226+
* Pastes data into the contenteditable area
227+
*/
154228
async paste(value: PasteData | string) {
155229
const data: PasteData = typeof value === 'string' ? {'text/plain': value} : value;
156230

@@ -166,12 +240,16 @@ export class MarkdownEditorPage {
166240
}, data);
167241
}
168242

169-
/** Fills the editable area with the given text */
243+
/**
244+
* Fills the contenteditable area with the provided text
245+
*/
170246
async fill(text: string) {
171247
this.locators.contenteditable.fill(text);
172248
}
173249

174-
/** Selects text inside the editable area */
250+
/**
251+
* Selects text within the contenteditable area
252+
*/
175253
async selectTextIn(selector?: string) {
176254
let loc = this.locators.contenteditable;
177255
if (selector) loc = loc.locator(selector);

tests/playwright/templates/Extension.template.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test.describe('%%name%%', () => {
1717
});
1818

1919
test.describe('insert', () => {
20-
test.skip(' should insert via toolbar @wysiwyg', async ({editor, wait}) => {
20+
test.skip('should insert via toolbar @wysiwyg', async ({editor, wait}) => {
2121
/* TODO: unskip */
2222
await editor.switchMode('wysiwyg');
2323
await editor.clearContent();

0 commit comments

Comments
 (0)