From 143547b5441b2eadb0daa7915d50654293728dfc Mon Sep 17 00:00:00 2001 From: Rikki Schulte Date: Mon, 13 Nov 2023 15:45:20 +0100 Subject: [PATCH] a few tests to demonstrate a few failing test cases --- src/__tests__/__fixtures__/schemas.ts | 30 +++++++++++++++ src/__tests__/json-completion.spec.ts | 54 ++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/__tests__/__fixtures__/schemas.ts b/src/__tests__/__fixtures__/schemas.ts index 8853f50..4b5f8ac 100644 --- a/src/__tests__/__fixtures__/schemas.ts +++ b/src/__tests__/__fixtures__/schemas.ts @@ -90,3 +90,33 @@ export const testSchema2 = { }, }, } as JSONSchema7; + +export const testSchema3 = { + $ref: "#/definitions/fancyObject", + definitions: { + fancyObject: { + type: "object", + properties: { + foo: { type: "string" }, + bar: { type: "number" }, + }, + }, + }, +} as JSONSchema7; + +export const testSchema4 = { + allOf: [ + { + $ref: "#/definitions/fancyObject", + }, + ], + definitions: { + fancyObject: { + type: "object", + properties: { + foo: { type: "string" }, + bar: { type: "number" }, + }, + }, + }, +} as JSONSchema7; diff --git a/src/__tests__/json-completion.spec.ts b/src/__tests__/json-completion.spec.ts index e3f03ba..4f7a0eb 100644 --- a/src/__tests__/json-completion.spec.ts +++ b/src/__tests__/json-completion.spec.ts @@ -1,6 +1,7 @@ import { describe, it } from "vitest"; -import { expectCompletion } from "./__helpers__/completion.js"; +import { expectCompletion } from "./__helpers__/completion"; +import { testSchema3, testSchema4 } from "./__fixtures__/schemas"; describe("jsonCompletion", () => { it("should return completion data for simple types", async () => { @@ -291,6 +292,57 @@ describe("jsonCompletion", () => { }, ]); }); + it("should autocomplete for array of objects with filter", async () => { + await expectCompletion('{ "arrayOfObjects": [ { "f|" } ] }', [ + { + detail: "string", + info: "", + label: "foo", + template: '"foo": "#{}"', + type: "property", + }, + ]); + }); + it("should autocomplete for a schema with top level $ref", async () => { + await expectCompletion( + '{ "| }', + [ + { + type: "property", + detail: "string", + info: "", + label: "foo", + }, + { + type: "property", + detail: "number", + info: "", + label: "bar", + }, + ], + { schema: testSchema3 } + ); + }); + it("should autocomplete for a schema with top level complex type", async () => { + await expectCompletion( + '{ "| }', + [ + { + type: "property", + detail: "string", + info: "", + label: "foo", + }, + { + type: "property", + detail: "number", + info: "", + label: "bar", + }, + ], + { schema: testSchema4 } + ); + }); }); describe("json5Completion", () => {