diff --git a/platform/commonUI/general/src/controllers/DateTimeFieldController.js b/platform/commonUI/general/src/controllers/DateTimeFieldController.js index d401a8b3fc..313471f21f 100644 --- a/platform/commonUI/general/src/controllers/DateTimeFieldController.js +++ b/platform/commonUI/general/src/controllers/DateTimeFieldController.js @@ -71,8 +71,8 @@ define( if (value !== $scope.ngModel[$scope.field]) { $scope.ngModel[$scope.field] = value; updateFromModel(value); - if ($scope.structure && $scope.structure.submit) { - $scope.structure.submit(); + if ($scope.ngBlur) { + $scope.ngBlur(); } } } diff --git a/platform/commonUI/general/test/controllers/DateTimeFieldControllerSpec.js b/platform/commonUI/general/test/controllers/DateTimeFieldControllerSpec.js index 714c7d072e..b737de309a 100644 --- a/platform/commonUI/general/test/controllers/DateTimeFieldControllerSpec.js +++ b/platform/commonUI/general/test/controllers/DateTimeFieldControllerSpec.js @@ -67,21 +67,13 @@ define( mockScope.ngModel = { testField: 12321 }; mockScope.field = "testField"; mockScope.structure = { format: "someFormat" }; + mockScope.ngBlur = jasmine.createSpy('blur'); controller = new DateTimeFieldController( mockScope, mockFormatService ); - }); - - it("updates models from user-entered text", function () { - var newText = "1977-05-25 17:30:00"; - - mockScope.textValue = newText; - fireWatch("textValue", newText); - expect(mockScope.ngModel.testField) - .toEqual(mockFormat.parse(newText)); - expect(mockScope.textInvalid).toBeFalsy(); + fireWatch("ngModel[field]", mockScope.ngModel.testField); }); it("updates text from model values", function () { @@ -91,6 +83,44 @@ define( expect(mockScope.textValue).toEqual("1977-05-25 17:30:00"); }); + describe("when valid text is entered", function () { + var newText; + + beforeEach(function () { + newText = "1977-05-25 17:30:00"; + mockScope.textValue = newText; + fireWatch("textValue", newText); + }); + + it("updates models from user-entered text", function () { + expect(mockScope.ngModel.testField) + .toEqual(mockFormat.parse(newText)); + expect(mockScope.textInvalid).toBeFalsy(); + }); + + it("does not indicate a blur event", function () { + expect(mockScope.ngBlur).not.toHaveBeenCalled(); + }); + }); + + describe("when a date is chosen via the date picker", function () { + var newValue; + + beforeEach(function () { + newValue = 12345654321; + mockScope.pickerModel.value = newValue; + fireWatch("pickerModel.value", newValue); + }); + + it("updates models", function () { + expect(mockScope.ngModel.testField).toEqual(newValue); + }); + + it("fires a blur event", function () { + expect(mockScope.ngBlur).toHaveBeenCalled(); + }); + }); + it("exposes toggle state for date-time picker", function () { expect(mockScope.picker.active).toBe(false); }); @@ -148,6 +178,10 @@ define( }).toThrow(); }); + describe("when values are changed via the date picker", function () { + + }); + describe("using the obtained format", function () { var testValue = 1234321, testText = "some text";