From 663585956b344582a75370a19284320ee3d46426 Mon Sep 17 00:00:00 2001 From: Filippo Ledda Date: Wed, 12 Oct 2022 19:19:58 +0200 Subject: [PATCH] Improve e2e tests --- .../src/components/common/OSBSpliButton.tsx | 3 +- .../src/components/header/Header.tsx | 4 +- .../workspace/WorkspaceActionsMenu.tsx | 29 +- .../components/workspace/WorkspaceCard.tsx | 6 +- .../osb-portal/test/e2e/main_flows.spec.ts | 576 ++++++------------ applications/osb-portal/test/e2e/selectors.ts | 59 +- 6 files changed, 230 insertions(+), 447 deletions(-) diff --git a/applications/osb-portal/src/components/common/OSBSpliButton.tsx b/applications/osb-portal/src/components/common/OSBSpliButton.tsx index 346248a9..411c3a69 100644 --- a/applications/osb-portal/src/components/common/OSBSpliButton.tsx +++ b/applications/osb-portal/src/components/common/OSBSpliButton.tsx @@ -54,13 +54,14 @@ export const OSBSplitButton = (props: OSBSplitButtonProps) => { ref={anchorRef} aria-label="split button" > - + ) : ( @@ -132,7 +132,7 @@ export const Header = (props: any) => { aria-haspopup="true" onClick={handleMenuToggle} startIcon={} - className={classes.button} + className={`${classes.button} user-menu-btn`} > {user.username} diff --git a/applications/osb-portal/src/components/workspace/WorkspaceActionsMenu.tsx b/applications/osb-portal/src/components/workspace/WorkspaceActionsMenu.tsx index 4e130b53..e22e5c96 100644 --- a/applications/osb-portal/src/components/workspace/WorkspaceActionsMenu.tsx +++ b/applications/osb-portal/src/components/workspace/WorkspaceActionsMenu.tsx @@ -124,52 +124,53 @@ export default (props: WorkspaceActionsMenuProps) => { return ( <> - + - {canEdit && Edit} - {canEdit && Delete} + {canEdit && Edit} + {canEdit && Delete} {canEdit && !props.workspace.publicable && ( - Make public + Make public )} {canEdit && props.workspace.publicable && ( - Make private + Make private )} {props.user && props.user.isAdmin && props.workspace.publicable && !props.workspace.featured && ( - + Add to featured )} {props.user && props.user.isAdmin && props.workspace.featured && ( - + Remove from featured )} {!props.isWorkspaceOpen && ( - Open workspace + Open workspace )} {props.user && ( Clone workspace )} - - {Object.keys(OSBApplications).map((item) => ( + + {Object.keys(OSBApplications).map((appCode) => ( { - handleOpenWorkspaceWithApp(item); + handleOpenWorkspaceWithApp(appCode); }} > - {OSBApplications[item].name} + {OSBApplications[appCode].name} ))} diff --git a/applications/osb-portal/src/components/workspace/WorkspaceCard.tsx b/applications/osb-portal/src/components/workspace/WorkspaceCard.tsx index e557950f..1cd2a5ac 100644 --- a/applications/osb-portal/src/components/workspace/WorkspaceCard.tsx +++ b/applications/osb-portal/src/components/workspace/WorkspaceCard.tsx @@ -116,7 +116,7 @@ export const WorkspaceCard = (props: Props) => { return ( <> - + {!props.hideMenu && ( { - + { - if (!process.env.SKIP_SMOKETEST) { - beforeAll(async () => { - browser = await puppeteer.launch({ - args: ["--no-sandbox", `--window-size=1600,700`], - headless: true, - defaultViewport: { - width: 1600, - height: 700, - }, - }); +const WORKSPACE_LOAD_TIMEOUT = TWO_MINUTES * 1.5; - page = await browser.newPage(); - console.log( - "Checking page", - process.env.APP_URL || "https://v2dev.opensourcebrain.org/" - ); - await page - .goto(process.env.APP_URL || "https://v2dev.opensourcebrain.org/", { - waitUntil: "networkidle0", - }) - .catch(() => {}); +const getCurrentWorkpaces: () => Promise> = async () => { + const pageFrame = page.mainFrame(); + return await pageFrame.$$( + "#workspaces-list .workspace-content" + ) +}; - console.log("Env", process.env); +const testApplication = + (appName: string, appSelectors: Array, url: string) => async () => { + console.log("Opening workspace with", appName); + await page.waitForSelector(selectors.OSB_LOGO); + await page.click(selectors.OSB_LOGO); - await page.waitForSelector(selectors.WORKSPACES_SELECTOR); - }); + await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE); - afterAll(() => { - browser.close(); - }); + // Try to open an already existing workspace + await page.waitForSelector(selectors.FEATURE_WORKSPACES_TAB); + await page.click(selectors.FEATURE_WORKSPACES_TAB); - test("Home Page", async () => { - await page.click(selectors.PUBLIC_WORKSPACES_SELECTOR); - await page.waitForSelector(selectors.WORKSPACES_SELECTOR); - await page.waitForTimeout(ONE_SECOND * 2); - }); + await page.waitForSelector(selectors.WORKSPACES); + const featuredWorkspaces = await getCurrentWorkpaces(); - test("Log in", async () => { - console.log("Attempting login on", page.url()); - - await page.evaluate(() => { - let map = document.getElementsByClassName( - "MuiButton-label" - ) as HTMLCollectionOf; - for (let i = 0; i < map.length; i++) { - map[i].innerText == "Sign in" && map[i].click(); - } - }); - - await page.waitForSelector(selectors.USERNAME_SELECTOR); - await page.waitForSelector(selectors.PASSWORD_SELECTOR); - expect(page.url()).toContain("accounts."); - await page.type( - selectors.USERNAME_SELECTOR, - process.env.USERNAME || "simao_user_osb" - ); - await page.type( - selectors.PASSWORD_SELECTOR, - process.env.PASSWORD || "metacell" - ); - await page.click(selectors.LOGIN_BUTTON_SELECTOR); - await page.waitForSelector(selectors.ALL_YOUR_WORKSPACES_TAB_SELECTOR); - - await page.waitForSelector(selectors.YOUR_WORKSPACES_SELECTOR); - const privateWorkspaces_beforeadding = await page.evaluate( - () => - document.querySelectorAll( - 'div[class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-6 MuiGrid-grid-sm-4 MuiGrid-grid-md-6 MuiGrid-grid-lg-4 MuiGrid-grid-xl-3"]' - ).length - ); - expect(privateWorkspaces_beforeadding).toBe(0); - }); - test("Create workspace", async () => { - console.log("Creating workspace"); - - await page.click(selectors.CREATE_WORKSPACE_SELECTOR); - await page.waitForSelector(selectors.WORKSPACE_CREATION_BOX_SELECTOR); - await page.type( - selectors.WORKSPACE_NAME_SELECTOR, - "Smoke Test Workspace" - ); - await page.type(selectors.WORKSPACE_TAGS_SELECTOR, "Test"); - await page.keyboard.press("Enter"); - await page.type( - selectors.WORKSPACE_DESCRIPTION_SELECTOR, - "Workspace created by the Automated Smoke tests" - ); + // Try to open an already existing workspace to speed up + if (featuredWorkspaces.length > 0) { + await page.click(".workspace-page-link"); + } else { await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.CREATE_NEW_WORKSPACE_SELECTOR) - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.waitForSelector(selectors.YOUR_WORKSPACES_SELECTOR); - - const privateWorkspaces = await page.evaluate( - () => - document.querySelectorAll( - 'div[class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-6 MuiGrid-grid-sm-4 MuiGrid-grid-md-6 MuiGrid-grid-lg-4 MuiGrid-grid-xl-3"]' - ).length - ); - expect(privateWorkspaces).toBe(1); - }); - - test("Open workspace with NWB Explorer", async () => { - console.log("Opening workspace with NWB Explorer"); - - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.OSB_LOGO_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.FEATURE_WORKSPACES_TAB_SELECTOR); - await page.waitForSelector(selectors.NEURO_ML2_WORKSPACE_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - const featuredWorkspaces = await page.evaluate( - () => - document.querySelectorAll( - 'div[class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-6 MuiGrid-grid-sm-4 MuiGrid-grid-md-6 MuiGrid-grid-lg-4 MuiGrid-grid-xl-3"]' - ).length - ); - await page.click(selectors.OSB_LOGO_SELECTOR); - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - - if (featuredWorkspaces != 0) { - await page.waitForTimeout(ONE_SECOND); - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.FEATURE_WORKSPACES_TAB_SELECTOR); - await page.waitForSelector(selectors.NEURO_ML2_WORKSPACE_SELECTOR); - await page.click(selectors.NEURO_ML2_WORKSPACE_SELECTOR); - await page.waitForSelector(selectors.OPENED_WORKSPACE_SELECTOR); - expect(page.url()).toContain("/workspace/"); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.SELECT_APPLICATION_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.evaluate(() => { - let map = document.getElementsByClassName( - "MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button" - ) as HTMLCollectionOf; - for (let i = 0; i < map.length; i++) { - map[i].innerText == "Open with NWB Explorer" && map[i].click(); - } - }); + await page.click(selectors.ALL_YOUR_WORKSPACES_TAB); - console.log("Loading NWB Explorer"); + await page.waitForSelector(selectors.WORKSPACES, { + timeout: ONE_SECOND, + }); + await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE); + await page.click(selectors.SMOKE_TEST_WORKSPACE); + } - await page.click(selectors.OPEN_WITH_APPLICATION_SELECTOR); - await page.waitForSelector(selectors.APPLICATION_FRAME_SELECTOR, { - timeout: ONE_MINUTE, - }); - expect(page.url()).toContain("/nwbexplorer"); - const elementHandle = await page.waitForSelector( - selectors.APPLICATION_FRAME_SELECTOR - ); - const frame = await elementHandle.contentFrame(); - await frame.waitForSelector(selectors.NWB_INPUT_FIELD_SELECTOR, { - timeout: TWO_MINUTES * 1.5, - }); + await page.waitForSelector(selectors.OPENED_WORKSPACE); + expect(page.url()).toContain("/workspace/"); - console.log("NWB Explorer loaded"); - } else { - await page.click(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.waitForSelector(selectors.OPENED_WORKSPACE_SELECTOR); - expect(page.url()).toContain("/workspace/"); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.SELECT_APPLICATION_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.evaluate(() => { - let map = document.getElementsByClassName( - "MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button" - ) as HTMLCollectionOf; - for (let i = 0; i < map.length; i++) { - map[i].innerText == "Open with NWB Explorer" && map[i].click(); - } - }); - await page.click(selectors.OPEN_WITH_APPLICATION_SELECTOR); - expect(page.url()).toContain("/nwbexplorer"); - - console.log("Loading NWB Explorer"); - - await page.waitForSelector(selectors.APPLICATION_FRAME_SELECTOR); - const elementHandle = await page.waitForSelector( - selectors.APPLICATION_FRAME_SELECTOR - ); - const frame = await elementHandle.contentFrame(); - await frame.waitForSelector(selectors.NWB_INPUT_FIELD_SELECTOR, { - timeout: TWO_MINUTES * 1.5, - }); + await page.waitForSelector(selectors.SELECT_APPLICATION); + await page.click(selectors.SELECT_APPLICATION); - console.log("NWB Explorer loaded"); + await page.mainFrame().$$eval("#split-button-menu li", (choices: Array, appName: string) => choices.forEach((choice: HTMLElement) => { + + if (choice?.innerText?.includes(appName)) { + console.log("Choosing app", appName) + choice.click(); } - }); + }, appName), appName); - test("Open workspace with NetPyNE", async () => { - console.log("Opening workspace with NetPyNE"); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.OSB_LOGO_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.FEATURE_WORKSPACES_TAB_SELECTOR); - await page.waitForSelector(selectors.NEURO_ML2_WORKSPACE_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - - const featuredWorkspaces = await page.evaluate( - () => - document.querySelectorAll( - 'div[class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-6 MuiGrid-grid-sm-4 MuiGrid-grid-md-6 MuiGrid-grid-lg-4 MuiGrid-grid-xl-3"]' - ).length - ); - await page.click(selectors.OSB_LOGO_SELECTOR); - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - - if (featuredWorkspaces != 0) { - await page.waitForTimeout(ONE_SECOND); - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.FEATURE_WORKSPACES_TAB_SELECTOR); - await page.waitForSelector(selectors.NEURO_ML2_WORKSPACE_SELECTOR); - await page.click(selectors.NEURO_ML2_WORKSPACE_SELECTOR); - await page.waitForSelector(selectors.OPENED_WORKSPACE_SELECTOR); - expect(page.url()).toContain("/workspace/"); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.SELECT_APPLICATION_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.evaluate(() => { - let map = document.getElementsByClassName( - "MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button" - ) as HTMLCollectionOf; - for (let i = 0; i < map.length; i++) { - map[i].innerText == "Open with NetPyNE" && map[i].click(); - } - }); - console.log("Loading NetPyNE"); - - await page.click(selectors.OPEN_WITH_APPLICATION_SELECTOR); - await page.waitForSelector(selectors.APPLICATION_FRAME_SELECTOR, { - timeout: ONE_MINUTE, - }); - expect(page.url()).toContain("/netpyne"); - const elementHandle = await page.waitForSelector( - selectors.APPLICATION_FRAME_SELECTOR - ); - const frame = await elementHandle.contentFrame(); - await frame.waitForSelector(selectors.NETPYNE_CELL_BUTTON_SELECTOR, { - timeout: TWO_MINUTES * 1.5, - }); + console.log("Loading", appName); - console.log("NetPyNE loaded"); - } else { - await page.click(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.waitForSelector(selectors.OPENED_WORKSPACE_SELECTOR); - expect(page.url()).toContain("/workspace/"); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.SELECT_APPLICATION_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.evaluate(() => { - let map = document.getElementsByClassName( - "MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button" - ) as HTMLCollectionOf; - for (let i = 0; i < map.length; i++) { - map[i].innerText == "Open with NetPyNE" && map[i].click(); - } - }); - await page.click(selectors.OPEN_WITH_APPLICATION_SELECTOR); - expect(page.url()).toContain("/netpyne"); - - console.log("Loading NetPyNE"); - - await page.waitForSelector(selectors.APPLICATION_FRAME_SELECTOR); - const elementHandle = await page.waitForSelector( - selectors.APPLICATION_FRAME_SELECTOR - ); - const frame = await elementHandle.contentFrame(); - await frame.waitForSelector(selectors.NETPYNE_CELL_BUTTON_SELECTOR, { - timeout: TWO_MINUTES * 1.5, - }); - - console.log("NetPyNE loaded"); - } + await page.click(selectors.OPEN_WITH_APPLICATION); + await page.waitForSelector(selectors.APPLICATION_FRAME, { + timeout: ONE_SECOND, }); - - test("Open workspace with Jupyter Lab", async () => { - console.log("Opening workspace with Jupyter Lab"); - - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.OSB_LOGO_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.FEATURE_WORKSPACES_TAB_SELECTOR); - await page.waitForSelector(selectors.NEURO_ML2_WORKSPACE_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - const featuredWorkspaces = await page.evaluate( - () => - document.querySelectorAll( - 'div[class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-6 MuiGrid-grid-sm-4 MuiGrid-grid-md-6 MuiGrid-grid-lg-4 MuiGrid-grid-xl-3"]' - ).length - ); - await page.click(selectors.OSB_LOGO_SELECTOR); - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - - if (featuredWorkspaces != 0) { - await page.waitForTimeout(ONE_SECOND); - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.FEATURE_WORKSPACES_TAB_SELECTOR); - await page.waitForSelector(selectors.NEURO_ML2_WORKSPACE_SELECTOR); - await page.click(selectors.NEURO_ML2_WORKSPACE_SELECTOR); - await page.waitForSelector(selectors.OPENED_WORKSPACE_SELECTOR); - expect(page.url()).toContain("/workspace/"); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.SELECT_APPLICATION_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.evaluate(() => { - let map = document.getElementsByClassName( - "MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button" - ) as HTMLCollectionOf; - for (let i = 0; i < map.length; i++) { - map[i].innerText == "Open with JupyterLab" && map[i].click(); - } - }); - - console.log("Loading Jupyter Lab"); - - await page.click(selectors.OPEN_WITH_APPLICATION_SELECTOR); - await page.waitForSelector(selectors.APPLICATION_FRAME_SELECTOR, { - timeout: ONE_MINUTE, - }); - expect(page.url()).toContain("/jupyter"); - const elementHandle = await page.waitForSelector( - selectors.APPLICATION_FRAME_SELECTOR - ); - const frame = await elementHandle.contentFrame(); - await frame.waitForSelector(selectors.JUPYTER_CONTENT_SELECTOR, { - timeout: TWO_MINUTES * 1.5, - }); - - console.log("Jupyter Lab loaded"); - - } else { - - await page.click(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.waitForSelector(selectors.OPENED_WORKSPACE_SELECTOR); - expect(page.url()).toContain("/workspace/"); - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.SELECT_APPLICATION_SELECTOR); - await page.waitForTimeout(ONE_SECOND); - await page.evaluate(() => { - let map = document.getElementsByClassName( - "MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button" - ) as HTMLCollectionOf; - for (let i = 0; i < map.length; i++) { - map[i].innerText == "Open with JupyterLab" && map[i].click(); - } - }); - await page.click(selectors.OPEN_WITH_APPLICATION_SELECTOR); - expect(page.url()).toContain("/jupyter"); - - console.log("Loading Jupyter Lab"); - - await page.waitForSelector(selectors.APPLICATION_FRAME_SELECTOR); - const elementHandle = await page.waitForSelector( - selectors.APPLICATION_FRAME_SELECTOR - ); - const frame = await elementHandle.contentFrame(); - await frame.waitForSelector(selectors.JUPYTER_CONTENT_SELECTOR, { - timeout: TWO_MINUTES * 1.5, + expect(page.url()).toContain(url); + const elementHandle = await page.waitForSelector( + selectors.APPLICATION_FRAME, + { + timeout: ONE_SECOND, + } + ); + const frame = await elementHandle.contentFrame(); + for(const appSelector of appSelectors) { + if(!frame.isDetached()) { + await frame.waitForSelector(appSelector, { + timeout: WORKSPACE_LOAD_TIMEOUT, }); - - console.log("Jupyter Lab loaded"); } - }); + } + + console.log(appName, "loaded"); + }; +describe("OSB v2 Smoke Tests", () => { + beforeAll(async () => { + browser = await puppeteer.launch({ + args: [ + "--no-sandbox", + `--window-size=1600,1000`, + "--ignore-certificate-errors" + ], + headless: true, + defaultViewport: { + width: 1600, + height: 1000, + }, + }); - test("Delete created workspace", async () => { - console.log("Deleting created workspace"); + page = await browser.newPage(); + console.log( + "Checking page", + process.env.APP_URL || "https://v2dev.opensourcebrain.org/" + ); + await page + .goto(process.env.APP_URL || "https://v2dev.opensourcebrain.org/", { + waitUntil: "networkidle0", + }) + .catch(() => {}); + + console.log("Env", process.env); + + await page.waitForSelector(selectors.WORKSPACES); + }); + + afterAll(() => { + browser.close(); + }); + + test("Home Page", async () => { + await page.click(selectors.PUBLIC_WORKSPACES); + await page.waitForSelector(selectors.WORKSPACES); + }); + + test("Log in", async () => { + console.log("Attempting login on", page.url()); + await page.waitForSelector(selectors.LOGIN_BTN); + await page.click(selectors.LOGIN_BTN); + + await page.waitForSelector(selectors.USERNAME); + await page.waitForSelector(selectors.PASSWORD); + expect(page.url()).toContain("accounts."); + await page.type( + selectors.USERNAME, + process.env.USERNAME || "simao_user_osb" + ); + await page.type(selectors.PASSWORD, process.env.PASSWORD || "metacell"); + await page.click(selectors.LOGIN_BUTTON); + await page.waitForSelector(selectors.ALL_YOUR_WORKSPACES_TAB); + + await page.waitForSelector(selectors.YOUR_WORKSPACES); + }); + + test("Create workspace", async () => { + console.log("Creating workspace"); + + await page.click(selectors.CREATE_WORKSPACE); + await page.waitForSelector(selectors.WORKSPACE_CREATION_BOX); + const privateWorkspacesBefore = await getCurrentWorkpaces(); + await page.type(selectors.WORKSPACE_NAME, "Smoke Test Workspace"); + await page.type(selectors.WORKSPACE_TAGS, "Test"); + await page.keyboard.press("Enter"); + await page.type( + selectors.WORKSPACE_DESCRIPTION, + "Workspace created by the Automated Smoke tests" + ); + await page.waitForSelector(selectors.CREATE_NEW_WORKSPACE, ONE_SECOND); + await page.click(selectors.CREATE_NEW_WORKSPACE); + await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE); + await page.waitForSelector(selectors.YOUR_WORKSPACES); + const privateWorkspacesAfter = await getCurrentWorkpaces(); + expect(privateWorkspacesAfter.length).toBe( + privateWorkspacesBefore.length + 1 + ); + }); + + test( + "Open workspace with NWB Explorer", + testApplication("NWB Explorer", [selectors.NWB_APP], "/nwbexplorer") + ); + + test("Open workspace with NetPyNE", testApplication("NetPyNE", [ + selectors.NETPYNE_CELL_BUTTON, + selectors.NETPYNE_MAIN_CONTAINER], "/netpyne")); + + test("Open workspace with Jupyter Lab", testApplication("JupyterLab", [ + selectors.JUPYTER_CONTENT], "/jupyter")); + + test("Delete created workspace", async () => { + console.log("Deleting created workspace"); + + await page.click(selectors.OSB_LOGO); + await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE); + + let menuBtn; + while(menuBtn = await page.mainFrame().$(selectors.WORKSPACE_OPTIONS_BTN)) { + + + await menuBtn.click(); + await page.waitForSelector(".delete-workspace", {timeout: ONE_SECOND}); + await page.evaluate(() => document.querySelector(".delete-workspace")?.click()); // page.click does not work on the popover + await page.waitForSelector(".delete-workspace", {hidden: true}); + } + + + - await page.waitForTimeout(ONE_SECOND); - await page.click(selectors.OSB_LOGO_SELECTOR); - await page.waitForSelector(selectors.SMOKE_TEST_WORKSPACE_SELECTOR); - await page.click(selectors.WORKSPACE_OPTIONS_SELECTOR); - await page.waitForSelector(selectors.WORKSPACE_OPTIONS_LIST_SELECTOR); - await page.evaluate(() => { - let map = document.getElementsByClassName( - "MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button" - ) as HTMLCollectionOf; - for (let i = 0; i < 5; i++) { - map[i].textContent == "Delete" && map[i].click(); - } - }); - await page.waitForTimeout(ONE_SECOND); - await page.waitForSelector(selectors.YOUR_WORKSPACES_SELECTOR); - const privateWorkspaces = await page.evaluate( - () => - document.querySelectorAll( - 'div[class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-6 MuiGrid-grid-sm-4 MuiGrid-grid-md-6 MuiGrid-grid-lg-4 MuiGrid-grid-xl-3"]' - ).length - ); - expect(privateWorkspaces).toBe(0); - }); - test("Logout", async () => { - console.log("Logging out"); - - await page.click(selectors.USER_MENU_SELECTOR); - await page.evaluate(() => { - let map = document.getElementsByClassName( - "MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button" - ) as HTMLCollectionOf; - for (let i = 0; i < 3; i++) { - map[i].textContent == "Logout" && map[i].click(); - } - }); - await page.waitForSelector(selectors.WORKSPACES_SELECTOR); + }); + test("Logout", async () => { + console.log("Logging out"); + await page.click(selectors.USER_MENU); + await page.waitForSelector(selectors.LOGOUT_ACTION, { + timeout: ONE_SECOND * 4, }); - - - } else { - test("Skip Smoke test", async () => {}); - } + await page.waitForSelector(selectors.WORKSPACES); + }); }); diff --git a/applications/osb-portal/test/e2e/selectors.ts b/applications/osb-portal/test/e2e/selectors.ts index ab651aa2..eb246bdd 100644 --- a/applications/osb-portal/test/e2e/selectors.ts +++ b/applications/osb-portal/test/e2e/selectors.ts @@ -1,30 +1,31 @@ //Selectors: -export const WORKSPACES_SELECTOR = "#workspace-box"; -export const PUBLIC_WORKSPACES_SELECTOR = '#public-tab'; -export const SIGN_IN_SELECTOR = 'button[class="MuiButtonBase-root MuiButton-root MuiButton-text jss9"]'; -export const USERNAME_SELECTOR = "#username"; -export const PASSWORD_SELECTOR = "#password"; -export const LOGIN_BUTTON_SELECTOR = "#kc-login"; -export const ALL_YOUR_WORKSPACES_TAB_SELECTOR = "#your-all-workspaces-tab"; -export const FEATURE_WORKSPACES_TAB_SELECTOR = "#featured-tab"; -export const YOUR_WORKSPACES_SELECTOR = 'div[class="MuiGrid-root MuiGrid-container MuiGrid-spacing-xs-1"]'; -export const CREATE_WORKSPACE_SELECTOR = '#computational-modeling-item'; -export const CREATE_NEW_WORKSPACE_SELECTOR = '#create-a-new-workspace-button' -export const WORKSPACE_CREATION_BOX_SELECTOR = 'div[class="MuiDialogContent-root"]'; -export const WORKSPACE_NAME_SELECTOR = "#workspaceName"; -export const WORKSPACE_TAGS_SELECTOR = 'input[class="MuiInputBase-input MuiFilledInput-input MuiAutocomplete-input MuiAutocomplete-inputFocused MuiInputBase-inputAdornedEnd MuiFilledInput-inputAdornedEnd"]'; -export const WORKSPACE_DESCRIPTION_SELECTOR = 'textarea[class="section-container input "]'; -export const OSB_LOGO_SELECTOR = 'img[title="Open Source Brain"]'; -export const WORKSPACE_OPTIONS_SELECTOR = 'button[class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall"]'; -export const WORKSPACE_OPTIONS_LIST_SELECTOR = 'ul[class="MuiList-root MuiMenu-list MuiList-padding"]'; -export const USER_MENU_SELECTOR = 'span[class = "MuiButton-startIcon MuiButton-iconSizeLarge"]'; -export const SMOKE_TEST_WORKSPACE_SELECTOR = 'a[title="Smoke Test Workspace"]'; -export const OPENED_WORKSPACE_SELECTOR = '#panel1a-content'; -export const SELECT_APPLICATION_SELECTOR = 'button[aria-label="select merge strategy"]'; -export const OPEN_WITH_APPLICATION_SELECTOR = 'button[class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButtonGroup-grouped MuiButtonGroup-groupedHorizontal MuiButtonGroup-groupedContained MuiButtonGroup-groupedContainedHorizontal MuiButtonGroup-groupedContainedPrimary MuiButton-containedPrimary"]'; -export const NETPYNE_MAIN_CONTAINER_SELECTOR = "#mainContainer"; -export const NETPYNE_CELL_BUTTON_SELECTOR = "#selectCellButton"; -export const APPLICATION_FRAME_SELECTOR = 'iframe[id="workspace-frame"]' -export const NWB_INPUT_FIELD_SELECTOR = "#nwb-url-input"; -export const JUPYTER_CONTENT_SELECTOR = '#jp-main-dock-panel'; -export const NEURO_ML2_WORKSPACE_SELECTOR = 'a[title="NeuroML2 examples"]'; +export const WORKSPACES = "#workspaces-list"; +export const PUBLIC_WORKSPACES = '#public-tab'; +export const SIGN_IN = 'button[class="MuiButtonBase-root MuiButton-root MuiButton-text jss9"]'; +export const USERNAME = "#username"; +export const PASSWORD = "#password"; +export const LOGIN_BTN = "button.sign-in" +export const LOGOUT_ACTION = ".logout-menu-item" +export const LOGIN_BUTTON = "#kc-login"; +export const ALL_YOUR_WORKSPACES_TAB = "#your-all-workspaces-tab"; +export const FEATURE_WORKSPACES_TAB = "#featured-tab"; +export const YOUR_WORKSPACES = 'div[class="MuiGrid-root MuiGrid-container MuiGrid-spacing-xs-1"]'; +export const CREATE_WORKSPACE = '#computational-modeling-item'; +export const CREATE_NEW_WORKSPACE = '#create-a-new-workspace-button' +export const WORKSPACE_CREATION_BOX = 'div[class="MuiDialogContent-root"]'; +export const WORKSPACE_NAME = "#workspaceName"; +export const WORKSPACE_TAGS = 'input[class="MuiInputBase-input MuiFilledInput-input MuiAutocomplete-input MuiAutocomplete-inputFocused MuiInputBase-inputAdornedEnd MuiFilledInput-inputAdornedEnd"]'; +export const WORKSPACE_DESCRIPTION = 'textarea[class="section-container input "]'; +export const OSB_LOGO = 'img[title="Open Source Brain"]'; +export const WORKSPACE_OPTIONS_BTN = '.btn-workspace-actions'; +export const WORKSPACE_OPTIONS_LIST = 'ul[class="MuiList-root MuiMenu-list MuiList-padding"]'; +export const USER_MENU = '.user-menu-btn'; +export const SMOKE_TEST_WORKSPACE = 'a[title="Smoke Test Workspace"]'; +export const OPENED_WORKSPACE = '#panel1a-content'; +export const SELECT_APPLICATION = '.split-button-control'; +export const OPEN_WITH_APPLICATION = '.open-workspace'; +export const NETPYNE_MAIN_CONTAINER = "#mainContainer"; +export const NETPYNE_CELL_BUTTON = "#selectCellButton"; +export const APPLICATION_FRAME = '#workspace-frame' +export const NWB_APP = "#main-container-inner"; +export const JUPYTER_CONTENT = '#jp-main-dock-panel';