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