-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathbucket-explorer.p.spec.ts
More file actions
375 lines (345 loc) · 14.8 KB
/
bucket-explorer.p.spec.ts
File metadata and controls
375 lines (345 loc) · 14.8 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*
# Copyright 2025 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
*/
// @ts-check
import { test, expect } from './fixture'
test.use({
toolPath: '/tools/bucketexplorer',
toolName: 'Bucket Explorer',
})
//
// Test the basic functionality of the application
//
test('navigate config bucket', async ({ page, utils }) => {
// Initially empty
await expect(
page.getByRole('cell', { name: 'No data available' }),
).toBeVisible()
await page.getByText('config').click()
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/config%2F/)
await page.getByRole('cell', { name: 'DEFAULT' }).click()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
'/ DEFAULT /',
)
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/config%2FDEFAULT%2F/)
await page.getByRole('cell', { name: 'targets', exact: true }).click()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
'/ DEFAULT / targets /',
)
await expect(page).toHaveURL(
/.*\/tools\/bucketexplorer\/config%2FDEFAULT%2Ftargets%2F/,
)
await page.getByRole('cell', { name: 'INST', exact: true }).click()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
'/ DEFAULT / targets / INST /',
)
await expect(page).toHaveURL(
/.*\/tools\/bucketexplorer\/config%2FDEFAULT%2Ftargets%2FINST%2F/,
)
await expect(page.locator('tbody > tr')).toHaveCount(9)
// Clicking a file should do nothing
await page.getByRole('cell', { name: 'target.txt' }).click()
await expect(page).toHaveURL(
/.*\/tools\/bucketexplorer\/config%2FDEFAULT%2Ftargets%2FINST%2F/,
)
await expect(page.locator('tbody > tr')).toHaveCount(9)
// Download the file
await utils.download(
page,
'tbody > tr:has-text("target.txt") [data-test="download-file"]',
function (contents) {
expect(contents).toContain('LANGUAGE')
expect(contents).toContain('IGNORE_PARAMETER')
expect(contents).toContain('IGNORE_ITEM')
},
)
await page.locator('[data-test="be-nav-back"]').click()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
'/ DEFAULT / targets /',
)
await expect(page).toHaveURL(
/.*\/tools\/bucketexplorer\/config%2FDEFAULT%2Ftargets%2F/,
)
await page.locator('[data-test="be-nav-back"]').click()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
'/ DEFAULT /',
)
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/config%2FDEFAULT%2F/)
await page.locator('[data-test="be-nav-back"]').click()
await expect(page.locator('[data-test="file-path"]')).toHaveText('/')
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/config%2F/)
// Back again just to show that doesn't break things
await page.locator('[data-test="be-nav-back"]').click()
await expect(page.locator('[data-test="file-path"]')).toHaveText('/')
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/config%2F/)
})
test('navigate gems volume', async ({ page, utils }) => {
await page.getByText('gems').click()
// Note the URL is prefixed with %2F, i.e. '/'
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/%2Fgems%2F/)
await page.getByRole('cell', { name: 'cosmoscache' }).click()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
'/ cosmoscache /',
)
await expect(page).toHaveURL(
/.*\/tools\/bucketexplorer\/%2Fgems%2Fcosmoscache%2F/,
)
await page.locator('[data-test="search-input"] input').fill('bucket')
await expect(page.locator('tbody > tr')).toHaveCount(1)
// Download the file
await utils.download(page, 'tbody > tr [data-test="download-file"]')
// Reload and ensure we get to the same place
await page.reload()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
'/ cosmoscache /',
)
await expect(page).toHaveURL(
/.*\/tools\/bucketexplorer\/%2Fgems%2Fcosmoscache%2F/,
)
await page.locator('[data-test="search-input"] input').fill('bucket')
await expect(page.locator('tbody > tr')).toHaveCount(1)
})
test('direct URLs', async ({ page }) => {
// Verify using slashes rather than %2F works
await page.goto('/tools/bucketexplorer/config%2FDEFAULT%2Ftargets%2F')
await expect(page.locator('.v-app-bar')).toContainText('Bucket Explorer')
// Can't match exact because Enterprise has the PW_TEST target
await expect.poll(() => page.locator('tr').count()).toBeGreaterThan(4)
// Basic makes it a bucket
await page.goto('/tools/bucketexplorer/blah')
await expect(page.locator('.v-app-bar')).toContainText('Bucket Explorer')
await expect(
page.getByText('Unknown bucket / volume OPENC3_BLAH_BUCKET'),
).toBeVisible()
// Prepending %2F makes it a volume
await page.goto('/tools/bucketexplorer/%2FBAD')
await expect(page.locator('.v-app-bar')).toContainText('Bucket Explorer')
await expect(
page.getByText('Unknown bucket / volume OPENC3_BAD_VOLUME'),
).toBeVisible()
})
test('view file', async ({ page, utils }) => {
await page.getByText('config').click()
await page.getByRole('cell', { name: 'DEFAULT' }).click()
await page.getByRole('cell', { name: 'targets', exact: true }).click()
await page.getByRole('cell', { name: 'INST', exact: true }).click()
await page.getByRole('cell', { name: 'procedures' }).click()
await page.locator('[data-test="search-input"] input').fill('calendar')
await page.locator('[data-test="view-file"]').first().click()
await expect(page.locator('pre')).toContainText('create_timeline')
await page.getByRole('button', { name: 'Ok' }).click()
await page.locator('[data-test="search-input"] input').fill('')
await page.getByText('/ INST').click()
await utils.sleep(500) // Allow the page to render
await page.locator('[data-test="search-input"] input').fill('target.txt')
await page.locator('[data-test="view-file"]').first().click()
await expect(page.locator('pre')).toContainText('LANGUAGE ruby')
await page.getByRole('button', { name: 'Ok' }).click()
})
test('upload and delete', async ({ page, utils }) => {
const randomDir = 'tmp_' + `${Math.random()}`.substring(2)
await page.getByText('config').click()
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/config%2F/)
await expect(page.locator('[data-test="file-path"]')).toHaveText('/')
await page.getByRole('cell', { name: 'DEFAULT' }).click()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
'/ DEFAULT /',
)
// Upload something to make sure the tmp dir exists
await expect(page.getByLabel('prepended action')).toBeVisible()
const [fileChooser1] = await Promise.all([
page.waitForEvent('filechooser'),
await page.getByLabel('prepended action').click(),
])
await fileChooser1.setFiles('package.json')
await page
.locator('[data-test="upload-file-path"] input')
.fill(`DEFAULT/${randomDir}/tmp.json`)
await page.locator('[data-test="upload-file-submit-btn"]').click()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
`/ DEFAULT / ${randomDir} /`,
)
await page.locator('tbody> tr').first().waitFor()
let count = await page.locator('tbody > tr').count()
// Note that Promise.all prevents a race condition
// between clicking and waiting for the file chooser.
await expect(page.getByLabel('prepended action')).toBeVisible()
const [fileChooser] = await Promise.all([
// It is important to call waitForEvent before click to set up waiting.
page.waitForEvent('filechooser'),
// Opens the file chooser.
await page.getByLabel('prepended action').click(),
])
await fileChooser.setFiles('package.json')
await page.locator('[data-test="upload-file-submit-btn"]').click()
await expect
.poll(() => page.locator('tbody > tr').count(), { timeout: 10000 })
.toBeGreaterThanOrEqual(count + 1)
await expect(page.getByRole('cell', { name: 'package.json' })).toBeVisible()
await page
.locator('tr:has-text("package.json") [data-test="delete-file"]')
.click()
await page.locator('[data-test="confirm-dialog-delete"]').click()
await expect
.poll(() => page.locator('tbody > tr').count(), { timeout: 10000 })
.toBeGreaterThanOrEqual(count)
// Note that Promise.all prevents a race condition
// between clicking and waiting for the file chooser.
await expect(page.getByLabel('prepended action')).toBeVisible()
const [fileChooser2] = await Promise.all([
// It is important to call waitForEvent before click to set up waiting.
page.waitForEvent('filechooser'),
// Opens the file chooser.
await page.getByLabel('prepended action').click(),
])
await fileChooser2.setFiles('package.json')
await page
.locator('[data-test="upload-file-path"] input')
.fill(`DEFAULT/${randomDir}/TEST/tmp/myfile.json`)
await page.locator('[data-test="upload-file-submit-btn"]').click()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
`/ DEFAULT / ${randomDir} / TEST / tmp /`,
)
await page
.locator('tr:has-text("myfile.json") [data-test="delete-file"]')
.click()
await page.locator('[data-test="confirm-dialog-delete"]').click()
// Cleanup tmp.json
await page.getByText('logs').click()
await page.getByText('config').click()
await page.getByRole('cell', { name: 'DEFAULT' }).click()
await page.getByRole('cell', { name: randomDir }).click()
await page
.locator('tr:has-text("tmp.json") [data-test="delete-file"]')
.click()
await page.locator('[data-test="confirm-dialog-delete"]').click()
})
test('navigate logs and tools bucket', async ({ page, utils }) => {
test.setTimeout(3 * 60 * 1000) // 3 minutes
// Keep clicking alternatively on tools and then logs to force a refresh
// This allows the DEFAULT folder to appear in time
await expect(async () => {
await page.getByText('tools', { exact: true }).click()
await page.getByText('logs', { exact: true }).click()
await expect(page.getByRole('cell', { name: 'DEFAULT' })).toBeVisible()
}).toPass()
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/logs%2F/)
await page.getByRole('cell', { name: 'DEFAULT' }).click()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
'/ DEFAULT /',
)
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/logs%2FDEFAULT%2F/)
await expect(page.locator('tbody > tr').first()).toHaveText(/\w+_logs/)
// Reload and ensure we get to the same place
await page.reload()
await expect(page.locator('[data-test="file-path"]')).toHaveText(
'/ DEFAULT /',
)
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/logs%2FDEFAULT%2F/)
// Ensure the log files have the correct dates
let date = new Date().toISOString().split('T')[0].replace(/-/g, '')
await page.getByRole('cell', { name: 'raw_logs' }).click()
await page.getByRole('cell', { name: 'tlm' }).click()
await page.getByRole('cell', { name: 'INST', exact: true }).click()
// Verify no bad dates
await expect(page.getByText('1970')).not.toBeVisible()
await page.getByRole('cell', { name: date }).click()
// Don't check for date because 2 files could be present
await expect(
page.getByText('DEFAULT__INST__ALL__rt__raw').first(),
).toBeVisible()
await page.getByText('tools').click()
await expect(page).toHaveURL(/.*\/tools\/bucketexplorer\/tools%2F/)
if (process.env.ENTERPRISE === '1') {
await expect(page.locator('tbody > tr')).toHaveCount(20)
} else {
await expect(page.locator('tbody > tr')).toHaveCount(17)
}
})
test('auto refreshes to update files', async ({
page,
utils,
toolPath,
context,
}) => {
const randomDir = 'tmp_' + `${Math.random()}`.substring(2)
// Upload something from the first tab to make sure the tmp dir exists
await page.getByText('config').click()
await expect(page.getByLabel('prepended action')).toBeVisible()
const [fileChooser1] = await Promise.all([
page.waitForEvent('filechooser'),
await page.getByLabel('prepended action').click(),
])
await fileChooser1.setFiles('package.json')
await page
.locator('[data-test="upload-file-path"] input')
.fill(`DEFAULT/${randomDir}/package1.json`)
await page.locator('[data-test="upload-file-submit-btn"]').click()
// Open another tab and navigate to the tmp dir
const pageTwo = await context.newPage()
pageTwo.goto(toolPath)
await pageTwo.getByText('config').click()
await pageTwo.getByRole('cell', { name: 'DEFAULT' }).click()
await pageTwo.getByRole('cell', { name: randomDir }).click()
// Set the refresh interval on the second tab to be really slow
await pageTwo.locator('[data-test=bucket-explorer-file]').click()
await pageTwo.locator('[data-test=bucket-explorer-file-options]').click()
await pageTwo
.locator('.v-dialog [data-test=refresh-interval] input')
.fill('1000')
await pageTwo
.locator('.v-dialog [data-test=refresh-interval] input')
.press('Enter')
await pageTwo.locator('.v-dialog').press('Escape')
// Upload a file from the first tab
await expect(page.getByLabel('prepended action')).toBeVisible()
const [fileChooser2] = await Promise.all([
page.waitForEvent('filechooser'),
await page.getByLabel('prepended action').click(),
])
await fileChooser2.setFiles('package.json')
await page
.locator('[data-test="upload-file-path"] input')
.fill(`DEFAULT/${randomDir}/package2.json`)
await page.locator('[data-test="upload-file-submit-btn"]').click()
// The second tab shouldn't have refreshed yet, so the file shouldn't be there
await page.locator('tbody> tr').first().waitFor()
await expect(
pageTwo.getByRole('cell', { name: 'package2.json' }),
).not.toBeVisible({ timeout: 10000 })
// Set the refresh interval on the second tab to 1s
await pageTwo.locator('[data-test=bucket-explorer-file]').click()
await pageTwo.locator('[data-test=bucket-explorer-file-options]').click()
await pageTwo
.locator('.v-dialog [data-test=refresh-interval] input')
.fill('1')
await pageTwo
.locator('.v-dialog [data-test=refresh-interval] input')
.press('Enter')
await pageTwo.locator('.v-dialog').press('Escape')
// Second tab should auto refresh in 1s and then the file should be there
await page.locator('tbody> tr').first().waitFor()
await expect(
pageTwo.getByRole('cell', { name: 'package2.json' }),
).toBeVisible()
// Cleanup
await page
.locator('tr:has-text("package1.json") [data-test="delete-file"]')
.click()
await page.locator('[data-test="confirm-dialog-delete"]').click()
await page
.locator('tr:has-text("package2.json") [data-test="delete-file"]')
.click()
await page.locator('[data-test="confirm-dialog-delete"]').click()
})