-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathrender.spec.ts
More file actions
189 lines (157 loc) · 5.7 KB
/
render.spec.ts
File metadata and controls
189 lines (157 loc) · 5.7 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { test, expect } from '@playwright/test'
import path from 'path'
import fs from 'fs-extra'
import os from 'os'
import { openLineageView, runCommand, SUSHI_SOURCE_PATH } from './utils'
import {
createPythonInterpreterSettingsSpecifier,
startCodeServer,
stopCodeServer,
} from './utils_code_server'
test('Render works correctly', async ({ page }) => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-test-sushi-'))
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
const context = await startCodeServer({
tempDir,
})
await createPythonInterpreterSettingsSpecifier(tempDir)
try {
await page.goto(`http://127.0.0.1:${context.codeServerPort}`)
// Wait for the models folder to be visible
await page.waitForSelector('text=models')
// Click on the models folder, excluding external_models
await page
.getByRole('treeitem', { name: 'models', exact: true })
.locator('a')
.click()
// Open the customer_revenue_lifetime model
await page
.getByRole('treeitem', { name: 'customers.sql', exact: true })
.locator('a')
.click()
await page.waitForSelector('text=grain')
await page.waitForSelector('text=Loaded SQLMesh Context')
// Render the model
await runCommand(page, 'Render Model')
// Check if the model is rendered by check if "`oi`.`order_id` AS `order_id`," is in the window
await expect(
page.locator('text="marketing"."customer_id" AS'),
).toBeVisible()
await expect(page.locator('text=sushi.customers (rendered)')).toBeVisible()
} finally {
await stopCodeServer(context)
}
})
test('Render works correctly with model without a description', async ({
page,
}) => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-test-sushi-'))
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
const context = await startCodeServer({
tempDir,
})
await createPythonInterpreterSettingsSpecifier(tempDir)
try {
await page.goto(`http://127.0.0.1:${context.codeServerPort}`)
// Wait for the models folder to be visible
await page.waitForSelector('text=models')
// Click on the models folder, excluding external_models
await page
.getByRole('treeitem', { name: 'models', exact: true })
.locator('a')
.click()
// Open the latest_order model
await page
.getByRole('treeitem', { name: 'latest_order.sql', exact: true })
.locator('a')
.click()
await page.waitForSelector('text=custom_full_with_custom_kind')
await page.waitForSelector('text=Loaded SQLMesh Context')
// Render the model
await runCommand(page, 'Render Model')
// Check if the model is rendered correctly
await expect(page.locator('text="orders"."id" AS "id",')).toBeVisible()
await expect(
page.locator('text=sushi.latest_order (rendered)'),
).toBeVisible()
} finally {
await stopCodeServer(context)
}
})
test('Render works correctly with every rendered model opening a new tab', async ({
page,
}) => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-test-sushi-'))
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
const context = await startCodeServer({
tempDir,
})
await createPythonInterpreterSettingsSpecifier(tempDir)
try {
await page.goto(`http://127.0.0.1:${context.codeServerPort}`)
// Wait for the models folder to be visible
await page.waitForSelector('text=models')
await page
.getByRole('treeitem', { name: 'models', exact: true })
.locator('a')
.click()
await page
.getByRole('treeitem', { name: 'latest_order.sql', exact: true })
.locator('a')
.click()
await page.waitForSelector('text=custom_full_with_custom_kind')
await page.waitForSelector('text=Loaded SQLMesh Context')
// Render the model
await runCommand(page, 'Render Model')
// Check if the model is rendered correctly
await expect(
page.locator('text=sushi.latest_order (rendered)'),
).toBeVisible()
// Open the customers model
await page
.getByRole('treeitem', { name: 'customers.sql', exact: true })
.locator('a')
.click()
await page.waitForSelector('text=grain')
// Render the customers model
await runCommand(page, 'Render Model')
// Assert both tabs exist
await expect(
page.locator('text=sushi.latest_order (rendered)'),
).toBeVisible()
await expect(page.locator('text=sushi.customers (rendered)')).toBeVisible()
} finally {
await stopCodeServer(context)
}
})
test('Render shows model picker when no active editor is open', async ({
page,
}) => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'vscode-test-sushi-'))
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
const context = await startCodeServer({
tempDir,
})
await createPythonInterpreterSettingsSpecifier(tempDir)
try {
// Navigate to code-server instance
await page.goto(`http://127.0.0.1:${context.codeServerPort}`)
await page.waitForLoadState('networkidle')
// Load the lineage view to initialize SQLMesh context (like lineage.spec.ts does)
await openLineageView(page)
// Wait for "Loaded SQLmesh Context" text to appear
await page.waitForSelector('text=Loaded SQLMesh Context')
// Run the render command without any active editor
await runCommand(page, 'Render Model')
// Type to filter for customers model and select it
await page.keyboard.type('customers')
await page.waitForSelector('text=sushi.customers', { timeout: 2_000 })
await page.locator('text=sushi.customers').click()
// Verify the rendered model is shown
await expect(page.locator('text=sushi.customers (rendered)')).toBeVisible({
timeout: 2_000,
})
} finally {
await stopCodeServer(context)
}
})