@@ -53,3 +53,111 @@ test('Autocomplete for model names', async () => {
5353 await fs . remove ( tempDir )
5454 }
5555} )
56+
57+ // Skip the macro completions test as regular checks because they are flaky and
58+ // covered in other non-integration tests.
59+ test . describe . skip ( 'Macro Completions' , ( ) => {
60+ test ( 'Completion for inbuilt macros' , async ( ) => {
61+ const tempDir = await fs . mkdtemp (
62+ path . join ( os . tmpdir ( ) , 'vscode-test-sushi-' ) ,
63+ )
64+ await fs . copy ( SUSHI_SOURCE_PATH , tempDir )
65+
66+ try {
67+ const { window, close } = await startVSCode ( tempDir )
68+
69+ // Wait for the models folder to be visible
70+ await window . waitForSelector ( 'text=models' )
71+
72+ // Click on the models folder
73+ await window
74+ . getByRole ( 'treeitem' , { name : 'models' , exact : true } )
75+ . locator ( 'a' )
76+ . click ( )
77+
78+ // Open the top_waiters model
79+ await window
80+ . getByRole ( 'treeitem' , { name : 'customers.sql' , exact : true } )
81+ . locator ( 'a' )
82+ . click ( )
83+
84+ await window . waitForSelector ( 'text=grain' )
85+ await window . waitForSelector ( 'text=Loaded SQLMesh Context' )
86+
87+ await window . locator ( 'text=grain' ) . first ( ) . click ( )
88+
89+ // Move to the end of the file
90+ await window . keyboard . press ( 'Control+End' )
91+
92+ // Add a new line
93+ await window . keyboard . press ( 'Enter' )
94+
95+ await window . waitForTimeout ( 500 )
96+
97+ // Hit the '@' key to trigger autocomplete for inbuilt macros
98+ await window . keyboard . press ( '@' )
99+ await window . keyboard . type ( 'eac' )
100+
101+ // Wait a moment for autocomplete to appear
102+ await window . waitForTimeout ( 500 )
103+
104+ // Check if the autocomplete suggestion for inbuilt macros is visible
105+ expect ( await window . locator ( 'text=@each' ) . count ( ) ) . toBe ( 1 )
106+
107+ await close ( )
108+ } finally {
109+ await fs . remove ( tempDir )
110+ }
111+ } )
112+
113+ test ( 'Completion for custom macros' , async ( ) => {
114+ const tempDir = await fs . mkdtemp (
115+ path . join ( os . tmpdir ( ) , 'vscode-test-sushi-' ) ,
116+ )
117+ await fs . copy ( SUSHI_SOURCE_PATH , tempDir )
118+
119+ try {
120+ const { window, close } = await startVSCode ( tempDir )
121+
122+ // Wait for the models folder to be visible
123+ await window . waitForSelector ( 'text=models' )
124+
125+ // Click on the models folder
126+ await window
127+ . getByRole ( 'treeitem' , { name : 'models' , exact : true } )
128+ . locator ( 'a' )
129+ . click ( )
130+
131+ // Open the top_waiters model
132+ await window
133+ . getByRole ( 'treeitem' , { name : 'customers.sql' , exact : true } )
134+ . locator ( 'a' )
135+ . click ( )
136+
137+ await window . waitForSelector ( 'text=grain' )
138+ await window . waitForSelector ( 'text=Loaded SQLMesh Context' )
139+
140+ await window . locator ( 'text=grain' ) . first ( ) . click ( )
141+
142+ // Move to the end of the file
143+ await window . keyboard . press ( 'Control+End' )
144+
145+ // Add a new line
146+ await window . keyboard . press ( 'Enter' )
147+
148+ // Type the beginning of a macro to trigger autocomplete
149+ await window . keyboard . press ( '@' )
150+ await window . keyboard . type ( 'add_o' )
151+
152+ // Wait a moment for autocomplete to appear
153+ await window . waitForTimeout ( 500 )
154+
155+ // Check if the autocomplete suggestion for custom macros is visible
156+ expect ( await window . locator ( 'text=@add_one' ) . count ( ) ) . toBe ( 1 )
157+
158+ await close ( )
159+ } finally {
160+ await fs . remove ( tempDir )
161+ }
162+ } )
163+ } )
0 commit comments