~james/core

core/e2e/specs/pulls.spec.ts -rw-r--r-- 11.9 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
377
378
379
380
381
382
383
384
385
386
import { expect } from "@playwright/test";

import { comments, editCob } from "../harness/api";
import { seeded } from "../harness/config";
import {
	bobbin,
	commentId,
	commitRow,
	component,
	type Ctx,
	type Flow,
	hydrant,
	knot,
	link,
	not,
	page,
	patchId,
	pds,
	pullId,
	record,
	refusal,
	replacing,
	rkeyOf,
	subscriptionId,
	target,
	testid,
	text,
	through,
	triage,
	unique,
	within
} from "../harness/flow";
import { lsRemote } from "../harness/git";
import {
	branches,
	defineLabel,
	labelOff,
	labelOn,
	merges,
	onBranches,
	pipelineFor,
	recall,
	remember,
	sendsPatch,
	stillStored,
	subscribesToPull
} from "../harness/shared";

const title = unique("add a feature");

onBranches("opening a pull request", { ci: true })
	.open(page.newPull(branches))
	.fill(within(component("PullCompose"), testid("title")), title)
	.click(within(component("PullCompose"), testid("submit")))
	.sends(
		pullId,
		knot,
		(ctx) => ({
			repo: ctx.repo.did,
			record: {
				state: "open",
				title: { text: title },
				targetBranch: branches.into
			}
		}),
		"create"
	)
	.trace(pullId, through(knot, hydrant, bobbin))
	.use(sendsPatch())
	.use(subscribesToPull)
	.at(page.pulls)
	.sees(link(title))
	.checkpoint("the pull is listed")
	.step(
		"spindle has a pipeline for the pull",
		pipelineFor("pullRequest", (ctx) => ctx.repo.heads[branches.from])
	)
	.open(page.pull(pullId))
	.sees(testid("workflowName", { name: "ci.yml" }));

onBranches("closing and reopening a pull request")
	.pull(pullId, patchId, branches)
	.open(page.pull(pullId))
	.changeState(pullId, "closed", testid("requestClose"), testid("changeState"))
	.changeState(pullId, "open", testid("changeState"), testid("requestClose"))
	.reload()
	.sees(testid("requestClose"));

// the diff lists a file only once the mirror can read the commits between the branches
const diffedFile = testid("diffFileName", { path: "e2e/feature.txt" });

onBranches("the new pull form lists the branch's file in its diff")
	.open(page.newPull(branches))
	.sees(diffedFile)
	.sees(within(component("PullCompose"), testid("submit")));

const viewedTitle = unique("a pull to view");

onBranches("the pull page shows the pull's title")
	.pull(pullId, patchId, { ...branches, title: viewedTitle })
	.open(page.pull(pullId))
	.sees(not(testid("errorTitle")))
	.sees(within(testid("ticketTitle"), text(viewedTitle)));

const otherPull = record("org.tangled.track.ticket");
const otherPatch = record("org.tangled.review.patch");

const searchPulls = within(component("TicketSearch"), testid("q"));

const pullNeedle = unique("search needle");
const pullHay = unique("unrelated");

const onTwoPulls = (name: string) =>
	onBranches(name)
		.pull(pullId, patchId, { ...branches, title: pullNeedle })
		.pull(otherPull, otherPatch, { ...branches, title: pullHay });

onTwoPulls("searching the pull list finds the pull you named")
	.open(page.pulls)
	.sees(link(pullNeedle))
	.sees(link(pullHay))
	.fill(searchPulls, pullNeedle)
	.press("Enter")
	.sees(link(pullNeedle))
	.sees(not(link(pullHay)));

const note = "first thoughts";
const secondThoughts = "second thoughts";
const commentMenu = within(component("PullReviewComment"), testid("moreMenu"));
const editor = within(component("PullReviewCommentEditor"), testid("body"));
const commentField = within(component("PullReviewCommentForm"), testid("reviewComment"));

const commented = (name: string) =>
	onBranches(name)
		.pull(pullId, patchId, branches)
		.open(page.pull(pullId))
		.fill(commentField, note)
		.click(within(component("PullReviewCommentForm"), testid("submit")))
		.sends(
			commentId,
			knot,
			(ctx) => ({ record: { subject: { uri: ctx.get(pullId).uri } } }),
			"create"
		)
		.trace(commentId, through(knot, hydrant, bobbin))
		.trace(subscriptionId, through(pds))
		.sees(within(testid("reviewCommentBody"), text(note)));

commented("commenting on a pull request")
	.reload()
	.sees(within(testid("reviewCommentBody"), text(note)));

