Skip to content

Commit cddd219

Browse files
committed
commit test progress #1638
1 parent 52a6935 commit cddd219

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed
+59-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
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+
218
it("Can participate in the DataModelItem calls like checkWarnings", function () {
319
var options = {
420
searchBieUrl: '/species/searchBie'
@@ -20,38 +36,62 @@ describe("SpeciesViewModel Spec", function () {
2036
let speciesViewModel = new SpeciesViewModel({}, options, {});
2137
speciesViewModel.loadData(data);
2238

23-
console.log("speciesViewModel.toJS()" + speciesViewModel.toJS().outputSpeciesId);
2439
expect(data.outputSpeciesId).toEqual(speciesViewModel.toJS().outputSpeciesId);
2540

2641
});
2742

2843
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'
3455
};
3556

57+
3658
let options = {searchBieUrl: '/test/searchBie', bieUrl: '/test/bie/', getOutputSpeciesIdUrl: 'test/getOutputSpeciesIdUrl'}
37-
let responseData = {outputSpeciesId: "55555"};
59+
let responseData = {outputSpeciesId: "666666"};
3860

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
4385
});
4486

45-
let speciesViewModel = new SpeciesViewModel({}, options, {});
46-
speciesViewModel.loadData(data);
4787

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);
5094

5195
});
5296

53-
function ajax_response(response) {
54-
var deferred = $.Deferred().resolve(response);
55-
return deferred.promise();
56-
}
5797
});

0 commit comments

Comments
 (0)