Skip to content

Commit

Permalink
Ensure we support structs of arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
grantcopley committed Jun 22, 2024
1 parent 98dcafe commit b47fbcd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 47 deletions.
49 changes: 25 additions & 24 deletions test-harness/tests/specs/CBWIRESpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -362,30 +362,6 @@ component extends="coldbox.system.testing.BaseTestCase" {
expect( reFindNoCase( "<div wire:id=""([A-Za-z0-9]+)"" x-data=""{", result.components.first().effects.html ) ).toBeGT( 0 );
} );

it( "should support array of struct data properties", function() {
var payload = incomingRequest(
memo = {
"name": "test.should_support_array_of_struct_data_properties",
"id": "Z1Ruz1tGMPXSfw7osBW2",
"children": []
},
data = {},
calls = [
{
"path": "",
"method": "setFirst",
"params": []
}
],
updates = {}
);
var result = cbwireController.handleRequest( payload, event );
var html = result.components.first().effects.html;
expect( html ).toInclude( '<a href="index.cfm">Home Updated</a>' );
expect( html ).toInclude( '<a href="about.cfm">About</a>' );
expect( html ).toInclude( '<a href="contact.cfm">Contact</a>' );
} );

it( "should throw a 403 forbidden error if the CSRF token doesn't match", function() {
var payload = incomingRequest(
memo = {
Expand Down Expand Up @@ -831,6 +807,31 @@ component extends="coldbox.system.testing.BaseTestCase" {
expect( response.components[1].effects.redirect ).toBe( "/some-uri" );
expect( response.components[1].effects.redirectUsingNavigate ).toBeTrue();
} );

it( "should handle array of struct data properties", function() {
var payload = incomingRequest(
memo = {
"name": "test.should_support_array_of_struct_data_properties",
"id": "Z1Ruz1tGMPXSfw7osBW2",
"children": []
},
data = {
"title": "CBWIRE Rocks!",
"states": [
{ "name" : "Maryland", "abr" : "MD" },
{ "name" : "Virginia", "abr" : "VA" },
{ "name" : "Florida", "abr" : "FL" },
{ "name" : "Wyoming", "abr" : "WY" }
]
},
calls = [],
updates = {
"title": "CBWIRE Slaps!"
}
);
var response = cbwireController.handleRequest( payload, event );
expect( response.components[1].effects.html ).toInclude( "CBWIRE Slaps!" );
} );
} );

describe("File Uploads", function() {
Expand Down
14 changes: 14 additions & 0 deletions test-harness/wires/DataWithStructWire.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<cfoutput>
<div>
<div>#args.title#</div>
<h1>States</h1>
<p>Number Of States In data.states: #states.len()#</p>
<cfif states.len() >
<ul>
<cfloop index="currentIndex" item="currentState" array="#states#">
<li>#currentState.abr# : #currentState.name#</li>
</cfloop>
</ul>
</cfif>
</div>
</cfoutput>
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
<cfscript>
// @startWire
data = {
"menu": [
{
"name": "Home",
"link": "index.cfm"
},
{
"name": "About",
"link": "about.cfm"
},
{
"name": "Contact",
"link": "contact.cfm"
}
]
};
data = [
"title": "CBWIRE Rocks!",
"states": []
];
function setFirst() {
data.menu[1].name = "Home Updated";
function addState( abr, name ){
data.states.append( { "name" : name, "abr" : abr } );
}
function onMount( params, event, rc, prc ) {
// Initialize some states
data.states.append( { "name" : "Maryland", "abr" : "MD" } );
data.states.append( { "name" : "Virginia", "abr" : "VA" } );
data.states.append( { "name" : "Florida", "abr" : "FL" } );
data.states.append( { "name" : "Wyoming", "abr" : "WY" } );
}
// @endWire
</cfscript>

<cfoutput>
<div>
<ul>
<cfloop array="#data.menu#" index="item">
<li><a href="#item.link#">#item.name#</a></li>
</cfloop>
</ul>
<div>#args.title#</div>
<h1>States</h1>
<p>Number Of States In data.states: #states.len()#</p>
<cfif states.len() >
<ul>
<cfloop index="currentIndex" item="currentState" array="#states#">
<li>#currentState.abr# : #currentState.name#</li>
</cfloop>
</ul>
</cfif>
</div>
</cfoutput>

0 comments on commit b47fbcd

Please sign in to comment.