-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmention.spec.ts
185 lines (176 loc) · 5.44 KB
/
mention.spec.ts
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { expect, test } from "@playwright/test";
import * as os from "os";
import { testUtils } from "./test-utils";
test.describe("mentions handling", () => {
test("should render a new mention with dashes", async ({
page,
browserName,
}) => {
const utils = await testUtils(
{ page, browserName },
{
initialValue: "due:2023-06-06",
},
);
await utils.sleep(200);
await utils.hasText("[due:2023-06-06]");
});
test("should insert a new mention that contains spaces", async ({
page,
browserName,
isMobile,
}) => {
const utils = await testUtils(
{ page, browserName },
{
allowSpaces: true,
creatable: true,
mentionEnclosure: true,
},
);
await utils.editorType("@John Doe");
isMobile
? await utils.mentionsMenu.getByText("John Doe").click()
: await utils.editor.press("Tab");
await utils.hasText(`[@"John Doe"]`);
});
test("should insert a selected mention by pressing space", async ({
page,
browserName,
isMobile,
}) => {
test.skip(!!isMobile, "desktop only");
const utils = await testUtils(
{ page, browserName },
{
creatable: true,
mentionEnclosure: true,
},
);
await utils.editorType("@C");
await expect(utils.mentionsMenu.getByText("Catherine")).toBeVisible();
await expect(utils.mentionsMenu.getByText(`Add user "C"`)).toBeVisible();
await expect(utils.mentionsMenu).toHaveAttribute(
"aria-activedescendant",
"Catherine",
);
await utils.editor.press("Space");
await utils.hasText(`[@Catherine] `);
});
test("should insert a new mention by pressing space", async ({
page,
browserName,
isMobile,
}) => {
test.skip(!isMobile, "mobile only");
const utils = await testUtils(
{ page, browserName },
{
creatable: true,
mentionEnclosure: true,
},
);
await utils.editorType("@C");
await expect(utils.mentionsMenu.getByText("Catherine")).toBeVisible();
await expect(utils.mentionsMenu.getByText(`Add user "C"`)).toBeVisible();
await expect(utils.mentionsMenu).toHaveAttribute(
"aria-activedescendant",
"",
);
await utils.editor.press("Space");
await utils.hasText(`[@C] `);
});
test("should prevent text deletion after inserting a mention if text comes directly after it", async ({
page,
browserName,
}) => {
const utils = await testUtils(
{ page, browserName },
{
autoSpace: false,
initialValue: "Test",
autofocus: "start",
},
);
await utils.editorType("@C");
await utils.mentionsMenu.getByText("Catherine").click();
await utils.hasText(`[@Catherine]Test`);
});
test("should remove a mention via undo command (Ctrl/Cmd + Z)", async ({
page,
browserName,
isMobile,
}) => {
test.skip(!!isMobile, "desktop only");
const utils = await testUtils({ page, browserName });
const undoCommand = process.platform === "darwin" ? "Meta+Z" : "Control+Z";
await utils.editorType("@Catherine");
await utils.editor.press("Enter");
await utils.hasText("[@Catherine]");
await utils.editor.press(undoCommand);
await utils.hasText("@Catherine");
await utils.editor.press(undoCommand);
await utils.hasText("@C");
await utils.editor.press(undoCommand);
await utils.hasText("@");
await utils.editor.press(undoCommand);
await utils.hasText("");
});
test("should use custom mention nodes", async ({
page,
browserName,
isMobile,
}) => {
test.skip(!!isMobile, "desktop only");
const utils = await testUtils(
{ page, browserName },
{
initialValue: "@Catherine",
customMentionNode: true,
},
);
const mentionPosition = await page
.locator(`[data-beautiful-mention="@Catherine"]`)
.boundingBox();
await expect(
page.locator(`[data-beautiful-mention="@Catherine"]`),
).toHaveAttribute("data-state", "closed");
await page.mouse.move(mentionPosition.x + 1, mentionPosition.y + 1);
await expect(
page.locator(`[data-beautiful-mention="@Catherine"]`),
).toHaveAttribute("data-state", "delayed-open");
await page.getByText("Remove Mention").click();
await utils.countMentions(0);
});
test("should insert a mention in brackets", async ({ page, browserName }) => {
const utils = await testUtils({ page, browserName });
await utils.editorType("(@Cath");
await utils.mentionsMenu.getByText("Catherine").click();
await utils.editorType(")");
await utils.hasText(`([@Catherine])`);
});
// only works when running in headful mode
// - https://github.com/kenthu/human-interest-verifier/issues/1
// - https://github.com/microsoft/playwright/issues/11654
test.skip("should copy mention to clipboard and paste it back in the editor", async ({
page,
browserName,
isMobile,
}) => {
test.skip(!!isMobile, "desktop only");
const utils = await testUtils(
{ page, browserName },
{
initialValue: "@Catherine",
customMentionNode: true,
},
);
await page.click(`[data-beautiful-mention="@Catherine"]`);
const isMac = os.platform() === "darwin";
const modifier = isMac ? "Meta" : "Control";
await page.keyboard.press(`${modifier}+KeyC`);
await page.keyboard.press("ArrowRight");
await page.keyboard.press(`${modifier}+KeyV`);
await utils.hasText("[@Catherine] [@Catherine]");
});
});