Release query Tools v0.1.0
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
const ORIGIN = "http://127.0.0.1:4220";
|
||||
async function local(page: Page) {
|
||||
const out: string[] = [];
|
||||
await page.route("**/*", async (r) => {
|
||||
const u = new URL(r.request().url());
|
||||
if (u.origin !== ORIGIN) {
|
||||
out.push(u.href);
|
||||
await r.abort();
|
||||
} else await r.continue();
|
||||
});
|
||||
return out;
|
||||
}
|
||||
test("nested local query workflow", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1800, height: 900 });
|
||||
const external = await local(page);
|
||||
await page.goto("/deep/nested/query/");
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "Query Tools" }),
|
||||
).toBeVisible();
|
||||
await page
|
||||
.getByRole("textbox", { name: "Query", exact: true })
|
||||
.fill("SELECT name, score WHERE score >= 84 ORDER BY score DESC");
|
||||
await page.getByRole("button", { name: "Run query" }).click();
|
||||
await expect(page.getByRole("cell", { name: "Ada" })).toBeVisible();
|
||||
expect(external).toEqual([]);
|
||||
expect(
|
||||
await page
|
||||
.locator(".toolbox-shell__main")
|
||||
.evaluate((n) => getComputedStyle(n).width),
|
||||
).toBe("1440px");
|
||||
});
|
||||
test("retains results on an error and exports", async ({ page }) => {
|
||||
await page.goto("/deep/nested/query/");
|
||||
await page
|
||||
.getByRole("textbox", { name: "Query", exact: true })
|
||||
.fill("eval(data)");
|
||||
await page.getByRole("button", { name: "Run query" }).click();
|
||||
await expect(page.getByRole("status")).toContainText("last valid result");
|
||||
const pending = page.waitForEvent("download");
|
||||
await page.getByRole("button", { name: "JSON", exact: true }).click();
|
||||
expect((await pending).suggestedFilename()).toBe("query-result.json");
|
||||
});
|
||||
test("shell PWA headers, offline reload, and theme", async ({
|
||||
page,
|
||||
context,
|
||||
request,
|
||||
}) => {
|
||||
await page.goto("/deep/nested/query/");
|
||||
await page.getByRole("button", { name: "Help" }).click();
|
||||
await expect(page.getByRole("dialog")).toContainText(
|
||||
"never evaluate JavaScript",
|
||||
);
|
||||
await page.keyboard.press("Escape");
|
||||
await page.getByRole("button", { name: "Personalize" }).click();
|
||||
await page.getByRole("button", { name: "Dark" }).click();
|
||||
await expect(page.locator(".toolbox-shell").first()).toHaveAttribute(
|
||||
"data-toolbox-theme",
|
||||
"dark",
|
||||
);
|
||||
expect(
|
||||
await page.evaluate(async () =>
|
||||
Boolean(await navigator.serviceWorker.ready),
|
||||
),
|
||||
).toBe(true);
|
||||
await context.setOffline(true);
|
||||
await page.reload();
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "Query Tools" }),
|
||||
).toBeVisible();
|
||||
await context.setOffline(false);
|
||||
const response = await request.get("/deep/nested/query/");
|
||||
expect(response.headers()["content-security-policy"]).toContain(
|
||||
"connect-src 'self'",
|
||||
);
|
||||
const manifest = await request.get("/deep/nested/query/toolbox-app.json");
|
||||
await expect(manifest.json()).resolves.toMatchObject({
|
||||
id: "de.add-ideas.query-tools",
|
||||
version: "0.1.0",
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { Workbench } from "../../src/components/Workbench";
|
||||
|
||||
describe("Query Workbench", () => {
|
||||
it("runs a query through the rendered controls", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Workbench />);
|
||||
|
||||
await user.clear(screen.getByRole("textbox", { name: "Query" }));
|
||||
await user.type(
|
||||
screen.getByRole("textbox", { name: "Query" }),
|
||||
"SELECT name, score WHERE score >= 84 ORDER BY score DESC",
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "Run query" }));
|
||||
|
||||
expect(screen.getByRole("status")).toHaveTextContent(
|
||||
"returned 2 result rows",
|
||||
);
|
||||
expect(screen.getByRole("cell", { name: "Ada" })).toBeVisible();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseData } from "../../src/core/data";
|
||||
describe("data parser", () => {
|
||||
it("parses CSV inference and NDJSON", () => {
|
||||
expect(parseData("name,n\nAda,3", "csv").rows[0]).toEqual({
|
||||
name: "Ada",
|
||||
n: 3,
|
||||
});
|
||||
expect(parseData('{"a":1}\n{"a":2}', "ndjson").rows).toHaveLength(2);
|
||||
});
|
||||
it("converts static XML and rejects entities", () => {
|
||||
expect(
|
||||
parseData(
|
||||
"<items><item id='1'>A</item><item id='2'>B</item></items>",
|
||||
"xml",
|
||||
).root,
|
||||
).toEqual({
|
||||
items: {
|
||||
item: [
|
||||
{ "@id": "1", "#text": "A" },
|
||||
{ "@id": "2", "#text": "B" },
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(() =>
|
||||
parseData('<!DOCTYPE x [<!ENTITY y "z">]><x>&y;</x>', "xml"),
|
||||
).toThrow(/entity/iu);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseData } from "../../src/core/data";
|
||||
import { runQuery } from "../../src/core/query";
|
||||
describe("query engine", () => {
|
||||
const root = parseData(
|
||||
'[{"team":"a","n":2},{"team":"a","n":4},{"team":"b","n":9}]',
|
||||
"json",
|
||||
).root;
|
||||
it("filters groups aggregates sorts and limits", () => {
|
||||
expect(
|
||||
runQuery(
|
||||
root,
|
||||
"SELECT team, COUNT(*) AS count, AVG(n) AS mean WHERE n >= 2 GROUP BY team ORDER BY mean DESC LIMIT 2",
|
||||
"sql",
|
||||
).rows,
|
||||
).toEqual([
|
||||
{ team: "b", count: 1, mean: 9 },
|
||||
{ team: "a", count: 2, mean: 3 },
|
||||
]);
|
||||
});
|
||||
it("supports bounded path navigation and filtering", () => {
|
||||
expect(runQuery(root, "$[?(@.n >= 4)].team", "path").value).toEqual([
|
||||
"a",
|
||||
"b",
|
||||
]);
|
||||
});
|
||||
it("rejects unsupported syntax rather than evaluating it", () => {
|
||||
expect(() => runQuery(root, "SELECT eval(n)", "sql")).toThrow(
|
||||
/Invalid SELECT/iu,
|
||||
);
|
||||
expect(() => runQuery(root, "$..team", "path")).toThrow(
|
||||
/Unsupported path/iu,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user