custom_date_popup_test.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. describe('empty values passed for end and start dates, validation should fail with appropriate message', function () {
  32. it('onPrimary is false', function () {
  33. expect(popup.onPrimary()).to.false;
  34. });
  35. it('isStartDateError is true', function () {
  36. expect(customDatePopup.get('errors.isStartDateError')).to.ok;
  37. });
  38. it('isEndDateError is true', function () {
  39. expect(customDatePopup.get('errors.isEndDateError')).to.ok;
  40. });
  41. it('startDate invalid', function () {
  42. expect(customDatePopup.get('errorMessages.startDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.required'));
  43. });
  44. it('endDate invalid', function () {
  45. expect(customDatePopup.get('errorMessages.endDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.required'));
  46. });
  47. });
  48. describe('passed start date is greater then end data, validation should fail with apporpriate message', function () {
  49. beforeEach(function () {
  50. customDatePopup.set('customDateFormFields.startDate', '11/11/11');
  51. customDatePopup.set('customDateFormFields.endDate', '11/10/11');
  52. });
  53. it('onPrimary is false', function () {
  54. expect(popup.onPrimary()).to.false;
  55. });
  56. it('isStartDateError is false', function () {
  57. expect(customDatePopup.get('errors.isStartDateError')).to.false;
  58. });
  59. it('isEndDateError is true', function () {
  60. expect(customDatePopup.get('errors.isEndDateError')).to.ok;
  61. });
  62. it('endDate invalid', function () {
  63. expect(customDatePopup.get('errorMessages.endDate')).to.equal(Em.I18n.t('jobs.customDateFilter.error.date.order'));
  64. });
  65. });
  66. describe('valid values passed, `valueObject` should contain `endTime` and `startTime`', function () {
  67. beforeEach(function () {
  68. customDatePopup.set('customDateFormFields.startDate', '11/11/11');
  69. customDatePopup.set('customDateFormFields.endDate', '11/12/11');
  70. popup.onPrimary();
  71. });
  72. it('startTime is valid', function() {
  73. expect(context.get('actualValues.startTime')).to.equal(new Date('11/11/11 01:00 AM').getTime());
  74. });
  75. it('endTime is valid', function() {
  76. expect(context.get('actualValues.endTime')).to.equal(new Date('11/12/11 01:00 AM').getTime());
  77. });
  78. });
  79. });
  80. });