const startEdit = <T extends ReturnType<typeof commented>>(flowSoFar: T) =>
	flowSoFar
		.click(commentMenu)
		.click(testid("setEditing"))
		.fill(editor, secondThoughts)
		.click(within(component("PullReviewCommentEditor"), testid("submit")))
		.sends(
			commentId,
			knot,
			replacing(commentId, (ctx) => ({
				subject: { uri: ctx.get(pullId).uri },
				body: { text: secondThoughts }
			})),
			"put"
		)
		.trace(commentId, through(knot, hydrant, bobbin));

startEdit(commented("editing a comment on a pull request"))
	.reload()
	.sees(within(testid("reviewCommentBody"), text(secondThoughts)))
	.sees(not(within(testid("reviewCommentBody"), text(note))));

startEdit(commented("an edited pull comment shows without a reload")).sees(
	within(testid("reviewCommentBody"), text(secondThoughts))
);

const bugTitle = unique("a pull to resubmit");
const pushedFile = testid("diffFileName", { path: "e2e/more.txt" });
// round labels only head comments, so commit rows are how to tell rounds apart here
const twoCommitRows = (flow: Flow) => flow.sees(commitRow(2)).sees(not(commitRow(3)));

onBranches("resubmitting a pull request after pushing to its source branch", { ci: true })
	.pull(pullId, patchId, { ...branches, title: bugTitle })
	.push({ "e2e/more.txt": "more\n" }, { branch: branches.from })
	.mirrored()
	.open(page.pull(pullId))
	.sees(not(pushedFile))
	.sees(testid("resubmit"))
	.click(testid("resubmit"))
	.sends(patchId, knot, (ctx) => ({ patch: { ticket: rkeyOf(ctx, pullId) } }), "create")
	.trace(patchId, through(knot, hydrant, bobbin))
	.reload()
	.sees(pushedFile)
	.use(twoCommitRows)
	.checkpoint("the resubmitted round shows in the diff")
	.step(
		"spindle has a pipeline for the new commit",
		pipelineFor("pullRequest", (ctx) => ctx.repo.heads[branches.from])
	);

const moreActions = within(component("Ticket"), testid("moreMenu"));
const editPull = within(component("Ticket"), testid("setEditing"));

const strangerTitle = "a pull from someone who can't contribute";

onBranches(
	"a stranger's pull is refused when only collaborators may contribute and the page says so"
)
	.policy("collaborators")

	.actor(seeded.charlie)
	.open(page.newPull(branches))
	.fill(within(component("PullCompose"), testid("title")), strangerTitle)
	.click(within(component("PullCompose"), testid("submit")))
	.refused(pullId, 403)
	.sees(refusal)
	.open(page.pulls)
	.sees(not(link(strangerTitle)));

const otherBranch = "other";

// keep it in its own folder, a shared file makes the knot refuse the merge
const withOtherBranch = (name: string) =>
	onBranches(name)
		.push({ "other/other.txt": "other\n" }, { branch: otherBranch, base: branches.into })
		.mirrored()
		.pull(pullId, patchId, branches);

const targetBranchPicker = within(
	component("TicketForm"),
	within(testid("targetBranch"), testid("trigger"))
);
const otherOption = testid("option", { value: otherBranch });
const targeting = (branch: string) => testid("targetBranchTag", { branch });

withOtherBranch("retargeting a pull request to another branch")
	.open(page.pull(pullId))
	.sees(targeting(branches.into))
	.click(moreActions)
	.click(editPull)
	.click(targetBranchPicker)
	.click(otherOption)
	.click(within(component("TicketForm"), testid("submit")))
	.sends(pullId, knot, replacing(pullId, { targetBranch: otherBranch }), "put")
	.trace(pullId, through(knot, hydrant, bobbin))
	.sees(targeting(otherBranch))
	.step("the knot's copy targets the other branch", async (ctx) =>
		expect((await knot.has(ctx.get(pullId))).targetBranch).toBe(otherBranch)
	)
	.reload()
	.sees(targeting(otherBranch))
	.sees(not(targeting(branches.into)));

// the page won't see this, so the knot's copy is edited directly
const retargetOnKnot = async (ctx: Ctx) => {
	const reply = await editCob(ctx.actor, ctx.get(pullId).uri, "retarget", (stored) => ({
		...stored,
		targetBranch: otherBranch
	}));
	expect(reply.status, `the retarget answered ${JSON.stringify(reply.body)}`).toBe(200);
	ctx.set(pullId, { uri: reply.body.uri, cid: reply.body.cid });
};

