From 3bea5218b84a9431158aae681693875c1eb3b150 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 2 Oct 2015 22:25:52 +0000 Subject: [PATCH] Fix old tests to reflect new validation and add new test to verify that new validation function works Js Hint fixes Js Hint fixes Js Hint fixes Fix typo found by Dave --- ang/crmMailing/RadioDate.js | 2 +- tests/karma/unit/crmMailingRadioDateSpec.js | 24 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ang/crmMailing/RadioDate.js b/ang/crmMailing/RadioDate.js index f509d62f13..153e9562b9 100644 --- a/ang/crmMailing/RadioDate.js +++ b/ang/crmMailing/RadioDate.js @@ -64,7 +64,7 @@ ngModel.$setValidity('dateTimeInThePast', !($(this).val().length && submittedDate < currentDate)); if ($(this).val().length && submittedDate < currentDate) { crmUiAlert({ - text: ts('The Scheulded date and time is in the past'), + text: ts('The scheduled date and time is in the past'), title: ts('Error') }); } diff --git a/tests/karma/unit/crmMailingRadioDateSpec.js b/tests/karma/unit/crmMailingRadioDateSpec.js index a90a820f6b..4ffee0cc6d 100644 --- a/tests/karma/unit/crmMailingRadioDateSpec.js +++ b/tests/karma/unit/crmMailingRadioDateSpec.js @@ -80,11 +80,31 @@ describe('crmMailingRadioDate', function() { model.the_date = '2014-01-02 02:03:00'; $rootScope.$digest(); - expect($rootScope.myForm.$valid).toBe(true); + expect($rootScope.myForm.$valid).toBe(false); expect(element.find('.radio-now').prop('checked')).toBe(false); expect(element.find('.radio-at').prop('checked')).toBe(true); expect(element.find('.crm-form-date').datepicker('getDate').toDateString()).toEqual('Thu Jan 02 2014'); expect(element.find('.crm-form-time').timeEntry('getTime').getMinutes()).toBe(3); + + var now = new Date(); + now.setDate(now.getDate() + 1); + var month = '' + (now.getMonth() + 1); + var day = '' + now.getDate(); + var year = now.getFullYear(); + var hours = '' + now.getHours(); + var minutes = '' + now.getMinutes(); + if (month.length < 2) month = '0' + month; + if (day.length < 2) day = '0' + day; + var datenow = [year, month, day].join('-'); + var time = [hours, minutes, "00"].join(':'); + var currentDate = datenow + ' ' + time; + var n = now.toDateString(); + model.the_date = currentDate; + $rootScope.$digest(); + expect($rootScope.myForm.$valid).toBe(true); + expect(element.find('.radio-now').prop('checked')).toBe(false); + expect(element.find('.radio-at').prop('checked')).toBe(true); + expect(element.find('.crm-form-date').datepicker('getDate').toDateString()).toEqual(n); }); it('should update the model after changing the date and time', function() { @@ -107,7 +127,7 @@ describe('crmMailingRadioDate', function() { element.find('.crm-form-time').timeEntry('setTime', '04:05').trigger('change'); $rootScope.$digest(); expect(model.the_date).toBe('2014-01-03 04:05:00'); - expect($rootScope.myForm.$valid).toBe(true); + expect($rootScope.myForm.$valid).toBe(false); expect(element.find('.radio-now').prop('checked')).toBe(false); expect(element.find('.radio-at').prop('checked')).toBe(true); -- 2.25.1