1
1
describe ( "SpeciesViewModel Spec" , function ( ) {
2
2
it ( "Can participate in the DataModelItem calls like checkWarnings" , function ( ) {
3
-
4
- let speciesViewModel = new SpeciesViewModel ( { } , { searchBieUrl :'/species/searchBie' } , { } ) ;
3
+ var options = {
4
+ searchBieUrl : '/species/searchBie'
5
+ }
6
+ let speciesViewModel = new SpeciesViewModel ( { } , options , { } ) ;
5
7
expect ( speciesViewModel . checkWarnings ( ) ) . toBeUndefined ( ) ;
6
8
} ) ;
9
+
10
+ it ( "Same outputSpeciesId is passed when the species has not changed" , function ( ) {
11
+ var data = {
12
+ outputSpeciesId : "5555555" ,
13
+ scientificName : "Test Scientific Name" ,
14
+ name :"Test name" ,
15
+ guid :"Test guid"
16
+ } ;
17
+
18
+ let options = { searchBieUrl : '/test/searchBie' , bieUrl : '/test/bie/' , getOutputSpeciesIdUrl : 'test/getOutputSpeciesIdUrl' }
19
+
20
+ let speciesViewModel = new SpeciesViewModel ( { } , options , { } ) ;
21
+ speciesViewModel . loadData ( data ) ;
22
+
23
+ console . log ( "speciesViewModel.toJS()" + speciesViewModel . toJS ( ) . outputSpeciesId ) ;
24
+ expect ( data . outputSpeciesId ) . toEqual ( speciesViewModel . toJS ( ) . outputSpeciesId ) ;
25
+
26
+ } ) ;
27
+
28
+ 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"
34
+ } ;
35
+
36
+ let options = { searchBieUrl : '/test/searchBie' , bieUrl : '/test/bie/' , getOutputSpeciesIdUrl : 'test/getOutputSpeciesIdUrl' }
37
+ let responseData = { outputSpeciesId : "55555" } ;
38
+
39
+ spyOn ( $ , 'ajax' ) . and . callFake ( function ( ) {
40
+ var d = $ . Deferred ( ) ;
41
+ d . resolve ( responseData ) ;
42
+ return d . promise ( ) ;
43
+ } ) ;
44
+
45
+ let speciesViewModel = new SpeciesViewModel ( { } , options , { } ) ;
46
+ speciesViewModel . loadData ( data ) ;
47
+
48
+ expect ( $ . ajax ) . toHaveBeenCalled ( ) ;
49
+ expect ( data . outputSpeciesId ) . toEqual ( speciesViewModel . outputSpeciesId ( ) ) ;
50
+
51
+ } ) ;
52
+
53
+ function ajax_response ( response ) {
54
+ var deferred = $ . Deferred ( ) . resolve ( response ) ;
55
+ return deferred . promise ( ) ;
56
+ }
7
57
} ) ;
0 commit comments