~james/core

core/e2e/specs/comments.spec.ts -rw-r--r-- 10.1 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
import { expect } from "@playwright/test";

import { comments } from "../harness/api";
import {
	bobbin,
	button,
	commentId,
	component,
	flow,
	hydrant,
	knot,
	not,
	page,
	pds,
	record,
	replacing,
	subscriptionId,
	target,
	testid,
	text,
	through,
	ticketId,
	within
} from "../harness/flow";
import { retry429 } from "../harness/net";
import {
	commented,
	deletesComment,
	made,
	note,
	onCommentedIssue,
	stillStored
} from "../harness/shared";

const busy = 101;
const saying = (at: number) => `comment ${String(at).padStart(3, "0")}`;
const exactly = (words: string) => within(testid("commentBody"), text(words));

flow("more than a hundred comments still show the newest one")
	.actor("owner")
	.repo()
	.ticket(ticketId, { title: "a busy thread" })
	.step(`${busy} comments`, async (ctx) => {
		const write = async (at: number) => {
			// a burst this big outlasts the usual back off, so it waits longer and tries more often
			const reply = await retry429(
				() => comments.add(ctx.actor, ctx.repo.did, ctx.get(ticketId), saying(at)),
				10,
				1_000
			);
			const written = made(`comment ${at}`, reply);
			ctx.adopt(commentId, written);
			return written;
		};
		for (let from = 1; from < busy; from += 4) {
			const burst = Array.from({ length: Math.min(4, busy - from) }, (_, at) => from + at);
			await Promise.all(burst.map(write));
		}
		await bobbin.indexed(await write(busy));
	})

	.open(page.issue(ticketId))
	.sees(exactly(saying(busy)))
	.sees(not(exactly(saying(1))))
	.click(button("Load older comments"))
	.sees(exactly(saying(1)))
	.sees(exactly(saying(busy)));

const reply = record("org.tangled.feed.comment");
const reaction = record("org.tangled.feed.reaction");

const replyBox = within(testid("commentEditor", { mode: "reply" }), testid("body"));
const replySubmit = within(testid("commentEditor", { mode: "reply" }), testid("submit"));
const editBox = within(testid("commentEditor", { mode: "edit" }), testid("body"));
const editSubmit = within(testid("commentEditor", { mode: "edit" }), testid("submit"));
const discussion = within(testid("commentEditor", { mode: "new" }), testid("body"));
const commentSubmit = within(testid("commentEditor", { mode: "new" }), testid("submit"));

const threadTitle = "needs a thread";
const parentText = "the parent says this";
const replyText = "and the reply says that";
const editedParent = "the parent, but better";

const issuePicker = within(component("Ticket"), testid("react"));
const commentPicker = within(component("CommentCard"), testid("react"));
const thumbs = testid("handlePick", { kind: "👍" });
const chip = testid("reactionChip", { kind: "👍" });
const chipSaying = (count: number) => testid("reactionChip", { kind: "👍", count });

// replies sit in the ml-2xl column under their parent, top level comments never do
const nested = (words: string) => within(testid("replies"), text(words));

const withOneComment = (name: string) =>
	onCommentedIssue(name, {
		title: threadTitle,
		words: parentText,
		// a reply looks the subscription up in bobbin, and writes a second one if it's missing
		subscription: through(pds, hydrant, bobbin)
	});

withOneComment("replying under a comment nests it and survives a reload")
	.sees(not(nested(parentText)))
	.fill(replyBox, replyText)
	.click(replySubmit)
	.sends(
		reply,
		knot,
		(ctx) => ({
			record: {
				subject: { uri: ctx.get(ticketId).uri },
				replyTo: { uri: ctx.get(commentId).uri, cid: ctx.get(commentId).cid },
				body: { text: replyText }
			}
		}),
		"create"
	)
	.trace(reply, through(knot, hydrant, bobbin))
	.sees(nested(replyText))
	.reload()
	.sees(text(parentText))
	.sees(nested(replyText))
	.sees(not(nested(parentText)))
	.step("the knot's copy of the reply names the parent", async (ctx) => {
		const stored = await knot.has(ctx.get(reply));
		if (stored.replyTo?.uri !== ctx.get(commentId).uri)
			throw new Error(`the reply says it answers ${stored.replyTo?.uri}`);
	});

