diff --git a/src/test/playwright/basic.spec.ts b/src/test/playwright/basic.spec.ts index 17ba67f..0cbf42f 100644 --- a/src/test/playwright/basic.spec.ts +++ b/src/test/playwright/basic.spec.ts @@ -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/); @@ -37,28 +37,4 @@ test('add step', async ({ page }) => { await step.getByLabel('Selector Name:').press('Tab'); await expect(step).toHaveScreenshot(); - - let runScriptRequest: Promise | 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 "!!" - `); }); diff --git a/src/test/playwright/basic.spec.ts-snapshots/renders-1-chromium-linux.png b/src/test/playwright/basic.spec.ts-snapshots/render-1-chromium-linux.png similarity index 100% rename from src/test/playwright/basic.spec.ts-snapshots/renders-1-chromium-linux.png rename to src/test/playwright/basic.spec.ts-snapshots/render-1-chromium-linux.png diff --git a/src/test/playwright/run.spec.ts b/src/test/playwright/run.spec.ts new file mode 100644 index 0000000..ba2f6f5 --- /dev/null +++ b/src/test/playwright/run.spec.ts @@ -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 = 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 = 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'); +}); diff --git a/src/test/playwright/run.spec.ts-snapshots/run-simple-1-chromium-linux.png b/src/test/playwright/run.spec.ts-snapshots/run-simple-1-chromium-linux.png new file mode 100644 index 0000000..43c6972 Binary files /dev/null and b/src/test/playwright/run.spec.ts-snapshots/run-simple-1-chromium-linux.png differ