mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-13 00:16:07 +02:00
Trim e2e to a single minimal collaborator-search test
Three boxes (repo/user/team) all share the same first-party module, so one happy-path test on the user box is sufficient as a regression gate. Drops the org/team helpers in tests/e2e/utils.ts that only those extra tests motivated. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
This commit is contained in:
parent
77f78076fe
commit
cfe9e70e3e
22
tests/e2e/repo-collab.test.ts
Normal file
22
tests/e2e/repo-collab.test.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import {env} from 'node:process';
|
||||
import {test, expect} from '@playwright/test';
|
||||
import {apiCreateRepo, apiCreateUser, login, randomString} from './utils.ts';
|
||||
|
||||
test('add collaborator search', async ({page, request}) => {
|
||||
const target = `rc-${randomString(8)}`;
|
||||
const repoName = `rc-${randomString(8)}`;
|
||||
|
||||
await apiCreateUser(request, target);
|
||||
await Promise.all([
|
||||
apiCreateRepo(request, {name: repoName, autoInit: false}),
|
||||
login(page),
|
||||
]);
|
||||
|
||||
await page.goto(`/${env.GITEA_TEST_E2E_USER}/${repoName}/settings/collaboration`);
|
||||
const input = page.locator('#search-user-box input.prompt');
|
||||
await input.fill(target.slice(-6));
|
||||
const result = page.locator('#search-user-box .results .result').first();
|
||||
await expect(result).toContainText(target);
|
||||
await result.click();
|
||||
await expect(input).toHaveValue(target);
|
||||
});
|
||||
@ -1,83 +0,0 @@
|
||||
import {test, expect} from '@playwright/test';
|
||||
import {apiCreateOrg, apiCreateOrgRepo, apiCreateRepo, apiCreateTeam, apiCreateUser, apiUserHeaders, loginUser, randomString} from './utils.ts';
|
||||
|
||||
// search queries use the unique random suffix (slice(-6)) to avoid result collisions
|
||||
// from concurrent workers' similarly-prefixed names
|
||||
|
||||
test('SearchRepoBox renders results and selects on click', async ({page, request}) => {
|
||||
const owner = `srb-${randomString(8)}`;
|
||||
const orgName = `srb-org-${randomString(8)}`;
|
||||
const repoName = `srb-repo-${randomString(8)}`;
|
||||
// a non-Owners team is required: the Owners team includes all repos, which hides the add-repo form
|
||||
const teamName = `srb-team-${randomString(8)}`;
|
||||
|
||||
await apiCreateUser(request, owner);
|
||||
const ownerHeaders = apiUserHeaders(owner);
|
||||
await apiCreateOrg(request, orgName, {headers: ownerHeaders});
|
||||
await Promise.all([
|
||||
apiCreateOrgRepo(request, orgName, repoName, {headers: ownerHeaders}),
|
||||
apiCreateTeam(request, orgName, teamName, {headers: ownerHeaders}),
|
||||
loginUser(page, owner),
|
||||
]);
|
||||
|
||||
await page.goto(`/org/${orgName}/teams/${teamName}/repositories`);
|
||||
|
||||
const box = page.locator('div[data-global-init="initSearchRepoBox"]');
|
||||
const input = box.locator('input.prompt');
|
||||
await input.fill(repoName.slice(-6));
|
||||
|
||||
const result = box.locator('.results .result').first();
|
||||
await expect(result).toContainText(repoName);
|
||||
await result.click();
|
||||
await expect(input).toHaveValue(new RegExp(repoName));
|
||||
});
|
||||
|
||||
test('SearchUserBox renders results and selects on click', async ({page, request}) => {
|
||||
const owner = `sub-${randomString(8)}`;
|
||||
const target = `sub-target-${randomString(8)}`;
|
||||
const repoName = `sub-repo-${randomString(8)}`;
|
||||
|
||||
await Promise.all([apiCreateUser(request, owner), apiCreateUser(request, target)]);
|
||||
await Promise.all([
|
||||
apiCreateRepo(request, {name: repoName, headers: apiUserHeaders(owner)}),
|
||||
loginUser(page, owner),
|
||||
]);
|
||||
|
||||
await page.goto(`/${owner}/${repoName}/settings/collaboration`);
|
||||
|
||||
const box = page.locator('#search-user-box');
|
||||
const input = box.locator('input.prompt');
|
||||
await input.fill(target.slice(-6));
|
||||
|
||||
const result = box.locator('.results .result').first();
|
||||
await expect(result).toContainText(target);
|
||||
await result.click();
|
||||
await expect(input).toHaveValue(target);
|
||||
});
|
||||
|
||||
test('SearchTeamBox renders results and selects on click', async ({page, request}) => {
|
||||
const owner = `stb-${randomString(8)}`;
|
||||
const orgName = `stb-org-${randomString(8)}`;
|
||||
const repoName = `stb-repo-${randomString(8)}`;
|
||||
const teamName = `stb-team-${randomString(8)}`;
|
||||
|
||||
await apiCreateUser(request, owner);
|
||||
const ownerHeaders = apiUserHeaders(owner);
|
||||
await apiCreateOrg(request, orgName, {headers: ownerHeaders});
|
||||
await Promise.all([
|
||||
apiCreateOrgRepo(request, orgName, repoName, {headers: ownerHeaders}),
|
||||
apiCreateTeam(request, orgName, teamName, {headers: ownerHeaders}),
|
||||
loginUser(page, owner),
|
||||
]);
|
||||
|
||||
await page.goto(`/${orgName}/${repoName}/settings/collaboration`);
|
||||
|
||||
const box = page.locator('#search-team-box');
|
||||
const input = box.locator('input.prompt');
|
||||
await input.fill(teamName.slice(-6));
|
||||
|
||||
const result = box.locator('.results .result').first();
|
||||
await expect(result).toContainText(teamName);
|
||||
await result.click();
|
||||
await expect(input).toHaveValue(teamName);
|
||||
});
|
||||
@ -47,34 +47,6 @@ export async function apiCreateRepo(requestContext: APIRequestContext, {name, au
|
||||
}), 'apiCreateRepo');
|
||||
}
|
||||
|
||||
export async function apiCreateOrg(requestContext: APIRequestContext, name: string, {headers}: {headers?: Record<string, string>} = {}) {
|
||||
await apiRetry(() => requestContext.post(`${baseUrl()}/api/v1/orgs`, {
|
||||
headers: headers || apiHeaders(),
|
||||
data: {username: name},
|
||||
}), 'apiCreateOrg');
|
||||
}
|
||||
|
||||
export async function apiCreateOrgRepo(requestContext: APIRequestContext, org: string, name: string, {headers}: {headers?: Record<string, string>} = {}) {
|
||||
await apiRetry(() => requestContext.post(`${baseUrl()}/api/v1/orgs/${org}/repos`, {
|
||||
headers: headers || apiHeaders(),
|
||||
data: {name, auto_init: true},
|
||||
}), 'apiCreateOrgRepo');
|
||||
}
|
||||
|
||||
/** Create a team with read permission on a fixed unit set, returning the team id. */
|
||||
export async function apiCreateTeam(requestContext: APIRequestContext, org: string, name: string, {includesAllRepositories = false, headers}: {includesAllRepositories?: boolean; headers?: Record<string, string>} = {}): Promise<number> {
|
||||
let teamID = 0;
|
||||
await apiRetry(async () => {
|
||||
const response = await requestContext.post(`${baseUrl()}/api/v1/orgs/${org}/teams`, {
|
||||
headers: headers || apiHeaders(),
|
||||
data: {name, permission: 'read', includes_all_repositories: includesAllRepositories, units: ['repo.code', 'repo.issues', 'repo.pulls']},
|
||||
});
|
||||
if (response.ok()) teamID = (await response.json()).id;
|
||||
return response;
|
||||
}, 'apiCreateTeam');
|
||||
return teamID;
|
||||
}
|
||||
|
||||
export async function apiCreateIssue(requestContext: APIRequestContext, owner: string, repo: string, {title, headers}: {title: string; headers?: Record<string, string>}) {
|
||||
await apiRetry(() => requestContext.post(`${baseUrl()}/api/v1/repos/${owner}/${repo}/issues`, {
|
||||
headers: headers || apiHeaders(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user