11import { expect } from '@playwright/test' ;
2- import { test , get , set } from './playwright'
2+ import { test , setEditorContent , expectEditorContent } from './playwright'
33
44test ( '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
2020test ( '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
3636test ( '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:
5151Line 3: Unknown type: 'invalid'` )
5252} )
5353
5454test ( '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
6464test ( '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
7070test ( '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
110110test ( '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} )
0 commit comments