edit_dataset_view_test.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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('controllers/main/mirroring/edit_dataset_controller');
  20. require('models/target_cluster');
  21. require('views/main/mirroring/edit_dataset_view');
  22. var mainMirroringEditDataSetView;
  23. describe('App.MainMirroringEditDataSetView', function () {
  24. beforeEach(function () {
  25. mainMirroringEditDataSetView = App.MainMirroringEditDataSetView.create({
  26. controller: App.MainMirroringEditDataSetController.create(),
  27. isLoaded: true
  28. });
  29. });
  30. describe('targetClusterSelect.content', function () {
  31. var targetClusterSelect;
  32. beforeEach(function () {
  33. targetClusterSelect = mainMirroringEditDataSetView.get('targetClusterSelect').create({
  34. parentView: mainMirroringEditDataSetView
  35. });
  36. });
  37. it('should be empty if data is not loaded', function () {
  38. targetClusterSelect.set('parentView.isLoaded', false);
  39. expect(targetClusterSelect.get('content')).to.be.empty;
  40. });
  41. it('should contain list of clusters if data is loaded', function () {
  42. targetClusterSelect.set('parentView.isLoaded', true);
  43. targetClusterSelect.set('parentView.targetClusters', [
  44. {name: 'test1'},
  45. {name: 'test2'},
  46. {name: App.get('clusterName')}
  47. ]);
  48. expect(targetClusterSelect.get('content')).to.eql([
  49. 'test1',
  50. 'test2',
  51. Em.I18n.t('mirroring.dataset.addTargetCluster')
  52. ]);
  53. });
  54. });
  55. describe('targetClusterSelect.change', function () {
  56. var targetClusterSelect;
  57. beforeEach(function () {
  58. targetClusterSelect = mainMirroringEditDataSetView.get('targetClusterSelect').create({
  59. parentView: mainMirroringEditDataSetView,
  60. content: ['test1', 'test2', 'test3']
  61. });
  62. sinon.stub(targetClusterSelect.parentView, 'manageClusters', Em.K);
  63. });
  64. afterEach(function () {
  65. targetClusterSelect.parentView.manageClusters.restore();
  66. });
  67. it('should open manage cluster popup if appropriate option was selected', function () {
  68. targetClusterSelect.set('selection', Em.I18n.t('mirroring.dataset.addTargetCluster'));
  69. targetClusterSelect.change();
  70. expect(targetClusterSelect.get('selection')).to.equal('test1');
  71. expect(targetClusterSelect.parentView.manageClusters.calledOnce).to.be.true;
  72. expect(targetClusterSelect.get('parentView.controller.formFields.datasetTargetClusterName')).to.equal('test1');
  73. });
  74. it('should not open manage cluster popup if appropriate option was not selected', function () {
  75. targetClusterSelect.set('selection', 'test3');
  76. targetClusterSelect.change();
  77. expect(targetClusterSelect.get('selection')).to.equal('test3');
  78. expect(targetClusterSelect.parentView.manageClusters.calledOnce).to.be.false;
  79. expect(targetClusterSelect.get('parentView.controller.formFields.datasetTargetClusterName')).to.equal('test3');
  80. });
  81. });
  82. describe('onTargetClustersChange', function () {
  83. var testCases = [
  84. {
  85. isLoaded: true,
  86. targetClusters: [1, 2, 3],
  87. targetClusterName: 'test',
  88. hasTargetClusters: true
  89. },
  90. {
  91. isLoaded: false,
  92. targetClusters: [1, 2, 3],
  93. targetClusterName: null,
  94. hasTargetClusters: false
  95. },
  96. {
  97. isLoaded: true,
  98. targetClusters: [1],
  99. targetClusterName: null,
  100. hasTargetClusters: false
  101. }
  102. ];
  103. testCases.forEach(function (test) {
  104. it('should set hasTargetClusters property depending on cluster list', function () {
  105. mainMirroringEditDataSetView.set('isLoaded', test.isLoaded);
  106. mainMirroringEditDataSetView.set('targetClusters', test.targetClusters);
  107. mainMirroringEditDataSetView.set('controller.formFields.datasetTargetClusterName', 'test');
  108. mainMirroringEditDataSetView.onTargetClustersChange();
  109. expect(mainMirroringEditDataSetView.get('hasTargetClusters')).to.equal(test.hasTargetClusters);
  110. expect(mainMirroringEditDataSetView.get('controller.formFields.datasetTargetClusterName')).to.equal(test.targetClusterName);
  111. });
  112. });
  113. });
  114. describe('fillForm', function () {
  115. App.store.loadMany(App.Dataset, [
  116. {
  117. id: 'test1',
  118. name: 'test1',
  119. target_cluster_name: 'testCluster1',
  120. source_dir: '/testDir1',
  121. target_dir: '/testDir1',
  122. frequency: '5',
  123. frequency_unit: 'days',
  124. schedule_start_date: new Date('11/29/2014 01:00 AM').toISOString().replace(/\:\d{2}\.\d{3}/, ''),
  125. schedule_end_date: new Date('11/29/2014 02:00 AM').toISOString().replace(/\:\d{2}\.\d{3}/, '')
  126. },
  127. {
  128. id: 'test2',
  129. name: 'test2',
  130. target_cluster_name: 'testCluster2',
  131. source_dir: '/testDir2',
  132. target_dir: '/testDir2',
  133. frequency: '10',
  134. frequency_unit: 'hours',
  135. schedule_start_date: new Date('11/20/2014 01:00 AM').toISOString().replace(/\:\d{2}\.\d{3}/, ''),
  136. schedule_end_date: new Date('11/21/2014 02:00 PM').toISOString().replace(/\:\d{2}\.\d{3}/, '')
  137. },
  138. {
  139. id: 'test3',
  140. name: 'test3',
  141. target_cluster_name: 'testCluster3',
  142. source_dir: '/testDir3',
  143. target_dir: '/testDir3',
  144. frequency: '1',
  145. frequency_unit: 'minutes',
  146. schedule_start_date: new Date('10/29/2014 01:00 AM').toISOString().replace(/\:\d{2}\.\d{3}/, ''),
  147. schedule_end_date: new Date('11/29/2015 02:00 AM').toISOString().replace(/\:\d{2}\.\d{3}/, '')
  148. }
  149. ]);
  150. var testCases = [
  151. {
  152. datasetName: 'test1',
  153. datasetSourceDir: '/testDir1',
  154. datasetTargetDir: '/testDir1',
  155. datasetTargetClusterName: 'testCluster1',
  156. datasetFrequency: '5',
  157. repeatOptionSelected: 'days',
  158. datasetStartDate: '11/29/14',
  159. datasetEndDate: '11/29/14',
  160. hoursForStart: '01',
  161. hoursForEnd: '02',
  162. minutesForStart: '00',
  163. minutesForEnd: '00',
  164. middayPeriodForStart: 'AM',
  165. middayPeriodForEnd: 'AM'
  166. },
  167. {
  168. datasetName: 'test2',
  169. datasetSourceDir: '/testDir2',
  170. datasetTargetDir: '/testDir2',
  171. datasetTargetClusterName: 'testCluster2',
  172. datasetFrequency: '10',
  173. repeatOptionSelected: 'hours',
  174. datasetStartDate: '11/20/14',
  175. datasetEndDate: '11/21/14',
  176. hoursForStart: '01',
  177. hoursForEnd: '02',
  178. minutesForStart: '00',
  179. minutesForEnd: '00',
  180. middayPeriodForStart: 'AM',
  181. middayPeriodForEnd: 'PM'
  182. },
  183. {
  184. datasetName: 'test3',
  185. datasetSourceDir: '/testDir3',
  186. datasetTargetDir: '/testDir3',
  187. datasetTargetClusterName: 'testCluster3',
  188. datasetFrequency: '1',
  189. repeatOptionSelected: 'minutes',
  190. datasetStartDate: '10/29/14',
  191. datasetEndDate: '11/29/15',
  192. hoursForStart: '01',
  193. hoursForEnd: '02',
  194. minutesForStart: '00',
  195. minutesForEnd: '00',
  196. middayPeriodForStart: 'AM',
  197. middayPeriodForEnd: 'AM'
  198. }
  199. ];
  200. it('should not set form fields if isLoaded is false', function () {
  201. mainMirroringEditDataSetView.set('isLoaded', false);
  202. mainMirroringEditDataSetView.fillForm();
  203. Em.keys(mainMirroringEditDataSetView.get('controller.formFields')).forEach(function (field) {
  204. expect(mainMirroringEditDataSetView.get('controller.formFields.' + field)).to.be.null;
  205. });
  206. });
  207. it('should not set form fields if controller.isEdit is false', function () {
  208. mainMirroringEditDataSetView.set('controller.isEdit', false);
  209. mainMirroringEditDataSetView.fillForm();
  210. Em.keys(mainMirroringEditDataSetView.get('controller.formFields')).forEach(function (field) {
  211. expect(mainMirroringEditDataSetView.get('controller.formFields.' + field)).to.be.null;
  212. });
  213. });
  214. testCases.forEach(function (test) {
  215. it('set appropriate form fields from dataset model', function () {
  216. mainMirroringEditDataSetView.set('controller.datasetIdToEdit', test.datasetName);
  217. mainMirroringEditDataSetView.set('controller.isEdit', true);
  218. mainMirroringEditDataSetView.fillForm();
  219. Em.keys(mainMirroringEditDataSetView.get('controller.formFields')).forEach(function (field) {
  220. expect(mainMirroringEditDataSetView.get('controller.formFields.' + field)).to.equal(test[field]);
  221. });
  222. });
  223. });
  224. });
  225. });