diff --git a/packages/e2e-tests/package.json b/packages/e2e-tests/package.json deleted file mode 100644 index 4fcfa4a69f..0000000000 --- a/packages/e2e-tests/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "e2e-tests", - "private": true -} diff --git a/packages/e2e-tests/tests/no-pool-specified.spec.ts b/packages/e2e-tests/tests/no-pool-specified.spec.ts deleted file mode 100644 index 0dd99392d1..0000000000 --- a/packages/e2e-tests/tests/no-pool-specified.spec.ts +++ /dev/null @@ -1,35 +0,0 @@ -import {expect, test} from "@playwright/test" -import TestApp from "../helpers/test-app" -import {getPath} from "zui-test-data" - -test.describe("No Pool Specified State", () => { - const app = new TestApp("No Pool Specified") - - test.beforeAll(async () => { - await app.init() - }) - - test.afterAll(async () => { - await app.shutdown() - }) - - test("Query missing a from with no pools", async () => { - await app.find("role=button[name=create]").click() - await app.find(':text("New Query Session")').click() - const msg = await app.find(':text("Load data into a pool")') - expect(msg).toBeDefined() - }) - - test("Query missing a from with some pools", async () => { - await app.createPool([getPath("small-zeek.zng")]) - await app.find("role=button[name=create]").click() - await app.find(':text("New Query Session")').click() - const msg = await app.find(':text("click one of the pools")') - expect(msg).toBeDefined() - const list = await app.find("role=list[name=from-pin-list]") - expect(list).toBeDefined() - await app.find("role=listitem[name=small-zeek.zng]").click() - const stats = await app.getViewerStats() - expect(stats).toEqual({results: 31, shapes: 8}) - }) -}) diff --git a/packages/e2e-tests/.env b/packages/zui-player/.env similarity index 100% rename from packages/e2e-tests/.env rename to packages/zui-player/.env diff --git a/packages/e2e-tests/README.md b/packages/zui-player/README.md similarity index 52% rename from packages/e2e-tests/README.md rename to packages/zui-player/README.md index bfc377c211..83c833b37b 100644 --- a/packages/e2e-tests/README.md +++ b/packages/zui-player/README.md @@ -1,10 +1,9 @@ -# e2e-tests +# Zui Player > End To End Testing Framework The Zui end-to-end test suite uses [Playwright](https://playwright.dev/) as the test runner. - ## Writing a test To write an e2e test, create a file called `[my-test].spec.ts` in the `tests` directory. @@ -14,24 +13,24 @@ Then create a describe block and initialize a new TestApp class within it. That Here's a template for getting started. ```ts -import {expect, test} from "@playwright/test" -import TestApp from "../helpers/test-app" +import { expect, test } from '@playwright/test'; +import TestApp from '../helpers/test-app'; -test.describe("Pool Groups", () => { - const app = new TestApp("Pool Groups") +test.describe('Pool Groups', () => { + const app = new TestApp('Pool Groups'); test.beforeAll(async () => { - await app.init() - }) + await app.init(); + }); test.afterAll(async () => { - await app.shutdown() - }) + await app.shutdown(); + }); - test("cases", async () => { - await app.query("1") // and the like... - }) -}) + test('cases', async () => { + await app.query('1'); // and the like... + }); +}); ``` ## Running tests @@ -45,22 +44,41 @@ yarn e2e To run just one of the tests, specify the name of the file in the `tests` directory, e.g., ``` -yarn e2e -- --grep="pool-loads.spec.ts" +nx test zui-player -g pool-loads.spec.ts ``` ## Selecting DOM Nodes -These are common ways to select nodes. +These are the four methods you need to know to get most work done. + +```ts +await app.click(); +await app.attached(); +await app.detacted(); +await app.hidden(); +await app.visible(); +await app.locate(); +``` + +They all have the same two signatures. + +The first selects by aria role and aria name. + +The second selects using regex for any text on the page. ```ts -await app.find("role=button[name=create]").click() -await app.find(':text("New Query Session")').click() +await app.click(aria - role, aria - name); +// or +await app.click(regexp); ``` +### Helpful Playwright Doc Links + https://playwright.dev/docs/api/class-locator https://playwright.dev/docs/other-locators (formerly "Selectors") https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques -https://playwright.dev/docs/api/class-page +https://playwright.dev/docs/api/class-pa +ge diff --git a/packages/e2e-tests/helpers/env.ts b/packages/zui-player/helpers/env.ts similarity index 100% rename from packages/e2e-tests/helpers/env.ts rename to packages/zui-player/helpers/env.ts diff --git a/packages/e2e-tests/helpers/helpers.ts b/packages/zui-player/helpers/helpers.ts similarity index 100% rename from packages/e2e-tests/helpers/helpers.ts rename to packages/zui-player/helpers/helpers.ts diff --git a/packages/e2e-tests/helpers/test-app.ts b/packages/zui-player/helpers/test-app.ts similarity index 96% rename from packages/e2e-tests/helpers/test-app.ts rename to packages/zui-player/helpers/test-app.ts index 6bd5f499e9..427ef6fe6e 100644 --- a/packages/e2e-tests/helpers/test-app.ts +++ b/packages/zui-player/helpers/test-app.ts @@ -40,16 +40,21 @@ export default class TestApp { // @ts-ignore if (bin) launchOpts.executablePath = bin; this.zui = await electron.launch(launchOpts); - this.zui.process().stdout.on('data', (data) => { - console.log(data.toString()); - }); + await waitForTrue(() => this.zui.windows().length === 2); await waitForTrue(async () => !!(await this.getWindowByTitle('Zui'))); await waitForTrue( async () => !!(await this.getWindowByTitle('Background')) ); this.mainWin = await this.getWindowByTitle('Zui'); - this.mainWin.on('console', console.log); + + const debug = false; + if (debug) { + this.mainWin.on('console', console.log); + this.zui.process().stdout.on('data', (data) => { + console.log(data.toString()); + }); + } } async dropFile(file: string) { diff --git a/packages/e2e-tests/index.ts b/packages/zui-player/index.ts similarity index 100% rename from packages/e2e-tests/index.ts rename to packages/zui-player/index.ts diff --git a/packages/zui-player/package.json b/packages/zui-player/package.json new file mode 100644 index 0000000000..63cdbe468a --- /dev/null +++ b/packages/zui-player/package.json @@ -0,0 +1,4 @@ +{ + "name": "zui-player", + "private": true +} diff --git a/packages/e2e-tests/playwright.config.js b/packages/zui-player/playwright.config.js similarity index 100% rename from packages/e2e-tests/playwright.config.js rename to packages/zui-player/playwright.config.js diff --git a/packages/e2e-tests/project.json b/packages/zui-player/project.json similarity index 53% rename from packages/e2e-tests/project.json rename to packages/zui-player/project.json index 77254658fa..16755cd53b 100644 --- a/packages/e2e-tests/project.json +++ b/packages/zui-player/project.json @@ -1,25 +1,25 @@ { - "name": "e2e-tests", + "name": "zui-player", "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "packages/e2e-tests", + "sourceRoot": "packages/zui-player", "implicitDependencies": ["zui"], "projectType": "library", "targets": { - "build": { + "lint": { "executor": "@nrwl/js:tsc", "outputs": ["{options.outputPath}"], "options": { - "outputPath": "dist/packages/e2e-tests", - "tsConfig": "packages/e2e-tests/tsconfig.json", - "main": "packages/e2e-tests/index.ts" + "outputPath": "dist/packages/zui-player", + "tsConfig": "packages/zui-player/tsconfig.json", + "main": "packages/zui-player/index.ts" } }, - "e2e": { + "test": { "executor": "@nxkit/playwright:test", "outputs": ["{workspaceRoot}/dist/{projectRoot}"], "options": { - "outputPath": "dist/packages/e2e-tests/test-results", - "playwrightConfig": "packages/e2e-tests/playwright.config.js", + "outputPath": "dist/packages/zui-player/test-results", + "playwrightConfig": "packages/zui-player/playwright.config.js", "baseUrl": "https://example.com" } } diff --git a/packages/e2e-tests/setup/global.ts b/packages/zui-player/setup/global.ts similarity index 100% rename from packages/e2e-tests/setup/global.ts rename to packages/zui-player/setup/global.ts diff --git a/packages/e2e-tests/tests/export.spec.ts b/packages/zui-player/tests/export.spec.ts similarity index 95% rename from packages/e2e-tests/tests/export.spec.ts rename to packages/zui-player/tests/export.spec.ts index c4ab6105d7..6ca17a45c7 100644 --- a/packages/e2e-tests/tests/export.spec.ts +++ b/packages/zui-player/tests/export.spec.ts @@ -14,7 +14,7 @@ const formats = [ { label: 'VNG', expectedSize: 7755 }, { label: 'Zeek', expectedSize: 10138 }, { label: 'ZJSON', expectedSize: 18007 }, - { label: 'ZNG', expectedSize: 3744 }, + { label: 'ZNG', expectedSize: 3745 }, { label: 'ZSON', expectedSize: 15137 }, ]; @@ -24,6 +24,7 @@ test.describe('Export tests', () => { test.beforeAll(async () => { await app.init(); await app.createPool([getPath('sample.tsv')]); + await app.click('button', 'Query Pool'); await app.query('sort ts, _path'); }); diff --git a/packages/e2e-tests/tests/histogram.spec.ts b/packages/zui-player/tests/histogram.spec.ts similarity index 100% rename from packages/e2e-tests/tests/histogram.spec.ts rename to packages/zui-player/tests/histogram.spec.ts diff --git a/packages/e2e-tests/tests/ingest.spec.ts b/packages/zui-player/tests/ingest.spec.ts similarity index 100% rename from packages/e2e-tests/tests/ingest.spec.ts rename to packages/zui-player/tests/ingest.spec.ts diff --git a/packages/zui-player/tests/no-pool-specified.spec.ts b/packages/zui-player/tests/no-pool-specified.spec.ts new file mode 100644 index 0000000000..4611d58958 --- /dev/null +++ b/packages/zui-player/tests/no-pool-specified.spec.ts @@ -0,0 +1,35 @@ +import { expect, test } from '@playwright/test'; +import TestApp from '../helpers/test-app'; +import { getPath } from 'zui-test-data'; + +test.describe('No Pool Specified State', () => { + const app = new TestApp('No Pool Specified'); + + test.beforeAll(async () => { + await app.init(); + }); + + test.afterAll(async () => { + await app.shutdown(); + }); + + test('Query missing a from with no pools', async () => { + await app.click('button', 'create'); + await app.click('listitem', 'New Query Session'); + await app.attached(/load data into a pool/i); + }); + + test('Query missing a from with some pools', async () => { + await app.createPool([getPath('small-zeek.zng')]); + await app.click('button', 'create'); + await app.click('listitem', 'New Query Session'); + + await app.attached(/click one of the pools/i); + + await app.attached('list', 'from-pin-list'); + await app.click('listitem', 'small-zeek.zng'); + + const stats = await app.getViewerStats(); + expect(stats).toEqual({ results: 31, shapes: 8 }); + }); +}); diff --git a/packages/e2e-tests/tests/pool-groups.spec.ts b/packages/zui-player/tests/pool-groups.spec.ts similarity index 100% rename from packages/e2e-tests/tests/pool-groups.spec.ts rename to packages/zui-player/tests/pool-groups.spec.ts diff --git a/packages/e2e-tests/tests/pool-loads.spec.ts b/packages/zui-player/tests/pool-loads.spec.ts similarity index 96% rename from packages/e2e-tests/tests/pool-loads.spec.ts rename to packages/zui-player/tests/pool-loads.spec.ts index 24ef1a5141..376a4ef2c5 100644 --- a/packages/e2e-tests/tests/pool-loads.spec.ts +++ b/packages/zui-player/tests/pool-loads.spec.ts @@ -30,6 +30,7 @@ test.describe('Pool Loads', () => { await app.page.getByLabel('Pool').selectOption({ label: 'prs.json' }); await app.click('button', 'Load'); await app.attached(/successfully loaded/i); + await app.click('button', 'Query Pool'); await app.query('count()'); const results = await app.getViewerResults(); expect(results).toEqual(['this', '2']); diff --git a/packages/e2e-tests/tests/queries.spec.ts b/packages/zui-player/tests/queries.spec.ts similarity index 97% rename from packages/e2e-tests/tests/queries.spec.ts rename to packages/zui-player/tests/queries.spec.ts index 7aba0b0251..43c7f2c83c 100644 --- a/packages/e2e-tests/tests/queries.spec.ts +++ b/packages/zui-player/tests/queries.spec.ts @@ -55,7 +55,7 @@ test.describe('Query tests', () => { ).toBeVisible(); // update - await titleBar.getByRole('button', { name: 'Save' }).click(); + await titleBar.getByRole('button', { name: 'Update' }).click(); await expect( await titleBar.getByRole('button', { name: 'Test Query Name' }) ).toBeVisible(); diff --git a/packages/e2e-tests/tests/table.spec.ts b/packages/zui-player/tests/table.spec.ts similarity index 100% rename from packages/e2e-tests/tests/table.spec.ts rename to packages/zui-player/tests/table.spec.ts diff --git a/packages/e2e-tests/tests/zed-events.spec.ts b/packages/zui-player/tests/zed-events.spec.ts similarity index 100% rename from packages/e2e-tests/tests/zed-events.spec.ts rename to packages/zui-player/tests/zed-events.spec.ts diff --git a/packages/e2e-tests/tsconfig.json b/packages/zui-player/tsconfig.json similarity index 100% rename from packages/e2e-tests/tsconfig.json rename to packages/zui-player/tsconfig.json diff --git a/yarn.lock b/yarn.lock index 04396987ca..e87c8a71e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8148,12 +8148,6 @@ __metadata: languageName: node linkType: hard -"e2e-tests@workspace:packages/e2e-tests": - version: 0.0.0-use.local - resolution: "e2e-tests@workspace:packages/e2e-tests" - languageName: unknown - linkType: soft - "eastasianwidth@npm:^0.2.0": version: 0.2.0 resolution: "eastasianwidth@npm:0.2.0" @@ -18196,6 +18190,12 @@ __metadata: languageName: unknown linkType: soft +"zui-player@workspace:packages/zui-player": + version: 0.0.0-use.local + resolution: "zui-player@workspace:packages/zui-player" + languageName: unknown + linkType: soft + "zui-test-data@workspace:*, zui-test-data@workspace:packages/zui-test-data": version: 0.0.0-use.local resolution: "zui-test-data@workspace:packages/zui-test-data"