From 761c24b855107cf8955feae6c97fa1730014ef05 Mon Sep 17 00:00:00 2001 From: ecmel Date: Mon, 4 Dec 2023 15:38:17 +0300 Subject: [PATCH] more tests --- test/fixtures/webview.ts | 1 + test/suite/webview.test.ts | 81 +++++++++++++++++++++++++++++++++----- 2 files changed, 72 insertions(+), 10 deletions(-) diff --git a/test/fixtures/webview.ts b/test/fixtures/webview.ts index 5118b381..b1f51ac4 100644 --- a/test/fixtures/webview.ts +++ b/test/fixtures/webview.ts @@ -32,6 +32,7 @@ global.acquireVsCodeApi = function () { export class LitElement { connectedCallback() {} disconnectedCallback() {} + requestUpdate() {} } export function html(strings: any, ...values: unknown[]) { return { strings, values }; diff --git a/test/suite/webview.test.ts b/test/suite/webview.test.ts index 9ce613a1..8f901d9c 100644 --- a/test/suite/webview.test.ts +++ b/test/suite/webview.test.ts @@ -239,40 +239,101 @@ describe("KdbDataSourceView", () => { describe("renderFilter", () => { it("should render filter", () => { const filter = createFilter(); - const result = view["renderFilter"](filter); - assert.ok(result.values); + const render = view["renderFilter"](filter); + (render.values[1] as any)({ target: { checked: true } }); + assert.strictEqual(filter.active, true); + (render.values[3] as any)({ target: { value: "test" } }); + assert.strictEqual(filter.column, "test"); + (render.values[6] as any)({ target: { value: "test" } }); + assert.strictEqual(filter.column, "test"); + (render.values[9] as any)({ target: { value: "test" } }); + assert.strictEqual(filter.column, "test"); + let result = false; + sinon.stub(view, "requestUpdate").value(() => (result = true)); + (render.values[11] as any)(); + assert.strictEqual(result, true); + result = false; + view.filters = [filter]; + (render.values[12] as any)(); + assert.strictEqual(result, true); }); }); describe("renderLabel", () => { it("should render label", () => { const label = createLabel(); - const result = view["renderLabel"](label); - assert.ok(result.values); + const render = view["renderLabel"](label); + (render.values[1] as any)({ target: { checked: true } }); + assert.strictEqual(label.active, true); + (render.values[3] as any)({ target: { value: "test" } }); + assert.strictEqual(label.key, "test"); + (render.values[6] as any)({ target: { value: "test" } }); + assert.strictEqual(label.key, "test"); + let result = false; + sinon.stub(view, "requestUpdate").value(() => (result = true)); + (render.values[8] as any)(); + assert.strictEqual(result, true); + view.labels = [label]; + (render.values[9] as any)(); + assert.strictEqual(result, true); }); }); describe("renderSort", () => { it("should render sort", () => { const sort = createSort(); - const result = view["renderSort"](sort); - assert.ok(result.values); + const render = view["renderSort"](sort); + (render.values[1] as any)({ target: { checked: true } }); + assert.strictEqual(sort.active, true); + (render.values[3] as any)({ target: { value: "test" } }); + assert.strictEqual(sort.column, "test"); + let result = false; + sinon.stub(view, "requestUpdate").value(() => (result = true)); + (render.values[5] as any)(); + assert.strictEqual(result, true); + view.sorts = [sort]; + (render.values[6] as any)(); + assert.strictEqual(result, true); }); }); describe("renderAgg", () => { it("should render agg", () => { const agg = createAgg(); - const result = view["renderAgg"](agg); - assert.ok(result.values); + const render = view["renderAgg"](agg); + (render.values[1] as any)({ target: { checked: true } }); + assert.strictEqual(agg.active, true); + (render.values[3] as any)({ target: { value: "test" } }); + assert.strictEqual(agg.key, "test"); + (render.values[6] as any)({ target: { value: "test" } }); + assert.strictEqual(agg.operator, "test"); + (render.values[9] as any)({ target: { value: "test" } }); + assert.strictEqual(agg.column, "test"); + let result = false; + sinon.stub(view, "requestUpdate").value(() => (result = true)); + (render.values[11] as any)(); + assert.strictEqual(result, true); + view.aggs = [agg]; + (render.values[12] as any)(); + assert.strictEqual(result, true); }); }); describe("renderGroup", () => { it("should render group", () => { const group = createGroup(); - const result = view["renderGroup"](group); - assert.ok(result.values); + const render = view["renderGroup"](group); + (render.values[1] as any)({ target: { checked: true } }); + assert.strictEqual(group.active, true); + (render.values[3] as any)({ target: { value: "test" } }); + assert.strictEqual(group.column, "test"); + let result = false; + sinon.stub(view, "requestUpdate").value(() => (result = true)); + (render.values[5] as any)(); + assert.strictEqual(result, true); + view.groups = [group]; + (render.values[6] as any)(); + assert.strictEqual(result, true); }); });