import { Cookie } from "playwright"; import { expect } from "playwright/test"; import { App } from "../app"; type User = { email: string; password: string; }; type AuthCache = Array; const jira = { name: "Jira", userAuthEnvVars: { email: "ZYGON_GOOGLE_EMAIL", password: "ZYGON_GOOGLE_PASSWORD", }, login: async (user, page) => { await page.goto("https://id.atlassian.com/login"); await page.getByRole("button", { name: "Google" }).click(); await page.locator("input#identifierId").fill(user.email); await page.getByText("Next").click(); await page.locator("input[type=password]").fill(user.password); await page.getByText("Next").click(); await expect(page.getByText("G'day")).toBeVisible({ timeout: 20000 }); }, cacheAuth: async (_, context) => { return await context.cookies(); }, restoreAuthCache: async (cache, _, context) => { await context.addCookies(cache); }, listCollaborators: async (page) => { await page.goto("https://ventail.atlassian.net/jira/people/search"); await page.getByRole("link", { name: "Manage users" }).click(); const userManagementPromise = page.waitForEvent("popup"); const userManagement = await userManagementPromise; await expect( userManagement.getByText( "Manage product access for all the users in your organization", ), ).toBeVisible(); return await userManagement.$$eval("tbody tr", (elements) => elements.map((element) => ({ fullName: element.querySelector( 'td:nth-child(1) [data-testid="account-name"]', )!.textContent!, email: element.querySelector( "td:nth-child(1) a > div > div:last-child > div:last-child", )!.textContent!, })), ); }, addCollaborator: async (collaborator, page) => { await page.goto("https://ventail.atlassian.net/jira/people/search"); await page.getByRole("link", { name: "Manage users" }).click(); const userManagementPromise = page.waitForEvent("popup"); const userManagement = await userManagementPromise; await expect( userManagement.getByText( "Manage product access for all the users in your organization", ), ).toBeVisible(); await userManagement.getByRole("button", { name: "Invite users" }).click(); await userManagement .locator("#invite-users-email-input") .fill(collaborator.email); await userManagement.locator("#invite-users-email-input").blur(); await userManagement.getByTestId("invite-submit-button").click(); await expect( userManagement.getByText("1 user is successfully added to your org."), ).toBeVisible(); }, removeCollaborator: async (collaborator, page) => { await page.goto("https://ventail.atlassian.net/jira/people/search"); await page.getByRole("link", { name: "Manage users" }).click(); const userManagementPromise = page.waitForEvent("popup"); const userManagement = await userManagementPromise; await expect( userManagement.getByText( "Manage product access for all the users in your organization", ), ).toBeVisible(); await userManagement .getByRole("link", { name: collaborator.email }) .click(); await userManagement.waitForSelector( '[data-testid="user-details-role-table--body"]', ); const productList = await userManagement.$$eval( '[data-testid="user-details-role-table--body"] tr', (elements) => elements.map((element) => element.textContent), ); const productIndex = productList.findIndex((item) => item?.includes("Jira"), ); await userManagement .locator(`tbody tr:nth-child(${productIndex + 1}) td:last-of-type button`) .click(); await userManagement.getByText("Remove product access").click(); await expect( userManagement.getByText("Revoked product role for user"), ).toBeVisible(); }, } satisfies App; export default jira;