/
FluidIoCTests.js
3114 lines (2751 loc) · 111 KB
/
FluidIoCTests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2010-2011 Lucendo Development Ltd.
Copyright 2010-2011 OCAD University
Licensed under the Educational Community License (ECL), Version 2.0 or the New
BSD license. You may not use this file except in compliance with one these
Licenses.
You may obtain a copy of the ECL 2.0 License and BSD License at
https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
*/
// Declare dependencies
/*global fluid, jqUnit, jQuery*/
// JSLint options
/*jslint white: true, funcinvoke: true, undef: true, newcap: true, nomen: true, regexp: true, bitwise: true, browser: true, forin: true, maxerr: 100, indent: 4 */
fluid.registerNamespace("fluid.tests");
(function ($) {
jqUnit.module("Fluid IoC Tests");
fluid.staticEnvironment.isTest = fluid.typeTag("fluid.test");
fluid.setLogging(fluid.logLevel.TRACE);
fluid.activityTracing = true;
fluid.defaults("fluid.tests.defaultMergePolicy", {
gradeNames: ["fluid.modelComponent", "autoInit"],
defaultSource: "sourceValue",
defaultTarget: "targetValue",
mergePolicy: {
defaultTarget: "defaultSource"
}
});
fluid.tests.fluid4736Tests = [
// Before FLUID-4330, we used to support this test case and not the last one - after FLUID-4330 the
// position is now reversed. Supporting "non-monotonic merges" that the first case would require much more
// complexity in the implementation in the form of a "provenance" object holding the merge depth of each
// value. In fact we don't require this support since the Reorderer defaults changed to be "monotonic" in any
// case, and the current implementation should be adequate for FLUID-4409/FLUID-4636 situations in UIOptions.
/*{
message: "merge policy has no effect on plain defaults",
options: undefined,
expected: {
defaultSource: "sourceValue",
defaultTarget: "targetValue"
}
}, */{
message: "merge policy copies user option to default value",
options: {
defaultSource: "userSource"
},
expected: {
defaultSource: "userSource",
defaultTarget: "userSource"
}
}, {
message: "merge policy has no effect on full user values",
options: {
defaultSource: "userSource",
defaultTarget: "userTarget"
},
expected: {
defaultSource: "userSource",
defaultTarget: "userTarget"
}
},
// With FLUID-4392, this test case can now be supported, but the first can't: see also FLUID-4733
{
message: "user modifies value to default",
options: {
defaultSource: "sourceValue",
},
expected: {
defaultSource: "sourceValue",
defaultTarget: "sourceValue"
}
}];
jqUnit.test("FLUID-4736: Interaction of default value merge policy with grade chain", function () {
fluid.each(fluid.tests.fluid4736Tests, function (fixture) {
var component = fluid.tests.defaultMergePolicy(fixture.options);
jqUnit.assertLeftHand(fixture.message, fixture.expected, component.options);
});
});
fluid.makeComponents({
"fluid.tests.multiResSub": "fluid.littleComponent",
"fluid.tests.multiResSub2": "fluid.littleComponent",
"fluid.tests.multiResSub3": "fluid.littleComponent",
"fluid.tests.fluid3818child": "fluid.littleComponent",
"fluid.tests.thatStackTail": "fluid.littleComponent",
"fluid.tests.reinsChild": "fluid.littleComponent" // standard blank "littleComponent" used throughout tests
});
fluid.defaults("fluid.tests.invokerComponent", {
gradeNames: ["fluid.littleComponent", "autoInit"],
template: "Every {0} has {1} {2}(s)",
invokers: {
render: {
funcName: "fluid.formatMessage",
args: ["{invokerComponent}.options.template", "@0"]
}
},
events: {
testEvent: null
}
});
jqUnit.test("invokers", function () {
jqUnit.expect(2);
var that = fluid.tests.invokerComponent();
jqUnit.assertValue("Constructed", that);
jqUnit.assertEquals("Rendered", "Every CATT has 4 Leg(s)",
that.render(["CATT", "4", "Leg"]));
});
fluid.defaults("fluid.tests.invokerComponent2", {
gradeNames: ["fluid.littleComponent", "autoInit"],
template: "Every {0} has {1} {2}(s)",
invokers: {
render: "stringRenderer"
},
events: {
testEvent: null
}
});
jqUnit.test("invokers with demands", function () {
jqUnit.expect(2);
var that = fluid.tests.invokerComponent2();
jqUnit.assertValue("Constructed", that);
jqUnit.assertEquals("Rendered", "Every CATT has 4 Leg(s)",
that.render(["CATT", "4", "Leg"]));
});
fluid.demands("stringRenderer", "fluid.tests.invokerComponent2", {
funcName: "fluid.formatMessage",
args: ["{invokerComponent2}.options.template", "@0"]
});
/** Correct transmission of model references */
fluid.defaults("fluid.tests.modelComponent", {
gradeNames: ["fluid.modelComponent", "autoInit"]
});
fluid.defaults("fluid.tests.dependentModel", {
gradeNames: ["fluid.littleComponent", "autoInit"],
mergePolicy: {
model: "preserve"
},
components: {
modelComponent: {
type: "fluid.tests.modelComponent",
options: {
model: "{dependentModel}.options.model"
}
}
}
});
jqUnit.test("Model reference aliasing test", function () {
jqUnit.expect(3);
var model = {unpollute: 1};
var that = fluid.tests.dependentModel({model: model});
jqUnit.assertValue("Constructed", that);
model.pollute = 3;
jqUnit.assertEquals("Transit 1", 3, that.options.model.pollute);
jqUnit.assertEquals("Transit 1", 3, that.modelComponent.options.model.pollute);
});
fluid.defaults("fluid.tests.multiResolution", {
gradeNames: ["fluid.littleComponent", "autoInit"],
components: {
resSub: {
type: "fluid.tests.multiResSub"
}
}
});
/** Resolution based on increasingly specific context combinations **/
fluid.demands("fluid.tests.multiResSub", ["fluid.tests.multiResolution", "fluid.tests.localFiles"], {
funcName: "fluid.tests.multiResSub2",
args: {
localKey1: "localValue1",
localKey2: "localValue2"
}
});
fluid.demands("fluid.tests.multiResSub", ["fluid.tests.multiResolution", "fluid.tests.localFiles", "fluid.tests.localTest"], {
funcName: "fluid.tests.multiResSub3",
args: [{
localKey1: "testValue1"
}, null]
});
jqUnit.test("Multi-resolution test", function () {
var that = fluid.tests.multiResolution();
jqUnit.assertValue("Constructed", that);
jqUnit.assertEquals("Standard subcomponent", "fluid.tests.multiResSub", that.resSub.typeName);
try {
fluid.staticEnvironment.localEnvironment = fluid.typeTag("fluid.tests.localFiles");
var that2 = fluid.tests.multiResolution();
jqUnit.assertValue("Constructed", that2);
var type2 = "fluid.tests.multiResSub2";
jqUnit.assertEquals("\"Local\" subcomponent", type2, that2.resSub.typeName);
var localDemandOptions = $.extend({}, fluid.demands("fluid.tests.multiResSub",
["fluid.tests.multiResolution", "fluid.tests.localFiles"]).args, {targetTypeName: type2});
jqUnit.assertLeftHand("\"Local\" subcomponent options", localDemandOptions, that2.resSub.options);
fluid.staticEnvironment.testEnvironment = fluid.typeTag("fluid.tests.localTest");
var that3 = fluid.tests.multiResolution();
jqUnit.assertValue("Constructed", that3);
var type3 = "fluid.tests.multiResSub3";
jqUnit.assertEquals("\"Test\" subcomponent", type3, that3.resSub.typeName);
var expectedOptions = {
localKey1: "testValue1"
// targetTypeName: type3 // This floats about a bit as we change policy on "typeName"
};
jqUnit.assertLeftHand("\"Test\" subcomponent merged options", expectedOptions, that3.resSub.options);
} finally {
delete fluid.staticEnvironment.testEnvironment;
delete fluid.staticEnvironment.localEnvironment;
}
});
fluid.demands("fluid.tests.staticResolution", [], {
funcName: "fluid.identity",
args: "{fluid.tests.localFiles}"
});
jqUnit.test("Static resolution test", function () {
try {
fluid.staticEnvironment.localEnvironment = fluid.typeTag("fluid.tests.localFiles");
var staticRes = fluid.invoke("fluid.tests.staticResolution");
jqUnit.assertNotUndefined("Resolved value from static environment", staticRes);
} finally {
delete fluid.staticEnvironment.localEnvironment;
}
});
// This is identical to a test in Fluid.js, but exposed a bug in the alternative workflow that was triggered by FLUID-4930 work - "evaluateFully"
fluid.defaults("fluid.tests.eventMerge", {
gradeNames: ["fluid.eventedComponent", "autoInit"],
events: {
event: "preventable"
}
});
jqUnit.test("Merge over named listener", function () {
var that = fluid.tests.eventMerge({
events: {
event: null
},
listeners: {
event: "fluid.identity"
}
});
var result = that.events.event.fire(false);
jqUnit.assertUndefined("Event returned to nonpreventable through merge", result);
});
/** FLUID-4634 demands exclusion test **/
fluid.defaults("fluid.tests.demandedEvent1", {
gradeNames: ["fluid.eventedComponent", "autoInit"],
events: {
event1: null
}
});
fluid.defaults("fluid.tests.demandedEvent2", {
gradeNames: ["fluid.eventedComponent", "autoInit"],
events: {
event2: null
}
});
fluid.demands("testDemandedEvent", ["fluid.tests.testContext", "fluid.tests.demandedEvent2"], ["demanded"]);
jqUnit.test("FLUID-4634: multiple components with the same boiled event name", function () {
fluid.staticEnvironment.currentTestEnvironment = fluid.typeTag("fluid.tests.testContext");
var orig = "original";
var e1 = fluid.tests.demandedEvent1({
events: {
testDemandedEvent: {
event: "event1"
}
}
});
var e2 = fluid.tests.demandedEvent2({
events: {
testDemandedEvent: {
event: "event2"
}
}
});
e1.events.testDemandedEvent.addListener(function (arg) {
jqUnit.assertEquals("The original argument should be passeed in.", orig, arg);
});
e2.events.testDemandedEvent.addListener(function (arg) {
jqUnit.assertEquals("The demanded argument should be passed in.", "demanded", arg);
});
e1.events.event1.fire(orig);
e2.events.event2.fire(orig);
delete fluid.staticEnvironment.currentTestEnvironment;
});
/** FLUID-4631 argument transmission test **/
fluid.defaults("fluid.tests.demandsEvents", {
gradeNames: ["fluid.eventedComponent", "autoInit"],
events: {
someEvent: null
}
});
fluid.demands("testEvent", ["fluid.tests.demandsEvents"], [
"newArg",
"{arguments}.0"
]);
jqUnit.test("FLUID-4631: double event dispatch issue", function () {
jqUnit.expect(3);
var origArg0 = "origArg";
var assertEvent = function (arg0, arg1) {
jqUnit.assertNotEquals("The two arguments should be different", arg0, arg1);
jqUnit.assertEquals("Injection of new first argument", "newArg", arg0);
jqUnit.assertEquals("Transmission of the original first arguement", origArg0, arg1);
};
var that = fluid.tests.demandsEvents({
events: {
testEvent: {
event: "someEvent"
}
},
listeners: {
testEvent: assertEvent
}
});
that.events.someEvent.fire(origArg0);
});
fluid.demands("testEvent2", ["fluid.tests.demandsEvents"], [
"{arguments}.1"
]);
jqUnit.test("FLUID-4631: multiple to single argument", function () {
jqUnit.expect(1);
var origArg0 = "origArg0";
var origArg1 = "origArg1";
var assertEvent = function (arg0) {
jqUnit.assertEquals("Transmission of the original second argument", origArg1, arg0);
};
var that = fluid.tests.demandsEvents({
events: {
testEvent2: {
event: "someEvent"
}
},
listeners: {
testEvent2: assertEvent
}
});
that.events.someEvent.fire(origArg0, origArg1);
});
/** FLUID-4637 component proximity resolution test **/
fluid.defaults("fluid.tests.twinSubComponent", {
gradeNames: ["fluid.eventedComponent", "autoInit"],
preInitFunction: "fluid.tests.twinSubComponent.preInit",
events: {
childEvent: null
},
listeners: {
childEvent: "{twinSubComponent}.testRealName"
},
realName: ""
});
fluid.tests.twinSubComponent.preInit = function (that) {
that.testRealName = function (expectedName) {
jqUnit.assertEquals("The correct component should be triggered", expectedName, that.options.realName);
};
};
fluid.defaults("fluid.tests.twinParent", {
gradeNames: ["fluid.littleComponent", "autoInit"],
components: {
twin1: {
type: "fluid.tests.twinSubComponent",
options: {
realName: "twin1"
}
},
twin2: {
type: "fluid.tests.twinSubComponent",
options: {
realName: "twin2"
}
}
}
});
jqUnit.test("FLUID-4637: Listener mix up with injected events in twin subcomponents", function () {
var that = fluid.tests.twinParent();
that.twin1.events.childEvent.fire(that.twin1.options.realName);
});
/** FLUID-4914 derived grade resolution tests **/
fluid.defaults("fluid.tests.dataSource", {
gradeNames: ["fluid.littleComponent", "autoInit"],
invokers: {
get: "fluid.tests.dataSource.get"
}
});
fluid.defaults("fluid.tests.URLDataSource", {
gradeNames: ["fluid.tests.dataSource", "autoInit"],
url: "http://jsforcats.com",
invokers: {
resolve: "fluid.tests.dataSource.urlResolver.resolve"
}
});
fluid.demands("fluid.tests.dataSource.urlResolver.resolve", "fluid.tests.URLDataSource", {
funcName: "fluid.identity",
args: "{dataSource}.options.url"
});
fluid.demands("fluid.tests.dataSource.get", "fluid.tests.dataSource", {
funcName: "fluid.identity",
args: {value: 4}
});
jqUnit.test("FLUID-4914: resolve grade as context name", function () {
var dataSource = fluid.tests.URLDataSource();
var url = dataSource.resolve();
jqUnit.assertEquals("Resolved grade context name via invoker", dataSource.options.url, url);
var data = dataSource.get();
jqUnit.assertDeepEq("Resolved grade context name as demands context", {value: 4}, data);
});
/** FLUID-4392 demands block merging tests **/
fluid.demands("fluid.tests.demandMerge", ["fluid.tests.context1"], {
funcName: "fluid.tests.demandMerge1",
options: {
mergeKey1: "topValue1",
mergeKey2: "topValue2",
mergeKey3: "topValue3"
}
});
fluid.demands("fluid.tests.demandMerge", ["fluid.tests.context1", "fluid.tests.context2"], {
funcName: "fluid.tests.demandMerge2",
options: {
mergeKey1: "middleValue1",
mergeKey2: "middleValue2"
}
});
fluid.demands("fluid.tests.demandMerge", ["fluid.tests.context1", "fluid.tests.context2", "fluid.tests.context3"], {
funcName: "fluid.tests.demandMerge3",
options: {
mergeKey1: "bottomValue1"
}
});
// We only create the most specific component since the most specific demands block will win on funcName
fluid.defaults("fluid.tests.demandMerge3", {
gradeNames: ["fluid.littleComponent", "autoInit"]
});
fluid.defaults("fluid.tests.demandHolder", {
gradeNames: ["fluid.littleComponent", "autoInit"],
components: {
context1: {
type: "fluid.typeFount",
options: {
targetTypeName: "fluid.tests.context1"
}
},
context2: {
type: "fluid.typeFount",
options: {
targetTypeName: "fluid.tests.context2"
}
},
context3: {
type: "fluid.typeFount",
options: {
targetTypeName: "fluid.tests.context3"
}
},
demandMerge: {
type: "fluid.tests.demandMerge"
}
}
});
/** FLUID-4916 dynamic grade support tests **/
fluid.defaults("fluid.tests.dynamicParent", {
gradeNames: ["fluid.littleComponent", "autoInit"],
parentOption: 1
});
fluid.defaults("fluid.tests.dynamicGrade", {
gradeNames: ["fluid.littleComponent", "autoInit", "{that}.computeGrade"],
invokers: {
computeGrade: "fluid.tests.computeDynamicParent",
respondParent: "fluid.tests.respondParent"
}
});
fluid.tests.computeDynamicParent = function () {
return "fluid.tests.dynamicParent";
};
fluid.demands("fluid.tests.respondParent", "fluid.tests.dynamicParent", {
funcName: "fluid.tests.respondParentImpl",
args: "{dynamicParent}.options.parentOption"
});
fluid.tests.respondParentImpl = fluid.identity;
jqUnit.test("FLUID-4916 Dynamic grade support", function () {
var that = fluid.tests.dynamicGrade();
jqUnit.assertTrue("Correctly resolved parent grade", fluid.hasGrade(that.options, "fluid.tests.dynamicParent"));
jqUnit.assertEquals("Correctly resolved options from parent grade", 1, that.options.parentOption);
jqUnit.assertEquals("Correctly resolved parent-contextualised invoker", 1, that.respondParent());
});
/** FLUID-4917 demands block horizon support **/
fluid.defaults("fluid.tests.horizonParent", {
gradeNames: ["fluid.littleComponent", "fluid.tests.horizonExtraParent", "autoInit"],
components: {
horizonMiddle: {
type: "fluid.tests.horizonMiddle"
}
}
});
fluid.defaults("fluid.tests.horizonMiddle", {
gradeNames: ["fluid.littleComponent", "fluid.tests.horizonExtra", "autoInit"],
invokers: {
horizonOp: "fluid.tests.horizonOp"
}
});
// This demands block would have force 3 and win if it were not horizoned
fluid.demands("fluid.tests.horizonOp", ["fluid.tests.horizonMiddle", "fluid.tests.horizonParent", "fluid.tests.horizonExtraParent"], {
horizon: "fluid.tests.horizonMiddle",
funcName: "fluid.tests.horizonByParent"
});
// As a result of the prior block eliminating itself down to force one through horizon, this one will win
fluid.demands("fluid.tests.horizonOp", ["fluid.tests.horizonMiddle", "fluid.tests.horizonExtra"], {
funcName: "fluid.tests.horizonByExtra"
});
fluid.tests.horizonByExtra = fluid.identity;
jqUnit.test("FLUID-4917 Demands block horizon support", function () {
var that = fluid.tests.horizonParent();
jqUnit.assertTrue("Correctly resolved horizoned demands block", that.horizonMiddle.horizonOp(true));
});
// NOTE! This test must be left COMPLETELY undisturbed - as well as testing support for "members" itself, it exposed
// a bug in the ginger pathway itself, whereby the driving effect of the "members" expander failed to cause "expanded"
// to be expanded as a result of its trunk path already being seen during the previous driving during options expansion
// which evaluated the expander, causing "emptyArray" to be driven and hence the trunk path for "members". This was
// patched in the merge strategy to ensure that any evaluations which occur after "initter" cause full evalution,
// but we expect similar such bugs in the future until we understand the ginger process properly.
// The idea was also to be able to verify reference equality of "expanded" and "emptyArray" but this seems not to be
// possible right now as a result of the recursion by the expander copying its arguments at args = options.recurse([], args);
fluid.defaults("fluid.tests.memberTest", {
gradeNames: ["fluid.littleComponent", "autoInit"],
members: {
expanded: {
expander: {
func: "{that}.identity",
args: "{that}.emptyArray"
}
},
emptyArray: [],
doubleTest: "{that}.options.invokers.dummy" // double expansion tester - will explode on double expansion
},
invokers: {
identity: "fluid.identity",
dummy: {
funcName: "fluid.identity",
args: "{arguments}.0"
}
}
});
jqUnit.test("FLUID-4918 Support for \"members\" directive", function () {
var member1 = fluid.tests.memberTest();
function testEmptyArray(that) {
jqUnit.assertDeepEq("Correctly instantiated member from literal", [], that.emptyArray);
jqUnit.assertDeepEq("Correctly instantiated member through expander", that.emptyArray, that.expanded);
}
testEmptyArray(member1);
member1.emptyArray.push("corruption");
var member2 = fluid.tests.memberTest(); // Ensure that expanded material in "members" has not become aliased
testEmptyArray(member2);
});
/** Basic IoC Tests **/
fluid.defaults("fluid.tests.defaultInteraction", {
gradeNames: ["fluid.littleComponent", "autoInit"],
components: {
popup: {
type: "fluid.tests.popup"
}
}
});
fluid.defaults("fluid.tests.popup", {
gradeNames: ["fluid.littleComponent", "autoInit"],
resources: {
template: {
forceCache: true,
url: "../html/AutocompleteAddPopup.html"
}
}
});
fluid.demands("fluid.tests.popup", "fluid.tests.localTest", {
args: {
resources: {
template: {
url: "../../html/AutocompleteAddPopup.html"
}
}
}
});
jqUnit.test("Basic interaction between defaults and demands", function () {
var that = fluid.tests.defaultInteraction();
jqUnit.assertValue("Constructed", that);
var standardDefaults = fluid.copy(fluid.defaults("fluid.tests.popup"));
delete standardDefaults.mergePolicy;
fluid.clearLifecycleFunctions(standardDefaults);
jqUnit.assertDeepEq("Default options", standardDefaults, that.popup.options);
try {
fluid.staticEnvironment.localEnvironment = fluid.typeTag("fluid.tests.localTest");
var demands = fluid.demands("fluid.tests.popup", "fluid.tests.localTest");
var that2 = fluid.tests.defaultInteraction();
standardDefaults.targetTypeName = "fluid.tests.popup"; // TODO: this floats about a bit
var mergedDefaults = $.extend(true, standardDefaults, demands.args);
jqUnit.assertDeepEq("Merged options", mergedDefaults, that2.popup.options);
} finally {
delete fluid.staticEnvironment.localEnvironment;
}
});
/** FLUID-4873 distributeOptions tests **/
fluid.tests.IoCSSParsing = [
{selector: "fluid.tests.contextName",
expected: [ {predList: [{
"context": "fluid.tests.contextName"
}]}
]
},
{selector: "fluid.tests.contextName & fluid.tests.contextName2",
expected: "fail"
},
{selector: "fluid.tests.contextName&fluid.tests.contextName2",
expected: [ {predList: [{
"context": "fluid.tests.contextName"
}, {
"context": "fluid.tests.contextName2"
}
]}
]
},
{selector: "fluid.tests.contextName#35 > fluid.tests.contextName2",
expected: [ {
child: true,
predList: [{
"context": "fluid.tests.contextName"
}, {
"id": "35"
}
]}, {
predList: [{
"context": "fluid.tests.contextName2"
}
]}
]
}
];
jqUnit.test("FLUID-4873 IoCSS selector parsing tests", function () {
fluid.pushSoftFailure(true);
fluid.each(fluid.tests.IoCSSParsing, function (fixture) {
var parser = function () { return fluid.parseSelector(fixture.selector, fluid.IoCSSMatcher);};
if (fixture.expected === "fail") {
jqUnit["throws"](parser, "Selector " + fixture.selector + " is invalid");
}
else {
var parsed = parser();
jqUnit.assertDeepEq("Parsed selector " + fixture.selector, fixture.expected, parsed);
}
});
fluid.pushSoftFailure(-1);
});
fluid.defaults("fluid.tests.uploader", {
gradeNames: ["fluid.littleComponent", "autoInit"],
components: {
uploaderContext: {
type: "fluid.progressiveCheckerForComponent",
options: {componentName: "fluid.tests.uploader"}
},
uploaderImpl: {
type: "fluid.tests.uploaderImpl"
}
},
distributeOptions: {
source: "{that}.options",
exclusions: ["components.uploaderContext", "components.uploaderImpl"],
target: "{that > uploaderImpl}.options"
},
progressiveCheckerOptions: {
checks: [
{
feature: "{fluid.test}",
contextName: "fluid.uploader.html5"
}
]
}
});
fluid.demands("fluid.tests.uploaderImpl", "fluid.uploader.html5", {
funcName: "fluid.tests.uploader.multiFileUploader"
});
fluid.defaults("fluid.tests.uploader.multiFileUploader", {
gradeNames: ["fluid.littleComponent", "autoInit"]
});
jqUnit.test("FLUID-4873 Total Skywalker Options Distribution", function () {
var uploader = fluid.tests.uploader({userOption: 5}).uploaderImpl;
jqUnit.assertEquals("Skywalker options transmission", 5, uploader.options.userOption);
jqUnit.assertNoValue("Options exclusion", uploader.uploaderContext);
});
/** FLUID-4926 Invoker tests **/
fluid.defaults("fluid.tests.invokerFunc", {
gradeNames: ["fluid.littleComponent", "autoInit"],
invokers: {
targetInvoker: "fluid.identity",
sourceInvoker: {
func: "{that}.targetInvoker",
args: false
}
}
});
jqUnit.test("FLUID-4926 Invoker resolution test", function () {
var that = fluid.tests.invokerFunc();
var result = that.sourceInvoker();
jqUnit.assertEquals("Invoker relay of false argument", false, result);
});
/** Expansion order test **/
// Example liberated from UIOptions implementation, which revealed requirement for
// "expansion before merging" when constructing the new framework. This is a perverse
// but probably valid usage of the framework. These kinds of "wholesale options transmissions"
// cases are intended to be handled by FLUID-4873 "Luke Skywalker Options" ("distributeOptions")
fluid.defaults("fluid.tests.uiEnhancer", {
gradeNames: ["fluid.littleComponent", "autoInit"],
value: 3,
outerValue: 4
});
fluid.defaults("fluid.tests.pageEnhancer", {
gradeNames: ["fluid.littleComponent", "autoInit"],
uiEnhancerOptions: {
outerValue: 3
},
components: {
uiEnhancer: {
type: "fluid.tests.uiEnhancer",
options: "{pageEnhancer}.options.uiEnhancerOptions"
}
}
});
jqUnit.test("Expansion order test", function () {
var that = fluid.tests.pageEnhancer();
var expected = {
value: 3,
outerValue: 3
};
jqUnit.assertLeftHand("Correctly merged options", expected, that.uiEnhancer.options);
});
/** Listener merging tests **/
fluid.tests.listenerMergingPreInit = function (that) {
that.eventFired = function (eventName) {
that[eventName] = true;
};
};
fluid.defaults("fluid.tests.listenerMerging", {
gradeNames: ["fluid.eventedComponent", "autoInit"],
preInitFunction: "fluid.tests.listenerMergingPreInit",
listeners: {
eventOne: "{fluid.tests.listenerMerging}.eventFired",
eventTwo: "{fluid.tests.listenerMerging}.eventFired"
},
events: {
eventOne: null,
eventTwo: null,
eventThree: null
}
});
jqUnit.test("Listener Merging Tests: FLUID-4196", function () {
var threeFired = false;
var that = fluid.tests.listenerMerging({
listeners: {
eventThree: function () {threeFired = true;}
}
});
that.events.eventThree.fire();
jqUnit.assertTrue("Event three listener notified", threeFired);
that.events.eventTwo.fire("twoFired");
jqUnit.assertTrue("Event two listener notified", that.twoFired);
});
/** FLUID-5082 auto-namespaces (soft) **/
fluid.tests.FLUID5082func = function (that, arg) {
that.fireRecord.push(arg);
};
fluid.tests.FLUID5082func2 = fluid.tests.FLUID5082func;
fluid.defaults("fluid.tests.FLUID5082Parent", {
gradeNames: ["fluid.eventedComponent", "autoInit"],
members: {
fireRecord: [],
self: "{that}"
},
events: {
testEvent: null,
},
listeners: {
testEvent: [{
funcName: "fluid.tests.FLUID5082func",
args: ["{that}", 1]
}, {
func: "{that}.FLUID5082invoker",
args: ["{that}", 2]
}, {
"this": "{that}.self",
method: "FLUID5082invoker2",
args: ["{that}", 3]
}, {
funcName: "fluid.tests.FLUID5082func2",
args: ["{that}", 4]
}]
},
invokers: {
FLUID5082invoker: {
funcName: "fluid.tests.FLUID5082func"
},
FLUID5082invoker2: {
funcName: "fluid.tests.FLUID5082func"
}
}
});
fluid.defaults("fluid.tests.FLUID5082Child", {
gradeNames: ["fluid.eventedComponent", "autoInit"],
listeners: {
testEvent: [{
funcName: "fluid.tests.FLUID5082func",
namespace: "fluid.tests.FLUID5082Parent.FLUID5082func", // will override
args: ["{FLUID5082Parent}", 5]
}, {
func: "{FLUID5082Parent}.FLUID5082invoker",
namespace: "fluid.tests.FLUID5082Parent.FLUID5082invoker", // will override
args: ["{FLUID5082Parent}", 6]
}, {
"this": "{FLUID5082Parent}.self",
namespace: "fluid.tests.FLUID5082Parent.self.FLUID5082invoker2", // will override
method: "FLUID5082invoker2",
args: ["{FLUID5082Parent}", 7]
}, {
funcName: "fluid.tests.FLUID5082func2", // will not override
args: ["{FLUID5082Parent}", 8]
}]
}
});
jqUnit.test("Listener Merging Tests: FLUID-5082", function () {
var that = fluid.tests.FLUID5082Parent();
that.events.testEvent.fire();
jqUnit.assertDeepEq("Base grade listeners fired", [1, 2, 3, 4], that.fireRecord);
// Test configuration with child superposed on parent
var that2 = fluid.tests.FLUID5082Child({gradeNames: "fluid.tests.FLUID5082Parent"});
that2.events.testEvent.fire();
jqUnit.assertDeepEq("Base grade listeners fired", [4, 5, 6, 7, 8], that2.fireRecord);
// Test configuration with child as child component - results should be identical
var that3 = fluid.tests.FLUID5082Parent( {
components: {
child: {
type: "fluid.tests.FLUID5082Child",
options: {
events: {
testEvent: "{FLUID5082Parent}.events.testEvent"
}
}
}
}
});
that3.events.testEvent.fire();
jqUnit.assertDeepEq("Base grade listeners fired", [4, 5, 6, 7, 8], that3.fireRecord);
});
/** withEnvironment tests - eventually to be deprecated **/
fluid.defaults("fluid.tests.fluid3818head", {
gradeNames: ["fluid.littleComponent", "autoInit"],
components: {
child: {
type: "fluid.tests.fluid3818child",
options: {
value: "{environmentalValue}.derived"
}
}
}
});
jqUnit.test("Environmental Tests II - FLUID-3818", function () {
var component = fluid.withEnvironment({
environmentalValue: $.extend(fluid.typeTag("environmentalValue"), {
derived: "derivedValue"
})
}, function () {
return fluid.tests.fluid3818head();
});
jqUnit.assertValue("child component constructed", component.child);
jqUnit.assertEquals("Resolved environmental value", "derivedValue", component.child.options.value);
});
fluid.registerNamespace("fluid.tests.envTests");
fluid.tests.envTests.config = {
viewURLTemplate: "http://titan.atrc.utoronto.ca:5984/%dbName/%view",
views: {
exhibitions: "_design/exhibitions/_view/browse"
}
};
jqUnit.test("Environmental Tests", function () {
var urlBuilder = {
type: "fluid.stringTemplate",
template: "{config}.viewURLTemplate",
mapper: {
dbName: "${{params}.db}_exhibitions",
view: "{config}.views.exhibitions"
}
};