1 | describe('ng-challenge',function() {
|
2 | var ngServices = factory('services/ng-services');
|
3 | var challenge, q;
|
4 |
|
5 | var dummyChallenge = {foo:'bar'};
|
6 |
|
7 | var fsMock, settingsMock,$q,$rootScope,$httpBackend;
|
8 | fsMock = createFsMock({'foo': JSON.stringify(dummyChallenge)});
|
9 |
|
10 | var module = factory('services/ng-challenge',{
|
11 | 'services/log': logMock,
|
12 | 'services/ng-services': ngServices,
|
13 | 'services/fs': fsMock
|
14 | });
|
15 |
|
16 | beforeEach(function() {
|
17 | angular.mock.module(module.name);
|
18 | angular.mock.module(function($provide) {
|
19 | $provide.service('$settings', function($q) {
|
20 | settingsMock = createSettingsMock($q, {});
|
21 | return settingsMock;
|
22 | });
|
23 | });
|
24 | angular.mock.inject(function($challenge,_$q_,_$rootScope_,_$httpBackend_) {
|
25 | challenge = $challenge;
|
26 | $q = _$q_;
|
27 | $rootScope = _$rootScope_;
|
28 | $httpBackend = _$httpBackend_;
|
29 | });
|
30 | });
|
31 |
|
32 | describe('getDependencies',function() {
|
33 | it('should resolve the arguments of a function',function() {
|
34 | var deps = challenge.getDependencies(function(foo,bar,baz) {});
|
35 | expect(deps).toEqual(['foo','bar','baz']);
|
36 | });
|
37 | });
|
38 |
|
39 | describe('load',function() {
|
40 | it('should load, then init',function(done) {
|
41 | $httpBackend.when('GET','challenge/foo')
|
42 | .respond(JSON.stringify(dummyChallenge));
|
43 | challenge.init = jasmine.createSpy('init').and.returnValue(42);
|
44 | challenge.load('foo').then(function() {
|
45 | expect(challenge.init).toHaveBeenCalledWith(dummyChallenge);
|
46 | done();
|
47 | });
|
48 | $httpBackend.flush();
|
49 | $rootScope.$digest();
|
50 | });
|
51 | });
|
52 |
|
53 | describe('init',function() {
|
54 | it('should prepare the challenge',function() {
|
55 | var field = {
|
56 | missions: [{
|
57 | id: 'test',
|
58 | objectives: [{
|
59 | id: 'moo',
|
60 | }]
|
61 | }]
|
62 | };
|
63 | var res = challenge.init(field);
|
64 |
|
65 | expect(res.field).toEqual(field);
|
66 | expect(res.missions).toEqual([{objectives:[{id:'moo'}],id:'test'}]);
|
67 | expect(res.objectiveIndex).toEqual({moo: {id:'moo'}});
|
68 | });
|
69 | });
|
70 | });
|