Skip to content

Commit

Permalink
validation test for project creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobbykumar706584 committed Sep 13, 2023
1 parent 5c24fa7 commit fee8d99
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
16 changes: 9 additions & 7 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, starProject, unstarProject } from './common';
import { DisplayLogin, checkLogInOrNot, commonFile, commonFolder, commonJson, createProjects, projectValidation, starProject, unstarProject } from './common';

const fs = require('fs');
const { _electron: electron } = require('@playwright/test');
Expand Down Expand Up @@ -65,9 +65,10 @@ test('Create a new user and login', async ({ userName }) => {
})


///CREATE PROJECTS FOR ALL FLAVOR TYPE
/*CREATE PROJECTS FOR ALL FLAVOR TYPE */
// // /* 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()
Expand All @@ -89,17 +90,18 @@ test('Click New and Fill project page details to create a new project for text t

});

// // // ///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")
})

// // /////Audio project
/////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")
})

///text translation
// /* STAR & UNSTAR PROJECT */
// ///text translation
test("Star the text project", async ({ textProject }) => {
await starProject(window, expect, textProject)
})
Expand All @@ -109,7 +111,7 @@ test("Unstar the text project", async ({ textProject }) => {
})


///obs
// ///obs
test("Star the obs project", async ({ obsProject }) => {
await starProject(window, expect, obsProject)
})
Expand All @@ -118,7 +120,7 @@ test("Unstar the obs project", async ({ obsProject }) => {
await unstarProject(window, expect, obsProject)
})

/////audio
// ///audio
test("Star the audio project", async ({ audioProject }) => {
await starProject(window, expect, audioProject)
})
Expand Down
60 changes: 41 additions & 19 deletions e2e-tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,43 @@ export const DisplayLogin = async (fs, folder, userName, json, file, window, exp
await window.reload()
}

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')
const title = await window.textContent('[aria-label=projects]');
expect(title).toBe('New Project');
}

export const createProjects = async (window, expect, projectname, type, description, abb) => {
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()
await window.locator(`//a[@data-id="${type}"]`).click()
////checking for create project validation
await projectValidation(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]');
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);
Expand All @@ -67,6 +100,10 @@ export const starProject = async(window, expect, 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)
}
}
}
Expand All @@ -76,33 +113,18 @@ 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');
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)
}
}
}

export const createProjects = async (window, expect, projectname, type, description, abb) => {
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()
await window.locator(`//a[@data-id="${type}"]`).click()
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]');
expect(title).toBe('Projects');
}

0 comments on commit fee8d99

Please sign in to comment.