1
1
describe ( "SpeciesViewModel Spec" , function ( ) {
2
+ var request , result ;
3
+ // jasmine.Ajax.install();
4
+
5
+ // beforeEach(function() {
6
+ // request = jasmine.Ajax.requests.mostRecent();
7
+ // expect(request.method).toBe('GET');
8
+ // });
9
+
10
+ afterEach ( function ( ) {
11
+ jasmine . Ajax . uninstall ( ) ;
12
+ } ) ;
13
+
14
+ beforeEach ( function ( ) {
15
+ jasmine . Ajax . install ( ) ;
16
+ } ) ;
17
+
2
18
it ( "Can participate in the DataModelItem calls like checkWarnings" , function ( ) {
3
19
var options = {
4
20
searchBieUrl : '/species/searchBie'
@@ -20,38 +36,62 @@ describe("SpeciesViewModel Spec", function () {
20
36
let speciesViewModel = new SpeciesViewModel ( { } , options , { } ) ;
21
37
speciesViewModel . loadData ( data ) ;
22
38
23
- console . log ( "speciesViewModel.toJS()" + speciesViewModel . toJS ( ) . outputSpeciesId ) ;
24
39
expect ( data . outputSpeciesId ) . toEqual ( speciesViewModel . toJS ( ) . outputSpeciesId ) ;
25
40
26
41
} ) ;
27
42
28
43
it ( "New outputSpeciesId is passed when the species has changed" , function ( ) {
29
- let data = {
30
- outputSpeciesId : "" ,
31
- scientificName : "Test Scientific Name" ,
32
- name :"Test name" ,
33
- guid :"Test guid"
44
+ let oldSpeciesSelectedData = {
45
+ outputSpeciesId : '5555555' ,
46
+ scientificName : 'Current scientific Name' ,
47
+ name : 'Current name' ,
48
+ guid : 'Current guid'
49
+ }
50
+
51
+ let newSpeciesSelectedData = {
52
+ scientificName : 'New scientific Name' ,
53
+ name : 'New name' ,
54
+ guid : 'New guid'
34
55
} ;
35
56
57
+
36
58
let options = { searchBieUrl : '/test/searchBie' , bieUrl : '/test/bie/' , getOutputSpeciesIdUrl : 'test/getOutputSpeciesIdUrl' }
37
- let responseData = { outputSpeciesId : "55555 " } ;
59
+ let responseData = { outputSpeciesId : "666666 " } ;
38
60
39
- spyOn ( $ , 'ajax' ) . and . callFake ( function ( ) {
40
- var d = $ . Deferred ( ) ;
41
- d . resolve ( responseData ) ;
42
- return d . promise ( ) ;
61
+ // spyOn($, 'ajax').and.callFake(function () {
62
+ // var d = $.Deferred();
63
+ // d.resolve(responseData);
64
+ // return d.promise();
65
+ // });
66
+
67
+
68
+
69
+
70
+
71
+ let speciesViewModel = new SpeciesViewModel ( oldSpeciesSelectedData , options , { } ) ;
72
+ // spyOn($, 'ajax').and.callFake(function () {
73
+ // var d = $.Deferred();
74
+ // d.resolve(responseData);
75
+ // return d.promise();
76
+ // });
77
+
78
+ speciesViewModel . loadData ( newSpeciesSelectedData ) ;
79
+
80
+ request = jasmine . Ajax . requests . mostRecent ( ) ;
81
+
82
+ request . respondWith ( {
83
+ status : 200 ,
84
+ responseJSON : responseData
43
85
} ) ;
44
86
45
- let speciesViewModel = new SpeciesViewModel ( { } , options , { } ) ;
46
- speciesViewModel . loadData ( data ) ;
47
87
48
- expect ( $ . ajax ) . toHaveBeenCalled ( ) ;
49
- expect ( data . outputSpeciesId ) . toEqual ( speciesViewModel . outputSpeciesId ( ) ) ;
88
+ // expect(request.url).toBe('test/getOutputSpeciesIdUrl');
89
+ expect ( speciesViewModel . toJS ( ) . outputSpeciesId ) . toEqual ( responseData . outputSpeciesId )
90
+
91
+ expect ( speciesViewModel . outputSpeciesId ( ) ) . not . toEqual ( oldSpeciesSelectedData . outputSpeciesId ) ;
92
+ // expect($.ajax).toHaveBeenCalled();
93
+ // expect(speciesViewModel.toJS().outputSpeciesId).toEqual(responseData.outputSpeciesId);
50
94
51
95
} ) ;
52
96
53
- function ajax_response ( response ) {
54
- var deferred = $ . Deferred ( ) . resolve ( response ) ;
55
- return deferred . promise ( ) ;
56
- }
57
97
} ) ;
0 commit comments