diff --git a/e2e-tests/base.test.ts b/e2e-tests/base.test.ts index 0c7daba54..6b0b1425b 100644 --- a/e2e-tests/base.test.ts +++ b/e2e-tests/base.test.ts @@ -2,7 +2,7 @@ import { test, expect } from './myFixtures'; import packageInfo from '../package.json'; -import { showLoginPage, checkLogInOrNot, userFile, userFolder, userJson, createUserValidation, createProjectValidation, createProjects, unstarProject, starProject } from './common'; +import { showLoginPage, checkLogInOrNot, userFile, userFolder, userJson, createProjectValidation, createProjects, unstarProject, starProject, userValidation, signOut, showActiveUsers } from './common'; const fs = require('fs'); const path = require('path'); @@ -38,9 +38,11 @@ test('If logged IN then logout and delete that user from the backend', async ({ const folder = await userFolder(window, userName, packageInfo, path) if (await checkLogInOrNot(window, expect)) { - await window.getByRole('button', { name: "Open user menu" }).click() + expect(await window.locator('//*[@id="user-profile"]')).toBeVisible() + await window.locator('//*[@id="user-profile"]').click() const currentUser = await window.textContent('[aria-label="userName"]') - await window.getByRole('menuitem', { name: "Sign out" }).click() + expect(await window.locator('//*[@aria-label="signout"]')).toBeVisible() + await window.locator('//*[@aria-label="signout"]').click() // projects page then logout and delete playwright user if (currentUser.toLowerCase() === userName.toLowerCase() && await fs.existsSync(folder)) { await showLoginPage(fs, folder, userName, json, file, window, expect) @@ -57,19 +59,20 @@ test('If logged IN then logout and delete that user from the backend', async ({ test('Create a new user and login', async ({ userName }) => { - await createUserValidation(window, expect) - await window.getByPlaceholder('Username').fill(userName) + await userValidation(window, expect) + await window.locator('//input[@placeholder="Username"]').fill(userName) await expect(window.locator('//button[@type="submit"]')).toBeVisible() await window.click('[type=submit]'); const title = await window.textContent('[aria-label=projects]'); expect(title).toBe('Projects'); }) + /*CREATE PROJECTS FOR ALL FLAVOR TYPE */ /* Translation Project */ test('Click New and Fill project page details to create a new project for text translation with custom book', async ({ textProject }) => { await expect(window.locator('//a[@aria-label="new"]')).toBeVisible() - await window.getByRole('link', { name: 'new' }).click() + await window.locator('//a[@aria-label="new"]').click() await createProjectValidation(window, expect) await expect(window.locator('//input[@id="project_name"]')).toBeVisible() await window.locator('//input[@id="project_name"]').fill(textProject) @@ -81,8 +84,8 @@ test('Click New and Fill project page details to create a new project for text t await window.locator('//button[@id="open-advancesettings"]').click() await expect(window.locator('//div[@aria-label="custom-book"]')).toBeVisible() await window.locator('//div[@aria-label="custom-book"]').click() - await window.getByLabel('nt-Matthew').click() - await window.getByRole('button', { name: 'Save' }).click() + await window.locator('//*[@aria-label="nt-Matthew"]').click() + await window.locator('//*[@id="save-canon"]').click() await window.locator('//button[@aria-label="create"]').click() const notifyMe = await window.textContent('//*[@id="__next"]/div/div[2]/div[2]/div/div') expect(await notifyMe).toBe('New project created') @@ -130,6 +133,47 @@ test("Unstar the audio project", async ({ audioProject }) => { await unstarProject(window, expect, audioProject) }) +test("Sign out the Application", async () => { + await signOut(window, expect) +}) + +test("Click the view users button, log in with playwright user, and sign out", async ({ userName }) => { + await showActiveUsers(window, expect) + const tabContent = await window.locator('//*[@id="active-tab-content"]') + const div = await tabContent.locator("div > div") + for (let i = 0; i < await div.count(); i++) { + if (await div.nth(i).textContent() === userName.toLowerCase()) { + await div.nth(i).click() + await window.waitForTimeout(2000) + const title = await window.textContent('[aria-label=projects]') + await expect(title).toBe('Projects') + await signOut(window, expect) + } + } +}) + +test("Delete the user from the active tab and check in the archived tab", async ({ userName }) => { + await showActiveUsers(window, expect) + const tabContent = await window.locator('//*[@id="active-tab-content"]') + const items = await tabContent.locator('div > div') + const div = await tabContent.locator("div > button") + for (let i = 0; i < await items.count(); i++) { + if (await items.nth(i).textContent() === userName.toLowerCase()) { + await div.nth(i).click() + expect(await window.locator('//*[@id="archived-tab"]')).toBeVisible() + await window.locator('//*[@id="archived-tab"]').click() + const text = await window.locator('//*[@id="archived-tab"]').textContent() + expect(await text).toBe('Archived') + await window.getByLabel('Archived').locator('button').click() + expect(await window.locator('//*[@id="active-tab"]')).toBeVisible() + await window.locator('//*[@id="active-tab"]').click() + await window.getByRole('button', { name: userName.toLowerCase() }).click() + } + } + const title = await window.textContent('[aria-label=projects]') + await expect(title).toBe('Projects') +}) + test("Logout and delete that playwright user from the backend", async ({ userName }) => { // user json const json = await userJson(window, packageInfo, fs, path) @@ -137,9 +181,11 @@ test("Logout and delete that playwright user from the backend", async ({ userNam const file = await userFile(window, packageInfo, path) // user folde name const folder = await userFolder(window, userName, packageInfo, path) - await window.getByRole('button', { name: "Open user menu" }).click() + expect(await window.locator('//*[@id="user-profile"]')).toBeVisible() + await window.locator('//*[@id="user-profile"]').click() const currentUser = await window.textContent('[aria-label="userName"]') - await window.getByRole('menuitem', { name: "Sign out" }).click() + expect(await window.locator('//*[@aria-label="signout"]')).toBeVisible() + await window.locator('//*[@aria-label="signout"]').click() // projects page then logout and delete playwright user if (currentUser.toLowerCase() === userName.toLowerCase() && await fs.existsSync(folder)) { await showLoginPage(fs, folder, userName, json, file, window, expect) diff --git a/e2e-tests/common.js b/e2e-tests/common.js index e97127a8d..3d8c36547 100644 --- a/e2e-tests/common.js +++ b/e2e-tests/common.js @@ -51,10 +51,12 @@ export const showLoginPage = async (fs, folder, userName, json, file, window, ex await expect(welcome).toBe("Welcome!") await window.reload() } -export const createUserValidation = async (window, expect) => { - await window.getByRole('button', { name: 'Create New Account' }).click() + +export const userValidation = async (window, expect) => { + expect(await window.locator('//*[@aria-label="create-new-account"]')).toBeVisible() + await window.locator('//*[@aria-label="create-new-account"]').click() await expect(window.locator('//input[@placeholder="Username"]')).toBeVisible() - await window.getByPlaceholder('Username').fill('jo') + await window.locator('//input[@placeholder="Username"]').fill('jo') await expect(window.locator('//button[@type="submit"]')).toBeVisible() await window.click('[type=submit]'); const lengthError = await window.locator('//*[@id="show-error"]') @@ -74,7 +76,7 @@ export const createProjectValidation = async (window, expect) => { /* function for creating a project for obs and audio */ export const createProjects = async (window, expect, projectname, type, description, abb) => { await expect(window.locator('//a[@aria-label="new"]')).toBeVisible() - await window.getByRole('link', { name: 'new' }).click() + await window.locator('//a[@aria-label="new"]').click() await expect(window.locator('//button[@aria-label="open-popover"]')).toBeVisible() await window.locator('//button[@aria-label="open-popover"]').click() await expect(window.locator(`//a[@data-id="${type}"]`)).toBeVisible() @@ -135,4 +137,22 @@ export const unstarProject = async (window, expect, projectname) => { } const title = await window.textContent('[aria-label=projects]', { timeout: 10000 }); expect(title).toBe('Projects'); +} + +export const signOut = async (window, expect) => { + expect(await window.locator('//*[@id="user-profile"]')).toBeVisible() + await window.locator('//*[@id="user-profile"]').click() + expect(await window.locator('//*[@aria-label="signout"]')).toBeVisible() + await window.locator('//*[@aria-label="signout"]').click() + await window.waitForTimeout(1000) + const welcome = await window.textContent('//*[@id="__next"]/div/div[1]/div/h2') + await expect(welcome).toBe("Welcome!") + +} + +export const showActiveUsers = async (window, expect) => { + expect(await window.locator('//*[@id="view-more"]')).toBeVisible() + await window.locator('//*[@id="view-more"]').click() + const active = await window.locator('//*[@id="active-tab"]').textContent() + expect(await active).toBe("Active") } \ No newline at end of file diff --git a/renderer/src/components/Login/LeftLogin.js b/renderer/src/components/Login/LeftLogin.js index 539e88751..89b5215d6 100644 --- a/renderer/src/components/Login/LeftLogin.js +++ b/renderer/src/components/Login/LeftLogin.js @@ -207,6 +207,7 @@ const LeftLogin = () => {