Skip to content

Commit

Permalink
Zui Player Tests Working
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskerr committed Oct 20, 2023
1 parent 14b875b commit 001a139
Show file tree
Hide file tree
Showing 23 changed files with 104 additions and 79 deletions.
4 changes: 0 additions & 4 deletions packages/e2e-tests/package.json

This file was deleted.

35 changes: 0 additions & 35 deletions packages/e2e-tests/tests/no-pool-specified.spec.ts

This file was deleted.

File renamed without changes.
56 changes: 37 additions & 19 deletions packages/e2e-tests/README.md → packages/zui-player/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions packages/zui-player/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "zui-player",
"private": true
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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"
}
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
];

Expand All @@ -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');
});

Expand Down
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions packages/zui-player/tests/no-pool-specified.spec.ts
Original file line number Diff line number Diff line change
@@ -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 });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 001a139

Please sign in to comment.