Transition RcmedSelectCtrl tests

Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/010da1e4
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/010da1e4
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/010da1e4

Branch: refs/heads/master
Commit: 010da1e45dfea1144fad85eee80e11f99600c18c
Parents: ab251b1
Author: Michael Joyce <[email protected]>
Authored: Fri Jul 25 19:12:29 2014 -0700
Committer: Michael Joyce <[email protected]>
Committed: Mon Aug 4 15:01:01 2014 -0700

----------------------------------------------------------------------
 .../test/spec/controllers/rcmedselection.js     | 112 ++++++++++++++++++-
 1 file changed, 108 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/010da1e4/ocw-ui/frontend-new/test/spec/controllers/rcmedselection.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend-new/test/spec/controllers/rcmedselection.js 
b/ocw-ui/frontend-new/test/spec/controllers/rcmedselection.js
index 0466e84..97011c7 100644
--- a/ocw-ui/frontend-new/test/spec/controllers/rcmedselection.js
+++ b/ocw-ui/frontend-new/test/spec/controllers/rcmedselection.js
@@ -19,7 +19,7 @@
 
 'use strict';
 
-describe('Controller: RcmedselectionCtrl', function () {
+describe('Controller: RcmedSelectionCtrl', function () {
 
   // load the controller's module
   beforeEach(module('ocwUiApp'));
@@ -30,12 +30,116 @@ describe('Controller: RcmedselectionCtrl', function () {
   // Initialize the controller and a mock scope
   beforeEach(inject(function ($controller, $rootScope) {
     scope = $rootScope.$new();
-    RcmedselectionCtrl = $controller('RcmedselectionCtrl', {
+    RcmedselectionCtrl = $controller('RcmedSelectionCtrl', {
       $scope: scope
     });
   }));
 
-  it('should attach a list of awesomeThings to the scope', function () {
-    expect(scope.awesomeThings.length).toBe(3);
+  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([]);
+    });
   });
 });

Reply via email to