11import { EditorState , Text } from "@codemirror/state" ;
22import type { EditorView } from "@codemirror/view" ;
33import { describe , expect , it } from "vitest" ;
4+ import { SqlParser } from "../parser.js" ;
45import { sqlStructureGutter } from "../structure-extension.js" ;
56
7+ const defaultParser = new SqlParser ( { dialect : "PostgresQL" } ) ;
8+
69// Mock EditorView
710const _createMockView = ( content : string , hasFocus = true ) => {
811 const doc = Text . of ( content . split ( "\n" ) ) ;
912 const state = EditorState . create ( {
1013 doc,
11- extensions : [ sqlStructureGutter ( ) ] ,
14+ extensions : [ sqlStructureGutter ( defaultParser ) ] ,
1215 } ) ;
1316
1417 return {
@@ -20,7 +23,7 @@ const _createMockView = (content: string, hasFocus = true) => {
2023
2124describe ( "sqlStructureGutter" , ( ) => {
2225 it ( "should create a gutter extension with default config" , ( ) => {
23- const extensions = sqlStructureGutter ( ) ;
26+ const extensions = sqlStructureGutter ( defaultParser ) ;
2427 expect ( Array . isArray ( extensions ) ) . toBe ( true ) ;
2528 expect ( extensions . length ) . toBeGreaterThan ( 0 ) ;
2629 } ) ;
@@ -36,39 +39,39 @@ describe("sqlStructureGutter", () => {
3639 hideWhenNotFocused : true ,
3740 } ;
3841
39- const extensions = sqlStructureGutter ( config ) ;
42+ const extensions = sqlStructureGutter ( defaultParser , config ) ;
4043 expect ( Array . isArray ( extensions ) ) . toBe ( true ) ;
4144 expect ( extensions . length ) . toBeGreaterThan ( 0 ) ;
4245 } ) ;
4346
4447 it ( "should handle empty configuration" , ( ) => {
45- const extensions = sqlStructureGutter ( { } ) ;
48+ const extensions = sqlStructureGutter ( defaultParser ) ;
4649 expect ( Array . isArray ( extensions ) ) . toBe ( true ) ;
4750 } ) ;
4851
4952 it ( "should create extensions for all required parts" , ( ) => {
50- const extensions = sqlStructureGutter ( ) ;
53+ const extensions = sqlStructureGutter ( defaultParser ) ;
5154 // Should include state field, update listener, theme, and gutter
5255 expect ( extensions . length ) . toBe ( 4 ) ;
5356 } ) ;
5457
5558 it ( "should handle unfocusedOpacity configuration" , ( ) => {
5659 const config = { unfocusedOpacity : 0.2 } ;
57- const extensions = sqlStructureGutter ( config ) ;
60+ const extensions = sqlStructureGutter ( defaultParser , config ) ;
5861 expect ( extensions . length ) . toBe ( 4 ) ;
5962 } ) ;
6063
6164 it ( "should handle whenHide configuration" , ( ) => {
6265 const config = {
6366 whenHide : ( view : EditorView ) => view . state . doc . length === 0 ,
6467 } ;
65- const extensions = sqlStructureGutter ( config ) ;
68+ const extensions = sqlStructureGutter ( defaultParser , config ) ;
6669 expect ( extensions . length ) . toBe ( 4 ) ;
6770 } ) ;
6871
6972 it ( "should work with minimal configuration" , ( ) => {
7073 const config = { width : 2 } ;
71- const extensions = sqlStructureGutter ( config ) ;
74+ const extensions = sqlStructureGutter ( defaultParser , config ) ;
7275 expect ( extensions . length ) . toBe ( 4 ) ;
7376 } ) ;
7477} ) ;
0 commit comments