-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathheadingBoldFromStyle.spec.ts
More file actions
125 lines (102 loc) · 3.66 KB
/
Copy pathheadingBoldFromStyle.spec.ts
File metadata and controls
125 lines (102 loc) · 3.66 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { test, expect } from '@playwright/test';
import { copyAndPasteBetween } from '../helpers/clipboard';
import {
getSerializedHtml,
gotoVisualRegression,
setEditorHtml,
setHtmlStyleOverride,
} from '../helpers/visual-regression';
import { toolbarButton } from '../helpers/toolbar';
function h1Inner(serialized: string): string | null {
const m = serialized.match(/<h1[^>]*>([\s\S]*?)<\/h1>/);
return m && m[1] ? m[1] : null;
}
const HTML_STYLE_H1_BOLD_TRUE = '{ "h1": { "bold": true } }';
const HTML_STYLE_H1_BOLD_FALSE = '{ "h1": { "bold": false } }';
test.describe('h1 bold from htmlStyle (h1.bold true)', () => {
test.beforeEach(async ({ page }) => {
await gotoVisualRegression(page);
await setHtmlStyleOverride(page, HTML_STYLE_H1_BOLD_TRUE);
});
test('bold toolbar is disabled inside h1 when htmlStyle h1.bold is true', async ({
page,
}) => {
await setEditorHtml(page, '<html><h1>Heading</h1></html>');
await page.locator('.eti-editor h1').click();
await expect(toolbarButton(page, 'bold')).toBeDisabled();
});
test('setValue strips redundant <b> inside h1', async ({ page }) => {
await setEditorHtml(page, '<html><h1><b>Hello</b></h1></html>');
const inner = h1Inner(await getSerializedHtml(page));
expect(inner).not.toBeNull();
expect(inner).not.toContain('<b>');
expect(inner).toContain('Hello');
});
test('paste into h1 strips copied bold mark', async ({ page }) => {
await setEditorHtml(
page,
'<html><p><b>pasteMe</b></p><h1>placeholder</h1></html>'
);
await copyAndPasteBetween(
page.locator('.eti-editor p').first(),
page.locator('.eti-editor h1')
);
await expect
.poll(async () => {
const inner = h1Inner(await getSerializedHtml(page));
return inner?.includes('pasteMe') ?? false;
})
.toBe(true);
const inner = h1Inner(await getSerializedHtml(page));
expect(inner).not.toBeNull();
expect(inner).not.toContain('<b>');
expect(inner).toContain('pasteMe');
});
});
test.describe('h1 bold from htmlStyle (h1.bold false)', () => {
test.beforeEach(async ({ page }) => {
await gotoVisualRegression(page);
await setHtmlStyleOverride(page, HTML_STYLE_H1_BOLD_FALSE);
});
test('bold toolbar is enabled and can be active inside h1 when htmlStyle h1.bold is false', async ({
page,
}) => {
await setEditorHtml(page, '<html><h1>Heading</h1></html>');
await page.locator('.eti-editor h1').click();
const boldBtn = toolbarButton(page, 'bold');
await expect(boldBtn).toBeEnabled();
await boldBtn.click();
await expect(boldBtn).toHaveClass(/toolbar-btn--active/);
});
test('setValue keeps <b> inside h1 when htmlStyle h1.bold is false', async ({
page,
}) => {
await setEditorHtml(page, '<html><h1><b>Hello</b></h1></html>');
const inner = h1Inner(await getSerializedHtml(page));
expect(inner).not.toBeNull();
expect(inner).toContain('<b>');
expect(inner).toContain('Hello');
});
test('paste into h1 keeps copied bold mark when htmlStyle h1.bold is false', async ({
page,
}) => {
await setEditorHtml(
page,
'<html><p><b>pasteMe</b></p><h1>placeholder</h1></html>'
);
await copyAndPasteBetween(
page.locator('.eti-editor p').first(),
page.locator('.eti-editor h1')
);
await expect
.poll(async () => {
const inner = h1Inner(await getSerializedHtml(page));
return inner?.includes('pasteMe') ?? false;
})
.toBe(true);
const inner = h1Inner(await getSerializedHtml(page));
expect(inner).not.toBeNull();
expect(inner).toContain('<b>');
expect(inner).toContain('pasteMe');
});
});