1
1
describe ( "SpeciesViewModel Spec" , function ( ) {
2
+ var request , result ;
2
3
it ( "Can participate in the DataModelItem calls like checkWarnings" , function ( ) {
3
-
4
- let speciesViewModel = new SpeciesViewModel ( { } , { searchBieUrl :'/species/searchBie' } , { } ) ;
4
+ var options = {
5
+ searchBieUrl : '/species/searchBie'
6
+ }
7
+ let speciesViewModel = new SpeciesViewModel ( { } , options , { } ) ;
5
8
expect ( speciesViewModel . checkWarnings ( ) ) . toBeUndefined ( ) ;
6
9
} ) ;
10
+
11
+ it ( "Same outputSpeciesId is passed when the species has not changed" , function ( ) {
12
+ var data = {
13
+ outputSpeciesId : "5555555" ,
14
+ scientificName : "Test Scientific Name" ,
15
+ name :"Test name" ,
16
+ guid :"Test guid"
17
+ } ;
18
+
19
+ let options = { searchBieUrl : '/test/searchBie' , bieUrl : '/test/bie/' , getOutputSpeciesIdUrl : 'test/getOutputSpeciesIdUrl' }
20
+
21
+ let speciesViewModel = new SpeciesViewModel ( { } , options , { } ) ;
22
+ speciesViewModel . loadData ( data ) ;
23
+
24
+ expect ( data . outputSpeciesId ) . toEqual ( speciesViewModel . toJS ( ) . outputSpeciesId ) ;
25
+
26
+ } ) ;
27
+
28
+ describe ( "Test ajax call to supply new outSpeciesId" , function ( ) {
29
+ beforeEach ( function ( ) {
30
+ jasmine . Ajax . install ( ) ;
31
+ } ) ;
32
+
33
+ afterEach ( function ( ) {
34
+ jasmine . Ajax . uninstall ( ) ;
35
+ } ) ;
36
+
37
+ it ( "New outputSpeciesId is passed when the species has changed" , function ( ) {
38
+ let oldSpeciesSelectedData = {
39
+ outputSpeciesId : '5555555' ,
40
+ scientificName : 'Current scientific Name' ,
41
+ name : 'Current name' ,
42
+ guid : 'Current guid'
43
+ }
44
+
45
+ let newSpeciesSelectedData = {
46
+ scientificName : 'New scientific Name' ,
47
+ name : 'New name' ,
48
+ guid : 'New guid'
49
+ } ;
50
+
51
+ let options = { searchBieUrl : '/test/searchBie' , bieUrl : '/test/bie/' , getOutputSpeciesIdUrl : 'test/getOutputSpeciesIdUrl' }
52
+ let responseData = { outputSpeciesId : "666666" } ;
53
+
54
+ let speciesViewModel = new SpeciesViewModel ( oldSpeciesSelectedData , options , { } ) ;
55
+
56
+ speciesViewModel . loadData ( newSpeciesSelectedData ) ;
57
+ request = jasmine . Ajax . requests . filter ( 'test/getOutputSpeciesIdUrl' ) [ 0 ] ;
58
+ request . respondWith ( {
59
+ status : 200 ,
60
+ responseJSON : responseData
61
+ } ) ;
62
+
63
+ expect ( request . url ) . toBe ( 'test/getOutputSpeciesIdUrl' ) ;
64
+ expect ( speciesViewModel . toJS ( ) . outputSpeciesId ) . toEqual ( responseData . outputSpeciesId )
65
+ expect ( speciesViewModel . outputSpeciesId ( ) ) . not . toEqual ( oldSpeciesSelectedData . outputSpeciesId ) ;
66
+
67
+ } ) ;
68
+ } )
69
+
7
70
} ) ;
0 commit comments