|
| 1 | +import { EditorState, Text } from "@codemirror/state"; |
| 2 | +import type { EditorView } from "@codemirror/view"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | +import { sqlStructureGutter } from "../structure-extension.js"; |
| 5 | + |
| 6 | +// Mock EditorView |
| 7 | +const _createMockView = (content: string, hasFocus = true) => { |
| 8 | + const doc = Text.of(content.split("\n")); |
| 9 | + const state = EditorState.create({ |
| 10 | + doc, |
| 11 | + extensions: [sqlStructureGutter()], |
| 12 | + }); |
| 13 | + |
| 14 | + return { |
| 15 | + state, |
| 16 | + hasFocus, |
| 17 | + dispatch: () => {}, |
| 18 | + } as any as EditorView; |
| 19 | +}; |
| 20 | + |
| 21 | +describe("sqlStructureGutter", () => { |
| 22 | + it("should create a gutter extension with default config", () => { |
| 23 | + const extensions = sqlStructureGutter(); |
| 24 | + expect(Array.isArray(extensions)).toBe(true); |
| 25 | + expect(extensions.length).toBeGreaterThan(0); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should accept custom configuration", () => { |
| 29 | + const config = { |
| 30 | + backgroundColor: "#ff0000", |
| 31 | + errorBackgroundColor: "#00ff00", |
| 32 | + width: 5, |
| 33 | + className: "custom-sql-gutter", |
| 34 | + showInvalid: false, |
| 35 | + inactiveOpacity: 0.5, |
| 36 | + hideWhenNotFocused: true, |
| 37 | + }; |
| 38 | + |
| 39 | + const extensions = sqlStructureGutter(config); |
| 40 | + expect(Array.isArray(extensions)).toBe(true); |
| 41 | + expect(extensions.length).toBeGreaterThan(0); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should handle empty configuration", () => { |
| 45 | + const extensions = sqlStructureGutter({}); |
| 46 | + expect(Array.isArray(extensions)).toBe(true); |
| 47 | + }); |
| 48 | + |
| 49 | + it("should create extensions for all required parts", () => { |
| 50 | + const extensions = sqlStructureGutter(); |
| 51 | + // Should include state field, update listener, theme, and gutter |
| 52 | + expect(extensions.length).toBe(4); |
| 53 | + }); |
| 54 | + |
| 55 | + it("should handle unfocusedOpacity configuration", () => { |
| 56 | + const config = { unfocusedOpacity: 0.2 }; |
| 57 | + const extensions = sqlStructureGutter(config); |
| 58 | + expect(extensions.length).toBe(4); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should handle whenHide configuration", () => { |
| 62 | + const config = { |
| 63 | + whenHide: (view: EditorView) => view.state.doc.length === 0, |
| 64 | + }; |
| 65 | + const extensions = sqlStructureGutter(config); |
| 66 | + expect(extensions.length).toBe(4); |
| 67 | + }); |
| 68 | + |
| 69 | + it("should work with minimal configuration", () => { |
| 70 | + const config = { width: 2 }; |
| 71 | + const extensions = sqlStructureGutter(config); |
| 72 | + expect(extensions.length).toBe(4); |
| 73 | + }); |
| 74 | +}); |
0 commit comments