forked from ezsystems/PlatformUIBundle
/
ez-locationviewview-tests.js
1108 lines (961 loc) · 37.3 KB
/
ez-locationviewview-tests.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 (C) eZ Systems AS. All rights reserved.
* For full copyright and license information view LICENSE file distributed with this source code.
*/
YUI.add('ez-locationviewview-tests', function (Y) {
var test, tabsTest, eventsTest, destroyTest, attrsToSubViewsTest,
selectedTest, forwardActiveTest, subitemBoxAttr, subitemListAttrTest,
addTabViewTest, removeTabViewTest,
Mock = Y.Mock, Assert = Y.Assert,
_getModelMock = function (serialized) {
var mock = new Y.Test.Mock();
Y.Mock.expect(mock, {
method: 'toJSON',
returns: serialized
});
return mock;
},
_getLocationModelMock = function (serializedLocation, serializedContentInfo) {
var locationMock = new Y.Test.Mock();
Y.Mock.expect(locationMock, {
method: 'toJSON',
returns: serializedLocation
});
return locationMock;
},
RenderedView = Y.Base.create('renderedView', Y.View, [], {
render: function () {
this.set('rendered', true);
return this;
},
});
test = new Y.Test.Case({
name: "eZ Location View view tests",
setUp: function () {
this.barMock = new RenderedView();
this.tab1 = new Y.View();
this.tab2 = new Y.View();
this.subitemBox = new RenderedView();
this.tab1.set('identifier', 'tab1');
this.tab1.set('title', 'Tab1');
this.tab2.set('identifier', 'tab2');
this.tab2.set('title', 'Tab2');
this.locationMock = new Mock();
this.contentMock = new Mock();
this.contentTypeMock = new Mock();
this.locationJSON = {};
this.contentJSON = {};
this.contentTypeJSON = {};
this.path = [];
this.languageCode = 'eng-GB';
Y.Mock.expect(this.locationMock, {
method: "toJSON",
args: [],
returns: this.locationJSON,
});
Y.Mock.expect(this.contentMock, {
method: "toJSON",
args: [],
returns: this.contentJSON,
});
Y.Mock.expect(this.contentTypeMock, {
method: "toJSON",
args: [],
returns: this.contentTypeJSON,
});
this.view = new Y.eZ.LocationViewView({
actionBar: this.barMock,
tabs: [this.tab1, this.tab2],
subitemBox: this.subitemBox,
subitemList: null,
location : this.locationMock,
content : this.contentMock,
contentType : this.contentTypeMock,
path: this.path,
languageCode: this.languageCode
});
this.view._set('selectedTab', 'tab1');
},
tearDown: function () {
this.view.destroy();
delete this.view;
},
"Test render": function () {
var templateCalled = false,
origTpl,
container = this.view.get('container');
origTpl = this.view.template;
this.view.template = function () {
templateCalled = true;
return origTpl.apply(this, arguments);
};
this.view.render();
Y.Assert.isTrue(
templateCalled,
"The template should have used to render the view"
);
Y.Assert.areNotEqual(
"", this.view.get('container').getHTML(),
"View container should contain the result of the view"
);
Y.Assert.areEqual(
container.one('.ez-locationview-content').getStyle('min-height'),
container.get('winHeight') + 'px'
);
},
_testRenderSubView: function (attr, selector) {
this.view.render();
Assert.isTrue(
this.view.get(attr).get('rendered'),
"The " + attr + " view should be rendered"
);
Assert.isTrue(
this.view.get('container').one('.ez-'+ selector + '-container').contains(
this.view.get(attr).get('container')
),
"The " + attr + " view should be rendered in the " + selector + " container"
);
},
"Should render the subitem box": function () {
this._testRenderSubView('subitemBox', 'subitem');
},
"Should render the action bar": function () {
this._testRenderSubView('actionBar', 'actionbar');
},
"Should handle a null subitem box": function () {
this.view._set('subitemBox', null);
this.view.render();
Assert.areEqual(
"", this.view.get('container').one('.ez-subitem-container').getContent(),
"The subitem box container should be empty"
);
},
"Test available variables in the template": function () {
var plainLocations = [{}, {}, {}],
origTpl = this.view.template,
location = this.locationMock,
content = this.contentMock,
contentType = this.contentTypeMock,
that = this;
Y.Array.each(plainLocations, function (val, k) {
this.path.push(_getLocationModelMock(plainLocations[k]));
}, this);
this.view.template = function (variables) {
Y.Array.each(variables.path, function (struct, k) {
Y.Mock.verify(struct);
Y.Assert.areSame(
struct, plainLocations[k],
"The jsonified location should be passed to the template"
);
});
Y.Mock.verify(contentType);
Y.Mock.verify(location);
Y.Mock.verify(content);
Y.Assert.areSame(
that.locationJSON, variables.location,
"location.toJSON() should be passed to the template"
);
Y.Assert.areSame(
that.contentJSON, variables.content,
"content.toJSON() should be passed to the template"
);
Y.Assert.areSame(
that.contentTypeJSON, variables.contentType,
"contentType.toJSON() should be passed to the template"
);
Assert.isArray(variables.tabs, "The tabs should be passed to the template");
Assert.areEqual(
that.tab1.get('title'), variables.tabs[0].title,
"The title of the tab view should be available"
);
Assert.areEqual(
that.tab1.get('identifier'), variables.tabs[0].identifier,
"The identifier of the tab view should be available"
);
Assert.isTrue(variables.tabs[0].selected, "The tab1 should be selected");
Assert.areEqual(
that.tab2.get('title'), variables.tabs[1].title,
"The title of the tab view should be available"
);
Assert.areEqual(
that.tab2.get('identifier'), variables.tabs[1].identifier,
"The identifier of the tab view should be available"
);
Assert.isFalse(variables.tabs[1].selected, "The tab2 should not be selected");
return origTpl.apply(this, arguments);
};
this.view.render();
},
"Should build the title from the content and the path": function () {
var contentName = 'Ryan Gosling',
contentPathNames = ['Hot', 'Male', 'Actors'],
content = this.contentMock,
that = this;
Y.Array.each(contentPathNames, function (val) {
var contentInfoMock = new Y.Mock(),
locationMock = new Y.Mock();
Y.Mock.expect(contentInfoMock, {
method: 'get',
args: ['name'],
returns: val
});
Y.Mock.expect(locationMock, {
method: 'get',
args: ['contentInfo'],
returns: contentInfoMock
});
that.path.push(locationMock);
});
Y.Mock.expect(content, {
method: 'get',
args: ['name'],
returns: contentName
});
Y.Assert.areEqual(
contentName + ' / ' + contentPathNames.join(' / '),
this.view.getTitle(),
"The title should be build with the content and the path"
);
},
});
attrsToSubViewsTest = new Y.Test.Case({
name: "eZ Location View view tests",
setUp: function () {
var contentType = new Mock();
Mock.expect(contentType, {
method: 'get',
args: ['isContainer'],
returns: true
});
Y.eZ.ActionBarView = Y.Base.create('actionBarView', Y.View, [], {}, {
ATTRS: {
content: {},
config: {},
actionList: {},
viewLessText: {},
viewMoreText: {},
},
});
Y.eZ.LocationViewViewTabView = Y.Base.create('locationViewTabView', Y.View, [], {}, {
ATTRS: {
content: {},
contentType: {},
location: {},
config: {},
priority: {},
languageCode: {},
}
});
Y.eZ.LocationViewDetailsTabView = Y.Base.create('locationViewDetailsTabView', Y.View, [], {}, {
ATTRS: {
content: {},
location: {},
config: {},
priority: {},
languageCode: {},
}
});
Y.eZ.LocationViewLocationsTabView = Y.Base.create('locationViewLocationsTabView', Y.View, [], {}, {
ATTRS: {
content: {},
locations: {},
config: {},
priority: {},
}
});
Y.eZ.SubitemBoxView = Y.Base.create('subitemBoxView', Y.View, [], {}, {
ATTRS: {
location: {},
content: {},
contentType: {},
config: {},
}
});
Y.eZ.LocationViewRelationsTabView = Y.Base.create('locationViewRelationsTabView', Y.View, [], {}, {
ATTRS: {
content: {},
contentType: {},
config: {},
priority: {},
}
});
Y.eZ.LocationViewVersionsTabView = Y.Base.create('locationViewVersionsTabView', Y.View, [], {}, {
ATTRS: {
content: {},
contentType: {},
config: {},
priority: {},
}
});
this.view = new Y.eZ.LocationViewView({
location: {},
content: {},
contentType: contentType,
config: {},
path: {},
languageCode: 'fre-FR',
subitemList: null,
});
},
tearDown: function () {
delete Y.eZ.ActionBarView;
delete Y.eZ.LocationViewViewTabView;
delete Y.eZ.LocationViewDetailsTabView;
delete Y.eZ.SubitemBoxView;
this.view.destroy();
delete this.view;
},
"Should set the content of the view tab view": function () {
Assert.areSame(
this.view.get('content'),
this.view.get('tabs')[0].get('content'),
'The content should have been set to the view tab view'
);
},
"Should set the location of the view tab view": function () {
Assert.areSame(
this.view.get('location'),
this.view.get('tabs')[0].get('location'),
'The location should have been set to the view tab view'
);
},
"Should set the contentType of the view tab view": function () {
Assert.areSame(
this.view.get('contentType'),
this.view.get('tabs')[0].get('contentType'),
'The contentType should have been set to the view tab view'
);
},
"Should set the config of the view tab view": function () {
Assert.areSame(
this.view.get('config'),
this.view.get('tabs')[0].get('config'),
'The config should have been set to the view tab view'
);
},
"Should set the priority of the view tab view": function () {
Assert.areSame(
4000,
this.view.get('tabs')[0].get('priority'),
'The priority should have been set to the view tab view'
);
},
"Should set the languageCode of the view tab view": function () {
Assert.areSame(
this.view.get('languageCode'),
this.view.get('tabs')[0].get('languageCode'),
'The languageCode should have been set to the view tab view'
);
},
"Should set the location view as a bubble target of the view tab view": function () {
var bubbled = false, evt = 'whatever';
this.view.on('*:' + evt, function () {
bubbled = true;
});
this.view.get('tabs')[0].fire(evt);
Assert.isTrue(bubbled, "The location view should be a bubble target of the tab view");
},
"Should set the content of the details tab view": function () {
Assert.areSame(
this.view.get('content'),
this.view.get('tabs')[1].get('content'),
'The content should have been set to the details tab view'
);
},
"Should set the location of the details tab view": function () {
Assert.areSame(
this.view.get('location'),
this.view.get('tabs')[1].get('location'),
'The location should have been set to the details tab view'
);
},
"Should set the config of the details tab view": function () {
Assert.areSame(
this.view.get('config'),
this.view.get('tabs')[1].get('config'),
'The config should have been set to the details tab view'
);
},
"Should set the priority of the details tab view": function () {
Assert.areSame(
3000,
this.view.get('tabs')[1].get('priority'),
'The priority should have been set to the details tab view'
);
},
"Should set the content of the versions tab view": function () {
Assert.areSame(
this.view.get('content'),
this.view.get('tabs')[2].get('content'),
'The content should have been set to the versions tab view'
);
},
"Should set the config of the versions tab view": function () {
Assert.areSame(
this.view.get('config'),
this.view.get('tabs')[2].get('config'),
'The config should have been set to the versions tab view'
);
},
"Should set the priority of the versions tab view": function () {
Assert.areSame(
2500,
this.view.get('tabs')[2].get('priority'),
'The priority should have been set to the versions tab view'
);
},
"Should set the location view as a bubble target of the details tab view": function () {
var bubbled = false, evt = 'whatever';
this.view.on('*:' + evt, function () {
bubbled = true;
});
this.view.get('tabs')[1].fire(evt);
Assert.isTrue(bubbled, "The location view should be a bubble target of the details tab view");
},
"Should set the content of the action bar": function () {
Y.Assert.areSame(
this.view.get('content'),
this.view.get('actionBar').get('content'),
'The content should have been set to the actionBar'
);
},
"Should set the contentType of the action bar": function () {
Y.Assert.areSame(
this.view.get('contentType'),
this.view.get('actionBar').get('contentType'),
'The contentType should have been set on the actionBar'
);
},
"Should set the config of the action bar": function () {
Assert.areSame(
this.view.get('config'),
this.view.get('actionBar').get('config'),
'The config should have been set on the actionBar'
);
},
"Should set the location on the subitem box": function () {
Assert.areSame(
this.view.get('location'),
this.view.get('subitemBox').get('location'),
'The location should have been set on the subitem box'
);
},
"Should set the config on the subitem box": function () {
Assert.areSame(
this.view.get('config'),
this.view.get('subitemBox').get('config'),
'The config should have been set on the subitem box'
);
},
"Should set the location view as a bubble target of the subitem box": function () {
var bubbled = false, evt = 'whatever';
this.view.on('*:' + evt, function () {
bubbled = true;
});
this.view.get('subitemBox').fire(evt);
Assert.isTrue(bubbled, "The location view should be a bubble target of the subitem box");
},
});
tabsTest = new Y.Test.Case({
name: "eZ Location view view tabs tests",
setUp: function () {
this.barMock = new Y.View();
this.subitemBox = new Y.View();
this.tab1 = new Y.View();
this.tab2 = new Y.View();
this.tab1.setAttrs({
title: "Tab 1",
identifier: "tab1",
});
this.tab2.setAttrs({
title: "Tab 2",
identifier: "tab2",
});
this.view = new Y.eZ.LocationViewView({
actionBar: this.barMock,
subitemBox: this.subitemBox,
subitemList: null,
tabs: [this.tab1, this.tab2],
selectedTab: 'tab1',
location: _getModelMock({}),
content: _getModelMock({}),
contentType: _getModelMock({}),
container: Y.one('.container')
});
this.view.render();
},
_selectTab: function (linkSelector, labelId) {
var that = this, c = this.view.get('container'),
target = c.one(linkSelector),
initialHash;
initialHash = Y.config.win.location.hash;
target.simulateGesture('tap', function () {
that.resume(function () {
Y.Assert.areEqual(
labelId, c.one('.is-tab-selected').get('id'),
"The last label should have been selected"
);
Y.Assert.areEqual(
c.all('.ez-tabs-list .is-tab-selected').size(), 1,
"Only one label should be selected"
);
Y.Assert.areEqual(
c.all('.ez-tabs-panels .is-tab-selected').size(), 1,
"Only one panel should be selected"
);
Y.Assert.areEqual(
target.getAttribute('href').replace(/^#/, ''),
c.one('.ez-tabs-panels .is-tab-selected').get('id'),
"The panel indicated by the label link should be selected"
);
Y.Assert.areEqual(
initialHash, Y.config.win.location.hash,
"The location hash should be intact (tap event is prevented)"
);
});
});
this.wait();
},
"Should select label on tap": function () {
this._selectTab('[data-tab-identifier="tab2"] a', 'li-tab2');
},
"Should not change selection, when already selected label is tapped": function () {
this._selectTab('[data-tab-identifier="tab1"] a', 'li-tab1');
},
tearDown: function () {
this.view.destroy();
},
});
eventsTest = new Y.Test.Case({
name: "eZ Location view view events handling tests",
setUp: function () {
this.view = new Y.eZ.LocationViewView({
actionBar: new Y.View(),
subitemBox: new Y.View(),
subitemList: null,
tabs: [],
container: '.container',
});
},
tearDown: function () {
this.view.destroy();
},
"The action bar minimized class should be toggled by the minimizeActionBarAction event": function () {
var container = this.view.get('container');
this.view.fire('whatever:minimizeActionBarAction');
Y.Assert.isTrue(
container.hasClass('is-actionbar-minimized'),
"The location view container should get the action bar minimized class"
);
this.view.fire('whatever:minimizeActionBarAction');
Y.Assert.isFalse(
container.hasClass('is-actionbar-minimized'),
"The location view container should NOT get the action bar minimized class"
);
},
});
destroyTest = new Y.Test.Case({
name: "eZ Location view view destructor test",
setUp: function () {
this.barMock = new Y.View();
this.tab1 = new Y.View();
this.tab2 = new Y.View();
this.subitemBox = new Y.View();
this.tab1.setAttrs({
title: "Tab 1",
identifier: "tab1",
});
this.tab2.setAttrs({
title: "Tab 2",
identifier: "tab2",
});
this.view = new Y.eZ.LocationViewView({
actionBar: this.barMock,
tabs: [this.tab1, this.tab2],
subitemBox: this.subitemBox,
subitemList: null,
selectedTab: 'tab1',
location: {},
content: {},
});
},
tearDown: function () {
this.tab1.destroy();
this.tab2.destroy();
this.barMock.destroy();
this.view.destroy();
this.subitemBox.destroy();
},
"Should destroy the action bar": function () {
this.view.destroy();
Assert.isTrue(
this.barMock.get('destroyed'),
"The action bar should have been destroyed"
);
},
"Should destroy the tabs": function () {
this.view.destroy();
Assert.isTrue(
this.tab1.get('destroyed'),
"The tabs should have been destroyed"
);
Assert.isTrue(
this.tab2.get('destroyed'),
"The tabs should have been destroyed"
);
},
"Should destroy the subitem box": function () {
this.view.destroy();
Assert.isTrue(
this.subitemBox.get('destroyed'),
"The action bar should have been destroyed"
);
},
});
addTabViewTest = new Y.Test.Case({
name: "eZ Location view view addTabView test",
setUp: function () {
this.barMock = new Y.View();
this.view = new Y.eZ.LocationViewView({
actionBar: this.barMock,
tabs: [],
});
},
tearDown: function () {
this.barMock.destroy();
this.view.destroy();
},
"Should add the tab view to the list": function () {
var tab = new Y.View({
identifier: "lz-hills",
title: "Led Zeppelin - Over the hills and far away"
}),
tabs = this.view.get('tabs');
this.view.addTabView(tab);
Assert.areEqual(
1, tabs.length,
"The tab should have been added to the list"
);
Assert.areSame(tab, tabs[0], "The tab should be in the list");
},
"Should maintain the order by priority": function () {
var tab1 = new Y.View({
identifier: "lz-hills",
title: "Led Zeppelin - Over the hills and far away",
priority: 1000,
}),
tab2 = new Y.View({
identifier: "lz-stairway",
title: "Led Zeppelin - Stairway to heaven",
priority: 500,
}),
tab3 = new Y.View({
identifier: "lz-ramble",
title: "Led Zeppelin - Ramble on",
priority: 700,
}),
tabs = this.view.get('tabs');
this.view.addTabView(tab3);
this.view.addTabView(tab1);
this.view.addTabView(tab2);
Assert.areEqual(
3, tabs.length,
"The tabs should have been added to the list"
);
Assert.areSame(tab1, tabs[0], "The tabs should be ordered by priority");
Assert.areSame(tab3, tabs[1], "The tabs should be ordered by priority");
Assert.areSame(tab2, tabs[2], "The tabs should be ordered by priority");
},
"Should set the location view a bubble target of the tab": function () {
var tab = new Y.View({
identifier: "lz-hills",
title: "Led Zeppelin - Over the hills and far away"
}),
evt = "whatever",
bubbled = false;
this.view.addTabView(tab);
this.view.on('*:' + evt, function () {
bubbled = true;
});
tab.fire(evt);
Assert.isTrue(
bubbled, "The location view should be a bubble target of the tab"
);
},
});
removeTabViewTest = new Y.Test.Case({
name: "eZ Location view view addTabView test",
setUp: function () {
this.barMock = new Y.View();
this.tabs = [
new Y.View({
identifier: "lz-hills",
title: "Led Zeppelin - Over the hills and far away",
priority: 1000,
}),
new Y.View({
identifier: "lz-ramble",
title: "Led Zeppelin - Ramble on",
priority: 700,
}),
new Y.View({
identifier: "lz-stairway",
title: "Led Zeppelin - Stairway to heaven",
priority: 500,
}),
];
this.view = new Y.eZ.LocationViewView({
actionBar: this.barMock,
tabs: [],
});
Y.Array.each(this.tabs, function (tab) {
this.view.addTabView(tab);
}, this);
},
tearDown: function () {
this.barMock.destroy();
Y.Array.each(this.tabs, function (t) {
t.destroy();
});
this.view.destroy();
},
"Should return null if the tabView is not found": function () {
Assert.isNull(
this.view.removeTabView('lady-gaga'),
"removeTabView should have returned null"
);
},
"Should remove the tab view from the list": function () {
this.view.removeTabView('lz-ramble');
Assert.areEqual(2, this.view.get('tabs').length, "Only 2 tabs should remain");
},
"Should return the found tab view": function () {
var tabView,
removedTabView;
tabView = this.tabs[1];
removedTabView = this.view.removeTabView(tabView.get('identifier'));
Assert.areSame(
tabView, removedTabView,
"The removed tab view should have been returned"
);
},
"Should remove the location view from the bubble targets of the tabView": function () {
var removedTabView, evt = 'whatever', bubbled = false;
this.view.on('*:' + evt, function () {
bubbled = true;
});
removedTabView = this.view.removeTabView(this.tabs[1].get('identifier'));
removedTabView.fire(evt);
Assert.isFalse(bubbled, "The event should not bubbled to the location view");
}
});
selectedTest = new Y.Test.Case({
name: "eZ Location view view addTabView test",
setUp: function () {
this.barMock = new Y.View();
this.tabs = [
new Y.View({
identifier: "lz-hills",
title: "Led Zeppelin - Over the hills and far away",
priority: 1000,
selected: true,
}),
new Y.View({
identifier: "lz-ramble",
title: "Led Zeppelin - Ramble on",
priority: 700,
selected: false,
}),
];
this.view = new Y.eZ.LocationViewView({
actionBar: this.barMock,
tabs: [],
});
Y.Array.each(this.tabs, function (tab) {
this.view.addTabView(tab);
}, this);
this.view._set('selectedTab', 'lz-hills');
},
tearDown: function () {
this.barMock.destroy();
Y.Array.each(this.tabs, function (t) {
t.destroy();
});
this.view.destroy();
},
"Should sync the selected tab attribute with selectedTab": function () {
this.view._set('selectedTab', this.tabs[1].get('identifier'));
Assert.isTrue(
this.tabs[1].get('selected'),
"The tab1 should be selected"
);
Assert.isFalse(
this.tabs[0].get('selected'),
"The tab0 should not be selected"
);
},
});
forwardActiveTest = new Y.Test.Case({
name: "eZ Location view view forward the active state test",
setUp: function () {
this.barMock = new Y.View();
this.tabs = [
new Y.View({
identifier: "let-there-be-rock",
title: "AC/DC - Let there be rock",
priority: 1000,
selected: true,
}),
new Y.View({
identifier: "thunderstruck",
title: "AC/DC - Thunderstruck",
priority: 700,
selected: false,
}),
];
this.view = new Y.eZ.LocationViewView({
actionBar: this.barMock,
tabs: [],
});
Y.Array.each(this.tabs, function (tab) {
this.view.addTabView(tab);
}, this);
},
tearDown: function () {
this.barMock.destroy();
Y.Array.each(this.tabs, function (t) {
t.destroy();
});
this.view.destroy();
},
"Should forward the active state (true)": function () {
this.view.set('active', true);
Y.Array.each(this.view.get('tabs'), function (t) {
Assert.isTrue(
t.get('active'),
"The tab '" + t.get('identifier') + "' should be active"
);
});
},
"Should forward the active state (false)": function () {
this["Should forward the active state (true)"]();
this.view.set('active', false);
Y.Array.each(this.view.get('tabs'), function (t) {
Assert.isFalse(
t.get('active'),
"The tab '" + t.get('identifier') + "' should NOT be active"
);
});
},
});
subitemBoxAttr = new Y.Test.Case({
name: "eZ Location view view subitemBox attribute test",
setUp: function () {
this.contentType = new Mock();
Mock.expect(this.contentType, {
method: 'get',
args: ['isContainer'],
run: Y.bind(function () {
return this.isContainer;
}, this)
});
Y.eZ.SubitemBoxView = Y.View;
},
tearDown: function () {
delete Y.eZ.SubitemBoxView;
this.view.destroy();
},