diff --git a/client/__tests__/e2e/data.js b/client/__tests__/e2e/data.js index 5423ca10..796f4357 100644 --- a/client/__tests__/e2e/data.js +++ b/client/__tests__/e2e/data.js @@ -100,6 +100,14 @@ export const datasets = { }, pan: { "coordinates-as-percent": { x1: 0.75, y1: 0.75, x2: 0.35, y2: 0.35 } + }, + features: { + panzoom: { + lasso: { + "coordinates-as-percent": { x1: 0.3, y1: 0.3, x2: 0.5, y2: 0.5 }, + count: "24" + } + } } } }; diff --git a/client/__tests__/e2e/e2e.test.js b/client/__tests__/e2e/e2e.test.js index 3fc3dfea..c7ced1ef 100644 --- a/client/__tests__/e2e/e2e.test.js +++ b/client/__tests__/e2e/e2e.test.js @@ -1,3 +1,8 @@ +/* +Smoke test suite that will be run in Travis CI + +Tests included in this file are expected to be relatively stable and test core features + */ import puppeteer from "puppeteer"; import { appUrlBase, DEBUG, DEV, DATASET } from "./config"; import { puppeteerUtils, cellxgeneActions } from "./puppeteerUtils"; diff --git a/client/__tests__/e2e/feature.test.js b/client/__tests__/e2e/feature.test.js new file mode 100644 index 00000000..8573ce5a --- /dev/null +++ b/client/__tests__/e2e/feature.test.js @@ -0,0 +1,118 @@ +/* +NOT run in Travis CI + +UX tests using puppeteer to be run locally. + +To run locally, ensure you are running the client is running on port 3000. +Then run jest --verbose false --config __tests__/e2e/e2eJestConfig.json feature. + */ + +import puppeteer from "puppeteer"; +import { appUrlBase, DEBUG, DEV, DATASET } from "./config"; +import { puppeteerUtils, cellxgeneActions } from "./puppeteerUtils"; +import { datasets } from "./data"; + +let browser, page, utils, cxgActions, spy; +const browserViewport = { width: 1280, height: 960 }; +let data = datasets[DATASET].features; + +if (DEBUG) jest.setTimeout(100000); +if (DEV) jest.setTimeout(10000); + +beforeAll(async () => { + const browserParams = DEV + ? { headless: false, slowMo: 5 } + : DEBUG + ? { headless: false, slowMo: 100, devtools: true } + : {}; + browser = await puppeteer.launch(browserParams); + page = await browser.newPage(); + await page.setViewport(browserViewport); + if (DEV || DEBUG) { + page.on("console", msg => console.log(`PAGE LOG: ${msg.text()}`)); + } + page.on("pageerror", err => { + throw new Error(`Console error: ${err}`); + }); + utils = puppeteerUtils(page); + cxgActions = cellxgeneActions(page); +}); + +beforeEach(async () => { + await page.goto(appUrlBase); +}); + +afterAll(() => { + if (!DEBUG) { + browser.close(); + } +}); + +describe("zoom interaction", async () => { + // Skip this test since UI is to hide lasso path when switching modes + test.skip("lasso visible after switching modes to pan/zoom", async () => { + const lassoSelection = await cxgActions.calcDragCoordinates( + "layout-graph", + data.panzoom.lasso["coordinates-as-percent"] + ); + await cxgActions.drag( + "layout-graph", + lassoSelection.start, + lassoSelection.end, + true + ); + await utils.waitByID("lasso-element", { visible: true }); + await utils.clickOn("mode-pan-zoom"); + await utils.waitByID("lasso-element", { visible: true }); + }); + + test("pan zoom mode resets lasso selection", async () => { + const lassoSelection = await cxgActions.calcDragCoordinates( + "layout-graph", + data.panzoom.lasso["coordinates-as-percent"] + ); + await cxgActions.drag( + "layout-graph", + lassoSelection.start, + lassoSelection.end, + true + ); + await utils.waitByID("lasso-element", { visible: true }); + const initialCount = await cxgActions.cellSet(1); + expect(initialCount).toBe(data.panzoom.lasso.count); + await utils.clickOn("mode-pan-zoom"); + await utils.clickOn("mode-lasso"); + const modeSwitchCount = await cxgActions.cellSet(1); + expect(modeSwitchCount).toBe(initialCount); + }); + + test("lasso moves after pan", async () => { + const lassoSelection = await cxgActions.calcDragCoordinates( + "layout-graph", + data.panzoom.lasso["coordinates-as-percent"] + ); + await cxgActions.drag( + "layout-graph", + lassoSelection.start, + lassoSelection.end, + true + ); + await utils.waitByID("lasso-element", { visible: true }); + const initialCount = await cxgActions.cellSet(1); + expect(initialCount).toBe(data.panzoom.lasso.count); + await utils.clickOn("mode-pan-zoom"); + const panCoords = await cxgActions.calcDragCoordinates( + "layout-graph", + data.panzoom.lasso["coordinates-as-percent"] + ); + await cxgActions.drag( + "layout-graph", + panCoords.start, + panCoords.end, + false + ); + await utils.clickOn("mode-lasso"); + const panCount = await cxgActions.cellSet(2); + expect(panCount).toBe(initialCount); + }); +}); diff --git a/client/__tests__/e2e/puppeteerUtils.js b/client/__tests__/e2e/puppeteerUtils.js index cf9443b2..17633c2b 100644 --- a/client/__tests__/e2e/puppeteerUtils.js +++ b/client/__tests__/e2e/puppeteerUtils.js @@ -1,11 +1,15 @@ export const puppeteerUtils = puppeteerPage => ({ - async waitByID(testid) { - return await puppeteerPage.waitForSelector(`[data-testid='${testid}']`); + async waitByID(testid, props = {}) { + return await puppeteerPage.waitForSelector( + `[data-testid='${testid}']`, + props + ); }, - async waitByClass(testclass) { + async waitByClass(testclass, props = {}) { return await puppeteerPage.waitForSelector( - `[data-testclass='${testclass}']` + `[data-testclass='${testclass}']`, + props ); }, diff --git a/client/package.json b/client/package.json index 82800b19..ada115ae 100644 --- a/client/package.json +++ b/client/package.json @@ -9,7 +9,7 @@ "build": "npm run clean && webpack --config configuration/webpack/webpack.config.prod.js", "clean": "rimraf build", "dev": "npm run clean && webpack --config configuration/webpack/webpack.config.dev.js", - "e2e": "jest --verbose false --config __tests__/e2e/e2eJestConfig.json e2e", + "e2e": "jest --verbose false --config __tests__/e2e/e2eJestConfig.json e2e/e2e.test.js", "lint": "eslint src", "smoke-test": "start-server-and-test start-server-for-test :5000 e2e", "start": "node server/development.js", diff --git a/client/src/components/graph/setupLasso.js b/client/src/components/graph/setupLasso.js index 241c005e..7771045f 100644 --- a/client/src/components/graph/setupLasso.js +++ b/client/src/components/graph/setupLasso.js @@ -28,6 +28,7 @@ const Lasso = () => { lassoPath = g .append("path") + .attr("data-testid", "lasso-element") .attr("fill", "#0bb") .attr("fill-opacity", 0.1) .attr("stroke", "#0bb")