custom_date_popup_test.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. describe('CustomDatePopup', function() {
  20. var customDatePopup = require('views/common/custom_date_popup');
  21. describe('#showCustomDatePopup', function() {
  22. var context = Em.Object.create({
  23. cancel: sinon.spy(),
  24. actualValues: Em.Object.create()
  25. });
  26. var popup = customDatePopup.showCustomDatePopup(context);
  27. it('`onSecondary` should call `cancel` method in passed context', function() {
  28. popup.onSecondary();
  29. expect(context.cancel.calledOnce).to.ok;
  30. });
  31. it('empty values passed for end and start dates, validation should fail with appropriate message', function() {
  32. expect(popup.onPrimary()).to.false;
  33. expect(customDatePopup.get('errors.isStartDateError')).to.ok;
  34. expect(customDatePopup.get('errors.isEndDateError')).to.ok;
  35. expect(customDatePopup.get('errorMessages.startDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.required'));
  36. expect(customDatePopup.get('errorMessages.endDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.required'));
  37. });
  38. it('passed start date is greater then end data, validation should fail with apporpriate message', function() {
  39. customDatePopup.set('customDateFormFields.startDate', '11/11/11');
  40. customDatePopup.set('customDateFormFields.endDate', '11/10/11');
  41. expect(popup.onPrimary()).to.false;
  42. expect(customDatePopup.get('errors.isStartDateError')).to.false;
  43. expect(customDatePopup.get('errors.isEndDateError')).to.ok;
  44. expect(customDatePopup.get('errorMessages.endDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.date.order'));
  45. });
  46. it('valid values passed, `valueObject` should contain `endTime` and `startTime`', function() {
  47. customDatePopup.set('customDateFormFields.startDate', '11/11/11');
  48. customDatePopup.set('customDateFormFields.endDate', '11/12/11');
  49. popup.onPrimary();
  50. expect(context.get('actualValues.startTime')).to.be.equal(1320966000000);
  51. expect(context.get('actualValues.endTime')).to.equal(1321052400000);
  52. });
  53. });
  54. });