@nordcraft/search 1.0.38 → 1.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,11 @@
1
+ import type { ToddleFormula } from '@nordcraft/core/dist/formula/formulaTypes'
2
+ import type { ProjectFiles } from '@nordcraft/ssr/dist/ssr.types'
1
3
  import { describe, expect, test } from 'bun:test'
4
+ import { fixProject } from '../../fixProject'
2
5
  import { searchProject } from '../../searchProject'
3
6
  import { legacyFormulaRule } from './legacyFormulaRule'
4
7
 
5
- describe('legacyFormula', () => {
8
+ describe('detect legacyFormula', () => {
6
9
  test('should detect legacy formulas used in global formula', () => {
7
10
  const problems = Array.from(
8
11
  searchProject({
@@ -328,3 +331,241 @@ describe('legacyFormula', () => {
328
331
  expect(problems).toEqual([])
329
332
  })
330
333
  })
334
+ describe('fix legacyFormula', () => {
335
+ test('should fix the legacy AND formula', () => {
336
+ const files: ProjectFiles = {
337
+ formulas: {
338
+ AND: {
339
+ name: 'AND',
340
+ arguments: [],
341
+ handler: '',
342
+ },
343
+ 'my-formula-1': {
344
+ name: 'my-formula-1',
345
+ arguments: [],
346
+ formula: {
347
+ type: 'function',
348
+ name: '@toddle/concatenate',
349
+ arguments: [
350
+ {
351
+ name: '0',
352
+ formula: {
353
+ type: 'function',
354
+ name: 'AND',
355
+ arguments: [
356
+ {
357
+ name: 'Condition',
358
+ formula: { type: 'value', value: true },
359
+ },
360
+ {
361
+ name: 'Condition',
362
+ formula: { type: 'value', value: true },
363
+ },
364
+ ],
365
+ variableArguments: true,
366
+ },
367
+ },
368
+ ],
369
+ variableArguments: true,
370
+ display_name: 'Concatenate',
371
+ },
372
+ },
373
+ },
374
+ components: {},
375
+ }
376
+ const fixedProject = fixProject({
377
+ files,
378
+ rule: legacyFormulaRule,
379
+ fixType: 'replace-legacy-formula',
380
+ })
381
+
382
+ expect(
383
+ (fixedProject.formulas?.['my-formula-1'] as ToddleFormula).formula,
384
+ ).toEqual({
385
+ type: 'function',
386
+ name: '@toddle/concatenate',
387
+ arguments: [
388
+ {
389
+ name: '0',
390
+ formula: {
391
+ type: 'and',
392
+ arguments: [
393
+ {
394
+ formula: { type: 'value', value: true },
395
+ },
396
+ {
397
+ formula: { type: 'value', value: true },
398
+ },
399
+ ],
400
+ variableArguments: true,
401
+ },
402
+ },
403
+ ],
404
+ variableArguments: true,
405
+ display_name: 'Concatenate',
406
+ } as any)
407
+ })
408
+ test('should fix the legacy IF formula', () => {
409
+ const files: ProjectFiles = {
410
+ formulas: {
411
+ IF: {
412
+ name: 'IF',
413
+ arguments: [],
414
+ handler: '',
415
+ },
416
+ },
417
+ components: {
418
+ 'project-sidebar-item': {
419
+ apis: {},
420
+ name: 'project-sidebar-item',
421
+ nodes: {},
422
+ events: [],
423
+ onLoad: {
424
+ actions: [],
425
+ trigger: 'Load',
426
+ },
427
+ contexts: {
428
+ EditorPage: {
429
+ formulas: ['XK0T8tQWA0YhkfDUzqu-h'],
430
+ workflows: ['sNo0Ya'],
431
+ componentName: 'EditorPage',
432
+ },
433
+ },
434
+ formulas: {
435
+ p_Z1PzOcDop79KGafQ7Lm: {
436
+ name: 'Preview domain',
437
+ formula: {
438
+ name: 'IF',
439
+ type: 'function',
440
+ arguments: [
441
+ {
442
+ name: 'If',
443
+ formula: {
444
+ name: '@toddle/equals',
445
+ type: 'function',
446
+ arguments: [
447
+ {
448
+ name: 'First',
449
+ formula: {
450
+ path: ['Attributes', 'branch-name'],
451
+ type: 'path',
452
+ },
453
+ },
454
+ {
455
+ name: 'Second',
456
+ formula: {
457
+ type: 'value',
458
+ value: 'main',
459
+ },
460
+ },
461
+ ],
462
+ display_name: 'Equals',
463
+ },
464
+ },
465
+ {
466
+ name: 'Then',
467
+ formula: {
468
+ name: '@toddle/concatenate',
469
+ type: 'function',
470
+ arguments: [
471
+ {
472
+ name: 'Items',
473
+ formula: {
474
+ type: 'value',
475
+ value: 'https://',
476
+ },
477
+ },
478
+ {
479
+ formula: {
480
+ path: ['Attributes', 'project-name'],
481
+ type: 'path',
482
+ },
483
+ },
484
+ {
485
+ formula: {
486
+ type: 'value',
487
+ value: '.toddle.site',
488
+ },
489
+ },
490
+ ],
491
+ display_name: 'Concatenate',
492
+ variableArguments: true,
493
+ },
494
+ },
495
+ {
496
+ name: 'Else',
497
+ formula: {
498
+ name: '@toddle/concatenate',
499
+ type: 'function',
500
+ arguments: [
501
+ {
502
+ formula: {
503
+ type: 'value',
504
+ value: 'https://',
505
+ },
506
+ },
507
+ {
508
+ formula: {
509
+ path: ['Attributes', 'branch-name'],
510
+ type: 'path',
511
+ },
512
+ },
513
+ {
514
+ formula: {
515
+ type: 'value',
516
+ value: '-',
517
+ },
518
+ },
519
+ {
520
+ formula: {
521
+ path: ['Attributes', 'project-name'],
522
+ type: 'path',
523
+ },
524
+ },
525
+ {
526
+ formula: {
527
+ type: 'value',
528
+ value: '.toddle.site',
529
+ },
530
+ },
531
+ ],
532
+ display_name: 'Concatenate',
533
+ variableArguments: true,
534
+ },
535
+ },
536
+ ],
537
+ },
538
+ memoize: false,
539
+ arguments: [],
540
+ },
541
+ },
542
+ variables: {},
543
+ workflows: {},
544
+ attributes: {},
545
+ },
546
+ },
547
+ }
548
+ const fixedProject = fixProject({
549
+ files,
550
+ rule: legacyFormulaRule,
551
+ fixType: 'replace-legacy-formula',
552
+ pathsToVisit: [
553
+ [
554
+ 'components',
555
+ 'project-sidebar-item',
556
+ 'formulas',
557
+ 'p_Z1PzOcDop79KGafQ7Lm',
558
+ 'formula',
559
+ ],
560
+ ],
561
+ useExactPaths: true,
562
+ })
563
+
564
+ const updatedFormula = (
565
+ fixedProject.components['project-sidebar-item']?.formulas?.[
566
+ 'p_Z1PzOcDop79KGafQ7Lm'
567
+ ] as any
568
+ )?.formula
569
+ expect(updatedFormula.type).toEqual('switch')
570
+ })
571
+ })