Skip to content

Commit

Permalink
removed unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobbykumar706584 committed Sep 26, 2023
1 parent a061d67 commit 252a0d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
39 changes: 20 additions & 19 deletions e2e-tests/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
}
}

Expand All @@ -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)
}
})
17 changes: 7 additions & 10 deletions e2e-tests/common.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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');
}

Expand All @@ -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!")
Expand Down

0 comments on commit 252a0d8

Please sign in to comment.