forked from googlearchive/cloud-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrollersSpec.js
More file actions
859 lines (658 loc) · 24.7 KB
/
Copy pathcontrollersSpec.js
File metadata and controls
859 lines (658 loc) · 24.7 KB
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
'use strict';
/* jasmine specs for controllers */
/* http://docs.angularjs.org/api/angular.mock.inject */
function make_project(key, subsecond) {
return {
'description': 'The project description',
'key': key,
'name': 'New project name',
'orderby': 'test@example.com-2013-01-03T01:05:32.' + subsecond,
'run_url': 'http://localhost:9200/?_mimic_project=' + key,
};
}
describe('AlertController', function() {
var scope, ctrl, Alert;
beforeEach(module('playgroundApp.services'));
beforeEach(inject(function($rootScope, _Alert_, $controller) {
scope = $rootScope.$new();
ctrl = $controller(AlertController, {$scope: scope});
Alert = _Alert_;
}));
it('should always show safety alert', function() {
expect(scope.alerts().length).toBe(1);
expect(scope.alerts()[0].msg)
.toMatch(/Your private source code and data are not safe here./);
});
it('should be able to remove an alert', function() {
scope.closeAlert(0);
expect(scope.alerts().length).toBe(0);
});
});
describe('HeaderController', function() {
var scope, $httpBackend, $location;
beforeEach(inject(function($rootScope, $injector) {
scope = $rootScope.$new();
//$httpBackend = $injector.get('$httpBackend');
}));
beforeEach(inject(function(_$location_) {
doInit();
$location = _$location_;
}));
function doInit() {
inject(function($controller) {
$controller(HeaderController, {$scope: scope});
flushDoSerial();
//$httpBackend.flush();
});
}
it('alreadyhome function should only return true for /playground/',
function() {
expect(typeof scope.alreadyhome).toEqual('function');
$location.path('/');
expect(scope.alreadyhome()).toBe(false);
$location.path('/playground');
expect(scope.alreadyhome()).toBe(false);
$location.path('/playground/');
expect(scope.alreadyhome()).toBe(true);
$location.path('/playground/p/42/');
expect(scope.alreadyhome()).toBe(false);
});
});
describe('ProjectController', function() {
var scope, $httpBackend;
function make_file(filename, mime_type, contents, dirty) {
var file = {
'path': filename,
'mime_type': mime_type,
};
if (contents) {
file.contents = contents;
}
if (dirty != undefined) {
file.dirty = dirty;
}
return file;
}
function make_files_response() {
return [
make_file('app.yaml', 'text/x-yaml'),
make_file('favicon.ico', 'image/x-icon'),
make_file('main.py', 'text/x-python'),
];
}
function make_files_data() {
return {
// Contents of first file fetched during controller initialization
'app.yaml': make_file('app.yaml', 'text/x-yaml', 'one: two', false),
'favicon.ico': make_file('favicon.ico', 'image/x-icon'),
'main.py': make_file('main.py', 'text/x-python'),
};
}
beforeEach(module(function($provide) {
// TODO: DETERMINE truth of 'there has to be a better way'
$provide.factory('$window', function() {
var $window = {
document: {},
navigator: {},
};
return $window;
});
}));
beforeEach(module('playgroundApp.services'));
beforeEach(module('mocks.dialog'));
beforeEach(inject(function($browser) {
$browser.url('http://localhost:8080/playground/p/76/');
}));
beforeEach(inject(function($rootScope, $injector, $window) {
scope = $rootScope.$new();
// TODO: extract config into service and inject into parent and
// child controllers
scope.config = {
'PLAYGROUND_USER_CONTENT_HOST': 'localhost:9100',
};
scope.projects = [
make_project(76),
];
$httpBackend = $injector.get('$httpBackend');
// TODO: DETERMINE if there's a better way to test JavaScript
// functions which are expected to exist thanks to script tags
$window.CodeMirror = jasmine.createSpy('CodeMirror').andReturn(
jasmine.createSpyObj(
'CodeMirror',
['getWrapperElement', 'setValue', 'setOption', 'focus', 'on'])
);
$httpBackend
.whenGET('//localhost:9100/_ah/mimic/dir?_mimic_project=76')
.respond(make_files_response());
$httpBackend
.whenGET('//localhost:9100/_ah/mimic/file?_mimic_project=42&path=app.yaml')
.respond('one: two');
$httpBackend
.whenGET('//localhost:9100/_ah/mimic/file?_mimic_project=76&path=app.yaml')
.respond('one: two');
}));
beforeEach(inject(function($routeParams) {
$routeParams.project_id = '76';
}));
afterEach(function() {
flushDoSerial();
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
function doInit() {
inject(function($controller) {
$controller(ProjectController, {$scope: scope});
flushDoSerial();
$httpBackend.flush();
});
}
describe('initialization', function() {
// TODO: DETERMINE if there's a better way to ensure that
// $routeParams is populated
it('should set $scope.project to the project identified by ' +
'$routeParams.project_id', inject(function($routeParams) {
var project = make_project(76);
scope.projects = [make_project(17), project, make_project(13)];
expect(scope.projects[1]).toBe(project);
expect(scope.project).toBeUndefined();
doInit();
expect(scope.project).toBe(project);
}));
it('should call $scope._list_files()',
inject(function($controller, DoSerial) {
spyOn(DoSerial, 'then').andCallThrough();
expect(DoSerial.then).not.toHaveBeenCalled();
doInit();
expect(DoSerial.then).toHaveBeenCalledWith(scope._list_files);
}));
it('should call $scope._select_first_file()',
inject(function($controller, DoSerial) {
spyOn(DoSerial, 'then').andCallThrough();
expect(DoSerial.then).not.toHaveBeenCalled();
doInit();
dump(scope);
expect(DoSerial.then).toHaveBeenCalledWith(scope._select_first_file);
}));
});
describe('runtime behavior', function() {
beforeEach(function() {
doInit();
});
describe('no_json_transform function', function() {
it('should provide the identity transform', function() {
var data = 'foo';
expect(scope.no_json_transform(data)).toBe(data);
expect(scope.no_json_transform(data)).toEqual('foo');
data = '[1,2,3]';
expect(scope.no_json_transform(data)).toBe(data);
expect(scope.no_json_transform(data)).toEqual('[1,2,3]');
data = undefined;
expect(scope.no_json_transform(data)).toBe(undefined);
data = null;
expect(scope.no_json_transform(data)).toBe(null);
data = Error('x');
expect(scope.no_json_transform(data)).toEqual(Error('x'));
expect(scope.no_json_transform(data)).toBe(data);
});
});
describe('is_image_mime_type function', function() {
it('should return true for "image/*" MIME types', function() {
expect(scope.is_image_mime_type('image/png')).toBe(true);
expect(scope.is_image_mime_type('image/gif')).toBe(true);
expect(scope.is_image_mime_type('image')).toBe(false);
expect(scope.is_image_mime_type('text/plain')).toBe(false);
expect(scope.is_image_mime_type('text/png')).toBe(false);
expect(scope.is_image_mime_type('application/octet-stream'))
.toBe(false);
});
});
describe('url_of function', function() {
it('should return //localhost:9100/_ah/mimic/file?_mimic_project=' +
':project_id&path=:filename', inject(function($window) {
var png = make_file('logo.png', 'image/png');
// TODO: DETERMINE how to avoid localhost:9100
expect(scope.url_of('file', {path: png.path}))
.toEqual('//localhost:9100/_ah/mimic/file?_mimic_project=76' +
'&path=logo.png');
}));
});
describe('image_url_of function', function() {
it('should return emtpty string when no file is given', function() {
expect(scope.image_url_of()).toEqual('');
expect(scope.image_url_of(null)).toEqual('');
});
it('should return empty string for none "image/*" MIME types ',
function() {
expect(scope.image_url_of(make_file('filename', 'text/html')))
.toEqual('');
});
it('should pass through to url_of() for "image/*" MIME types ',
function() {
var png = make_file('filename', 'image/png');
var file_url = scope.url_of('file', {path: png.path});
expect(scope.image_url_of(png)).toBe(file_url);
});
});
describe('_get function', function() {
it('should call success_cb when file has contents', function() {
var success_cb = jasmine.createSpy();
var file = make_file('app.yaml', 'text/x-yaml', 'version: 1');
scope._get(file, success_cb);
expect(success_cb).toHaveBeenCalledWith();
});
it('should call success_cb when file has no contents', function() {
var success_cb = jasmine.createSpy();
var file = make_file('app.yaml', 'text/x-yaml');
expect(file.contents).toBeUndefined();
expect(file.hasOwnProperty('contents')).toBe(false);
$httpBackend.expectGET(scope.url_of('file', {path: file.path}))
.respond('foo: bar');
scope._get(file, success_cb);
$httpBackend.flush();
expect(file.contents).toEqual('foo: bar');
expect(success_cb).toHaveBeenCalledWith();
});
it('should not overwrite file contents regardless of dirty flag',
function() {
var noop = function() {};
var file = make_file('app.yaml', 'text/x-yaml', 'version: 1');
scope._get(file, noop);
expect(file.dirty).not.toBeDefined();
expect(file.hasOwnProperty('dirty')).toBe(false);
expect(file.contents).toEqual('version: 1');
file.dirty = true;
scope._get(file, noop);
expect(file.contents).toEqual('version: 1');
file.dirty = false;
scope._get(file, noop);
expect(file.contents).toEqual('version: 1');
});
it('should set file.dirty=false after fetching contents', function() {
var success_cb = jasmine.createSpy();
var file = make_file('app.yaml', 'text/x-yaml');
expect(file.contents).toBeUndefined();
expect(file.hasOwnProperty('contents')).toBe(false);
expect(file.dirty).toBe(undefined);
$httpBackend.expectGET(scope.url_of('file', {path: file.path}))
.respond('version: bar');
scope._get(file, success_cb);
$httpBackend.flush();
expect(file.contents).toEqual('version: bar');
expect(file.dirty).toBe(false);
});
it('should HTTP GET missing file contents', function() {
var success_cb = jasmine.createSpy();
var file = make_file('app.yaml', 'text/x-yaml');
$httpBackend.expectGET(scope.url_of('file', {path: file.path}))
.respond('x: y');
expect(file.contents).toBeUndefined();
scope._get(file, success_cb);
$httpBackend.flush();
expect(file.contents).toEqual('x: y');
});
});
describe('_list_files function', function() {
function make_plain_file() {
return make_file('foo.txt', 'text/plain');
}
it('should call //localhost:9100/_ah/mimic/dir?_mimic_project=' +
':project_id', function() {
$httpBackend.verifyNoOutstandingRequest();
$httpBackend.verifyNoOutstandingExpectation();
expect(scope.files).toEqual(make_files_data());
$httpBackend
.expectGET('//localhost:9100/_ah/mimic/dir?_mimic_project=76')
.respond([make_plain_file()]);
scope.files = null;
scope._list_files();
$httpBackend.flush();
expect(scope.files).toEqual({'foo.txt': make_plain_file()});
});
});
describe('select_file function', function() {
describe('with "image/*" MIME types', function() {
function make_image_file() {
return make_file('foo.png', 'image/png');
}
it('should set $scope.current_file', function() {
scope.current_file = undefined;
scope.select_file(make_image_file());
expect(scope.current_file).toEqual(make_image_file());
});
it('should return undefined', function() {
var result = scope.select_file(make_image_file());
expect(result).toBeUndefined();
});
});
describe('with MIME types other than "image/*"', function() {
function make_text_file() {
return make_file('app.yaml', 'text/x-yaml', 'version: 1');
}
it('should set $scope.current_file', function() {
scope.current_file = undefined;
scope.select_file(make_text_file());
flushDoSerial();
expect(scope.current_file).toEqual(make_text_file());
});
});
});
describe('_select_first_file function', function() {
it('should call $scope.select_file(:first_file)', function() {
doInit();
scope.select_file = jasmine.createSpy();
var expected_file = make_file('app.yaml', 'text/x-yaml', 'one: two',
false);
expect(scope.select_file).not.toHaveBeenCalled();
scope._select_first_file();
expect(scope.select_file).toHaveBeenCalledWith(expected_file);
});
});
describe('dialog tests', function() {
var dialogMock;
beforeEach(inject(function($dialog) {
doInit();
dialogMock = $dialog;
}));
describe('prompt_new_file function', function() {
it('should call $scope.insert_path(path)', function() {
scope.insert_path = jasmine.createSpy();
dialogMock.dialogShouldBeCalledWith({
controller: 'NewFileController',
templateUrl: '/playground/new_file_modal.html'
});
dialogMock.willCloseWith('test_file.py');
scope.prompt_new_file();
expect(scope.insert_path).toHaveBeenCalledWith('test_file.py');
});
});
});
});
});
describe('PageController', function() {
var scope, $httpBackend;
function doInit() {
inject(function($controller) {
$controller(PageController, {$scope: scope});
flushDoSerial();
$httpBackend.flush();
});
}
beforeEach(module('mocks.dialog'));
beforeEach(module('playgroundApp.services'));
beforeEach(inject(function($rootScope, $injector) {
scope = $rootScope.$new();
$httpBackend = $injector.get('$httpBackend');
$httpBackend
.whenGET('/playground/getconfig')
.respond({
'PLAYGROUND_USER_CONTENT_HOST': 'localhost:9100',
'email': 'user_q0inuf3vs5',
'git_playground_url': 'http://code.google.com/p/cloud-playground/',
'is_admin': false,
'is_logged_in': false,
'playground_namespace': '_playground',
});
$httpBackend
.whenGET('/playground/getprojects')
.respond([]);
$httpBackend
.whenGET('/playground/gettemplateprojects')
.respond([make_project(89), make_project(91)]);
}));
describe('initialization', function() {
afterEach(function() {
flushDoSerial();
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
it('should, when instantiated, get configuration, then project data',
function() {
expect(scope.config).toBeUndefined();
expect(scope.projects).toBeUndefined();
$httpBackend.expectGET('/playground/getconfig');
$httpBackend.expectGET('/playground/getprojects');
doInit();
expect(scope.config).toBeDefined();
expect(scope.config.email).toBeDefined();
expect(scope.config.playground_namespace).toBe('_playground');
expect(scope.projects).toBeDefined();
expect(scope.projects.length).toBe(0);
});
it('should get template projects', function() {
expect(scope.template_projects).toBeUndefined();
$httpBackend.expectGET('/playground/gettemplateprojects');
doInit();
expect(scope.template_projects).toBeDefined();
expect(scope.template_projects.length).toBe(2);
expect(scope.template_projects[0]).toEqual(make_project(89))
expect(scope.template_projects[1]).toEqual(make_project(91))
});
});
describe('runtion behavior', function() {
beforeEach(function() {
doInit();
});
describe('namespace function', function() {
var routeParams;
beforeEach(inject(function($routeParams) {
scope.config = {};
routeParams = $routeParams;
routeParams.project_id = undefined;
}));
it('should have no default', function() {
expect(scope.namespace()).toBeUndefined();
});
it('should use $routeParams project_id', function() {
expect(scope.namespace()).toBeUndefined();
routeParams.project_id = 'route_param';
expect(scope.namespace()).toBe('route_param');
});
it('should use $scope.config.playground_namespace', function() {
expect(scope.namespace()).toBeUndefined();
scope.config.playground_namespace = 'pg_namespace';
expect(scope.namespace()).toBe('pg_namespace');
});
it('should prefer $routeParams to $scope.config', function() {
expect(scope.namespace()).toBeUndefined();
routeParams.project_id = 'route_param';
scope.config.playground_namespace = 'pg_namespace';
expect(scope.namespace()).toBe('route_param');
});
});
describe('link functions', function() {
var WindowService;
beforeEach(inject(function($routeParams, _WindowService_) {
$routeParams.project_id = 'some_namespace';
WindowService = _WindowService_;
spyOn(WindowService, 'open');
}));
describe('open_datastore_admin function', function() {
it('should open new window to /playground/datastore/some_namespace',
function() {
expect(WindowService.open).not.toHaveBeenCalled();
scope.open_datastore_admin();
expect(WindowService.open).toHaveBeenCalledWith(
'/playground/datastore/some_namespace', '_blank');
});
});
describe('open_memcache_admin function', function() {
it('should open new window to /playground/memcache/some_namespace',
function() {
expect(WindowService.open).not.toHaveBeenCalled();
scope.open_memcache_admin();
expect(WindowService.open).toHaveBeenCalledWith(
'/playground/memcache/some_namespace', '_blank');
});
});
});
});
describe('big_red_button function', function() {
var $httpBackend, WindowService;
beforeEach(inject(function(_$httpBackend_, _WindowService_) {
$httpBackend = _$httpBackend_;
WindowService = _WindowService_;
spyOn(WindowService, 'reload');
doInit();
$httpBackend.expectPOST('/playground/nuke').respond();
}));
afterEach(function() {
flushDoSerial();
});
it('should post /playground/nuke', function() {
scope.big_red_button();
$httpBackend.flush();
expect(WindowService.reload).toHaveBeenCalled();
});
});
describe('select_project function', function() {
var $location;
beforeEach(inject(function(_$location_) {
$location = _$location_;
doInit();
$httpBackend
.when('POST', '/playground/p/15/touch')
.respond(make_project(15, 2));
}));
it('should call /playground/p/:project_id/touch', function() {
var project = make_project(15, 1);
scope.projects = [make_project(14, 1), project, make_project(16, 1),
make_project(17, 1)];
expect(scope.projects[1]).toEqual(make_project(15, 1));
expect($location.path()).toEqual('');
scope.select_project(project);
flushDoSerial();
$httpBackend.flush();
expect(scope.projects[1]).not.toEqual(make_project(15, 1));
expect(scope.projects[1]).toEqual(make_project(15, 2));
expect($location.path()).toEqual('/playground/p/15');
});
});
describe('delete_project function', function() {
var $httpBackend, $location;
var project_to_delete = make_project(1, 12);
beforeEach(inject(function(_$httpBackend_, _$location_) {
$httpBackend = _$httpBackend_;
$location = _$location_;
doInit();
scope.projects = [project_to_delete, make_project(2, 13)];
scope.project = project_to_delete;
$httpBackend
.expectPOST('/playground/p/1/delete')
.respond();
}));
it('should delete the project', function() {
expect(scope.project).toBe(project_to_delete);
scope.delete_project(project_to_delete);
expect(scope.projects.length).toBe(2);
$httpBackend.flush();
expect(scope.project).toBe(undefined);
expect(scope.projects.length).toBe(1);
expect($location.path()).toBe('/playground/');
});
});
describe('dialog tests', function() {
var dialogMock;
beforeEach(inject(function($dialog) {
doInit();
dialogMock = $dialog;
}));
describe('prompt_delete_project function', function() {
var mockProject = {'name': 'test_project'};
var title = 'Confirm project deletion';
var msg = 'Are you sure you want to delete project "' +
mockProject.name + '"?';
var btns = [{result: false, label: 'Cancel'},
{result: true, label: 'DELETE PROJECT',
cssClass: 'btn btn-danger'}];
it('should call $scope.delete_project()', function() {
scope.delete_project = jasmine.createSpy();
dialogMock.messageBoxShouldBeCalledWith(title, msg, btns);
dialogMock.willCloseWith(true);
scope.prompt_delete_project(mockProject);
expect(scope.delete_project).toHaveBeenCalledWith(mockProject);
});
it('shouldn\'t call $scope.delete_project()', function() {
scope.delete_project = jasmine.createSpy();
dialogMock.messageBoxShouldBeCalledWith(title, msg, btns);
dialogMock.willCloseWith(false);
scope.prompt_delete_project(mockProject);
expect(scope.delete_project).not.toHaveBeenCalled();
});
});
});
});
describe('MainController', function() {
var scope, $httpBackend;
beforeEach(module('playgroundApp.services'));
beforeEach(module(function($provide) {
$provide.factory('$window', function() {
return {
location: { replace: jasmine.createSpy() },
navigator: {},
};
});
}));
beforeEach(inject(function($rootScope, $injector) {
scope = $rootScope.$new();
scope.set_loaded = jasmine.createSpy('set_loaded');
scope.projects = [];
scope.template_projects = [make_project(12)];
$httpBackend = $injector.get('$httpBackend');
$httpBackend
.whenGET('/playground/getprojects')
.respond([]);
}));
afterEach(function() {
flushDoSerial();
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
function doInit() {
inject(function($controller) {
$controller(MainController, {$scope: scope});
flushDoSerial();
//$httpBackend.flush();
});
}
describe('initialization', function() {
it('should call $scope.set_loaded()', function() {
doInit();
expect(scope.set_loaded).toHaveBeenCalled();
});
});
describe('runtime behavior', function() {
var $location;
beforeEach(inject(function(_$location_) {
doInit();
$location = _$location_;
}));
describe('login function', function() {
it('should navigate to /playground/login', inject(function($window) {
expect($window.location.replace).not.toHaveBeenCalled();
scope.login();
expect($window.location.replace)
.toHaveBeenCalledWith('/playground/login');
// TODO: expect(Browser.url()).toEqual(....)
}));
});
describe('new_project function', function() {
beforeEach(function() {
$httpBackend
.when('POST', '/playground/p/12/copy')
.respond(make_project(42, 1));
});
it('should call /playground/p/12/copy', inject(function() {
expect(scope.projects).toBeDefined();
expect(scope.template_projects).toBeDefined();
expect(scope.template_projects.length).toBeGreaterThan(0);
$httpBackend.expectPOST('/playground/p/12/copy');
scope.new_project(scope.template_projects[0]);
flushDoSerial();
$httpBackend.flush();
expect(scope.projects.length).toBe(1);
expect(scope.projects[0].key).toBe(42);
expect(scope.projects[0].name).toBe('New project name');
}));
});
});
});