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