Skip to content

Commit

Permalink
Create separate test for runner functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sabberworm committed Nov 19, 2024
1 parent 05eac24 commit 8960df5
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 25 deletions.
26 changes: 1 addition & 25 deletions src/test/playwright/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect, Request } from '@playwright/test';

test('renders', async ({ page }) => {
test('render', async ({ page }) => {
await page.goto('/');

await expect(page).toHaveTitle(/JCR Hopper Script Builder/);
Expand Down Expand Up @@ -37,28 +37,4 @@ test('add step', async ({ page }) => {
await step.getByLabel('Selector Name:').press('Tab');

await expect(step).toHaveScreenshot();

let runScriptRequest: Promise<Request> | Request = page.waitForRequest('/mock/mock-response.jsonl');
await page.getByRole('button', { name: 'Run' }).click();
runScriptRequest = await runScriptRequest;

expect(runScriptRequest.method()).toBe('POST');
expect(runScriptRequest.postData()).toContain(
'{"logLevel":"trace","hops":[{"type":"nodeQuery","query":"SELECT * FROM [cq:Page] AS page","queryType":"JCR-SQL2","hops":[],"selectorName":"page"}],"parameters":[]}',
);

const output = page.locator('.output');

await expect(output).toMatchAriaSnapshot(`
- group:
- text: ▼
- heading /✅ \\d+\\/\\d+\\/\\d+, \\d+:\\d+:\\d+/ [level=3]
- text: "/trace Starting JCR Hopper with 6 parameters, for 4 of which arguments were passed: \\\\[\\\\] debug JCR Hopper script started at \\\\d+ Some plain text output/"
- img "file csv"
- text: /Test\\.csv text\\/csv;charset=utf-8 \\d+ bytes/
- link "Download":
- button "Download"
- text: /info JCR Hopper script finished after \\d+[hmsp]+ warn Not saving changes as dry run is enabled error Script execution aborted with exception/
- button "!!"
`);
});
77 changes: 77 additions & 0 deletions src/test/playwright/run.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { test, expect, Request } from '@playwright/test';

test('run simple', async ({ page }) => {
await page.goto('/');

await page.getByRole('button', { name: 'Add', exact: true }).click();
await page.getByRole('option', { name: 'Query JCR' }).click();
await page.getByLabel('Log Level: INFO').click();
await page.getByRole('option', { name: 'ERROR' }).click();

let runScriptRequest: Promise<Request> | Request = page.waitForRequest('/mock/mock-response.jsonl');
await page.getByRole('button', { name: 'Run' }).click();
runScriptRequest = await runScriptRequest;

expect(runScriptRequest.method()).toBe('POST');
expect(runScriptRequest.postData()).toContain(
'{"logLevel":"error","hops":[{"type":"nodeQuery","query":"SELECT * FROM [cq:Page] AS page","queryType":"JCR-SQL2","hops":[]}],"parameters":[]}',
);

const output = page.locator('.output');
await expect(output).toMatchAriaSnapshot(`
- group:
- text: ▼
- heading /✅ \\d+\\/\\d+\\/\\d+, \\d+:\\d+:\\d+/ [level=3]
- text: "/trace Starting JCR Hopper with 6 parameters, for 4 of which arguments were passed: \\\\[\\\\] debug JCR Hopper script started at \\\\d+ Some plain text output/"
- img "file csv"
- text: /Test\\.csv text\\/csv;charset=utf-8 \\d+ bytes/
- link "Download":
- button "Download"
- text: /info JCR Hopper script finished after \\d+ms warn Not saving changes as dry run is enabled error Script execution aborted with exception/
- button "!!"
`);

await expect(output).toHaveScreenshot({
mask: [output.getByRole('heading', { level: 3 })],
});
});

test('run with arguments', async ({ page }) => {
await page.goto('/');

await page.getByRole('button', { name: 'Add', exact: true }).click();
await page.getByRole('option', { name: 'Resolve Specific Node' }).click();
await page.getByRole('button', { name: 'add circle' }).click();
await page.getByRole('option', { name: 'Get Child Nodes' }).click();
await page.getByRole('heading', { name: 'Get Child Nodes Matching' }).click();

const namePattern = page.getByLabel('Name Pattern:');
await namePattern.click();
await namePattern.press('ControlOrMeta+a');
await namePattern.fill('');
await namePattern.press('Tab');

await page.getByRole('button', { name: 'add', exact: true }).click();
const paramName = page.getByPlaceholder('Name');
await paramName.click();
await paramName.press('ControlOrMeta+a');
await paramName.fill('myparam');
await paramName.press('Tab');

const argValue = page.getByLabel('myparam:');
await argValue.click();
await argValue.fill('myvalue');
await argValue.press('Tab');
await page.getByRole('button', { name: 'Run' }).click();

let runScriptRequest: Promise<Request> | Request = page.waitForRequest('/mock/mock-response.jsonl');
await page.getByRole('button', { name: 'Run' }).click();
runScriptRequest = await runScriptRequest;

expect(runScriptRequest.method()).toBe('POST');
expect(runScriptRequest.postData()).toContain(
'{"logLevel":"info","hops":[{"type":"resolveNode","conflict":"ignore","name":"child-name","hops":[{"type":"childNodes","namePattern":"","hops":[]}]}],"parameters":[{"name":"myparam","defaultValue":"","type":"text","evaluation":"STRING"}]}',
);
expect(runScriptRequest.postData()).toContain('myparam');
expect(runScriptRequest.postData()).toContain('myvalue');
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8960df5

Please sign in to comment.