Skip to content

Commit 0142677

Browse files
committed
Convert to use prettier
1 parent 35efd8d commit 0142677

File tree

2 files changed

+113
-100
lines changed

2 files changed

+113
-100
lines changed

packages/compass-collection/src/components/mock-data-generator-modal/script-generation-utils.spec.ts

Lines changed: 98 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ describe('Script Generation', () => {
9494

9595
expect(result.success).to.equal(true);
9696
if (result.success) {
97-
const expectedReturnBlock = `return {
98-
tags: Array.from({length: 3}, () => faker.lorem.word())
99-
};`;
100-
expect(result.script).to.contain(expectedReturnBlock);
97+
expect(result.script).to.contain('Array.from');
98+
expect(result.script).to.contain('length: 3');
99+
expect(result.script).to.contain('faker.lorem.word()');
101100

102101
// Test that the generated document code is executable
103102
const document = testDocumentCodeExecution(result.script);
@@ -122,9 +121,8 @@ describe('Script Generation', () => {
122121

123122
expect(result.success).to.equal(true);
124123
if (result.success) {
125-
// Should generate the complete return block with proper structure
126124
const expectedReturnBlock = `return {
127-
users: Array.from({length: 3}, () => ({
125+
users: Array.from({ length: 3 }, () => ({
128126
name: faker.person.fullName(),
129127
email: faker.internet.email()
130128
}))
@@ -157,7 +155,11 @@ describe('Script Generation', () => {
157155
expect(result.success).to.equal(true);
158156
if (result.success) {
159157
const expectedReturnBlock = `return {
160-
matrix: Array.from({length: 3}, () => Array.from({length: 3}, () => faker.number.int()))
158+
matrix: Array.from({ length: 3 }, () =>
159+
Array.from({ length: 3 }, () =>
160+
faker.number.int()
161+
)
162+
)
161163
};`;
162164
expect(result.script).to.contain(expectedReturnBlock);
163165

@@ -186,9 +188,11 @@ describe('Script Generation', () => {
186188
expect(result.success).to.equal(true);
187189
if (result.success) {
188190
const expectedReturnBlock = `return {
189-
users: Array.from({length: 3}, () => ({
191+
users: Array.from({ length: 3 }, () => ({
190192
name: faker.person.fullName(),
191-
tags: Array.from({length: 3}, () => faker.lorem.word())
193+
tags: Array.from({ length: 3 }, () =>
194+
faker.lorem.word()
195+
)
192196
}))
193197
};`;
194198
expect(result.script).to.contain(expectedReturnBlock);
@@ -224,9 +228,11 @@ describe('Script Generation', () => {
224228
if (result.success) {
225229
const expectedReturnBlock = `return {
226230
title: faker.lorem.sentence(),
227-
authors: Array.from({length: 3}, () => ({
231+
authors: Array.from({ length: 3 }, () => ({
228232
name: faker.person.fullName(),
229-
books: Array.from({length: 3}, () => faker.lorem.words())
233+
books: Array.from({ length: 3 }, () =>
234+
faker.lorem.words()
235+
)
230236
})),
231237
publishedYear: faker.date.recent()
232238
};`;
@@ -282,10 +288,7 @@ describe('Script Generation', () => {
282288

283289
expect(result.success).to.equal(true);
284290
if (result.success) {
285-
const expectedReturnBlock = `return {
286-
value: faker.number.int()
287-
};`;
288-
expect(result.script).to.contain(expectedReturnBlock);
291+
expect(result.script).to.contain('faker.number.int()');
289292

290293
// Test that the generated document code is executable
291294
const document = testDocumentCodeExecution(result.script);
@@ -346,13 +349,10 @@ describe('Script Generation', () => {
346349

347350
expect(result.success).to.equal(true);
348351
if (result.success) {
349-
// These should be treated as regular field names, not arrays
350-
const expectedReturnBlock = `return {
351-
"squareBrackets[]InMiddle": faker.lorem.word(),
352-
"field[]WithMore": faker.lorem.word(),
353-
"start[]middle[]end": faker.lorem.word()
354-
};`;
355-
expect(result.script).to.contain(expectedReturnBlock);
352+
// Verify these are treated as regular field names, not arrays
353+
expect(result.script).to.contain('"squareBrackets[]InMiddle"');
354+
expect(result.script).to.contain('"field[]WithMore"');
355+
expect(result.script).to.contain('"start[]middle[]end"');
356356
expect(result.script).not.to.contain('Array.from');
357357

358358
// Test that the generated document code is executable
@@ -385,6 +385,9 @@ describe('Script Generation', () => {
385385
// Should not contain unescaped special characters that could break JS
386386
expect(result.script).not.to.contain("use('test'db");
387387
expect(result.script).not.to.contain("getCollection('coll\nwith");
388+
389+
// Test that the generated document code is executable
390+
testDocumentCodeExecution(result.script);
388391
}
389392
});
390393
});
@@ -403,10 +406,8 @@ describe('Script Generation', () => {
403406

404407
expect(result.success).to.equal(true);
405408
if (result.success) {
406-
const expectedReturnBlock = `return {
407-
tags: Array.from({length: 3}, () => faker.lorem.word())
408-
};`;
409-
expect(result.script).to.contain(expectedReturnBlock);
409+
expect(result.script).to.contain('length: 3');
410+
expect(result.script).to.contain('faker.lorem.word()');
410411

411412
// Test that the generated document code is executable
412413
const document = testDocumentCodeExecution(result.script);
@@ -432,10 +433,8 @@ describe('Script Generation', () => {
432433

433434
expect(result.success).to.equal(true);
434435
if (result.success) {
435-
const expectedReturnBlock = `return {
436-
tags: Array.from({length: 5}, () => faker.lorem.word())
437-
};`;
438-
expect(result.script).to.contain(expectedReturnBlock);
436+
expect(result.script).to.contain('length: 5');
437+
expect(result.script).to.contain('faker.lorem.word()');
439438

440439
// Test that the generated document code is executable
441440
const document = testDocumentCodeExecution(result.script);
@@ -463,8 +462,10 @@ describe('Script Generation', () => {
463462
expect(result.success).to.equal(true);
464463
if (result.success) {
465464
const expectedReturnBlock = `return {
466-
users: Array.from({length: 5}, () => ({
467-
tags: Array.from({length: 4}, () => faker.lorem.word())
465+
users: Array.from({ length: 5 }, () => ({
466+
tags: Array.from({ length: 4 }, () =>
467+
faker.lorem.word()
468+
)
468469
}))
469470
};`;
470471
expect(result.script).to.contain(expectedReturnBlock);
@@ -498,10 +499,13 @@ describe('Script Generation', () => {
498499

499500
expect(result.success).to.equal(true);
500501
if (result.success) {
501-
// Should have tags array with length 0 (empty array) and categories with length 2
502502
const expectedReturnBlock = `return {
503-
tags: Array.from({length: 0}, () => faker.lorem.word()),
504-
categories: Array.from({length: 2}, () => faker.lorem.word())
503+
tags: Array.from({ length: 0 }, () =>
504+
faker.lorem.word()
505+
),
506+
categories: Array.from({ length: 2 }, () =>
507+
faker.lorem.word()
508+
)
505509
};`;
506510
expect(result.script).to.contain(expectedReturnBlock);
507511

@@ -537,8 +541,18 @@ describe('Script Generation', () => {
537541
expect(result.success).to.equal(true);
538542
if (result.success) {
539543
const expectedReturnBlock = `return {
540-
matrix: Array.from({length: 2}, () => Array.from({length: 5}, () => faker.number.int())),
541-
cube: Array.from({length: 3}, () => Array.from({length: 4}, () => Array.from({length: 2}, () => faker.number.float())))
544+
matrix: Array.from({ length: 2 }, () =>
545+
Array.from({ length: 5 }, () =>
546+
faker.number.int()
547+
)
548+
),
549+
cube: Array.from({ length: 3 }, () =>
550+
Array.from({ length: 4 }, () =>
551+
Array.from({ length: 2 }, () =>
552+
faker.number.float()
553+
)
554+
)
555+
)
542556
};`;
543557
expect(result.script).to.contain(expectedReturnBlock);
544558

@@ -572,17 +586,24 @@ describe('Script Generation', () => {
572586

573587
expect(result.success).to.equal(true);
574588
if (result.success) {
575-
// Complex nested structure with custom array lengths
576589
const expectedReturnBlock = `return {
577-
users: Array.from({length: 2}, () => ({
590+
users: Array.from({ length: 2 }, () => ({
578591
name: faker.person.fullName(),
579-
tags: Array.from({length: 3}, () => faker.lorem.word()),
580-
posts: Array.from({length: 4}, () => ({
592+
tags: Array.from({ length: 3 }, () =>
593+
faker.lorem.word()
594+
),
595+
posts: Array.from({ length: 4 }, () => ({
581596
title: faker.lorem.sentence(),
582-
comments: Array.from({length: 5}, () => faker.lorem.words())
597+
comments: Array.from({ length: 5 }, () =>
598+
faker.lorem.words()
599+
)
583600
}))
584601
})),
585-
matrix: Array.from({length: 2}, () => Array.from({length: 3}, () => faker.number.int()))
602+
matrix: Array.from({ length: 2 }, () =>
603+
Array.from({ length: 3 }, () =>
604+
faker.number.int()
605+
)
606+
)
586607
};`;
587608
expect(result.script).to.contain(expectedReturnBlock);
588609

@@ -614,19 +635,18 @@ describe('Script Generation', () => {
614635
expect(result.success).to.equal(true);
615636
if (result.success) {
616637
// Verify field names with [] in middle are treated as regular field names
617-
expect(result.script).to.contain(
618-
'"brackets[]InMiddle": faker.lorem.word()'
619-
);
638+
expect(result.script).to.contain('"brackets[]InMiddle"');
639+
expect(result.script).to.contain('faker.lorem.word()');
620640

621641
// Verify array of objects with bracket field names containing arrays
622-
expect(result.script).to.contain(
623-
'items: Array.from({length: 2}, () => ({\n "nested[]ArrayFieldWithBrackets": Array.from({length: 3}, () => faker.lorem.sentence())'
624-
);
642+
expect(result.script).to.contain('"nested[]ArrayFieldWithBrackets"');
643+
expect(result.script).to.contain('Array.from({ length: 3 }');
644+
expect(result.script).to.contain('faker.lorem.sentence()');
625645

626646
// Verify multi-dimensional arrays with bracket field names
627-
expect(result.script).to.contain(
628-
'"matrix[]WithBrackets": Array.from({length: 2}, () => Array.from({length: 4}, () => faker.number.int()))'
629-
);
647+
expect(result.script).to.contain('"matrix[]WithBrackets"');
648+
expect(result.script).to.contain('Array.from({ length: 2 }');
649+
expect(result.script).to.contain('faker.number.int()');
630650

631651
// Test that the generated document code is executable
632652
const document = testDocumentCodeExecution(result.script);
@@ -673,10 +693,7 @@ describe('Script Generation', () => {
673693

674694
expect(result.success).to.equal(true);
675695
if (result.success) {
676-
const expectedReturnBlock = `return {
677-
unknownField: faker.lorem.word()
678-
};`;
679-
expect(result.script).to.contain(expectedReturnBlock);
696+
expect(result.script).to.contain('faker.lorem.word()');
680697

681698
// Test that the generated document code is executable
682699
const document = testDocumentCodeExecution(result.script);
@@ -997,9 +1014,9 @@ describe('Script Generation', () => {
9971014

9981015
expect(result.success).to.equal(true);
9991016
if (result.success) {
1000-
expect(result.script).to.contain(
1001-
'faker.number.int({"min":0,"max":100})'
1002-
);
1017+
expect(result.script).to.contain('faker.number.int(');
1018+
expect(result.script).to.contain('min: 0');
1019+
expect(result.script).to.contain('max: 100');
10031020

10041021
// Test that the generated document code is executable
10051022
testDocumentCodeExecution(result.script);
@@ -1023,9 +1040,10 @@ describe('Script Generation', () => {
10231040

10241041
expect(result.success).to.equal(true);
10251042
if (result.success) {
1026-
expect(result.script).to.contain(
1027-
"faker.helpers.arrayElement(['red', 'blue', 'green'])"
1028-
);
1043+
expect(result.script).to.contain('faker.helpers.arrayElement(');
1044+
expect(result.script).to.contain('red');
1045+
expect(result.script).to.contain('blue');
1046+
expect(result.script).to.contain('green');
10291047

10301048
// Test that the generated document code is executable
10311049
testDocumentCodeExecution(result.script);
@@ -1075,9 +1093,9 @@ describe('Script Generation', () => {
10751093

10761094
expect(result.success).to.equal(true);
10771095
if (result.success) {
1078-
expect(result.script).to.contain(
1079-
'faker.helpers.arrayElement(["It\'s a \'test\' string", "another option"])'
1080-
);
1096+
expect(result.script).to.contain('faker.helpers.arrayElement(');
1097+
expect(result.script).to.contain("It's a 'test' string");
1098+
expect(result.script).to.contain('another option');
10811099

10821100
// Test that the generated document code is executable
10831101
testDocumentCodeExecution(result.script);
@@ -1210,7 +1228,9 @@ describe('Script Generation', () => {
12101228
expect(result.success).to.equal(true);
12111229
if (result.success) {
12121230
const expectedReturnBlock = `return {
1213-
...(Math.random() < 0.7 ? { optionalField: faker.lorem.word() } : {})
1231+
...(Math.random() < 0.7
1232+
? { optionalField: faker.lorem.word() }
1233+
: {})
12141234
};`;
12151235
expect(result.script).to.contain(expectedReturnBlock);
12161236

@@ -1237,8 +1257,14 @@ describe('Script Generation', () => {
12371257
if (result.success) {
12381258
const expectedReturnBlock = `return {
12391259
alwaysPresent: faker.person.fullName(),
1240-
...(Math.random() < 0.8 ? { sometimesPresent: faker.internet.email() } : {}),
1241-
...(Math.random() < 0.2 ? { rarelyPresent: faker.phone.number() } : {}),
1260+
...(Math.random() < 0.8
1261+
? {
1262+
sometimesPresent: faker.internet.email()
1263+
}
1264+
: {}),
1265+
...(Math.random() < 0.2
1266+
? { rarelyPresent: faker.phone.number() }
1267+
: {}),
12421268
defaultProbability: faker.lorem.word()
12431269
};`;
12441270
expect(result.script).to.contain(expectedReturnBlock);
@@ -1272,9 +1298,8 @@ describe('Script Generation', () => {
12721298

12731299
expect(result.success).to.equal(true);
12741300
if (result.success) {
1275-
expect(result.script).to.contain(
1276-
'...(Math.random() < 0.9 ? { conditionalAge: faker.number.int(18, 65) } : {})'
1277-
);
1301+
expect(result.script).to.contain('Math.random() < 0.9');
1302+
expect(result.script).to.contain('faker.number.int(18, 65)');
12781303

12791304
// Test that the generated document code is executable
12801305
testDocumentCodeExecution(result.script);
@@ -1299,9 +1324,8 @@ describe('Script Generation', () => {
12991324

13001325
expect(result.success).to.equal(true);
13011326
if (result.success) {
1302-
expect(result.script).to.contain(
1303-
'...(Math.random() < 0.5 ? { unknownField: faker.lorem.word() } : {})'
1304-
);
1327+
expect(result.script).to.contain('Math.random() < 0.5');
1328+
expect(result.script).to.contain('faker.lorem.word()');
13051329

13061330
// Test that the generated document code is executable
13071331
testDocumentCodeExecution(result.script);

0 commit comments

Comments
 (0)