select_custom_date_view_test.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. require('views/common/select_custom_date_view');
  20. describe('App.JobsCustomDatesSelectView', function () {
  21. var view;
  22. beforeEach(function () {
  23. view = App.JobsCustomDatesSelectView.create();
  24. });
  25. describe('#isCustomEndDate', function () {
  26. var cases = [
  27. {
  28. duration: null,
  29. isCustomEndDate: false,
  30. title: 'duration not set'
  31. },
  32. {
  33. duration: 1000,
  34. isCustomEndDate: false,
  35. title: 'preset duration'
  36. },
  37. {
  38. duration: 0,
  39. isCustomEndDate: true,
  40. title: 'custom duration'
  41. }
  42. ];
  43. beforeEach(function () {
  44. view.reopen({
  45. validate: Em.K
  46. });
  47. });
  48. cases.forEach(function (item) {
  49. it(item.title, function () {
  50. view.set('customDateFormFields.duration', {
  51. value: item.duration
  52. });
  53. expect(view.get('isCustomEndDate')).to.equal(item.isCustomEndDate);
  54. });
  55. });
  56. });
  57. describe('#createCustomStartDate', function () {
  58. var cases = [
  59. {
  60. startDate: '01/01/2016',
  61. hoursForStart: '01',
  62. minutesForStart: '00',
  63. middayPeriodForStart: 'AM',
  64. isInvalidDate: false,
  65. title: 'valid date and time'
  66. },
  67. {
  68. startDate: '',
  69. hoursForStart: '01',
  70. minutesForStart: '00',
  71. middayPeriodForStart: 'AM',
  72. isInvalidDate: true,
  73. title: 'no date specified'
  74. },
  75. {
  76. startDate: '01/01/2016',
  77. hoursForStart: '',
  78. minutesForStart: '00',
  79. middayPeriodForStart: 'AM',
  80. isInvalidDate: true,
  81. title: 'no hours specified'
  82. },
  83. {
  84. startDate: '01/01/2016',
  85. hoursForStart: '01',
  86. minutesForStart: '',
  87. middayPeriodForStart: 'AM',
  88. isInvalidDate: true,
  89. title: 'no minutes specified'
  90. },
  91. {
  92. startDate: '01/01/2016',
  93. hoursForStart: '01',
  94. minutesForStart: '00',
  95. middayPeriodForStart: '',
  96. isInvalidDate: true,
  97. title: 'no midday period specified'
  98. }
  99. ];
  100. beforeEach(function () {
  101. view.reopen({
  102. validate: Em.K
  103. });
  104. });
  105. cases.forEach(function (item) {
  106. it(item.title, function () {
  107. view.get('customDateFormFields').setProperties({
  108. startDate: item.startDate,
  109. hoursForStart: item.hoursForStart,
  110. minutesForStart: item.minutesForStart,
  111. middayPeriodForStart: item.middayPeriodForStart
  112. });
  113. expect(Em.isNone(view.createCustomStartDate())).to.equal(item.isInvalidDate);
  114. });
  115. });
  116. });
  117. describe('#createCustomEndDate', function () {
  118. var customEndCases = [
  119. {
  120. endDate: '01/01/2016',
  121. hoursForEnd: '01',
  122. minutesForEnd: '00',
  123. middayPeriodForEnd: 'AM',
  124. isInvalidDate: false,
  125. title: 'valid date and time'
  126. },
  127. {
  128. endDate: '',
  129. hoursForEnd: '01',
  130. minutesForEnd: '00',
  131. middayPeriodForEnd: 'AM',
  132. isInvalidDate: true,
  133. title: 'no date specified'
  134. },
  135. {
  136. endDate: '01/01/2016',
  137. hoursForEnd: '',
  138. minutesForEnd: '00',
  139. middayPeriodForEnd: 'AM',
  140. isInvalidDate: true,
  141. title: 'no hours specified'
  142. },
  143. {
  144. endDate: '01/01/2016',
  145. hoursForEnd: '01',
  146. minutesForEnd: '',
  147. middayPeriodForEnd: 'AM',
  148. isInvalidDate: true,
  149. title: 'no minutes specified'
  150. },
  151. {
  152. endDate: '01/01/2016',
  153. hoursForEnd: '01',
  154. minutesForEnd: '00',
  155. middayPeriodForEnd: '',
  156. isInvalidDate: true,
  157. title: 'no midday period specified'
  158. }
  159. ];
  160. beforeEach(function () {
  161. view.reopen({
  162. validate: Em.K
  163. });
  164. });
  165. customEndCases.forEach(function (item) {
  166. it(item.title, function () {
  167. view.get('customDateFormFields').setProperties({
  168. endDate: item.endDate,
  169. hoursForEnd: item.hoursForEnd,
  170. minutesForEnd: item.minutesForEnd,
  171. middayPeriodForEnd: item.middayPeriodForEnd,
  172. duration: {
  173. value: 0
  174. }
  175. });
  176. expect(Em.isNone(view.createCustomEndDate(1000))).to.equal(item.isInvalidDate);
  177. });
  178. });
  179. it('preset duration', function () {
  180. view.set('customDateFormFields.duration', {
  181. value: 900000
  182. });
  183. expect(view.createCustomEndDate(1000)).to.equal(901000);
  184. });
  185. });
  186. describe('#setErrorMessage', function () {
  187. var cases = [
  188. {
  189. key: 'startDate',
  190. property: 'isStartDateError',
  191. value: true,
  192. message: 'error',
  193. errorMessage: 'error',
  194. title: 'error'
  195. },
  196. {
  197. key: 'endDate',
  198. property: 'isEndDateError',
  199. value: false,
  200. message: null,
  201. errorMessage: '',
  202. title: 'no error'
  203. }
  204. ];
  205. cases.forEach(function (item) {
  206. describe(item.title, function () {
  207. beforeEach(function () {
  208. view.get('errors').setProperties({
  209. isStartDateError: false,
  210. isEndDateError: true
  211. });
  212. view.get('errorMessages').setProperties({
  213. startDate: '',
  214. endDate: 'error'
  215. });
  216. view.setErrorMessage(item.key, item.message);
  217. });
  218. it('should set error flag', function () {
  219. expect(view.get('errors').get(item.property)).to.equal(item.value);
  220. });
  221. it('should set error message', function () {
  222. expect(view.get('errorMessages').get(item.key)).to.equal(item.errorMessage);
  223. });
  224. });
  225. });
  226. });
  227. describe('#durationSelect', function () {
  228. var select;
  229. beforeEach(function () {
  230. select = view.get('durationSelect').create();
  231. });
  232. describe('#willInsertElement', function () {
  233. var cases = [
  234. {
  235. duration: 1800000,
  236. selection: {
  237. value: 1800000,
  238. label: Em.I18n.t('jobs.customDateFilter.duration.30min')
  239. },
  240. title: 'should detect preset option by value'
  241. },
  242. {
  243. duration: Em.I18n.t('jobs.customDateFilter.duration.2hr'),
  244. selection: {
  245. value: 7200000,
  246. label: Em.I18n.t('jobs.customDateFilter.duration.2hr')
  247. },
  248. title: 'should detect preset option by label'
  249. },
  250. {
  251. duration: '40 minutes',
  252. selection: {
  253. value: 0,
  254. label: Em.I18n.t('common.custom')
  255. },
  256. title: 'should set "Custom" option if preset one can\'t be detected'
  257. }
  258. ];
  259. cases.forEach(function (item) {
  260. it(item.title, function () {
  261. select.set('selection', item.duration);
  262. select.willInsertElement();
  263. expect(select.get('selection')).to.eql(item.selection);
  264. });
  265. });
  266. });
  267. });
  268. });