Skip to content

Commit

Permalink
user validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobbykumar706584 committed Sep 20, 2023
1 parent fee8d99 commit 57ba965
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 39 deletions.
87 changes: 51 additions & 36 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 { DisplayLogin, checkLogInOrNot, commonFile, commonFolder, commonJson, createProjects, projectValidation, starProject, unstarProject } from './common';
import { DisplayLogin, checkLogInOrNot, commonFile, commonFolder, commonJson, createProjects, createUserValidation, projectValidation, searchProject, starProject, unstarProject } from './common';

const fs = require('fs');
const { _electron: electron } = require('@playwright/test');
Expand Down Expand Up @@ -54,9 +54,9 @@ 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]');
Expand All @@ -69,8 +69,6 @@ test('Create a new user and login', async ({ userName }) => {
// // /* Translation Project */
test('Click New and Fill project page details to create a new project for text translation', async ({ textProject }) => {
await projectValidation(window, expect)
await expect(window.locator('//a[@aria-label="new"]')).toBeVisible()
await window.getByRole('link', { name: 'new' }).click()
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()
Expand All @@ -83,14 +81,16 @@ test('Click New and Fill project page details to create a new project for text t
await window.locator('//div[@aria-label="new-testament"]').click()
await window.locator('//button[contains(text(),"Ok")]').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
// ///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")
})
Expand All @@ -101,7 +101,7 @@ test('Click Click New and Fill project page details to create a new project for
})

// /* STAR & UNSTAR PROJECT */
// ///text translation
///text translation
test("Star the text project", async ({ textProject }) => {
await starProject(window, expect, textProject)
})
Expand All @@ -110,37 +110,52 @@ 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("Star the obs project", async ({ obsProject }) => {
// await starProject(window, expect, obsProject)
// })

test("Unstar the obs project", async ({ obsProject }) => {
await unstarProject(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)
})
// // ///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("Unstar the audio project", async ({ audioProject }) => {
// await unstarProject(window, expect, audioProject)
// })

test("Logout and delete that playwright user from the backend", async ({ userName }) => {
///return json
const json = await commonJson(window, userName, packageInfo, fs)
/// return file
const file = await commonFile(window, packageInfo)
/// return folde name
const folder = await commonFolder(window, userName, packageInfo)
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
if (currentUser.toLowerCase() === userName.toLowerCase() && await fs.existsSync(folder)) {
await DisplayLogin(fs, folder, userName, json, file, window, expect)
}
})
test('Search a text project in all projects list', async ({ textProject }) => {
await searchProject(window, expect, textProject, 'translation')
});



// test('Search an obs project in all projects list', async ({ obsProject }) => {
// await searchProject(window, expect, obsProject, 'obs')
// });

// test('Search an audio project in all projects list', async ({ audioProject }) => {
// await searchProject(window, expect, audioProject, 'audio')
// });



// test("Logout and delete that playwright user from the backend", async ({ userName }) => {
// ///return json
// const json = await commonJson(window, userName, packageInfo, fs)
// /// return file
// const file = await commonFile(window, packageInfo)
// /// return folde name
// const folder = await commonFolder(window, userName, packageInfo)
// 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
// if (currentUser.toLowerCase() === userName.toLowerCase() && await fs.existsSync(folder)) {
// await DisplayLogin(fs, folder, userName, json, file, window, expect)
// }
// })
26 changes: 23 additions & 3 deletions e2e-tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,29 @@ export const DisplayLogin = async (fs, folder, userName, json, file, window, exp
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.textContent('//*[@id="show-error"]')
expect(await lengthError).toBe('The input has to be between 3 and 15 characters long')
await window.getByPlaceholder('Username').fill('job')
await window.click('[type=submit]');
const userExistError = await window.textContent('//*[@id="show-error"]')
expect(await userExistError).toBe('User exists, Check archived and active tab by click on view more.')
}

export const projectValidation = async (window,expect) => {
await expect(window.locator('//a[@aria-label="new"]')).toBeVisible()
await window.getByRole('link', { name: 'new' }).click()
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')
expect(await snackbar).toBe('Fill all the fields')
const title = await window.textContent('[aria-label=projects]');
expect(title).toBe('New Project');
await window.waitForTimeout(5000)
}

export const createProjects = async (window, expect, projectname, type, description, abb) => {
Expand All @@ -83,7 +98,7 @@ export const createProjects = async (window, expect, projectname, type, descript
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]');
const title = await window.textContent('[aria-label=projects]', {timeout:10000});
expect(title).toBe('Projects');
}

Expand Down Expand Up @@ -113,7 +128,6 @@ export const unstarProject = async (window, expect, projectname) => {
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');
Expand All @@ -128,3 +142,9 @@ export const unstarProject = async (window, expect, projectname) => {
}
}

export const searchProject = async (window, expect, projectName, searchtext) => {
await expect(window.locator('//input[@id="search_box"]')).toBeVisible()
await window.locator('//input[@id="search_box"]').fill(searchtext)
const projectname = await window.innerText(`//*[@id="${projectName}"]`);
expect(projectname).toBe(projectName);
}

0 comments on commit 57ba965

Please sign in to comment.