withOtherBranch("a retargeted pull merges into its new branch and leaves the old one alone")
	.step("the pull is retargeted", retargetOnKnot)
	.open(page.pull(pullId))
	.sees(targeting(otherBranch))
	.use(merges)
	.knotStored(pullId, "completed")
	.step("only the other branch moved", async (ctx) => {
		const heads = await lsRemote(ctx.actor, ctx.repo.did, "refs/heads/");
		expect(heads[`refs/heads/${branches.into}`]).toBe(ctx.repo.heads[branches.into]);
		expect(heads[`refs/heads/${otherBranch}`]).not.toBe(ctx.repo.heads[otherBranch]);
	});

onBranches("putting a label on a pull request and taking it off")
	.pull(pullId, patchId, branches)
	.step("define the label", defineLabel(triage))

	.open(page.pull(pullId))
	.use(labelOn(pullId, "pull"))
	.sees(targeting(branches.into))
	.use(labelOff(pullId, "pull"));

const reviewNote = "looks fine to me";
const peerSays = async (ctx: Ctx) => {
	const reply = await comments.add(ctx.actor, ctx.repo.did, ctx.get(pullId), reviewNote);
	expect(reply.status, `the review comment answered ${JSON.stringify(reply.body)}`).toBe(200);
	await bobbin.indexed({ uri: reply.body.uri, cid: reply.body.cid });
};

// the wrapper has the same testid, so match the button
const assigneePicker = target("the assignee picker", (tab) =>
	tab
		.locator('[data-component="TicketForm"] button[data-testid="assignee"]')
		.filter({ visible: true })
);
const peerOption = target("the peer in the picker", (tab, ctx) =>
	testid("option", { value: recall(ctx, "peer").did }).locate(tab, ctx)
);
const assignedTo = target("the assignee in the pull's header", (tab, ctx) =>
	testid("assignee", { handle: recall(ctx, "peer").handle }).locate(tab, ctx)
);

onBranches("assigning a pull request to a peer keeps the assignee after a reload")
	.pull(pullId, patchId, branches)
	.actor("peer")
	.step("remember the peer", remember("peer"))
	.member()
	.step("the peer comments on the pull", peerSays)

	.actor("owner")
	.open(page.pull(pullId))
	.click(moreActions)
	.click(editPull)
	.click(assigneePicker)
	.click(peerOption)
	.click(within(component("TicketForm"), testid("submit")))
	.sends(pullId, knot, replacing(pullId), "put")
	.trace(pullId, through(knot, hydrant, bobbin))
	.sees(assignedTo)
	.reload()
	.sees(assignedTo);

const afterWords = "a note on the second round";
const inRound = (round: string, words: string) =>
	within(
		testid("roundGroup", { version: round.replace(/^v/, "") }),
		within(testid("reviewCommentBody"), text(words))
	);

onBranches("a comment written after a resubmit files under the new round")
	.pull(pullId, patchId, branches)
	.push({ "e2e/more.txt": "more\n" }, { branch: branches.from })
	.mirrored()
	.open(page.pull(pullId))
	.sees(testid("resubmit"))
	.click(testid("resubmit"))
	.use(sendsPatch())
	.use(twoCommitRows)

	.fill(commentField, afterWords)
	.click(within(component("PullReviewCommentForm"), testid("submit")))
	.sends(
		commentId,
		knot,
		(ctx) => ({ record: { subject: { uri: ctx.get(pullId).uri } } }),
		"create"
	)
	.trace(commentId, through(knot, hydrant, bobbin))
	.trace(subscriptionId, through(pds))
	.sees(inRound("v1", afterWords))
	.sees(not(inRound("v0", afterWords)))
	.reload()
	.sees(inRound("v1", afterWords))
	.sees(not(inRound("v0", afterWords)));

const edited = "same here, again";

const cancel = within(component("PullReviewCommentEditor"), testid("cancel"));

onBranches("cancelling a pull comment edit leaves the comment as it was")
	.pull(pullId, patchId, branches)
	.open(page.pull(pullId))
	.fill(commentField, note)
	.click(within(component("PullReviewCommentForm"), testid("submit")))
	.trace(commentId, through(knot, hydrant, bobbin))
	.trace(subscriptionId, through(pds))
	.sees(within(testid("reviewCommentBody"), text(note)))

	.click(commentMenu)
	.click(testid("setEditing"))
	.fill(editor, edited)
	.click(cancel)
	.sendsNothing(commentId)
	.sees(within(testid("reviewCommentBody"), text(note)))
	.sees(not(within(testid("reviewCommentBody"), text(edited))))
	.reload()
	.sees(within(testid("reviewCommentBody"), text(note)))
	.sees(not(within(testid("reviewCommentBody"), text(edited))))
	.step(
		"the knot and hydrant still have the first version",
		stillStored(commentId, (value) => value.body.text, note)
	);