diff --git a/tests/e2e/repo-collab.test.ts b/tests/e2e/repo-collab.test.ts new file mode 100644 index 0000000000..bc4f9329ca --- /dev/null +++ b/tests/e2e/repo-collab.test.ts @@ -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); +}); diff --git a/tests/e2e/search-box.test.ts b/tests/e2e/search-box.test.ts deleted file mode 100644 index db54d64ed8..0000000000 --- a/tests/e2e/search-box.test.ts +++ /dev/null @@ -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); -}); diff --git a/tests/e2e/utils.ts b/tests/e2e/utils.ts index 049b80f504..3f7c8ed3d1 100644 --- a/tests/e2e/utils.ts +++ b/tests/e2e/utils.ts @@ -47,34 +47,6 @@ export async function apiCreateRepo(requestContext: APIRequestContext, {name, au }), 'apiCreateRepo'); } -export async function apiCreateOrg(requestContext: APIRequestContext, name: string, {headers}: {headers?: Record} = {}) { - 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} = {}) { - 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} = {}): Promise { - 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}) { await apiRetry(() => requestContext.post(`${baseUrl()}/api/v1/repos/${owner}/${repo}/issues`, { headers: headers || apiHeaders(),