diff --git a/e2e-tests/base.test.ts b/e2e-tests/base.test.ts index 1e3cc14bb..63158ce82 100644 --- a/e2e-tests/base.test.ts +++ b/e2e-tests/base.test.ts @@ -2,9 +2,10 @@ import { test, expect } from './myFixtures'; import packageInfo from '../package.json'; -import { DisplayLogin, checkLogInOrNot, commonFile, commonFolder, commonJson, removeFolderAndFile } from './common'; +import { showLoginPage, checkLogInOrNot, userFile, userFolder, userJson } from './common'; const fs = require('fs'); +const path = require('path'); const { _electron: electron } = require('@playwright/test'); let electronApp; @@ -24,31 +25,31 @@ test("Start the scribe application", async () => { }) -test('Check whether the app is being logged IN', async ({ userName }) => { - await checkLogInOrNot(window, expect, userName) +test('Check whether the app is being logged IN', async () => { + await checkLogInOrNot(window, expect) }); test('If logged IN then logout and delete that 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) + ///user json + const json = await userJson(window, packageInfo, fs, path) + /// user file + const file = await userFile(window, packageInfo, path) + /// user folde name + const folder = await userFolder(window, userName, packageInfo, path) - if (await checkLogInOrNot(window, expect, userName)) { + 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 if (currentUser.toLowerCase() === userName.toLowerCase() && await fs.existsSync(folder)) { - await DisplayLogin(fs, folder, userName, json, file, window, expect) + await showLoginPage(fs, folder, userName, json, file, window, expect) } } else { ///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 DisplayLogin(fs, folder, userName, json, file, window, expect) + await showLoginPage(fs, folder, userName, json, file, window, expect) } } @@ -67,17 +68,17 @@ test('Create a new user and login', async ({ userName }) => { 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) + ///user json + const json = await userJson(window, packageInfo, fs, path) + /// user file + 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() 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) + await showLoginPage(fs, folder, userName, json, file, window, expect) } }) \ No newline at end of file diff --git a/e2e-tests/common.js b/e2e-tests/common.js index 74916f3cc..0f2d1afb5 100644 --- a/e2e-tests/common.js +++ b/e2e-tests/common.js @@ -1,4 +1,4 @@ -export const checkLogInOrNot = async(window, expect, userName) => { +export const checkLogInOrNot = async(window, expect) => { await window.waitForSelector('//*[@id="__next"]/div', '//*[@id="__next"]/div[1]') const textVisble = await window.locator('//h1["@aria-label=projects"]', {timeout:3000}).isVisible() if (textVisble) { @@ -14,29 +14,26 @@ export const checkLogInOrNot = async(window, expect, userName) => { } export const filterUser = (json, name) => { - const filtered = json.filter((item) => - item.username.toLowerCase() !== name.toLowerCase() + const filtered = json.filter((user) => + user.username.toLowerCase() !== name.toLowerCase() ) return filtered } -export const commonJson = async(window, userName, packageInfo, fs) => { +export const userJson = async(window, packageInfo, fs, path) => { const newpath = await window.evaluate(() => Object.assign({}, window.localStorage)) - const path = require('path'); const file = path.join(newpath.userPath, packageInfo.name, 'users', 'users.json'); const data = await fs.readFileSync(file); return JSON.parse(data); } -export const commonFolder = async (window, userName, packageInfo) => { +export const userFolder = async (window, userName, packageInfo, path) => { const newpath = await window.evaluate(() => Object.assign({}, window.localStorage)) - const path = require('path'); return path.join(newpath.userPath, packageInfo.name, 'users', userName.toLowerCase()) } -export const commonFile = async (window, packageInfo) => { +export const userFile = async (window, packageInfo, path) => { const newpath = await window.evaluate(() => Object.assign({}, window.localStorage)) - const path = require('path'); return path.join(newpath.userPath, packageInfo.name, 'users', 'users.json'); } @@ -48,7 +45,7 @@ export const removeFolderAndFile = async (fs, folder, userName, json, file) => { return await fs.writeFileSync(file, JSON.stringify(filtered)) } -export const DisplayLogin = async (fs, folder, userName, json, file, window, expect) => { +export const showLoginPage = async (fs, folder, userName, json, file, window, expect) => { await removeFolderAndFile(fs, folder, userName, json, file) const welcome = await window.textContent('//*[@id="__next"]/div/div[1]/div/h2') await expect(welcome).toBe("Welcome!")