@@ -5,12 +5,11 @@ import {
5
5
ActionValue ,
6
6
AssetValue ,
7
7
expression ,
8
- ExpressionValue ,
9
8
PageValue ,
10
9
Parameter ,
11
- ParameterValue ,
12
10
PlaceholderValue ,
13
11
renderTemplate ,
12
+ ResourceValue ,
14
13
Variable ,
15
14
} from "./jsx" ;
16
15
import { css } from "./css" ;
@@ -154,10 +153,7 @@ test("render literal props", () => {
154
153
155
154
test ( "render defined props" , ( ) => {
156
155
const { props } = renderTemplate (
157
- < $ . Body
158
- data-expression = { new ExpressionValue ( "1 + 1" ) }
159
- data-parameter = { new ParameterValue ( "parameterId" ) }
160
- >
156
+ < $ . Body >
161
157
< $ . Box
162
158
data-asset = { new AssetValue ( "assetId" ) }
163
159
data-page = { new PageValue ( "pageId" ) }
@@ -166,20 +162,6 @@ test("render defined props", () => {
166
162
</ $ . Body >
167
163
) ;
168
164
expect ( props ) . toEqual ( [
169
- {
170
- id : "0:data-expression" ,
171
- instanceId : "0" ,
172
- name : "data-expression" ,
173
- type : "expression" ,
174
- value : "1 + 1" ,
175
- } ,
176
- {
177
- id : "0:data-parameter" ,
178
- instanceId : "0" ,
179
- name : "data-parameter" ,
180
- type : "parameter" ,
181
- value : "parameterId" ,
182
- } ,
183
165
{
184
166
id : "1:data-asset" ,
185
167
instanceId : "1" ,
@@ -493,6 +475,86 @@ test("render parameter bound to prop expression", () => {
493
475
] ) ;
494
476
} ) ;
495
477
478
+ test ( "render resource variable" , ( ) => {
479
+ const value = new Variable ( "value" , "value" ) ;
480
+ const myResource = new ResourceValue ( "myResource" , {
481
+ url : expression `"https://my-url.com/" + ${ value } ` ,
482
+ method : "get" ,
483
+ headers : [ { name : "auth" , value : expression `${ value } ` } ] ,
484
+ body : expression `${ value } ` ,
485
+ } ) ;
486
+ const { dataSources, resources } = renderTemplate (
487
+ < $ . Body ws :id = "body" > { expression `${ myResource } .title` } </ $ . Body >
488
+ ) ;
489
+ expect ( dataSources ) . toEqual ( [
490
+ {
491
+ id : "1" ,
492
+ name : "value" ,
493
+ scopeInstanceId : "body" ,
494
+ type : "variable" ,
495
+ value : { type : "string" , value : "value" } ,
496
+ } ,
497
+ {
498
+ id : "0" ,
499
+ scopeInstanceId : "body" ,
500
+ name : "myResource" ,
501
+ type : "resource" ,
502
+ resourceId : "resource:0" ,
503
+ } ,
504
+ ] ) ;
505
+ expect ( resources ) . toEqual ( [
506
+ {
507
+ id : "resource:0" ,
508
+ name : "myResource" ,
509
+ url : `"https://my-url.com/" + $ws$dataSource$1` ,
510
+ method : "get" ,
511
+ headers : [ { name : "auth" , value : `$ws$dataSource$1` } ] ,
512
+ body : `$ws$dataSource$1` ,
513
+ } ,
514
+ ] ) ;
515
+ } ) ;
516
+
517
+ test ( "render resource prop" , ( ) => {
518
+ const value = new Variable ( "value" , "value" ) ;
519
+ const myResource = new ResourceValue ( "myResource" , {
520
+ url : expression `"https://my-url.com/" + ${ value } ` ,
521
+ method : "get" ,
522
+ headers : [ { name : "auth" , value : expression `${ value } ` } ] ,
523
+ body : expression `${ value } ` ,
524
+ } ) ;
525
+ const { props, dataSources, resources } = renderTemplate (
526
+ < $ . Body ws :id = "body" action = { myResource } > </ $ . Body >
527
+ ) ;
528
+ expect ( props ) . toEqual ( [
529
+ {
530
+ id : "body:action" ,
531
+ instanceId : "body" ,
532
+ name : "action" ,
533
+ type : "resource" ,
534
+ value : "resource:0" ,
535
+ } ,
536
+ ] ) ;
537
+ expect ( dataSources ) . toEqual ( [
538
+ {
539
+ id : "1" ,
540
+ name : "value" ,
541
+ scopeInstanceId : "body" ,
542
+ type : "variable" ,
543
+ value : { type : "string" , value : "value" } ,
544
+ } ,
545
+ ] ) ;
546
+ expect ( resources ) . toEqual ( [
547
+ {
548
+ id : "resource:0" ,
549
+ name : "myResource" ,
550
+ url : `"https://my-url.com/" + $ws$dataSource$1` ,
551
+ method : "get" ,
552
+ headers : [ { name : "auth" , value : `$ws$dataSource$1` } ] ,
553
+ body : `$ws$dataSource$1` ,
554
+ } ,
555
+ ] ) ;
556
+ } ) ;
557
+
496
558
test ( "render ws:show attribute" , ( ) => {
497
559
const { props } = renderTemplate (
498
560
< $ . Body ws :id = "body" ws :show = { true } > </ $ . Body >
0 commit comments