flow("reacting to an issue and taking the reaction back")
	.actor("owner")
	.repo()
	.ticket(ticketId, { title: "react to me" })

	.open(page.issue(ticketId))
	.click(issuePicker)
	.click(thumbs)
	.sends(
		reaction,
		knot,
		(ctx) => ({
			record: { reaction: "👍", subject: { uri: ctx.get(ticketId).uri } }
		}),
		"create"
	)
	.sees(chipSaying(1))
	.trace(reaction, through(knot, hydrant, bobbin))
	.sees(chipSaying(1))
	.reload()
	.sees(chipSaying(1))

	.click(chip)
	.sends(reaction, knot, replacing(reaction), "delete")
	.sees(not(chip))
	.trace(reaction, through(knot, hydrant, bobbin))
	.sees(not(chip))
	.reload()
	.sees(not(chip));

flow("a reaction from each of two people adds up and one taking theirs back leaves the other")
	.actor("owner")
	.repo()
	.ticket(ticketId, { title: "react to me twice" })

	.open(page.issue(ticketId))
	.click(issuePicker)
	.click(thumbs)
	.trace(reaction, through(knot, hydrant, bobbin))
	.sees(chipSaying(1))

	.actor("fan")
	.open(page.issue(ticketId))
	.sees(chipSaying(1))
	.click(chip)
	.sends(reaction, knot, { record: { reaction: "👍" } }, "create")
	.trace(reaction, through(knot, hydrant, bobbin))
	.sees(chipSaying(2))
	.reload()
	.sees(chipSaying(2))
	.click(chip)
	.sends(reaction, knot, replacing(reaction), "delete")
	.trace(reaction, through(knot, hydrant, bobbin))
	.sees(chipSaying(1))
	.reload()
	.sees(chipSaying(1))

	.actor("owner")
	.open(page.issue(ticketId))
	.sees(chipSaying(1));

withOneComment("reacting to a comment and taking the reaction back")
	.click(commentPicker)
	.click(thumbs)
	.sends(
		reaction,
		knot,
		(ctx) => ({
			record: {
				reaction: "👍",
				subject: { uri: ctx.get(commentId).uri, cid: ctx.get(commentId).cid }
			}
		}),
		"create"
	)
	.trace(reaction, through(knot, hydrant, bobbin))
	.sees(chipSaying(1))
	.reload()
	.sees(chipSaying(1))

	.click(chip)
	.sends(reaction, knot, replacing(reaction), "delete")
	.trace(reaction, through(knot, hydrant, bobbin))
	.sees(not(chip))
	.reload()
	.sees(not(chip))
	.sees(text(parentText));

withOneComment("deleting a comment that has replies keeps the replies under a tombstone")
	.fill(replyBox, replyText)
	.click(replySubmit)
	.trace(reply, through(knot, hydrant, bobbin))
	.sees(nested(replyText))

	.use(deletesComment)
	.sees(testid("deletedCommentNotice"))
	.sees(not(text(parentText)))
	.sees(text(replyText))
	.reload()
	.sees(testid("deletedCommentNotice"))
	.sees(not(text(parentText)))
	.sees(nested(replyText))
	.step("the reply is still on the knot", async (ctx) => {
		await knot.has(ctx.get(reply));
	});

// scoped to the edited card, so a chip elsewhere can't stand in for it
const chipOnEdited = target("the 👍 chip on the edited comment", (page, ctx) =>
	testid("commentCard")
		.locate(page, ctx)
		.filter({ hasText: editedParent })
		.locator('[data-testid="reactionChip"][data-kind="👍"][data-count="1"]')
);

