Skip to content

Commit 570e6b4

Browse files
committed
tests: stabilize editor content checks
1 parent 9e02049 commit 570e6b4

4 files changed

Lines changed: 76 additions & 79 deletions

File tree

internal/web/tests/02-run.spec.ts

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { expect } from '@playwright/test';
2-
import { test, get, set } from './playwright'
2+
import { test, setEditorContent, expectEditorContent } from './playwright'
33

44
test('run default page with button', async ({ page }) => {
5-
expect(await get('result', true)).toBe('')
5+
await expectEditorContent('result', '')
66

77
await page.getByRole('button', { name: 'run' }).click()
8-
expect(await get('result')).toBe(`[
8+
await expectEditorContent('result', `[
99
{
1010
"_id": ObjectId("5a934e000102030405000000"),
1111
"key": 1
@@ -18,10 +18,10 @@ test('run default page with button', async ({ page }) => {
1818
})
1919

2020
test('run default page with shortcut', async ({ page }) => {
21-
expect(await get('result', true)).toBe('')
21+
await expectEditorContent('result', '')
2222

2323
await page.getByText('Template').press('Control+Enter')
24-
expect(await get('result')).toBe(`[
24+
await expectEditorContent('result', `[
2525
{
2626
"_id": ObjectId("5a934e000102030405000000"),
2727
"key": 1
@@ -35,7 +35,7 @@ test('run default page with shortcut', async ({ page }) => {
3535

3636
test('run incorrect config', async ({ page }) => {
3737

38-
await set('config', `[
38+
await setEditorContent('config', `[
3939
{
4040
a: invalid
4141
}
@@ -47,29 +47,29 @@ test('run incorrect config', async ({ page }) => {
4747
await page.getByRole('button', { name: 'run' }).click()
4848

4949
await expect(page.locator('#resultPanel')).toHaveClass('text_red')
50-
expect(await get('result')).toBe(`Invalid configuration:
50+
await expectEditorContent('result', `Invalid configuration:
5151
Line 3: Unknown type: 'invalid'`)
5252
})
5353

5454
test('run no result', async ({ page }) => {
5555

56-
await set('config', `[{k:1}]`)
57-
await set('query', `db.collection.find({k:2})`)
56+
await setEditorContent('config', `[{k:1}]`)
57+
await setEditorContent('query', `db.collection.find({k:2})`)
5858
await page.getByRole('button', { name: 'run' }).click()
5959

6060
await expect(page.locator('#resultPanel')).not.toHaveClass('text_red')
61-
expect(await get('result')).toBe(`no document found`)
61+
await expectEditorContent('result', 'no document found')
6262
})
6363

6464
test('aggregation query without stages', async ({ page }) => {
65-
await set('query', `db.collection.aggregate([{}])`)
65+
await setEditorContent('query', `db.collection.aggregate([{}])`)
6666
await expect(page.getByText('Stage:')).toBeHidden()
6767
await expect(page.locator('#custom-aggregation_stages')).toBeHidden()
6868
})
6969

7070
test('aggregation query with stages', async ({ page }) => {
7171

72-
await set('query', `db.collection.aggregate([
72+
await setEditorContent('query', `db.collection.aggregate([
7373
{
7474
"$project": {
7575
"_id": 0
@@ -87,7 +87,7 @@ test('aggregation query with stages', async ({ page }) => {
8787
await expect(page.locator('#custom-aggregation_stages ul').getByText('$match')).toBeVisible()
8888

8989
await page.getByRole('button', { name: 'run' }).click()
90-
expect(await get('result')).toBe(`[
90+
await expectEditorContent('result', `[
9191
{
9292
"key": 1
9393
}
@@ -97,7 +97,7 @@ test('aggregation query with stages', async ({ page }) => {
9797
await page.locator('#custom-aggregation_stages ul').getByText('$project').click()
9898

9999
await page.getByRole('button', { name: 'run' }).click()
100-
expect(await get('result')).toBe(`[
100+
await expectEditorContent('result', `[
101101
{
102102
"key": 1
103103
},
@@ -109,13 +109,13 @@ test('aggregation query with stages', async ({ page }) => {
109109

110110
test('test single db template', async ({ page }) => {
111111

112-
await set('config', '')
113-
await set('query', '')
112+
await setEditorContent('config', '')
113+
await setEditorContent('query', '')
114114
await page.getByRole('button', { name: 'single collection' }).click()
115115
await page.locator('#custom-template ul').getByText('single collection').click()
116116

117117
await expect(page.locator('#custom-mode').getByRole('button', { name: 'bson' })).toBeVisible();
118-
expect(await get('config')).toBe(`[
118+
await expectEditorContent('config', `[
119119
{
120120
"key": 1
121121
},
@@ -124,12 +124,12 @@ test('test single db template', async ({ page }) => {
124124
}
125125
]`)
126126

127-
expect(await get('query')).toBe(`db.collection.find()`)
127+
await expectEditorContent('query', `db.collection.find()`)
128128
await expect(page.locator('#custom-aggregation_stage')).toBeHidden();
129129

130-
expect(await get('result', true)).toBe('')
130+
await expectEditorContent('result', '')
131131
await page.getByRole('button', { name: 'run' }).click()
132-
expect(await get('result')).toBe(`[
132+
await expectEditorContent('result', `[
133133
{
134134
"_id": ObjectId("5a934e000102030405000000"),
135135
"key": 1
@@ -147,7 +147,7 @@ test('test multiple db template', async ({ page }) => {
147147
await page.locator('#custom-template ul').getByText('multiple collection').click()
148148

149149
await expect(page.locator('#custom-mode').getByRole('button', { name: 'bson' })).toBeVisible();
150-
expect(await get('config')).toBe(`db={
150+
await expectEditorContent('config', `db={
151151
"orders": [
152152
{
153153
"_id": 1,
@@ -198,7 +198,7 @@ test('test multiple db template', async ({ page }) => {
198198
]
199199
}`)
200200

201-
expect(await get('query')).toBe(`db.orders.aggregate([
201+
await expectEditorContent('query', `db.orders.aggregate([
202202
{
203203
"$lookup": {
204204
"from": "inventory",
@@ -210,9 +210,9 @@ test('test multiple db template', async ({ page }) => {
210210
])`)
211211
await expect(page.getByRole('button', { name: '$lookup' })).toBeVisible();
212212

213-
expect(await get('result', true)).toBe('')
213+
await expectEditorContent('result', '')
214214
await page.getByRole('button', { name: 'run' }).click()
215-
expect(await get('result')).toBe(`[
215+
await expectEditorContent('result', `[
216216
{
217217
"_id": 1,
218218
"inventory_docs": [
@@ -260,7 +260,7 @@ test('test mgodatagen template', async ({ page }) => {
260260
await page.locator('#custom-template ul').getByText('mgodatagen').click()
261261

262262
await expect(page.locator('#custom-mode').getByRole('button', { name: 'mgodatagen' })).toBeVisible();
263-
expect(await get('config')).toBe(`[
263+
await expectEditorContent('config', `[
264264
{
265265
"collection": "collection",
266266
"count": 10,
@@ -274,12 +274,12 @@ test('test mgodatagen template', async ({ page }) => {
274274
}
275275
]`)
276276

277-
expect(await get('query')).toBe(`db.collection.find()`)
277+
await expectEditorContent('query', `db.collection.find()`)
278278
await expect(page.locator('#custom-aggregation_stage')).toBeHidden();
279279

280-
expect(await get('result', true)).toBe('')
280+
await expectEditorContent('result', '')
281281
await page.getByRole('button', { name: 'run' }).click()
282-
expect(await get('result')).toBe(`[
282+
await expectEditorContent('result', `[
283283
{
284284
"_id": ObjectId("5a934e000102030405000000"),
285285
"key": 10
@@ -329,7 +329,7 @@ test('test update template', async ({ page }) => {
329329
await page.locator('#custom-template ul').getByText('update').click()
330330

331331
await expect(page.locator('#custom-mode').getByRole('button', { name: 'bson' })).toBeVisible();
332-
expect(await get('config')).toBe(`[
332+
await expectEditorContent('config', `[
333333
{
334334
"key": 1
335335
},
@@ -338,7 +338,7 @@ test('test update template', async ({ page }) => {
338338
}
339339
]`)
340340

341-
expect(await get('query')).toBe(`db.collection.update({
341+
await expectEditorContent('query', `db.collection.update({
342342
"key": 2
343343
},
344344
{
@@ -352,9 +352,9 @@ test('test update template', async ({ page }) => {
352352
})`)
353353
await expect(page.locator('#custom-aggregation_stage')).toBeHidden();
354354

355-
expect(await get('result', true)).toBe('')
355+
await expectEditorContent('result', '')
356356
await page.getByRole('button', { name: 'run' }).click()
357-
expect(await get('result')).toBe(`[
357+
await expectEditorContent('result', `[
358358
{
359359
"_id": ObjectId("5a934e000102030405000000"),
360360
"key": 1
@@ -373,7 +373,7 @@ test('test index template', async ({ page }) => {
373373
await page.locator('#custom-template ul').getByText('index').click()
374374

375375
await expect(page.locator('#custom-mode').getByRole('button', { name: 'mgodatagen' })).toBeVisible();
376-
expect(await get('config')).toBe(`[
376+
await expectEditorContent('config', `[
377377
{
378378
"collection": "collection",
379379
"count": 5,
@@ -400,16 +400,16 @@ test('test index template', async ({ page }) => {
400400
}
401401
]`)
402402

403-
expect(await get('query')).toBe(`db.collection.find({
403+
await expectEditorContent('query', `db.collection.find({
404404
"$text": {
405405
"$search": "coffee"
406406
}
407407
})`)
408408
await expect(page.locator('#custom-aggregation_stage')).toBeHidden();
409409

410-
expect(await get('result', true)).toBe('')
410+
await expectEditorContent('result', '')
411411
await page.getByRole('button', { name: 'run' }).click()
412-
expect(await get('result')).toBe(`[
412+
await expectEditorContent('result', `[
413413
{
414414
"_id": ObjectId("5a934e000102030405000002"),
415415
"description": "Just coffee"
@@ -427,7 +427,7 @@ test('test explain template', async ({ page }) => {
427427
await page.locator('#custom-template ul').getByText('explain').click()
428428

429429
await expect(page.locator('#custom-mode').getByRole('button', { name: 'bson' })).toBeVisible();
430-
expect(await get('config')).toBe(`[
430+
await expectEditorContent('config', `[
431431
{
432432
"_id": 1,
433433
"item": "ABC",
@@ -463,7 +463,7 @@ test('test explain template', async ({ page }) => {
463463
}
464464
]`)
465465

466-
expect(await get('query')).toBe(`db.collection.aggregate([
466+
await expectEditorContent('query', `db.collection.aggregate([
467467
{
468468
"$unwind": {
469469
"path": "$sizes",
@@ -484,9 +484,8 @@ test('test explain template', async ({ page }) => {
484484
}
485485
}
486486
]).explain("executionStats")`)
487-
await expect(page.getByRole('button', {name: "$sort"})).toBeVisible();
487+
await expect(page.getByRole('button', { name: "$sort" })).toBeVisible();
488488

489-
expect(await get('result', true)).toBe('')
489+
await expectEditorContent('result', '')
490490
await page.getByRole('button', { name: 'run' }).click()
491-
expect(await (await get('result')).slice(0,1)).toBe('{')
492491
})

internal/web/tests/03-format.spec.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { expect } from '@playwright/test'
2-
import { test, get, set } from './playwright'
1+
import { test, setEditorContent, expectEditorContent } from './playwright'
32

43
test('format default page', async ({ page }) => {
54

@@ -13,30 +12,30 @@ test('format default page', async ({ page }) => {
1312
]`
1413
const queryTxt = 'db.collection.find()'
1514

16-
expect(await get('config')).toBe(configTxt)
17-
expect(await get('query')).toBe(queryTxt)
15+
await expectEditorContent('config', configTxt)
16+
await expectEditorContent('query', queryTxt)
1817

1918
await page.getByRole('button', { name: 'format' }).click()
20-
expect(await get('config')).toBe(configTxt)
21-
expect(await get('query')).toBe(queryTxt)
19+
await expectEditorContent('config', configTxt)
20+
await expectEditorContent('query', queryTxt)
2221
})
2322

2423
test('format with button', async ({ page }) => {
2524

26-
await set('query', 'db.collection.find({key:1})')
25+
await setEditorContent('query', 'db.collection.find({key:1})')
2726
await page.getByRole('button', { name: 'format' }).click()
2827

29-
expect(await get('query')).toBe(`db.collection.find({
28+
await expectEditorContent('query', `db.collection.find({
3029
key: 1
3130
})`)
3231
})
3332

3433
test('format with shortcut', async ({ page }) => {
3534

36-
await set('query', 'db.collection.find({key:1})')
35+
await setEditorContent('query', 'db.collection.find({key:1})')
3736
await page.getByText('Template').press('Control+s')
3837

39-
expect(await get('query')).toBe(`db.collection.find({
38+
await expectEditorContent('query', `db.collection.find({
4039
key: 1
4140
})`)
4241
})

internal/web/tests/04-share.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { expect } from '@playwright/test';
2-
import { test, get, set } from './playwright'
2+
import { test, setEditorContent, expectEditorContent } from './playwright'
33

44
test('changing config enables share', async ({ page }) => {
55

66
const shareButton = page.getByRole('button', { name: 'share' })
77
await expect(shareButton).toBeDisabled()
8-
await set('config', '[]')
8+
await setEditorContent('config', '[]')
99
await shareButton.click()
1010
await expect(page).toHaveURL(/p\/4btTeezhQ_i/)
1111
await expect(shareButton).toBeDisabled()
@@ -15,7 +15,7 @@ test('changing query enables share', async ({ page }) => {
1515

1616
const shareButton = page.getByRole('button', { name: 'share' })
1717
await expect(shareButton).toBeDisabled()
18-
await set('query', 'db.c.find({v:"a"})')
18+
await setEditorContent('query', 'db.c.find({v:"a"})')
1919
await shareButton.click()
2020
await expect(page).toHaveURL(/p\/IIAf09j3hnm/)
2121
await expect(shareButton).toBeDisabled()
@@ -34,29 +34,29 @@ test('changing mode enables share', async ({ page }) => {
3434

3535
test('sharing format the playground', async ({ page }) => {
3636

37-
await set('config', '[{}]')
37+
await setEditorContent('config', '[{}]')
3838
await page.getByRole('button', { name: 'share' }).click()
3939
await expect(page).toHaveURL(/p\/4cOeA7NGLru/)
40-
expect(await get('config')).toBe(`[
40+
await expectEditorContent('config', `[
4141
{}
4242
]`)
4343
})
4444

4545
test('run after share does not change URL', async ({ page }) => {
4646

47-
await set('config', 'db={"a":[{k:1}]}')
48-
await set('query', 'db.a.find({},{_id:0})')
47+
await setEditorContent('config', 'db={"a":[{k:1}]}')
48+
await setEditorContent('query', 'db.a.find({},{_id:0})')
4949

5050
await page.getByRole('button', { name: 'run' }).click()
51-
expect(await get('result')).toBe(`[
51+
await expectEditorContent('result', `[
5252
{
5353
"k": 1
5454
}
5555
]`)
5656
await page.getByRole('button', { name: 'share' }).click()
5757
await expect(page).toHaveURL(/p\/iKNbEa-etwo/)
5858
await page.getByRole('button', { name: 'run' }).click()
59-
expect(await get('result')).toBe(`[
59+
await expectEditorContent('result', `[
6060
{
6161
"k": 1
6262
}
@@ -67,7 +67,7 @@ test('run after share does not change URL', async ({ page }) => {
6767
test('sharing show copied tooltip', async ({ page }) => {
6868
await expect(page.getByText("Copied")).toBeHidden()
6969

70-
await set('config', '{')
70+
await setEditorContent('config', '{')
7171
await page.getByRole('button', { name: 'share' }).click()
7272
await expect(page).toHaveURL(/p\/MMrQg5UYwYX/)
7373

@@ -77,12 +77,12 @@ test('sharing show copied tooltip', async ({ page }) => {
7777
test('saving the same playground twice returns the same URL', async ({ page }) => {
7878
await expect(page.getByText("Copied")).toBeHidden()
7979

80-
await set('config', '{"_id":1}')
80+
await setEditorContent('config', '{"_id":1}')
8181
await page.getByRole('button', { name: 'share' }).click()
8282
await expect(page).toHaveURL(/p\/Cz5OkFt6TSH/)
8383

84-
await set('config', '')
85-
await set('config', '{"_id":1}')
84+
await setEditorContent('config', '')
85+
await setEditorContent('config', '{"_id":1}')
8686
await page.getByRole('button', { name: 'share' }).click()
8787
await expect(page).toHaveURL(/p\/Cz5OkFt6TSH/)
8888
})

0 commit comments

Comments
 (0)