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
|
import { test, expect } from "@playwright/test";
import {
uid,
TEST_PASSWORD,
pushTestCommit,
pushFeatureBranch,
cleanupDir,
} from "./fixtures";
let owner: string;
let repoName: string;
let featureBranch: string;
let tmpDir: string;
test.beforeAll(async ({ browser }) => {
owner = uid("pruser");
repoName = uid("prerepo");
featureBranch = uid("feat-");
const page = await browser.newPage();
await page.goto("/register");
await page.fill('input[name="username"]', owner);
await page.fill('input[name="email"]', `${owner}@test.example`);
await page.fill('input[name="password"]', TEST_PASSWORD);
await page.click('button[type="submit"]');
await page.waitForURL(/\/(dashboard|[a-z])/);
await page.goto("/new");
await page.fill('input[name="name"]', repoName);
await page.click('button[type="submit"]');
await page.waitForURL(new RegExp(`/${owner}/${repoName}`));
await page.close();
tmpDir = await pushTestCommit({
owner,
repo: repoName,
username: owner,
password: TEST_PASSWORD,
fileName: "README.md",
fileContent: `# ${repoName}\n`,
commitMsg: "Initial commit",
});
featureBranch = await pushFeatureBranch({
repoDir: tmpDir,
username: owner,
branchName: featureBranch,
fileName: "feature.md",
fileContent: "Feature branch content.\n",
commitMsg: "Add feature file",
});
});
test.afterAll(async () => {
await cleanupDir(tmpDir);
});
async function loginAsOwner(page: Parameters<typeof test>[1] extends never ? never : any): Promise<void> {
await page.goto("/login");
await page.fill('input[name="username"]', owner);
await page.fill('input[name="password"]', TEST_PASSWORD);
await page.click('button[type="submit"]');
await page.waitForURL(/\/(dashboard|[a-z])/);
}
test.describe("Pull request creation", () => {
test("PR list page is accessible", async ({ page }) => {
await page.goto(`/${owner}/${repoName}/pulls`);
await expect(page).toHaveURL(new RegExp(`/${owner}/${repoName}/pulls`));
await expect(page.locator("body")).not.toContainText(/500|Internal Server Error/i);
});
test("can open a new PR from the compare page", async ({ page }) => {
await loginAsOwner(page);
await page.goto(`/${owner}/${repoName}/compare/main...${featureBranch}`);
const titleInput = page.locator('input[name="title"]');
await expect(titleInput).toBeVisible({ timeout: 8_000 });
const prTitle = `E2E PR ${uid("pr")}`;
await titleInput.fill(prTitle);
await page.click('button[type="submit"]');
await expect(page).toHaveURL(new RegExp(`/${owner}/${repoName}/pulls/\\d+`));
await expect(page.locator("body")).toContainText(prTitle);
});
});
test.describe("Pull request comment", () => {
let prUrl: string;
test.beforeAll(async ({ browser }) => {
const page = await browser.newPage();
await loginAsOwner(page);
await page.goto(`/${owner}/${repoName}/compare/main...${featureBranch}`);
const titleInput = page.locator('input[name="title"]');
await titleInput.waitFor({ timeout: 8_000 });
await titleInput.fill(`Comment-test PR ${uid("c")}`);
await page.click('button[type="submit"]');
await page.waitForURL(new RegExp(`/${owner}/${repoName}/pulls/\\d+`));
prUrl = page.url();
await page.close();
});
test("can post a comment on a PR", async ({ page }) => {
await loginAsOwner(page);
await page.goto(prUrl);
const commentBox = page.locator(
'textarea[name="body"], textarea[name="comment"]'
).first();
await expect(commentBox).toBeVisible({ timeout: 8_000 });
const commentText = `Test comment ${uid("cmt")}`;
await commentBox.fill(commentText);
await page.click('button[type="submit"]');
await expect(page.locator("body")).toContainText(commentText, {
timeout: 8_000,
});
});
});
test.describe("Pull request merge", () => {
let prUrl: string;
test.beforeAll(async ({ browser }) => {
const page = await browser.newPage();
await loginAsOwner(page);
await page.goto(`/${owner}/${repoName}/compare/main...${featureBranch}`);
const titleInput = page.locator('input[name="title"]');
await titleInput.waitFor({ timeout: 8_000 });
await titleInput.fill(`Merge-test PR ${uid("m")}`);
await page.click('button[type="submit"]');
await page.waitForURL(new RegExp(`/${owner}/${repoName}/pulls/\\d+`));
prUrl = page.url();
await page.close();
});
test("merge button is visible on an open PR", async ({ page }) => {
await loginAsOwner(page);
await page.goto(prUrl);
const mergeBtn = page.locator(
'button:has-text("Merge"), button[name="action"][value="merge"], form[action*="merge"] button'
).first();
await expect(mergeBtn).toBeVisible({ timeout: 8_000 });
});
test("can merge an open PR", async ({ page }) => {
await loginAsOwner(page);
await page.goto(prUrl);
const mergeBtn = page.locator(
'button:has-text("Merge"), button[name="action"][value="merge"], form[action*="merge"] button'
).first();
if (await mergeBtn.isEnabled()) {
await mergeBtn.click();
await expect(page.locator("body")).toContainText(/merged/i, {
timeout: 10_000,
});
} else {
test.skip();
}
});
});
test.describe("Pull request close", () => {
let prUrl: string;
test.beforeAll(async ({ browser }) => {
const closeBranch = uid("close-");
await pushFeatureBranch({
repoDir: tmpDir,
username: owner,
branchName: closeBranch,
fileName: `close-${uid()}.md`,
fileContent: "Close branch file.\n",
commitMsg: "Add close-branch file",
});
const page = await browser.newPage();
await loginAsOwner(page);
await page.goto(`/${owner}/${repoName}/compare/main...${closeBranch}`);
const titleInput = page.locator('input[name="title"]');
await titleInput.waitFor({ timeout: 8_000 });
await titleInput.fill(`Close-test PR ${uid("cl")}`);
await page.click('button[type="submit"]');
await page.waitForURL(new RegExp(`/${owner}/${repoName}/pulls/\\d+`));
prUrl = page.url();
await page.close();
});
test("can close an open PR", async ({ page }) => {
await loginAsOwner(page);
await page.goto(prUrl);
const closeBtn = page.locator(
'button:has-text("Close"), button[value="close"], form[action*="close"] button'
).first();
await expect(closeBtn).toBeVisible({ timeout: 8_000 });
await closeBtn.click();
await expect(page.locator("body")).toContainText(/closed/i, {
timeout: 8_000,
});
});
});
|