withOneComment("editing a comment keeps its reactions on screen")
	.click(commentPicker)
	.click(thumbs)
	.trace(reaction, through(knot, hydrant, bobbin))
	.sees(chipSaying(1))

	.click(within(component("CommentCard"), testid("moreMenu")))
	.click(testid("setEditingUri"))
	.fill(editBox, editedParent)
	.click(editSubmit)
	.sends(
		commentId,
		knot,
		replacing(commentId, (ctx) => ({
			subject: { uri: ctx.get(ticketId).uri },
			body: { text: editedParent }
		})),
		"put"
	)
	.trace(commentId, through(knot, hydrant, bobbin))
	.sees(text(editedParent))
	// before the reload, which would hide it
	.sees(chipOnEdited)
	.reload()
	.sees(text(editedParent))
	.sees(chipOnEdited);

const title = "the build is broken";

const edited = "same here, again";

flow("commenting on an issue you opened")
	.actor("owner")
	.repo()

	.open(page.newIssue)
	.fill(testid("title"), title)
	.click(testid("submit"))
	.trace(ticketId, through(knot, hydrant, bobbin))
	// opening subscribed the author, so the comment must not subscribe again
	.trace(subscriptionId, through(pds, hydrant, bobbin))

	.open(page.issue(ticketId))
	.sees(testid("toggleSubscription", { subscribed: "true" }))
	.fill(discussion, note)
	.click(commentSubmit)
	.trace(commentId, through(knot, hydrant, bobbin))
	.sees(text(note))
	.reload()
	.sees(text(note))
	.sees(testid("toggleSubscription", { subscribed: "true" }));

flow("commenting on an issue")
	.actor("owner")
	.repo()
	.ticket(ticketId, { title: commented })

	.open(page.issue(ticketId))
	.fill(discussion, note)
	.click(commentSubmit)
	// the knot only takes a comment that names the version of the ticket it saw
	.sends(
		commentId,
		knot,
		(ctx) => ({
			record: { subject: { $type: "com.atproto.repo.strongRef", ...ctx.get(ticketId) } }
		}),
		"create"
	)
	.sees(text(commented))
	.sees(not(text(note)))
	.trace(commentId, through(knot, hydrant, bobbin))
	.sees(text(note))
	.trace(subscriptionId, through(pds))
	.reload()
	.sees(text(note));

onCommentedIssue("editing a comment")
	.click(within(component("CommentCard"), testid("moreMenu")))
	.click(testid("setEditingUri"))
	.fill(editBox, edited)
	.click(editSubmit)
	.sends(
		commentId,
		knot,
		// the knot wants an edit to resend the subject too
		replacing(commentId, (ctx) => ({
			subject: { uri: ctx.get(ticketId).uri },
			body: { text: edited }
		})),
		"put"
	)
	.trace(commentId, through(knot, hydrant, bobbin))
	.sees(text(edited))
	.reload()
	.sees(text(edited));

onCommentedIssue("deleting a comment")
	.use(deletesComment)
	.sees(text(commented))
	.sees(not(text(note)))
	.reload()
	.sees(text(commented))
	.sees(not(text(note)));

const draft = "typed and never sent";

const cancel = testid("cancel");

onCommentedIssue("cancelling a comment edit leaves the comment as it was")
	.click(within(component("CommentCard"), testid("moreMenu")))
	.click(testid("setEditingUri"))
	.fill(editBox, edited)
	.click(cancel)
	.sendsNothing(commentId)
	.sees(text(note))
	.sees(not(text(edited)))
	.reload()
	.sees(text(note))
	.sees(not(text(edited)))
	.step(
		"the knot and hydrant still have the first version",
		stillStored(commentId, (value) => value.body.text, note)
	);

onCommentedIssue("a comment typed and never sent is not written")
	.fill(discussion, draft)
	.open(page.issues)
	.sendsNothing(commentId)
	.open(page.issue(ticketId))
	.sees(not(text(draft)))
	.step("the box starts empty", async (ctx) => {
		await expect(discussion.locate(ctx.page, ctx)).toHaveValue("");
	});