@@ -770,7 +770,6 @@ describe('[function] updateCardTemplate', () => {
770
770
expect ( await updateCardTemplate ( card , { template } ) ) . toStrictEqual ( {
771
771
type : 'template' ,
772
772
ll_template : 'template' ,
773
- ll_context : { } ,
774
773
number : 3 ,
775
774
ll_keys : { 'number' : 'number' } ,
776
775
} ) ;
@@ -1382,7 +1381,6 @@ describe('[function] updateCardTemplate v2', () => {
1382
1381
expect ( await updateCardTemplate ( card , { template } ) ) . toStrictEqual ( {
1383
1382
type : 'template' ,
1384
1383
ll_template : 'template' ,
1385
- ll_context : { } ,
1386
1384
number : 3 ,
1387
1385
ll_keys : { 'number' : 'number' } ,
1388
1386
} ) ;
@@ -1445,6 +1443,115 @@ describe('[function] updateCardTemplate v2', () => {
1445
1443
expect ( oldTemplate ) . toStrictEqual ( template )
1446
1444
} ) ;
1447
1445
1446
+ test ( 'Not Overriding linked LL_Context when ll_replicate_ctx is true' , async ( ) => {
1447
+ const template : DashboardCard = {
1448
+ type : "custom_collapsable-cards" ,
1449
+ ll_key : "test_card" ,
1450
+ ll_context : {
1451
+ group : "sensor.tempratures_koelkasten" ,
1452
+ name : "Temperatuur"
1453
+ } ,
1454
+ title_card : {
1455
+ type : "tile" ,
1456
+ name : "<%= context.name %>" ,
1457
+ entity : "<%= context.group %>"
1458
+ } ,
1459
+ } ;
1460
+ const card : DashboardCard = {
1461
+ type : "text" ,
1462
+ ll_template : "test_card" ,
1463
+ ll_context : {
1464
+ group : "sensor.tempratures_another" ,
1465
+ }
1466
+ } ;
1467
+ const oldTemplate = JSON . parse ( JSON . stringify ( template ) )
1468
+ expect ( await updateCardTemplate ( card , { [ template . ll_key ! ] : template } ) ) . toStrictEqual ( {
1469
+ type : "custom_collapsable-cards" ,
1470
+ ll_template : "test_card" ,
1471
+ ll_context : {
1472
+ group : "sensor.tempratures_another" ,
1473
+ name : "Temperatuur"
1474
+ } ,
1475
+ title_card : {
1476
+ type : "tile" ,
1477
+ name : "Temperatuur" ,
1478
+ entity : "sensor.tempratures_another"
1479
+ } ,
1480
+ } ) ;
1481
+ expect ( oldTemplate ) . toStrictEqual ( template )
1482
+ } ) ;
1483
+
1484
+
1485
+ test ( 'Not Replicating LL_Context when ll_replicate_ctx is false' , async ( ) => {
1486
+ const template : DashboardCard = {
1487
+ type : "custom_collapsable-cards" ,
1488
+ ll_replicate_ctx : false ,
1489
+ ll_key : "test_card" ,
1490
+ ll_context : {
1491
+ group : "sensor.tempratures_koelkasten" ,
1492
+ name : "Temperatuur"
1493
+ } ,
1494
+ title_card : {
1495
+ type : "tile" ,
1496
+ name : "<%= context.name %>" ,
1497
+ entity : "<%= context.group %>"
1498
+ } ,
1499
+ } ;
1500
+ const card : DashboardCard = {
1501
+ type : "text" ,
1502
+ ll_template : "test_card"
1503
+ } ;
1504
+ const oldTemplate = JSON . parse ( JSON . stringify ( template ) )
1505
+ expect ( await updateCardTemplate ( card , { [ template . ll_key ! ] : template } ) ) . toStrictEqual ( {
1506
+ type : "custom_collapsable-cards" ,
1507
+ ll_template : "test_card" ,
1508
+ title_card : {
1509
+ type : "tile" ,
1510
+ name : "Temperatuur" ,
1511
+ entity : "sensor.tempratures_koelkasten"
1512
+ } ,
1513
+ } ) ;
1514
+ expect ( oldTemplate ) . toStrictEqual ( template )
1515
+ } ) ;
1516
+
1517
+ test ( 'Not Overriding linked LL_Context when ll_replicate_ctx is false' , async ( ) => {
1518
+ const template : DashboardCard = {
1519
+ type : "custom_collapsable-cards" ,
1520
+ ll_replicate_ctx : false ,
1521
+ ll_key : "test_card" ,
1522
+ ll_context : {
1523
+ group : "sensor.tempratures_koelkasten" ,
1524
+ name : "Temperatuur"
1525
+ } ,
1526
+ title_card : {
1527
+ type : "tile" ,
1528
+ name : "<%= context.name %>" ,
1529
+ entity : "<%= context.group %>"
1530
+ } ,
1531
+ } ;
1532
+ const card : DashboardCard = {
1533
+ type : "text" ,
1534
+ ll_template : "test_card" ,
1535
+ ll_context : {
1536
+ group : "sensor.tempratures_another" ,
1537
+ } ,
1538
+ } ;
1539
+ const oldTemplate = JSON . parse ( JSON . stringify ( template ) )
1540
+ expect ( await updateCardTemplate ( card , { [ template . ll_key ! ] : template } ) ) . toStrictEqual ( {
1541
+ type : "custom_collapsable-cards" ,
1542
+ ll_template : "test_card" ,
1543
+ ll_context : {
1544
+ group : "sensor.tempratures_another" ,
1545
+ } ,
1546
+ title_card : {
1547
+ type : "tile" ,
1548
+ name : "Temperatuur" ,
1549
+ entity : "sensor.tempratures_another"
1550
+ } ,
1551
+ } ) ;
1552
+ expect ( oldTemplate ) . toStrictEqual ( template )
1553
+ } ) ;
1554
+
1448
1555
test ( 'merges ll_card_config complex object into main card config' , async ( ) => {
1449
1556
const template : DashboardCard = {
1450
1557
type : 'custom:complex-card' ,
@@ -1508,15 +1615,52 @@ describe('[function] updateCardTemplate v2', () => {
1508
1615
} ;
1509
1616
const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
1510
1617
const result = await updateCardTemplate ( card , { complex_card : template } ) ;
1511
- expect ( result ) . toMatchObject ( {
1618
+ expect ( result ) . toStrictEqual ( {
1512
1619
type : 'custom:complex-card' ,
1513
1620
ll_template : 'complex_card' ,
1514
- foo : 'bar'
1621
+ foo : 'bar' ,
1622
+ ll_error : "Error rendering template 'complex_card': Error: Failed to parse ll_card_config for template 'complex_card': SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)" ,
1623
+ ll_template_card : {
1624
+ foo : "bar" ,
1625
+ ll_card_config : "{invalid json}" ,
1626
+ ll_key : "complex_card" ,
1627
+ ll_replicate_ctx : true ,
1628
+ type : "custom:complex-card" ,
1629
+ }
1515
1630
} ) ;
1516
- expect ( result . ll_card_config ) . toBe ( '{invalid json}' ) ;
1631
+ expect ( result . ll_template_card . ll_card_config ) . toBe ( '{invalid json}' ) ;
1517
1632
expect ( spy ) . toHaveBeenCalledWith (
1518
1633
new Error ( "Failed to parse ll_card_config for template 'complex_card': SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)" ) ,
1519
1634
) ;
1520
1635
spy . mockRestore ( ) ;
1521
1636
} ) ;
1637
+
1638
+
1639
+ test ( 'linked card error information is removed when error is resolved' , async ( ) => {
1640
+ const template : DashboardCard = {
1641
+ type : 'custom:complex-card' ,
1642
+ ll_key : 'complex_card' ,
1643
+ ll_card_config : '{"foo": "barbaz"}' ,
1644
+ foo : 'bar'
1645
+ } ;
1646
+ const card : DashboardCard = {
1647
+ type : 'custom:complex-card' ,
1648
+ ll_template : 'complex_card' ,
1649
+ foo : 'bar' ,
1650
+ ll_error : "some error from previous state" ,
1651
+ ll_template_card : {
1652
+ foo : "bar" ,
1653
+ ll_card_config : "{invalid json}" ,
1654
+ ll_key : "complex_card" ,
1655
+ ll_replicate_ctx : true ,
1656
+ type : "custom:complex-card" ,
1657
+ }
1658
+ } ;
1659
+ const result = await updateCardTemplate ( card , { complex_card : template } ) ;
1660
+ expect ( result ) . toStrictEqual ( {
1661
+ type : 'custom:complex-card' ,
1662
+ ll_template : 'complex_card' ,
1663
+ foo : 'barbaz' ,
1664
+ } ) ;
1665
+ } ) ;
1522
1666
} ) ;
0 commit comments