-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathdrag-page.spec.ts
315 lines (258 loc) · 9 KB
/
drag-page.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import { test } from '@affine-test/kit/playwright';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
createLinkedPage,
dragTo,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
import {
getCurrentCollectionIdFromUrl,
getCurrentDocIdFromUrl,
getDocIdFromUrl,
} from '@affine-test/kit/utils/url';
import type { Locator, Page } from '@playwright/test';
import { expect } from '@playwright/test';
const dragToFavourites = async (
page: Page,
dragItem: Locator,
id: string,
type: 'doc' | 'collection' | 'tag' | 'folder' = 'doc'
) => {
const favourites = page.getByTestId('explorer-favorite-category-divider');
await dragTo(page, dragItem, favourites);
const item = page
.getByTestId(`explorer-favorites`)
.locator(`[data-testid="explorer-${type}-${id}"]`);
await expect(item).toBeVisible();
return item;
};
const createCollection = async (page: Page, name: string) => {
await page.getByTestId('explorer-bar-add-collection-button').click();
const input = page.getByTestId('prompt-modal-input');
await expect(input).toBeVisible();
await input.fill(name);
await page.getByTestId('prompt-modal-confirm').click();
const newCollectionId = getCurrentCollectionIdFromUrl(page);
const collection = page.getByTestId(`explorer-collection-${newCollectionId}`);
await expect(collection).toBeVisible();
return collection;
};
const createPage = async (page: Page, title: string) => {
await clickNewPageButton(page, title);
};
const dragToCollection = async (page: Page, dragItem: Locator) => {
const collection = await createCollection(page, 'test collection');
await clickSideBarAllPageButton(page);
await dragTo(page, dragItem, collection);
await page.waitForTimeout(500);
const collectionPage = collection.locator('[data-testid^="explorer-doc-"]');
await expect(collectionPage).toBeVisible();
return collectionPage;
};
const dragToTrash = async (page: Page, title: string, dragItem: Locator) => {
// drag to trash
await dragTo(page, dragItem, page.getByTestId('trash-page'));
const confirmTip = page.getByText('Delete doc?');
await expect(confirmTip).toBeVisible();
await page.getByRole('button', { name: 'Delete' }).click();
await expect(
page.getByText(title),
'The deleted post is no longer on the All Page list'
).toHaveCount(0);
await page.waitForTimeout(500);
await page.getByTestId('trash-page').click();
await expect(
page.getByText(title),
'The deleted post exists in the Trash list'
).toHaveCount(1);
};
test.beforeEach(async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
});
test('drag a page from "All pages" list to favourites, then drag to trash', async ({
page,
}) => {
const title = 'this is a new page to drag';
await waitForEditorLoad(page);
await createPage(page, title);
const pageId = getCurrentDocIdFromUrl(page);
await clickSideBarAllPageButton(page);
await page.waitForTimeout(500);
const favouritePage = await dragToFavourites(
page,
page.locator(`[data-testid="page-list-item"]:has-text("${title}")`),
pageId
);
await dragToTrash(page, title, favouritePage);
});
test('drag a page from "All pages" list to collections, then drag to trash', async ({
page,
}) => {
const title = 'this is a new page to drag';
await waitForEditorLoad(page);
await createPage(page, title);
await clickSideBarAllPageButton(page);
await page.waitForTimeout(500);
const collectionPage = await dragToCollection(
page,
page.locator(`[data-testid="page-list-item"]:has-text("${title}")`)
);
await dragToTrash(page, title, collectionPage);
});
test('drag a page from "All pages" list to trash', async ({ page }) => {
const title = 'this is a new page to drag';
await createPage(page, title);
await clickSideBarAllPageButton(page);
await page.waitForTimeout(500);
await dragToTrash(
page,
title,
page.locator(`[data-testid="page-list-item"]:has-text("${title}")`)
);
});
test('drag a page from favourites to collection', async ({ page }) => {
const title = 'this is a new page to drag';
await createPage(page, title);
const pageId = getCurrentDocIdFromUrl(page);
await clickSideBarAllPageButton(page);
await page.waitForTimeout(500);
// drag to favourites
const favouritePage = await dragToFavourites(
page,
page.locator(`[data-testid="page-list-item"]:has-text("${title}")`),
pageId
);
// drag to collections
await dragToCollection(page, favouritePage);
});
test('drag a collection to favourites', async ({ page }) => {
await clickSideBarAllPageButton(page);
await page.waitForTimeout(500);
const collection = await createCollection(page, 'test collection');
const collectionId = getCurrentCollectionIdFromUrl(page);
await dragToFavourites(page, collection, collectionId, 'collection');
});
test('items in favourites can be reordered by dragging', async ({ page }) => {
const title0 = 'this is a new page to drag';
await createPage(page, title0);
await page.getByTestId('pin-button').click();
const title1 = 'this is another new page to drag';
await createPage(page, title1);
await page.getByTestId('pin-button').click();
{
const collection = await createCollection(page, 'test collection');
const collectionId = getCurrentCollectionIdFromUrl(page);
await dragToFavourites(page, collection, collectionId, 'collection');
}
// assert the order of the items in favourites
await expect(
page.getByTestId('explorer-favorites').locator('[draggable]')
).toHaveCount(3);
await expect(
page.getByTestId('explorer-favorites').locator('[draggable]').first()
).toHaveText('test collection');
await expect(
page.getByTestId('explorer-favorites').locator('[draggable]').last()
).toHaveText(title0);
// drag the first item to the last
const firstItem = page
.getByTestId('explorer-favorites')
.locator('[draggable]')
.first();
const lastItem = page
.getByTestId('explorer-favorites')
.locator('[draggable]')
.last();
await dragTo(page, firstItem, lastItem, 'bottom');
// now check the order again
await expect(
page.getByTestId('explorer-favorites').locator('[draggable]')
).toHaveCount(3);
await expect(
page.getByTestId('explorer-favorites').locator('[draggable]').first()
).toHaveText(title1);
await expect(
page.getByTestId('explorer-favorites').locator('[draggable]').last()
).toHaveText('test collection');
});
test('drag a page link in editor to favourites', async ({ page }) => {
await clickNewPageButton(page);
await page.waitForTimeout(500);
await page.keyboard.press('Enter');
await createLinkedPage(page, 'hi from another page');
const pageReference = page.locator('a').filter({
has: page.locator(
'.affine-reference-title:has-text("hi from another page")'
),
});
const pageLink = await pageReference.evaluate(
el => (el as HTMLAnchorElement).href
);
expect(pageLink).toBeTruthy();
if (!pageLink) {
return;
}
const pageId = getDocIdFromUrl(pageLink);
await dragToFavourites(
page,
page.locator('.affine-reference-title:has-text("hi from another page")'),
pageId
);
});
test('drag a page card block to another page', async ({ page }) => {
await clickNewPageButton(page);
await page.waitForTimeout(500);
await page.keyboard.press('Enter');
await createLinkedPage(page, 'hi from another page');
const pageReference = page.locator('a').filter({
has: page.locator(
'.affine-reference-title:has-text("hi from another page")'
),
});
const pageLink = await pageReference.evaluate(
el => (el as HTMLAnchorElement).href
);
expect(pageLink).toBeTruthy();
if (!pageLink) {
return;
}
const pageId = getDocIdFromUrl(pageLink);
await pageReference.hover();
const inlineToolbar = page.locator('reference-popup');
// convert page reference to card block
await inlineToolbar.getByRole('button', { name: 'Switch view' }).click();
await inlineToolbar.getByRole('button', { name: 'Card view' }).click();
// hover the card block to show the drag handle
const box = await page.locator('affine-embed-linked-doc-block').boundingBox();
expect(box).toBeTruthy();
if (!box) {
return;
}
await page.mouse.move(box.x - 5, box.y + box.height / 2);
await dragToFavourites(
page,
page.locator('.affine-drag-handle-container'),
pageId
);
});
test('drag a favourite page into blocksuite', async ({ page }) => {
await clickNewPageButton(page, 'hi from page');
await page.getByTestId('pin-button').click();
const pageId = getCurrentDocIdFromUrl(page);
const item = page
.getByTestId(`explorer-favorites`)
.locator(`[data-testid="explorer-doc-${pageId}"]`);
await expect(item).toBeVisible();
// drag item into blocksuite editor
await dragTo(
page,
item,
page.locator('.affine-paragraph-block-container').first()
);
await expect(page.locator('affine-embed-linked-doc-block')).toContainText(
'hi from page'
);
});