diff --git a/src/codemirror/utils/__tests__/autocomplete-utils.test.ts b/src/codemirror/utils/__tests__/autocomplete-utils.test.ts new file mode 100644 index 0000000..bdd5765 --- /dev/null +++ b/src/codemirror/utils/__tests__/autocomplete-utils.test.ts @@ -0,0 +1,333 @@ +import { + extractAlreadyUsedProps, + isInsideAttribute, + isInsideOpenTag, + getNewTagContext, + shouldTriggerPropSuggestions, +} from "../autocomplete-utils"; +import { describe } from "vitest"; + +describe("autocomplete-utils", () => { + describe("getNewTagContext", () => { + it('should return an empty string if just "<" is typed', () => { + expect(getNewTagContext("<")).toBe(""); + }); + + it("should return the partial tag name if in the middle of typing a tag", () => { + expect(getNewTagContext(" { + expect(getNewTagContext("Just some random text")).toBe(null); + }); + + it("should handle multiple tags correctly and return the latest context if cursor is at the end", () => { + expect(getNewTagContext("
{ + expect(getNewTagContext("
")).toBe(null); + }); + + it("should return null if tag is completed and closed with matching tag", () => { + expect(getNewTagContext("
")).toBe(null); + }); + + it("should return null if complete tag contains attributes", () => { + expect(getNewTagContext("
")).toBe(null); + }); + + it("should return null if incomplete tag contains attributes", () => { + expect(getNewTagContext("
{ + expect(getNewTagContext(""; + const cursorPos = text.indexOf(">"); + expect(isInsideOpenTag(text, cursorPos)).toBeTruthy(); + }); + + it("should return false if cursor is at tag children position", () => { + const text = ""; + const cursorPos = text.indexOf(">") + 1; + expect(isInsideOpenTag(text, cursorPos)).toBeFalsy(); + }); + + it("should return true if cursor is within the open tag that has a space after the tag name and before a close bracket", () => { + const text = "