Skip to content

Commit

Permalink
Merge pull request #164 from bible-technology/testTranslation
Browse files Browse the repository at this point in the history
Test for text translation, obs and audio
  • Loading branch information
vipinpaul authored Sep 27, 2023
2 parents 25ad4ef + 653d8fb commit 6e1f10e
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 16 deletions.
89 changes: 76 additions & 13 deletions e2e-tests/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { test, expect } from './myFixtures';
import packageInfo from '../package.json';
import { showLoginPage, checkLogInOrNot, userFile, userFolder, userJson } from './common';
import { showLoginPage, checkLogInOrNot, userFile, userFolder, userJson, createUserValidation, createProjectValidation, createProjects, unstarProject, starProject } from './common';

const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -30,23 +30,23 @@ test('Check whether the app is being logged IN', async () => {
});

test('If logged IN then logout and delete that user from the backend', async ({ userName }) => {
///user json
//user json
const json = await userJson(window, packageInfo, fs, path)
/// user file
// user file
const file = await userFile(window, packageInfo, path)
/// user folde name
// user folde name
const folder = await userFolder(window, userName, packageInfo, path)

if (await checkLogInOrNot(window, expect)) {
await window.getByRole('button', { name: "Open user menu" }).click()
const currentUser = await window.textContent('[aria-label="userName"]')
await window.getByRole('menuitem', { name: "Sign out" }).click()
/// projects page then logout and delete playwright user
// 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)
}
} else {
///loging page, if playwright user exist then reload app and remove
// loging page, if playwright user exist then reload app and remove
const existUser = json.some((item) => item.username.toLowerCase() === userName.toLowerCase())
if (existUser && await fs.existsSync(folder)) {
await showLoginPage(fs, folder, userName, json, file, window, expect)
Expand All @@ -57,28 +57,91 @@ test('If logged IN then logout and delete that user from the backend', async ({


test('Create a new user and login', async ({ userName }) => {
await window.getByRole('button', { name: 'Create New Account' }).click()
await expect(window.locator('//input[@placeholder="Username"]')).toBeVisible()
await createUserValidation(window, expect)
await window.getByPlaceholder('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 createProjectValidation(window, expect)
await expect(window.locator('//input[@id="project_name"]')).toBeVisible()
await window.locator('//input[@id="project_name"]').fill(textProject)
await expect(window.locator('//textarea[@id="project_description"]')).toBeVisible()
await window.locator('//textarea[@id="project_description"]').fill('test description')
await expect(window.locator('//input[@id="version_abbreviated"]')).toBeVisible()
await window.locator('//input[@id="version_abbreviated"]').fill('ttp')
await expect(window.locator('//button[@id="open-advancesettings"]')).toBeVisible()
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('//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')
const projectName = await window.innerText(`//div[@id="${textProject}"]`)
expect(projectName).toBe(textProject);
const title = await window.textContent('[aria-label=projects]');
expect(title).toBe('Projects');
})

/* Obs translation project */
test('Click New and Fill project page details to create a new project for obs', async ({ obsProject }) => {
await createProjects(window, expect, obsProject, "OBS", "test description", "otp")
})

/* Audio project */
test('Click Click New and Fill project page details to create a new project for audio', async ({ audioProject }) => {
await createProjects(window, expect, audioProject, "Audio", "test description", "atp")
})

/* STAR & UNSTAR PROJECT */
// text translation
test("Star the text project", async ({ textProject }) => {
await starProject(window, expect, textProject)
})

test("Unstar the text project", async ({ textProject }) => {
await unstarProject(window, expect, textProject)
})

// obs
test("Star the obs project", async ({ obsProject }) => {
await starProject(window, expect, obsProject)
})

test("Unstar the obs project", async ({ obsProject }) => {
await unstarProject(window, expect, obsProject)
})

// audio
test("Star the audio project", async ({ audioProject }) => {
await starProject(window, expect, audioProject)
})

test("Unstar the audio project", async ({ audioProject }) => {
await unstarProject(window, expect, audioProject)
})

test("Logout and delete that playwright user from the backend", async ({ userName }) => {
///user json
// user json
const json = await userJson(window, packageInfo, fs, path)
/// user file
// user file
const file = await userFile(window, packageInfo, path)
/// user folde name
// user folde name
const folder = await userFolder(window, userName, packageInfo, path)
await window.getByRole('button', { name: "Open user menu" }).click()
const currentUser = await window.textContent('[aria-label="userName"]')
await window.getByRole('menuitem', { name: "Sign out" }).click()
/// projects page then logout and delete playwright user
// 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)
}
})
})
85 changes: 85 additions & 0 deletions e2e-tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,89 @@ export const showLoginPage = async (fs, folder, userName, json, file, window, ex
const welcome = await window.textContent('//*[@id="__next"]/div/div[1]/div/h2')
await expect(welcome).toBe("Welcome!")
await window.reload()
}
export const createUserValidation = async (window, expect) => {
await window.getByRole('button', { name: 'Create New Account' }).click()
await expect(window.locator('//input[@placeholder="Username"]')).toBeVisible()
await window.getByPlaceholder('Username').fill('jo')
await expect(window.locator('//button[@type="submit"]')).toBeVisible()
await window.click('[type=submit]');
const lengthError = await window.locator('//*[@id="show-error"]')
expect(await lengthError === true)
expect(await lengthError.textContent()).toBe('The input has to be between 3 and 15 characters long')
}

export const createProjectValidation = async (window, expect) => {
await window.locator('//button[@aria-label="create"]').click()
const snackbar = await window.textContent('//*[@id="__next"]/div/div[2]/div[2]/div/div')
expect(await snackbar).toBe('Fill all the fields')
const title = await window.textContent('[aria-label=projects]');
expect(title).toBe('New Project');
await window.waitForTimeout(3000)
}

/* 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 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()
await window.locator(`//a[@data-id="${type}"]`).click()
// checking for create project validation
await createProjectValidation(window, expect)
await expect(window.locator('//input[@id="project_name"]')).toBeVisible()
await window.locator('//input[@id="project_name"]').fill(projectname)
await expect(window.locator('//textarea[@id="project_description"]')).toBeVisible()
await window.locator('//textarea[@id="project_description"]').fill(description)
await expect(window.locator('//input[@id="version_abbreviated"]')).toBeVisible()
await window.locator('//input[@id="version_abbreviated"]').fill(abb)
await expect(window.locator('//button[@aria-label="create"]')).toBeVisible()
await window.locator('//button[@aria-label="create"]').click()
const projectName = await window.innerText(`//div[@id="${projectname}"]`)
expect(projectName).toBe(projectname);
const title = await window.textContent('[aria-label=projects]', { timeout: 10000 });
expect(title).toBe('Projects');
}

export const starProject = async (window, expect, projectname) => {
await expect(window.locator('//*[@id="projects-list"]')).toBeVisible()
const table = window.locator('//*[@id="projects-list"]')
const body = table.locator('//*[@id="projects-list-unstar"]')
const starBody = table.locator('//*[@id="projects-list-star"]')
const rows = await body.locator('tr')
for (let i = 0; i < await rows.count(); i++) {
const row = await rows.nth(i);
const tds = await row.locator('td');
if (await tds.nth(1).textContent() === projectname) {
expect(await tds.first().locator('[aria-label=unstar-project]')).toBeVisible()
await tds.first().locator('[aria-label=unstar-project]').click()
expect(await rows.count()).toBe(2)
const starRows = await starBody.locator('tr')
const starProjectName = await starRows.locator("td").nth(1).innerText()
expect(await starProjectName).toBe(projectname)
expect(await starRows.count()).toBe(1)
}
}
}

export const unstarProject = async (window, expect, projectname) => {
await expect(window.locator('//*[@id="projects-list"]')).toBeVisible()
const table = window.locator('//*[@id="projects-list"]')
const body = table.locator('//*[@id="projects-list-star"]')
const rows = await body.locator('tr')
for (let i = 0; i < await rows.count(); i++) {
const row = await rows.nth(i);
const tds = await row.locator('td');
if (await tds.nth(1).textContent() === projectname) {
expect(await tds.first().locator('[aria-label=star-project]')).toBeVisible()
await tds.first().locator('[aria-label=star-project]').click()
const unstarBody = table.locator('//*[@id="projects-list-unstar"]')
const unstarRows = await unstarBody.locator('tr')
expect(await rows.count()).toBe(0)
expect(await unstarRows.count()).toBe(3)
}
}
const title = await window.textContent('[aria-label=projects]', { timeout: 10000 });
expect(title).toBe('Projects');
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export default function AdvancedSettingsDropdown({ call, project, projectType })
onClick={() => selectCanon(canonList[3])}
role="button"
tabIndex="0"
aria-label="custom-book"
>
{t('label-custom')}
</div>
Expand Down
6 changes: 3 additions & 3 deletions renderer/src/modules/projects/ProjectList.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ export default function ProjectList() {
<div className="-my-2 sm:-mx-6 lg:-mx-8">
<div className="align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div className="shadow border-b border-gray-200 sm:rounded-lg">
<table data-testid="tablelayout" className="min-w-full divide-y divide-gray-200 mb-9">
<table id="projects-list" data-testid="tablelayout" className="min-w-full divide-y divide-gray-200 mb-9">
<EnhancedTableHead
order={order}
orderBy={orderBy}
onRequestSort={handleRequestSort}
/>
<tbody className="bg-white divide-y divide-gray-200">
<tbody id="projects-list-star" className="bg-white divide-y divide-gray-200">
{starredrow && (stableSort(
starredrow,
getComparator(order, orderBy),
Expand Down Expand Up @@ -310,7 +310,7 @@ export default function ProjectList() {
))
)}
</tbody>
<tbody className="bg-white divide-y divide-gray-200">
<tbody id="projects-list-unstar" className="bg-white divide-y divide-gray-200">
{unstarredrow && (stableSort(
unstarredrow,
getComparator(order, orderBy),
Expand Down

0 comments on commit 6e1f10e

Please sign in to comment.