@@ -191,7 +191,7 @@ component extends="coldbox.system.testing.BaseTestCase" {
191
191
var result = CBWIREController .wire ( " test.should_support_computed_properties" );
192
192
expect ( reFindNoCase ( " UUID: [A-Za-z0-9-]+" , result ) ).toBeGT ( 0 );
193
193
} );
194
-
194
+
195
195
it ( " should cache computed properties" , function () {
196
196
var result = CBWIREController .wire ( " test.should_cache_computed_properties" );
197
197
var firstUUID = reFindNoCase ( " UUID: ([A-Za-z0-9-]+)" , result , 1 , true ).match [ 2 ];
@@ -685,7 +685,7 @@ component extends="coldbox.system.testing.BaseTestCase" {
685
685
expect ( response .components [1 ].effects .html ).toInclude ( " CBWIRE Slays!" );
686
686
} );
687
687
688
- it ( " should run action we pass it with parameters" , function () {
688
+ it ( " should run action we pass it with parameters" , function () {
689
689
var payload = incomingRequest (
690
690
memo = {
691
691
" name" : " TestComponent" ,
@@ -704,7 +704,7 @@ component extends="coldbox.system.testing.BaseTestCase" {
704
704
],
705
705
updates = {}
706
706
);
707
-
707
+
708
708
var response = cbwireController .handleRequest ( payload , event );
709
709
expect ( response .components [1 ].effects .html ).toInclude ( " Title: Hello world from CBWIRE!" );
710
710
} );
@@ -1128,6 +1128,100 @@ component extends="coldbox.system.testing.BaseTestCase" {
1128
1128
var response = cbwireController .handleRequest ( payload , event );
1129
1129
expect ( response .components [1 ].effects .html ).toInclude ( " CBWIRE Slaps!" );
1130
1130
} );
1131
+
1132
+ it ( " should throw a CBWIREException when trying to update a locked property (array)" , function () {
1133
+ var payload = incomingRequest (
1134
+ memo = {
1135
+ " name" : " test.should_throw_exception_on_locked_data_property_array" ,
1136
+ " id" : " Z1Ruz1tGMPXSfw7osBW2" ,
1137
+ " children" : []
1138
+ },
1139
+ data = {},
1140
+ calls = [],
1141
+ updates = { " lockedPropertyKey" : " Changed Value" }
1142
+ );
1143
+ expect ( function () {
1144
+ cbwireController .handleRequest ( payload , event );
1145
+ } ).toThrow ( message = " The property lockedPropertyKey is locked and cannot be updated." );
1146
+ } );
1147
+
1148
+ it ( " should throw a CBWIREException when trying to update a locked property (list)" , function () {
1149
+ var payload = incomingRequest (
1150
+ memo = {
1151
+ " name" : " test.should_throw_exception_on_locked_data_property_list" ,
1152
+ " id" : " Z1Ruz1tGMPXSfw7osBW2" ,
1153
+ " children" : []
1154
+ },
1155
+ data = {},
1156
+ calls = [],
1157
+ updates = { " lockedPropertyKey" : " Changed Value" }
1158
+ );
1159
+ expect ( function () {
1160
+ cbwireController .handleRequest ( payload , event );
1161
+ } ).toThrow ( message = " The property lockedPropertyKey is locked and cannot be updated." );
1162
+ } );
1163
+
1164
+ it ( " should throw a CBWIREException when trying to update a locked property (string)" , function () {
1165
+ var payload = incomingRequest (
1166
+ memo = {
1167
+ " name" : " test.should_throw_exception_on_locked_data_property_string" ,
1168
+ " id" : " Z1Ruz1tGMPXSfw7osBW2" ,
1169
+ " children" : []
1170
+ },
1171
+ data = {},
1172
+ calls = [],
1173
+ updates = { " lockedPropertyKey" : " Changed Value" }
1174
+ );
1175
+ expect ( function () {
1176
+ cbwireController .handleRequest ( payload , event );
1177
+ } ).toThrow ( message = " The property lockedPropertyKey is locked and cannot be updated." );
1178
+ } );
1179
+
1180
+ it ( " should not throw an error when empty array is used for locked property " , function () {
1181
+ var payload = incomingRequest (
1182
+ memo = {
1183
+ " name" : " test.should_not_throw_exception_on_locked_data_property_empty_array" ,
1184
+ " id" : " Z1Ruz1tGMPXSfw7osBW2" ,
1185
+ " children" : []
1186
+ },
1187
+ data = {},
1188
+ calls = [],
1189
+ updates = { " lockedPropertyKey" : " Changed Value" }
1190
+ );
1191
+ var response = cbwireController .handleRequest ( payload , event );
1192
+ expect ( response .components [1 ].effects .html ).toInclude ( " Locked Property Value: Changed Value" );
1193
+ } );
1194
+
1195
+ it ( " should not throw an error when empty string is used for locked property " , function () {
1196
+ var payload = incomingRequest (
1197
+ memo = {
1198
+ " name" : " test.should_not_throw_exception_on_locked_data_property_empty_string" ,
1199
+ " id" : " Z1Ruz1tGMPXSfw7osBW2" ,
1200
+ " children" : []
1201
+ },
1202
+ data = {},
1203
+ calls = [],
1204
+ updates = { " lockedPropertyKey" : " Changed Value" }
1205
+ );
1206
+ var response = cbwireController .handleRequest ( payload , event );
1207
+ expect ( response .components [1 ].effects .html ).toInclude ( " Locked Property Value: Changed Value" );
1208
+ } );
1209
+
1210
+ it ( " should not throw an error when data type other than array or string is used for locked property " , function () {
1211
+ var payload = incomingRequest (
1212
+ memo = {
1213
+ " name" : " test.should_not_throw_exception_on_locked_data_property_other" ,
1214
+ " id" : " Z1Ruz1tGMPXSfw7osBW2" ,
1215
+ " children" : []
1216
+ },
1217
+ data = {},
1218
+ calls = [],
1219
+ updates = { " lockedPropertyKey" : " Changed Value" }
1220
+ );
1221
+ var response = cbwireController .handleRequest ( payload , event );
1222
+ expect ( response .components [1 ].effects .html ).toInclude ( " Locked Property Value: Changed Value" );
1223
+ } );
1224
+
1131
1225
} );
1132
1226
1133
1227
describe (" File Uploads" , function () {
@@ -1360,7 +1454,7 @@ component extends="coldbox.system.testing.BaseTestCase" {
1360
1454
it ( " throws error if it's unable to find a module component" , function () {
1361
1455
expect ( function () {
1362
1456
var result = cbwireController .wire ( " missing@someModule" );
1363
- } ).toThrow ( type = " ModuleNotFound" );
1457
+ } ).toThrow ( type = " ModuleNotFound" );
1364
1458
} );
1365
1459
1366
1460
it ( " can render component from nested module using default wires location" , function () {
@@ -1383,41 +1477,41 @@ component extends="coldbox.system.testing.BaseTestCase" {
1383
1477
preprocessor = getInstance (" CBWIREPreprocessor@cbwire" );
1384
1478
prepareMock ( preprocessor );
1385
1479
});
1386
-
1480
+
1387
1481
it (" should parse and replace single cbwire tag with no arguments" , function () {
1388
1482
var input = " <cbwire:testComponent/>" ;
1389
1483
var expected = " ## wire( name="" testComponent"" , params={ }, lazy=false )## " ;
1390
1484
var result = preprocessor .handle (input );
1391
1485
expect (result ).toBe (expected );
1392
1486
});
1393
-
1487
+
1394
1488
it (" should parse and replace cbwire tag with multiple arguments" , function () {
1395
1489
var input = " <cbwire:testComponent :param1='value1' param2='value2'/>" ;
1396
1490
var expected = " ## wire( name="" testComponent"" , params={ param1=value1, param2='value2' }, lazy=false )## " ;
1397
1491
var result = preprocessor .handle (input );
1398
1492
expect (result ).toBe (expected );
1399
1493
});
1400
-
1494
+
1401
1495
it (" should correctly handle arguments with expressions" , function () {
1402
1496
var input = " <cbwire:testComponent :expr='someExpression'/>" ;
1403
1497
var expected = " ## wire( name="" testComponent"" , params={ expr=someExpression }, lazy=false )## " ;
1404
1498
var result = preprocessor .handle (input );
1405
1499
expect (result ).toBe (expected );
1406
1500
});
1407
-
1501
+
1408
1502
it (" should maintain order and syntax of multiple attributes" , function () {
1409
1503
var input = " <cbwire:testComponent attr1='foo' :expr='bar' attr2='baz'/>" ;
1410
1504
var expected = " ## wire( name="" testComponent"" , params={ attr1='foo', expr=bar, attr2='baz' }, lazy=false )## " ;
1411
1505
var result = preprocessor .handle (input );
1412
1506
expect (result ).toBe (expected );
1413
1507
});
1414
-
1508
+
1415
1509
it (" should replace multiple cbwire tags in a single content string" , function () {
1416
1510
var input = " Here is a test <cbwire:firstComponent attr='value'/> and another <cbwire:secondComponent :expr='expression'/>" ;
1417
1511
var expected = " Here is a test ## wire( name="" firstComponent"" , params={ attr='value' }, lazy=false )## and another ## wire( name="" secondComponent"" , params={ expr=expression }, lazy=false )## " ;
1418
1512
var result = preprocessor .handle (input );
1419
1513
expect (result ).toBe (expected );
1420
- });
1514
+ });
1421
1515
1422
1516
it (" should throw an exception for unparseable tags" , function () {
1423
1517
var input = " <cbwire:testComponent :broken='noEndQuote>" ;
@@ -1434,56 +1528,56 @@ component extends="coldbox.system.testing.BaseTestCase" {
1434
1528
// Create an instance of the component that handles teleport preprocessing
1435
1529
preprocessor = getInstance ( " TeleportPreprocessor@cbwire" );
1436
1530
});
1437
-
1531
+
1438
1532
it (" should replace @teleport with the correct template tag" , function () {
1439
1533
var content = " @teleport(selector) content @endteleport" ;
1440
1534
var expected = ' <template x-teleport="selector"> content </template>' ;
1441
1535
var result = preprocessor .handle (content );
1442
1536
expect (result ).toBe (expected );
1443
1537
});
1444
-
1538
+
1445
1539
it (" should handle single quotes around the selector" , function () {
1446
1540
var content = " @teleport('selector') content @endteleport" ;
1447
1541
var expected = ' <template x-teleport="selector"> content </template>' ;
1448
1542
var result = preprocessor .handle (content );
1449
1543
expect (result ).toBe (expected );
1450
1544
});
1451
-
1545
+
1452
1546
it (" should handle double quotes around the selector" , function () {
1453
1547
var content = ' @teleport("selector") content @endteleport' ;
1454
1548
var expected = ' <template x-teleport="selector"> content </template>' ;
1455
1549
var result = preprocessor .handle (content );
1456
1550
expect (result ).toBe (expected );
1457
1551
});
1458
-
1552
+
1459
1553
it (" should handle no quotes around the selector" , function () {
1460
1554
var content = " @teleport(selector) content @endteleport" ;
1461
1555
var expected = ' <template x-teleport="selector"> content </template>' ;
1462
1556
var result = preprocessor .handle (content );
1463
1557
expect (result ).toBe (expected );
1464
1558
});
1465
-
1559
+
1466
1560
it (" should handle spaces within the parentheses" , function () {
1467
1561
var content = " @teleport( selector ) content @endteleport" ;
1468
1562
var expected = ' <template x-teleport="selector"> content </template>' ;
1469
1563
var result = preprocessor .handle (content );
1470
1564
expect (result ).toBe (expected );
1471
1565
});
1472
-
1566
+
1473
1567
it (" should handle multiple teleport directives in the same content" , function () {
1474
1568
var content = " @teleport(selector1) content1 @endteleport @teleport(selector2) content2 @endteleport" ;
1475
1569
var expected = ' <template x-teleport="selector1"> content1 </template> <template x-teleport="selector2"> content2 </template>' ;
1476
1570
var result = preprocessor .handle (content );
1477
1571
expect (result ).toBe (expected );
1478
1572
});
1479
-
1573
+
1480
1574
it (" should handle nested teleport directives" , function () {
1481
1575
var content = " @teleport(outer) @teleport(inner) content @endteleport @endteleport" ;
1482
1576
var expected = ' <template x-teleport="outer"> <template x-teleport="inner"> content </template> </template>' ;
1483
1577
var result = preprocessor .handle (content );
1484
1578
expect (result ).toBe (expected );
1485
1579
});
1486
-
1580
+
1487
1581
it (" should not alter content without teleport directives" , function () {
1488
1582
var content = " Normal content without directives" ;
1489
1583
var result = preprocessor .handle (content );
@@ -1497,9 +1591,9 @@ component extends="coldbox.system.testing.BaseTestCase" {
1497
1591
/**
1498
1592
* Helper test method for creating incoming request payloads
1499
1593
*
1500
- * @data
1594
+ * @data
1501
1595
* @calls
1502
- *
1596
+ *
1503
1597
* @return struct
1504
1598
*/
1505
1599
private function incomingRequest (
@@ -1539,24 +1633,24 @@ component extends="coldbox.system.testing.BaseTestCase" {
1539
1633
/**
1540
1634
* Take a rendered HTML component and breaks out its snapshot,
1541
1635
* effects, etc for analysis during tests.
1542
- *
1636
+ *
1543
1637
* @return struct
1544
1638
*/
1545
1639
private function parseRendering ( html , index = 1 ) {
1546
1640
local .result = {};
1547
1641
// Determine outer element
1548
1642
local .outerElementMatches = reMatchNoCase ( " <([a-z]+)\s*" , html );
1549
1643
local .result [ " outerElement" ] = reFindNoCase ( " <([a-z]+)\s*" , html , 1 , true ).match [ 2 ];
1550
- // Parse snapshot
1644
+ // Parse snapshot
1551
1645
local .result [ " snapshot" ] = parseSnapshot ( html , index );
1552
- // Parse effects
1646
+ // Parse effects
1553
1647
local .result [ " effects" ] = parseEffects ( html , index );
1554
1648
return local .result ;
1555
1649
}
1556
1650
1557
1651
/**
1558
1652
* Parse the snapshot from a rendered HTML component
1559
- *
1653
+ *
1560
1654
* @return struct
1561
1655
*/
1562
1656
private function parseSnapshot ( html , index = 1 ) {
@@ -1569,7 +1663,7 @@ component extends="coldbox.system.testing.BaseTestCase" {
1569
1663
1570
1664
/**
1571
1665
* Parse the effects from a rendered HTML component
1572
- *
1666
+ *
1573
1667
* @return struct
1574
1668
*/
1575
1669
private function parseEffects ( html , index = 1 ) {
0 commit comments