http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/datasetdisplay.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/datasetdisplay.js b/ocw-ui/frontend/test/spec/controllers/datasetdisplay.js new file mode 100644 index 0000000..15a4a02 --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/datasetdisplay.js @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: DatasetDisplayCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var DatasetdisplayctrlCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + DatasetdisplayctrlCtrl = $controller('DatasetDisplayCtrl', { + $scope: scope + }); + })); + + it('should initialize the removeDataset function', function() { + scope.datasets.push(1); + scope.datasets.push(2); + + expect(scope.datasets[0]).toBe(1); + + scope.removeDataset(0); + + expect(scope.datasets[0]).toBe(2); + }); + + it('should initialize the removeDataset function', function() { + scope.datasets.push(1); + scope.datasets.push(2); + + expect(scope.datasets[0]).toBe(1); + + scope.removeDataset(0); + + expect(scope.datasets[0]).toBe(2); + }); +});
http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/datasetselect.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/datasetselect.js b/ocw-ui/frontend/test/spec/controllers/datasetselect.js new file mode 100644 index 0000000..abaeb43 --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/datasetselect.js @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: DatasetSelectCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var DatasetselectCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + DatasetselectCtrl = $controller('DatasetSelectCtrl', { + $scope: scope + }); + })); + + it('should initialize the disable clear button function', function() { + inject(function(selectedDatasetInformation) { + expect(scope.shouldDisableClearButton()).toBe(true); + selectedDatasetInformation.addDataset({}); + expect(scope.shouldDisableClearButton()).toBe(false); + }); + }); + + it('should initialize the clear datasets function', function() { + inject(function(selectedDatasetInformation) { + selectedDatasetInformation.addDataset({}); + expect(selectedDatasetInformation.getDatasetCount()).toBe(1); + scope.clearDatasets(); + expect(selectedDatasetInformation.getDatasetCount()).toBe(0); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/main.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/main.js b/ocw-ui/frontend/test/spec/controllers/main.js new file mode 100644 index 0000000..dad1469 --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/main.js @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: MainCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var MainCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + MainCtrl = $controller('MainCtrl', { + $scope: scope + }); + })); + + it('should attach a list of awesomeThings to the scope', function () { + expect(scope.awesomeThings.length).toBe(3); + }); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/observationselect.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/observationselect.js b/ocw-ui/frontend/test/spec/controllers/observationselect.js new file mode 100644 index 0000000..f544e22 --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/observationselect.js @@ -0,0 +1,122 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: ObservationSelectCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var ObservationselectCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + ObservationselectCtrl = $controller('ObservationSelectCtrl', { + $scope: scope + }); + })); + + it('should grab the default set of selected datasets from the service', function() { + expect(typeof scope.datasetCount).toBe('object'); + expect(Object.keys(scope.datasetCount).length).toBe(0); + }); + + it('should initialize option arrays and default to the first element', function() { + expect(scope.params.length).toBe(1); + expect(scope.lats.length).toBe(1); + expect(scope.lons.length).toBe(1); + expect(scope.times.length).toBe(1); + + expect(scope.params[0]).toEqual("Please select a file above"); + expect(scope.lats[0]).toEqual("Please select a file above"); + expect(scope.lons[0]).toEqual("Please select a file above"); + expect(scope.times[0]).toEqual("Please select a file above"); + }); + + it('should initialize scope attributes properly', function() { + inject(function($httpBackend, $rootScope, $controller) { + $rootScope.baseURL = "http://localhost:8082" + $httpBackend.expectJSONP($rootScope.baseURL + '/dir/path_leader/?callback=JSON_CALLBACK'). + respond(200, {'leader': '/usr/local/ocw'}); + $httpBackend.whenGET('views/main.html').respond(200); + $httpBackend.flush(); + + expect(scope.pathLeader).toEqual('/usr/local/ocw'); + expect(scope.loadingFile).toBe(false); + expect(scope.fileAdded).toBe(false); + expect(typeof scope.latLonVals).toEqual('object'); + expect(scope.latLonVals.length).toBe(0); + expect(typeof scope.timeVals).toEqual('object'); + expect(scope.timeVals.length).toEqual(0); + expect(typeof scope.localSelectForm).toEqual('object'); + expect(Object.keys(scope.localSelectForm).length).toEqual(0); + }); + }); + + it('should initialize the uploadLocalFile function', function() { + inject(function($httpBackend, $rootScope, $controller) { + $rootScope.baseURL = "http://localhost:8082" + $httpBackend.expectJSONP($rootScope.baseURL + '/dir/path_leader/?callback=JSON_CALLBACK'). + respond(200, {'leader': null}); + $httpBackend.whenGET('views/main.html').respond(200); + + $httpBackend.expectJSONP($rootScope.baseURL + '/lfme/list_vars/undefined?callback=JSON_CALLBACK'). + respond(200, {"variables": ["lat", "lon", "prec", "time" ]}); + $httpBackend.expectJSONP($rootScope.baseURL + '/lfme/list_latlon/undefined?callback=JSON_CALLBACK'). + respond(200, {'latMax': '75.25', 'success': 1, 'lat_name': 'lat', 'lonMax': '-29.75', 'lonMin': '-159.75', 'lon_name': 'lon', 'latMin': '15.25'}); + $httpBackend.expectJSONP($rootScope.baseURL + '/lfme/list_time/undefined?callback=JSON_CALLBACK'). + respond(200, {"start_time": "1980-01-01 00:00:00", "time_name": "time", "success": 1, "end_time": "2004-12-01 00:00:00"}); + + scope.uploadLocalFile(); + $httpBackend.flush(); + + expect(scope.latsSelect).toEqual("lat"); + expect(scope.lonsSelect).toEqual("lon"); + expect(scope.timeSelect).toEqual("time"); + expect(scope.paramSelect).toEqual("prec"); + + // Simulate failure on one of the backend calls. Should + $httpBackend.expectJSONP($rootScope.baseURL + '/lfme/list_vars/undefined?callback=JSON_CALLBACK'). + respond(200, {}); + $httpBackend.expectJSONP($rootScope.baseURL + '/lfme/list_latlon/undefined?callback=JSON_CALLBACK'). + respond(404, {}); + $httpBackend.expectJSONP($rootScope.baseURL + '/lfme/list_time/undefined?callback=JSON_CALLBACK'). + respond(200, {}); + + scope.uploadLocalFile(); + $httpBackend.flush(); + + expect(scope.paramSelect).toEqual("Unable to load variable(s)"); + expect(scope.params.length).toEqual(1); + expect(scope.latsSelect).toEqual("Unable to load variable(s)"); + expect(scope.lats.length).toEqual(1); + expect(scope.lonsSelect).toEqual("Unable to load variable(s)"); + expect(scope.lons.length).toEqual(1); + expect(scope.timeSelect).toEqual("Unable to load variable(s)"); + expect(scope.times.length).toEqual(1); + }); + }); + + it('should initialize the addDatasets function', function() { + expect(typeof(scope.addDataSet)).toBe("function"); + }); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/parameterselect.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/parameterselect.js b/ocw-ui/frontend/test/spec/controllers/parameterselect.js new file mode 100644 index 0000000..aa4cbd8 --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/parameterselect.js @@ -0,0 +1,136 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: ParameterSelectCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var ParameterselectCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + ParameterselectCtrl = $controller('ParameterSelectCtrl', { + $scope: scope + }); + })); + + it('should initialize spatial and temporal range default values properly', function() { + expect(scope.latMin).toBe(-90); + expect(scope.latMax).toBe(90); + expect(scope.lonMin).toBe(-180); + expect(scope.lonMax).toBe(180); + expect(scope.start).toBe("1900-01-01 00:00:00"); + expect(scope.end).toBe("2030-01-01 00:00:00"); + }); + + it('should grab the default set of selected datasets from the service', function() { + // We should get an object with no keys since the user hasn't selected any + // datasets by default. Object.keys returns an array of all the user defined + // keys in the object. + expect(typeof scope.datasets).toBe('object'); + expect(Object.keys(scope.datasets).length).toBe(0); + }); + + it('should grab the default region select param object from the regionSelectParams service', function() { + // The default display values aren't going to be changing any time soon. This test + // is a bit of a duplicate since this is really testing functionality of the service. + // Can't hurt to make sure that we're getting results though! + expect(typeof scope.displayParams).toBe('object'); + expect(Object.keys(scope.displayParams).length).toBe(7); + }); + + it('should initialize misc. values properly', function() { + expect(scope.runningEval).toBe(false); + expect(scope.areInUserRegridState).toBe(false); + expect(scope.latSliderVal).toBe(0); + expect(scope.lonSliderVal).toBe(0); + }); + + it('should set the default datepicker settings', function() { + // This tests the default values that get passed to the datepicker objects that we + // initialize with a directive. + expect(Object.keys(scope.datepickerSettings).length).toBe(2); + expect(scope.datepickerSettings.changeMonth).toBe(true); + expect(scope.datepickerSettings.changeYear).toBe(true); + }); + + it('should initialize the control disable function', function() { + // Add to dummy values to datasets to make sure the disable function + // triggers properly. + scope.datasets.push(1); + scope.datasets.push(2); + expect(scope.shouldDisableControls()).toBe(false); + }); + + it('should initialize the disable evaluation button function', function() { + expect(scope.shouldDisableEvaluateButton()).toBe(true); + scope.datasets.push(1); + expect(scope.shouldDisableEvaluateButton()).toBe(true); + scope.datasets.push(2); + expect(scope.shouldDisableEvaluateButton()).toBe(false); + scope.runningEval = true; + expect(scope.shouldDisableEvaluateButton()).toBe(true); + }); + + it('should initialize the disable results view function', function() { + inject(function($rootScope) { + expect(scope.shouldDisableResultsView()).toBe(true); + + // Set evalResults to something other than the default value + $rootScope.evalResults = "this is not an empty string"; + + expect(scope.shouldDisableResultsView()).toBe(false); + }); + }); + + /* + * TODO: $scope.$apply() in the controller is breaking this test. Need to + * find a way to deal with that or rethink how we handle this test. + * + */ + /* + it('should initialize the check parameters function', function() { + // Set the displayParams values to be "out of bounds" values so checkParams + // adjusts them properly. + scope.displayParams.latMin = "-95"; + scope.displayParams.latMax = "95"; + scope.displayParams.lonMin = "-185"; + scope.displayParams.lonMax = "185"; + scope.displayParams.start = "1980-00-00 00:00:00"; + scope.displayParams.end = "2031-01-01 00:00:00"; + + // If we don't remove the watch on datasets we end up with displayParam values + // all being undefined (but only during testing, which is odd...) + scope.unwatchDatasets(); + scope.checkParameters(); + + expect(scope.displayParams.latMin).toBe(-90); + expect(scope.displayParams.latMax).toBe(90); + expect(scope.displayParams.lonMin).toBe(-180); + expect(scope.displayParams.lonMax).toBe(180); + expect(scope.displayParams.start).toBe('1980-01-01 00:00:00'); + expect(scope.displayParams.end).toBe('2030-01-01 00:00:00'); + }); + */ +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/rcmedselection.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/rcmedselection.js b/ocw-ui/frontend/test/spec/controllers/rcmedselection.js new file mode 100644 index 0000000..97011c7 --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/rcmedselection.js @@ -0,0 +1,145 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: RcmedSelectionCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var RcmedselectionCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + RcmedselectionCtrl = $controller('RcmedSelectionCtrl', { + $scope: scope + }); + })); + + it('should automatically query RCMED on initialization', function() { + inject(function($rootScope, $httpBackend) { + $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/datasets/?callback=JSON_CALLBACK'). + respond(200, [{longname: 1}, {longname: 2}]); + $httpBackend.expectGET($rootScope.baseURL + '/rcmed/parameters/bounds/').respond(503) + $httpBackend.expectGET('views/main.html').respond(200); + $httpBackend.flush(); + + expect(scope.availableObs.length).toBe(3); + expect(scope.availableObs[0]).toEqual({longname: "Please select an option"}); + expect(scope.availableObs[1]).toEqual({longname: 1}); + }); + }); + + it('should initialize the getObservations function', function() { + inject(function($rootScope, $httpBackend) { + $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/datasets/?callback=JSON_CALLBACK'). + respond(200, [{longname: 1}, {longname: 2}]); + $httpBackend.expectGET($rootScope.baseURL + '/rcmed/parameters/bounds/').respond(503) + $httpBackend.expectGET('views/main.html').respond(200); + $httpBackend.flush(); + + expect(scope.availableObs.length).toBe(3); + expect(scope.availableObs[0]).toEqual({longname: "Please select an option"}); + expect(scope.availableObs[1]).toEqual({longname: 1}); + + // Set up a failed query + $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/datasets/?callback=JSON_CALLBACK'). + respond(404); + scope.getObservations(); + $httpBackend.flush(); + + expect(scope.availableObs.length).toBe(1); + expect(scope.availableObs[0]).toEqual('Unable to query RCMED'); + }); + }); + + it('should initialize dataSelectUpdated function', function() { + inject(function($rootScope, $controller, $httpBackend) { + $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/datasets/?callback=JSON_CALLBACK'). + respond(200, [{longname: 1}, {longname: 2}]); + $httpBackend.expectGET($rootScope.baseURL + '/rcmed/parameters/bounds/').respond(503) + $httpBackend.expectGET('views/main.html').respond(200); + $httpBackend.flush(); + + // Add the test dataset to our scope + scope.datasetSelection = {shortname: 'TRMM'} + + // Test return with only single parameter + $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/parameters/?dataset=' + + scope.datasetSelection['shortname'] + + '&callback=JSON_CALLBACK'). + respond(200, ['pcp']); + scope.dataSelectUpdated(); + $httpBackend.flush(); + + expect(scope.parameterSelection).toEqual('pcp'); + + // Test return with multiple parameters + $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/parameters/?dataset=' + + scope.datasetSelection['shortname'] + + '&callback=JSON_CALLBACK'). + respond(200, ['pcp', 'pcp2']); + scope.dataSelectUpdated(); + $httpBackend.flush(); + + expect(scope.parameterSelection).toEqual({shortname: 'Please select a parameter'}); + }); + }); + + it('should initialze the addObservation function', function() { + inject(function($rootScope, $controller, $httpBackend) { + $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/datasets/?callback=JSON_CALLBACK'). + respond(200, [{longname: 1}, {longname: 2}]); + $httpBackend.expectGET($rootScope.baseURL + '/rcmed/parameters/bounds/').respond(503) + $httpBackend.expectGET('views/main.html').respond(200); + $httpBackend.flush(); + + scope.datasetSelection = { + "dataset_id" : "3", + "shortname" : "TRMM", + "longname" : "Tropical Rainfall Measuring Mission Dataset", + "source" : "Readme for the Tropical Rainfall Measuring Mission (TRMM) Data Set" + }; + + scope.parameterSelection = { + "parameter_id":"36", + "shortname":"pcp", + "datasetshortname":"TRMM", + "longname":"TRMM v.6 Monthly Precipitation", + "units":"mm\/day" + }; + + // addObservations does a refresh of the selections with a re-query of the backend + // so we need to catch that call! + $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/datasets/?callback=JSON_CALLBACK'). + respond(200, [{longname: 1}, {longname: 2}]); + + scope.addObservation(); + $httpBackend.flush(); + + expect(scope.datasetCount.length).toBe(1); + // The selection observation should be reset so we shouldn't have + // any selected observation parameters. + expect(scope.retrievedObsParams).toEqual([]); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/result.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/result.js b/ocw-ui/frontend/test/spec/controllers/result.js new file mode 100644 index 0000000..495a473 --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/result.js @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: ResultCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var ResultCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + ResultCtrl = $controller('ResultCtrl', { + $scope: scope + }); + })); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/resultdetail.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/resultdetail.js b/ocw-ui/frontend/test/spec/controllers/resultdetail.js new file mode 100644 index 0000000..a29e508 --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/resultdetail.js @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: ResultdetailCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var ResultdetailCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + ResultdetailCtrl = $controller('ResultdetailCtrl', { + $scope: scope + }); + })); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/settings.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/settings.js b/ocw-ui/frontend/test/spec/controllers/settings.js new file mode 100644 index 0000000..e45accd --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/settings.js @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: SettingsCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var SettingsCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + SettingsCtrl = $controller('SettingsCtrl', { + $scope: scope + }); + })); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/timeline.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/timeline.js b/ocw-ui/frontend/test/spec/controllers/timeline.js new file mode 100644 index 0000000..1f3580f --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/timeline.js @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: TimelineCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var TimelineCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + TimelineCtrl = $controller('TimelineCtrl', { + $scope: scope + }); + })); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/controllers/worldmap.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/controllers/worldmap.js b/ocw-ui/frontend/test/spec/controllers/worldmap.js new file mode 100644 index 0000000..76c702b --- /dev/null +++ b/ocw-ui/frontend/test/spec/controllers/worldmap.js @@ -0,0 +1,57 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Controller: WorldMapCtrl', function () { + + // load the controller's module + beforeEach(module('ocwUiApp')); + + var WorldmapCtrl, + scope; + + // Initialize the controller and a mock scope + beforeEach(inject(function ($controller, $rootScope) { + scope = $rootScope.$new(); + WorldmapCtrl = $controller('WorldMapCtrl', { + $scope: scope + }); + })); + + it('should initialize the updateMap function', function() { + inject(function($rootScope, $controller) { + var scope = $rootScope.$new(); + var ctrl = $controller("WorldMapCtrl", {$scope: scope}); + + // Set the important attributes for a fake dataset + scope.datasets.push({shouldDisplay: true, latlonVals: {latMin: 0, latMax: 0, lonMin: 0, lonMax: 0}}); + // Don't try to add the user defined region since we don't have one + scope.regionParams.areValid = false; + // We need to fake the map object. The only thing we care about is faking the "addLayer" function + // and the "fitBounds" functions which our map controllers makes use of. + $rootScope.map = {addLayer: function(){}, fitBounds: function(){}}; + $rootScope.fillColors = ['#ff0000']; + + expect("rectangleGroup" in $rootScope).toBe(false); + scope.updateMap(); + expect("rectangleGroup" in $rootScope).toBe(true); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/directives/bootstrapmodal.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/directives/bootstrapmodal.js b/ocw-ui/frontend/test/spec/directives/bootstrapmodal.js new file mode 100644 index 0000000..465f65e --- /dev/null +++ b/ocw-ui/frontend/test/spec/directives/bootstrapmodal.js @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Directive: bootstrapModal', function () { + + // load the directive's module + beforeEach(module('ocwUiApp')); + + var element, + scope; + + beforeEach(inject(function ($rootScope) { + scope = $rootScope.$new(); + })); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/directives/bootstrapmodalopen.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/directives/bootstrapmodalopen.js b/ocw-ui/frontend/test/spec/directives/bootstrapmodalopen.js new file mode 100644 index 0000000..699210c --- /dev/null +++ b/ocw-ui/frontend/test/spec/directives/bootstrapmodalopen.js @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Directive: bootstrapModalOpen', function () { + + // load the directive's module + beforeEach(module('ocwUiApp')); + + var element, + scope; + + beforeEach(inject(function ($rootScope) { + scope = $rootScope.$new(); + })); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/directives/leafletmap.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/directives/leafletmap.js b/ocw-ui/frontend/test/spec/directives/leafletmap.js new file mode 100644 index 0000000..85ccc6d --- /dev/null +++ b/ocw-ui/frontend/test/spec/directives/leafletmap.js @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Directive: leafletMap', function () { + + // load the directive's module + beforeEach(module('ocwUiApp')); + + var element, + scope; + + beforeEach(inject(function ($rootScope) { + scope = $rootScope.$new(); + })); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/directives/onblur.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/directives/onblur.js b/ocw-ui/frontend/test/spec/directives/onblur.js new file mode 100644 index 0000000..7e8b83a --- /dev/null +++ b/ocw-ui/frontend/test/spec/directives/onblur.js @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Directive: onBlur', function () { + + // load the directive's module + beforeEach(module('ocwUiApp')); + + var element, + scope; + + beforeEach(inject(function ($rootScope) { + scope = $rootScope.$new(); + })); + + it('should call the supplied function on the blur event', function() { + inject(function($compile) { + // Set a scope variable to make sure that on-blur calls + // the function that we pass to it. + scope.bogusFunction = function() { + scope.test = "hi" + } + + var element = angular.element('<input on-blur="bogusFunction();" />') + element = $compile(element)(scope) + + expect(scope.test).toNotBe('hi'); + element.triggerHandler('blur'); + expect(scope.test).toBe('hi'); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/directives/predictivefilebrowserinput.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/directives/predictivefilebrowserinput.js b/ocw-ui/frontend/test/spec/directives/predictivefilebrowserinput.js new file mode 100644 index 0000000..162b361 --- /dev/null +++ b/ocw-ui/frontend/test/spec/directives/predictivefilebrowserinput.js @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Directive: predictiveFileBrowserInput', function () { + + // load the directive's module + beforeEach(module('ocwUiApp')); + + var element, + scope; + + beforeEach(inject(function ($rootScope) { + scope = $rootScope.$new(); + })); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/directives/previewmap.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/directives/previewmap.js b/ocw-ui/frontend/test/spec/directives/previewmap.js new file mode 100644 index 0000000..2a831c6 --- /dev/null +++ b/ocw-ui/frontend/test/spec/directives/previewmap.js @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Directive: previewMap', function () { + + // load the directive's module + beforeEach(module('ocwUiApp')); + + var element, + scope; + + beforeEach(inject(function ($rootScope) { + scope = $rootScope.$new(); + })); + + it('should set the proper class', function() { + inject(function($compile, $rootScope) { + $rootScope.dataset = {latlonVals: {latMax: 90, lonMax: 90, latMin: -90, lonMin: -90}, name: "TRMM"}; + + var element = $compile('<div preview-map="dataset"></div>')($rootScope); + + expect(element.hasClass("preview-map")).toBeTruthy(); + }); + }); + + it('should set the id of the template to the name of the dataset', function() { + inject(function($compile, $rootScope) { + $rootScope.dataset = {latlonVals: {latMax: 90, lonMax: 90, latMin: -90, lonMin: -90}, name: "TRMM"}; + + var element = $compile('<div preview-map="dataset"></div>')($rootScope); + + expect(element.attr('id')).toEqual("{{dataset.name}}"); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/directives/timeline.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/directives/timeline.js b/ocw-ui/frontend/test/spec/directives/timeline.js new file mode 100644 index 0000000..06c72e1 --- /dev/null +++ b/ocw-ui/frontend/test/spec/directives/timeline.js @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Directive: timeline', function () { + + // load the directive's module + beforeEach(module('ocwUiApp')); + + var element, + scope; + + beforeEach(inject(function ($rootScope) { + scope = $rootScope.$new(); + })); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/filters/isodatetomiddleendian.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/filters/isodatetomiddleendian.js b/ocw-ui/frontend/test/spec/filters/isodatetomiddleendian.js new file mode 100644 index 0000000..966b333 --- /dev/null +++ b/ocw-ui/frontend/test/spec/filters/isodatetomiddleendian.js @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Filter: ISODateToMiddleEndian', function () { + + // load the filter's module + beforeEach(module('ocwUiApp')); + + // initialize a new instance of the filter before each test + var ISODateToMiddleEndian; + beforeEach(inject(function ($filter) { + ISODateToMiddleEndian = $filter('ISODateToMiddleEndian'); + })); + + describe('ISODateToMiddleEndian', function() { + it('should replace the ISO Date/Time stamp', function() { + inject(function($filter) { + var filter = $filter('ISODateToMiddleEndian'); + expect(filter('2012-01-02T00:00:00')).toEqual('01/02/2012'); + }); + }); + + it('should replace the modified ISO Date/Time stamp', function() { + inject(function($filter) { + var filter = $filter('ISODateToMiddleEndian'); + expect(filter('2012-01-02 00:00:00')).toEqual('01/02/2012'); + }); + }); + + it('should replace the ISO Date stamp', function() { + inject(function($filter) { + var filter = $filter('ISODateToMiddleEndian'); + expect(filter('2012-01-02')).toEqual('01/02/2012'); + }); + }); + + it('should replace leading and trailing whitespace', function() { + inject(function($filter) { + var filter = $filter('ISODateToMiddleEndian'); + expect(filter(' 2012-01-02T00:00:00 ')).toEqual('01/02/2012'); + }); + }); + + it('should do nothing when the date format has the incorrect number of hyphens', function() { + inject(function($filter) { + var filter = $filter('ISODateToMiddleEndian'); + expect(filter('2012-234T234')).toEqual('2012-234T234') + }); + }); + + it('should do nothing when the date format has no hyphens', function() { + inject(function($filter) { + var filter = $filter('ISODateToMiddleEndian'); + expect(filter('2012234T234')).toEqual('2012234T234') + }); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/services/evaluationsettings.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/services/evaluationsettings.js b/ocw-ui/frontend/test/spec/services/evaluationsettings.js new file mode 100644 index 0000000..01fa63b --- /dev/null +++ b/ocw-ui/frontend/test/spec/services/evaluationsettings.js @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Service: evaluationSettings', function () { + + // load the service's module + beforeEach(module('ocwUiApp')); + + // instantiate service + var evaluationSettings; + beforeEach(inject(function (_evaluationSettings_) { + evaluationSettings = _evaluationSettings_; + })); + + it('should initialize the evaluationSettings service', function() { + inject(function(evaluationSettings) { + expect(evaluationSettings).not.toEqual(null); + }); + }); + + it('should provide a getSettings function', function() { + inject(function(evaluationSettings) { + expect(evaluationSettings.getSettings()).not.toEqual(null); + }) + }) +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/services/regionselectparams.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/services/regionselectparams.js b/ocw-ui/frontend/test/spec/services/regionselectparams.js new file mode 100644 index 0000000..34cfe54 --- /dev/null +++ b/ocw-ui/frontend/test/spec/services/regionselectparams.js @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Service: regionSelectParams', function () { + + // load the service's module + beforeEach(module('ocwUiApp')); + + // instantiate service + var regionSelectParams; + beforeEach(inject(function (_regionSelectParams_) { + regionSelectParams = _regionSelectParams_; + })); + + it('should initialize the regionSelectParams service', function() { + inject(function(regionSelectParams) { + expect(regionSelectParams).not.toEqual(null); + }); + }); + + it('should provide the getParameters function', function() { + inject(function(regionSelectParams) { + expect(regionSelectParams.getParameters()).not.toEqual(null); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/spec/services/selecteddatasetinformation.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/spec/services/selecteddatasetinformation.js b/ocw-ui/frontend/test/spec/services/selecteddatasetinformation.js new file mode 100644 index 0000000..60c1ac2 --- /dev/null +++ b/ocw-ui/frontend/test/spec/services/selecteddatasetinformation.js @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http: *www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +'use strict'; + +describe('Service: selectedDatasetInformation', function () { + + // load the service's module + beforeEach(module('ocwUiApp')); + + // instantiate service + var selectedDatasetInformation; + beforeEach(inject(function (_selectedDatasetInformation_) { + selectedDatasetInformation = _selectedDatasetInformation_; + })); + + it('should initialize the selectedDatasetInformation service', function() { + inject(function(selectedDatasetInformation) { + expect(selectedDatasetInformation).not.toEqual(null); + }); + }); + + it('should provide the getDatasets function', function() { + inject(function(selectedDatasetInformation) { + expect(selectedDatasetInformation.getDatasets()).not.toEqual(null); + }); + }); + + it('should provide the getDatasetCount function', function() { + inject(function(selectedDatasetInformation) { + expect(selectedDatasetInformation.getDatasetCount()).toEqual(0); + }); + }); + + it('should provide the addDataset function', function() { + inject(function(selectedDatasetInformation) { + selectedDatasetInformation.addDataset({}); + expect(selectedDatasetInformation.getDatasetCount()).toEqual(1); + }); + }); + + it('should set the shouldDisplay attribute when adding a dataset', function() { + inject(function(selectedDatasetInformation) { + selectedDatasetInformation.addDataset({}); + expect(selectedDatasetInformation.getDatasets()[0].shouldDisplay).toBe(false); + }); + }); + + it('should set the regrid attribute when adding a dataset', function() { + inject(function(selectedDatasetInformation) { + selectedDatasetInformation.addDataset({}); + expect(selectedDatasetInformation.getDatasets()[0].regrid).toBe(false); + }); + }); + + it('should provide the removeDataset function', function() { + inject(function(selectedDatasetInformation) { + selectedDatasetInformation.addDataset(1); + selectedDatasetInformation.addDataset(2); + + expect(selectedDatasetInformation.getDatasets()[0]).toEqual(1); + selectedDatasetInformation.removeDataset(0); + expect(selectedDatasetInformation.getDatasets()[0]).toEqual(2); + }); + }); + + it('should provide the clearDatasets function', function() { + inject(function(selectedDatasetInformation) { + selectedDatasetInformation.addDataset({}); + expect(selectedDatasetInformation.getDatasetCount()).toEqual(1); + + selectedDatasetInformation.clearDatasets(); + expect(selectedDatasetInformation.getDatasetCount()).toEqual(0); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/unit/controllers/DatasetDisplayCtrlTest.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/unit/controllers/DatasetDisplayCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/DatasetDisplayCtrlTest.js deleted file mode 100644 index b6fe620..0000000 --- a/ocw-ui/frontend/test/unit/controllers/DatasetDisplayCtrlTest.js +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http: *www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. -**/ - -'use strict'; - -describe('OCW Controllers', function() { - - beforeEach(module('ocw.controllers')); - beforeEach(module('ocw.services')); - - describe('DatasetDisplayCtrl', function() { - it('should initialize the removeDataset function', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("DatasetDisplayCtrl", {$scope: scope}); - - scope.datasets.push(1); - scope.datasets.push(2); - - expect(scope.datasets[0]).toBe(1); - - scope.removeDataset(0); - - expect(scope.datasets[0]).toBe(2); - }); - }); - - it('should initialize the setRegridBase function', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("DatasetDisplayCtrl", {$scope: scope}); - - scope.datasets.push({regrid: false}); - scope.datasets.push({regrid: true}); - scope.datasets.push({regrid: true}); - scope.datasets.push({regrid: false}); - - expect(scope.datasets[1].regrid).toBe(true); - expect(scope.datasets[2].regrid).toBe(true); - - // setRegridBase should set all indices to 'false' if if it's not the passed index - scope.setRegridBase(2); - - expect(scope.datasets[1].regrid).toBe(false); - expect(scope.datasets[2].regrid).toBe(true); - }); - }); - }); -}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/unit/controllers/DatasetSelectCtrlTest.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/unit/controllers/DatasetSelectCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/DatasetSelectCtrlTest.js deleted file mode 100644 index 7091562..0000000 --- a/ocw-ui/frontend/test/unit/controllers/DatasetSelectCtrlTest.js +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http: *www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. -**/ - -'use strict'; - -describe('OCW Controllers', function() { - - beforeEach(module('ocw.controllers')); - beforeEach(module('ocw.services')); - - describe('DatasetSelectCtrl', function() { - it('should initialize the disable clear button function', function() { - inject(function($rootScope, $controller, selectedDatasetInformation) { - var scope = $rootScope.$new(); - var ctrl = $controller('DatasetSelectCtrl', {$scope: scope}); - - expect(scope.shouldDisableClearButton()).toBe(true); - selectedDatasetInformation.addDataset({}); - expect(scope.shouldDisableClearButton()).toBe(false); - }); - }); - - it('should initialize the clear datasets function', function() { - inject(function($rootScope, $controller, selectedDatasetInformation) { - var scope = $rootScope.$new(); - var ctrl = $controller('DatasetSelectCtrl', {$rootScope: $rootScope, $scope: scope}); - - selectedDatasetInformation.addDataset({}); - expect(selectedDatasetInformation.getDatasetCount()).toBe(1); - scope.clearDatasets(); - expect(selectedDatasetInformation.getDatasetCount()).toBe(0); - }); - }); - }); -}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/unit/controllers/ObservationSelectCtrlTest.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/unit/controllers/ObservationSelectCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/ObservationSelectCtrlTest.js deleted file mode 100644 index e076eb0..0000000 --- a/ocw-ui/frontend/test/unit/controllers/ObservationSelectCtrlTest.js +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http: *www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. -**/ - -'use strict'; - -describe('OCW Controllers', function() { - - beforeEach(module('ocw.controllers')); - beforeEach(module('ocw.services')); - - describe('ObservationSelectCtrl', function() { - it('should grab the default set of selected datasets from the service', function() { - inject(function($httpBackend, $rootScope, $controller) { - $rootScope.baseURL = "http://localhost:8082" - $httpBackend.expectJSONP($rootScope.baseURL + '/getPathLeader/?callback=JSON_CALLBACK'). - respond(200, {'leader': '/usr/local/rcmes'}); - - var scope = $rootScope.$new(); - var ctrl = $controller("ObservationSelectCtrl", {$scope: scope}); - $httpBackend.flush(); - - expect(typeof scope.datasetCount).toBe('object'); - expect(Object.keys(scope.datasetCount).length).toBe(0); - }); - }); - - it('should initialize option arrays and default to the first element', function() { - inject(function($httpBackend, $rootScope, $controller) { - $rootScope.baseURL = "http://localhost:8082" - $httpBackend.expectJSONP($rootScope.baseURL + '/getPathLeader/?callback=JSON_CALLBACK'). - respond(200, {'leader': '/usr/local/rcmes'}); - - var scope = $rootScope.$new(); - var ctrl = $controller("ObservationSelectCtrl", {$scope: scope}); - $httpBackend.flush(); - - expect(scope.params.length).toBe(1); - expect(scope.lats.length).toBe(1); - expect(scope.lons.length).toBe(1); - expect(scope.times.length).toBe(1); - - expect(scope.params[0]).toEqual("Please select a file above"); - expect(scope.lats[0]).toEqual("Please select a file above"); - expect(scope.lons[0]).toEqual("Please select a file above"); - expect(scope.times[0]).toEqual("Please select a file above"); - }); - }); - - it('should initialize scope attributes properly', function() { - inject(function($httpBackend, $rootScope, $controller) { - $rootScope.baseURL = "http://localhost:8082" - $httpBackend.expectJSONP($rootScope.baseURL + '/getPathLeader/?callback=JSON_CALLBACK'). - respond(200, {'leader': '/usr/local/rcmes'}); - - var scope = $rootScope.$new(); - var ctrl = $controller("ObservationSelectCtrl", {$scope: scope}); - $httpBackend.flush(); - - expect(scope.pathLeader).toEqual('/usr/local/rcmes'); - expect(scope.loadingFile).toBe(false); - expect(scope.fileAdded).toBe(false); - expect(typeof scope.latLonVals).toEqual('object'); - expect(scope.latLonVals.length).toBe(0); - expect(typeof scope.timeVals).toEqual('object'); - expect(scope.timeVals.length).toEqual(0); - expect(typeof scope.localSelectForm).toEqual('object'); - expect(Object.keys(scope.localSelectForm).length).toEqual(0); - }); - }); - - it('should initialize the uploadLocalFile function', function() { - inject(function($httpBackend, $rootScope, $controller) { - $rootScope.baseURL = "http://localhost:8082" - $httpBackend.expectJSONP($rootScope.baseURL + '/getPathLeader/?callback=JSON_CALLBACK'). - respond(200, {'leader': '/usr/local/rcmes'}); - - var scope = $rootScope.$new(); - var ctrl = $controller("ObservationSelectCtrl", {$scope: scope}); - $httpBackend.flush(); - - $httpBackend.expectJSONP($rootScope.baseURL + '/list/vars/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK'). - respond(200, {"variables": ["lat", "lon", "prec", "time" ]}); - $httpBackend.expectJSONP($rootScope.baseURL + '/list/latlon/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK'). - respond(200, {'latMax': '75.25', 'success': 1, 'latname': 'lat', 'lonMax': '-29.75', 'lonMin': '-159.75', 'lonname': 'lon', 'latMin': '15.25'}); - $httpBackend.expectJSONP($rootScope.baseURL + '/list/time/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK'). - respond(200, {"start_time": "1980-01-01 00:00:00", "timename": "time", "success": 1, "end_time": "2004-12-01 00:00:00"}); - - scope.uploadLocalFile(); - $httpBackend.flush(); - - expect(scope.latsSelect).toEqual("lat"); - expect(scope.lonsSelect).toEqual("lon"); - expect(scope.timeSelect).toEqual("time"); - expect(scope.paramSelect).toEqual("prec"); - - // Simulate failure on one of the backend calls. Should - $httpBackend.expectJSONP($rootScope.baseURL + '/list/vars/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK'). - respond(200, {}); - $httpBackend.expectJSONP($rootScope.baseURL + '/list/latlon/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK'). - respond(404, {}); - $httpBackend.expectJSONP($rootScope.baseURL + '/list/time/"/usr/local/rcmesundefined"?callback=JSON_CALLBACK'). - respond(200, {}); - - scope.uploadLocalFile(); - $httpBackend.flush(); - - expect(scope.paramSelect).toEqual("Unable to load variable(s)"); - expect(scope.params.length).toEqual(1); - expect(scope.latsSelect).toEqual("Unable to load variable(s)"); - expect(scope.lats.length).toEqual(1); - expect(scope.lonsSelect).toEqual("Unable to load variable(s)"); - expect(scope.lons.length).toEqual(1); - expect(scope.timeSelect).toEqual("Unable to load variable(s)"); - expect(scope.times.length).toEqual(1); - }); - }); - - it('should initialize the addDatasets function', function() { - inject(function($httpBackend, $rootScope, $controller) { - $rootScope.baseURL = "http://localhost:8082" - $httpBackend.expectJSONP($rootScope.baseURL + '/getPathLeader/?callback=JSON_CALLBACK'). - respond(200, {'leader': '/usr/local/rcmes'}); - - var scope = $rootScope.$new(); - var ctrl = $controller("ObservationSelectCtrl", {$scope: scope}); - $httpBackend.flush(); - - // Add a bunch of bogus data as a dataset - scope.addDataSet(); - - expect(scope.datasetCount.length).toBe(1); - }); - }); - }); -}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/unit/controllers/ParameterSelectCtrlTest.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/unit/controllers/ParameterSelectCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/ParameterSelectCtrlTest.js deleted file mode 100644 index 6845245..0000000 --- a/ocw-ui/frontend/test/unit/controllers/ParameterSelectCtrlTest.js +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http: *www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. -**/ - -'use strict'; - -describe('OCW Controllers', function() { - - beforeEach(module('ocw.controllers')); - beforeEach(module('ocw.services')); - - - describe('ParameterSelectCtrl', function() { - it('should initialize spatial and temporal range default values properly', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$scope: scope}); - - expect(scope.latMin).toBe(-90); - expect(scope.latMax).toBe(90); - expect(scope.lonMin).toBe(-180); - expect(scope.lonMax).toBe(180); - expect(scope.start).toBe("1980-01-01 00:00:00"); - expect(scope.end).toBe("2030-01-01 00:00:00"); - }); - }); - - it('should grab the default set of selected datasets from the service', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$scope: scope}); - - // We should get an object with no keys since the user hasn't selected any - // datasets by default. Object.keys returns an array of all the user defined - // keys in the object. - expect(typeof scope.datasets).toBe('object'); - expect(Object.keys(scope.datasets).length).toBe(0); - }); - }); - - it('should grab the default region select param object from the regionSelectParams service', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$scope: scope}); - - // The default display values aren't going to be changing any time soon. This test - // is a bit of a duplicate since this is really testing functionality of the service. - // Can't hurt to make sure that we're getting results though! - expect(typeof scope.displayParams).toBe('object'); - expect(Object.keys(scope.displayParams).length).toBe(7); - }); - }); - - it('should initialize misc. values properly', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$scope: scope}); - - expect(scope.runningEval).toBe(false); - expect(scope.areInUserRegridState).toBe(false); - expect(scope.latSliderVal).toBe(0); - expect(scope.lonSliderVal).toBe(0); - }); - }); - - it('should set the default datepicker settings', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$scope: scope}); - - // This tests the default values that get passed to the datepicker objects that we - // initialize with a directive. - expect(Object.keys(scope.datepickerSettings).length).toBe(2); - expect(scope.datepickerSettings.changeMonth).toBe(true); - expect(scope.datepickerSettings.changeYear).toBe(true); - }); - }); - - it('should define the slide "slide" callback functions', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$scope: scope}); - - expect(scope.latSliderVal).toBe(0); - expect(scope.lonSliderVal).toBe(0); - scope.updateLatSliderDisplayValue(1); - scope.updateLonSliderDisplayValue(2); - expect(scope.latSliderVal).toBe(1); - expect(scope.lonSliderVal).toBe(2); - }); - }); - - it('should initialize the control disable function', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$scope: scope}); - - expect(scope.shouldDisableControls()).toBe(true); - // Add to dummy values to datasets to make sure the disable function - // triggers properly. - scope.datasets.push(1); - scope.datasets.push(2); - expect(scope.shouldDisableControls()).toBe(false); - }); - }); - - it('should initialize the disable evaluation button function', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$scope: scope}); - - expect(scope.shouldDisableEvaluateButton()).toBe(true); - scope.datasets.push(1); - expect(scope.shouldDisableEvaluateButton()).toBe(true); - scope.datasets.push(2); - expect(scope.shouldDisableEvaluateButton()).toBe(false); - scope.runningEval = true; - expect(scope.shouldDisableEvaluateButton()).toBe(true); - }); - }); - - it('should initialize the disable results view function', function() { - inject(function($rootScope, $controller) { - $rootScope.evalResults = ""; - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$rootScope: $rootScope, $scope: scope}); - - expect(scope.shouldDisableResultsView()).toBe(true); - - // Set evalResults to something other than the default value - $rootScope.evalResults = "this is not an empty string"; - - expect(scope.shouldDisableResultsView()).toBe(false); - }); - }); - - it('should initialize the check parameters function', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$scope: scope}); - - // Set the displayParams values to be "out of bounds" values so checkParams - // adjusts them properly. - scope.displayParams.latMin = "-95"; - scope.displayParams.latMax = "95"; - scope.displayParams.lonMin = "-185"; - scope.displayParams.lonMax = "185"; - scope.displayParams.start = "1980-00-00 00:00:00"; - scope.displayParams.end = "2031-01-01 00:00:00"; - - // If we don't remove the watch on datasets we end up with displayParam values - // all being undefined (but only during testing, which is odd...) - scope.unwatchDatasets(); - scope.checkParameters(); - - expect(scope.displayParams.latMin).toBe(-90); - expect(scope.displayParams.latMax).toBe(90); - expect(scope.displayParams.lonMin).toBe(-180); - expect(scope.displayParams.lonMax).toBe(180); - expect(scope.displayParams.start).toBe('1980-01-01 00:00:00'); - expect(scope.displayParams.end).toBe('2030-01-01 00:00:00'); - }); - }); - - it('should properly set the results of running an evaluation', function() { - inject(function($rootScope, $controller, $httpBackend) { - var scope = $rootScope.$new(); - var ctrl = $controller("ParameterSelectCtrl", {$scope: scope}); - - // Seed rootScope with a known URL for test queries and holder for eval results - $rootScope.baseURL = "http://localhost:9876"; - $rootScope.evalResults = {}; - - // Seed the displayParams so the query is properly formatted - scope.displayParams.lonMin = -180; - scope.displayParams.lonMax = 180; - scope.displayParams.latMin = -90; - scope.displayParams.latMax = 90; - scope.displayParams.start = "1980-01-01"; - scope.displayParams.end = "2030-01-01"; - - // The expected URL string that the frontend generates given this example set - var urlString = "http://localhost:9876/rcmes/run/?" + - "callback=JSON_CALLBACK&" + - "endTime=2030-01-01%2000%3A00%3A00&" + - "filelist=%2Fusr%2Flocal%2Frcmes%2FmodelsForUI%2Fprec.HRM3.ncep.monavg.nc&" + - "latMax=90&" + - "latMin=-90&" + - "lonMax=180&" + - "lonMin=-180&" + - "metricOption=bias&" + - "modelLatVarName=lat&" + - "modelLonVarName=lon&" + - "modelTimeVarName=time&" + - "modelVarName=prec&" + - "obsDatasetId=3&" + - "obsParameterId=36&" + - "regridOption=model&" + - "startTime=1980-01-01%2000%3A00%3A00&" + - "timeRegridOption=monthly"; - - // Example dataset configuration for the test. - scope.datasets = [ - { - "isObs" : 1, - "id" : "3", - "name" : "Tropical Rainfall Measuring Mission Dataset", - "param" : "36", - "paramName" : "TRMM v.6 Monthly Precipitation", - "latlonVals" : {"latMin" : -90, "latMax" : 90, "lonMin" : -180, "lonMax" : 180}, - "lat" : "N/A", - "lon" : "N/A", - "timeVals" : {"start" : "1998-01-01 00:00:00", - "end" : "2010-01-01 00:00:00"}, - "time" : "N/A", - "shouldDisplay" : true, - "regrid" : false - },{ - "isObs" : 0, - "id" : "/usr/local/rcmes/modelsForUI/prec.HRM3.ncep.monavg.nc", - "name" : "prec.HRM3.ncep.monavg.nc", - "param" : "prec", - "paramName" : "prec", - "lat" : "lat", - "lon" : "lon", - "latlonVals" : {"latMin" : "15.25", - "latMax" : "75.25", - "lonMin" : "-159.75", - "lonMax" : "-29.75"}, - "time" : "time", - "timeVals" : {"start":"1980-01-01 00:00:00", - "end" : "2004-12-01 00:00:00"}, - "shouldDisplay" : true, - "regrid" : false - } - ]; - - // Mock return URLs that the frontend will parse - $httpBackend.expectJSONP(urlString).respond(200, - {'comparisonPath': '/fake/path1', - 'modelPath': '/fake/path2', - 'obsPath': '/fake/path3'}); - - - scope.runEvaluation(); - $httpBackend.flush(); - - expect($rootScope.evalResults.comparisonPath).toBe('path1'); - expect($rootScope.evalResults.modelPath).toBe('path2'); - expect($rootScope.evalResults.obsPath).toBe('path3'); - }); - }); - }); -}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/unit/controllers/RcmedSelectionCtrlTest.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/unit/controllers/RcmedSelectionCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/RcmedSelectionCtrlTest.js deleted file mode 100644 index 3279ecc..0000000 --- a/ocw-ui/frontend/test/unit/controllers/RcmedSelectionCtrlTest.js +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http: *www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. -**/ - -'use strict'; - -describe('OCW Controllers', function() { - - beforeEach(module('ocw.controllers')); - beforeEach(module('ocw.services')); - - describe('RcmedSelectionCtrl', function() { - it('should automatically query RCMED on initialization', function() { - inject(function($rootScope, $controller, $httpBackend) { - $rootScope.baseURL = "http://localhost:8082" - $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK'). - respond(200, [{longname: 1}, {longname: 2}]); - - var scope = $rootScope.$new(); - var ctrl = $controller("RcmedSelectionCtrl", {$scope: scope}); - $httpBackend.flush(); - - expect(scope.availableObs.length).toBe(3); - expect(scope.availableObs[0]).toEqual({longname: "Please select an option"}); - expect(scope.availableObs[1]).toEqual({longname: 1}); - }); - }); - - it('should initialize the getObservations function', function() { - inject(function($rootScope, $controller, $httpBackend) { - $rootScope.baseURL = "http://localhost:8082" - $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK'). - respond(200, [{longname: 1}, {longname: 2}]); - - var scope = $rootScope.$new(); - var ctrl = $controller("RcmedSelectionCtrl", {$scope: scope}); - $httpBackend.flush(); - - expect(scope.availableObs.length).toBe(3); - expect(scope.availableObs[0]).toEqual({longname: "Please select an option"}); - expect(scope.availableObs[1]).toEqual({longname: 1}); - - // Set up a failed query - $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK'). - respond(404); - scope.getObservations(); - $httpBackend.flush(); - - expect(scope.availableObs.length).toBe(1); - expect(scope.availableObs[0]).toEqual('Unable to query RCMED'); - - }); - }); - - it('should initialze the getObservationTimeRange function', function() { - inject(function($rootScope, $controller, $httpBackend) { - $rootScope.baseURL = "http://localhost:8082" - $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK'). - respond(200, [{longname: 1}, {longname: 2}]); - - var scope = $rootScope.$new(); - var ctrl = $controller("RcmedSelectionCtrl", {$scope: scope}); - $httpBackend.flush(); - - expect(scope.getObservationTimeRange(1)).toEqual({'start' : '1989-01-01 00:00:00', - 'end' : '2009-12-31 00:00:00'}); - expect(scope.getObservationTimeRange(-1)).toEqual(false); - }); - }); - - it('should initialize dataSelectUpdated function', function() { - inject(function($rootScope, $controller, $httpBackend) { - $rootScope.baseURL = "http://localhost:8082" - $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK'). - respond(200, [{longname: 1}, {longname: 2}]); - - var scope = $rootScope.$new(); - var ctrl = $controller("RcmedSelectionCtrl", {$scope: scope}); - $httpBackend.flush(); - - // Add the test dataset to our scope - scope.datasetSelection = {shortname: 'TRMM'} - - // Test return with only single parameter - $httpBackend.expectJSONP($rootScope.baseURL + '/getDatasetParam?dataset=' + - scope.datasetSelection['shortname'] + - '&callback=JSON_CALLBACK'). - respond(200, ['pcp']); - scope.dataSelectUpdated(); - $httpBackend.flush(); - - expect(scope.parameterSelection).toEqual('pcp'); - - // Test return with multiple parameters - $httpBackend.expectJSONP($rootScope.baseURL + '/getDatasetParam?dataset=' + - scope.datasetSelection['shortname'] + - '&callback=JSON_CALLBACK'). - respond(200, ['pcp', 'pcp2']); - scope.dataSelectUpdated(); - $httpBackend.flush(); - - expect(scope.parameterSelection).toEqual({shortname: 'Please select a parameter'}); - }); - }); - - it('should initialze the addObservation function', function() { - inject(function($rootScope, $controller, $httpBackend) { - $rootScope.baseURL = "http://localhost:8082" - $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK'). - respond(200, [{longname: 1}, {longname: 2}]); - - var scope = $rootScope.$new(); - var ctrl = $controller("RcmedSelectionCtrl", {$scope: scope}); - $httpBackend.flush(); - - scope.datasetSelection = { - "dataset_id" : "3", - "shortname" : "TRMM", - "longname" : "Tropical Rainfall Measuring Mission Dataset", - "source" : "Readme for the Tropical Rainfall Measuring Mission (TRMM) Data Set" - }; - - scope.parameterSelection = { - "parameter_id":"36", - "shortname":"pcp", - "datasetshortname":"TRMM", - "longname":"TRMM v.6 Monthly Precipitation", - "units":"mm\/day" - }; - - // addObservations does a refresh of the selections with a re-query of the backend - // so we need to catch that call! - $httpBackend.expectJSONP($rootScope.baseURL + '/getObsDatasets?callback=JSON_CALLBACK'). - respond(200, [{longname: 1}, {longname: 2}]); - - scope.addObservation(); - $httpBackend.flush(); - - expect(scope.datasetCount.length).toBe(1); - // The selection observation should be reset so we shouldn't have - // any selected observation parameters. - expect(scope.retrievedObsParams).toEqual([]); - }); - }); - }); -}); http://git-wip-us.apache.org/repos/asf/climate/blob/652ea657/ocw-ui/frontend/test/unit/controllers/SettingsCtrlTest.js ---------------------------------------------------------------------- diff --git a/ocw-ui/frontend/test/unit/controllers/SettingsCtrlTest.js b/ocw-ui/frontend/test/unit/controllers/SettingsCtrlTest.js deleted file mode 100644 index 12c133d..0000000 --- a/ocw-ui/frontend/test/unit/controllers/SettingsCtrlTest.js +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http: *www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. -**/ - -'use strict'; - -describe('OCW Controllers', function() { - - beforeEach(module('ocw.controllers')); - beforeEach(module('ocw.services')); - - describe('SettingsCtrl', function() { - it('should initialize settings object from evaluationSettings service', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("SettingsCtrl", {$scope: scope}); - - expect(Object.keys(scope.settings)).toEqual(["metrics", "temporal", "spatialSelect"]); - }); - }); - - it('should pull the dataset information', function() { - inject(function($rootScope, $controller) { - var scope = $rootScope.$new(); - var ctrl = $controller("SettingsCtrl", {$scope: scope}); - - expect(typeof scope.datasets).toBe('object'); - expect(Object.keys(scope.datasets).length).toBe(0); - }); - }); - }); -});
