Skip to content

Commit

Permalink
a few tests to demonstrate a few failing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Nov 13, 2023
1 parent 04d9368 commit 143547b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/__tests__/__fixtures__/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
54 changes: 53 additions & 1 deletion src/__tests__/json-completion.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down Expand Up @@ -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", () => {
Expand Down

0 comments on commit 143547b

Please sign in to comment.