app_contoller_test.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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/apps_controller');
  20. describe('MainAppsController', function () {
  21. describe('#iTotalDisplayRecordsObserver()', function () {
  22. it('should set number of filtered jobs when switching to all jobs', function () {
  23. var mainAppsController = App.MainAppsController.create();
  24. mainAppsController.set("paginationObject.iTotalDisplayRecords", 5);
  25. expect(mainAppsController.get('filterObject.filteredDisplayRecords')).to.equal(5);
  26. })
  27. });
  28. describe('#filterObject.onRunTypeChange()', function () {
  29. it('should set sSearch_2 of filterObject when changing value of filterObject.runType', function () {
  30. var mainAppsController = App.MainAppsController.create();
  31. mainAppsController.set("filterObject.runType", "MapReduce");
  32. expect(mainAppsController.get('filterObject.sSearch_2')).to.equal("mr");
  33. mainAppsController.set("filterObject.runType", "Hive");
  34. expect(mainAppsController.get('filterObject.sSearch_2')).to.equal("hive");
  35. mainAppsController.set("filterObject.runType", "Pig");
  36. expect(mainAppsController.get('filterObject.sSearch_2')).to.equal("pig");
  37. })
  38. });
  39. describe('#filterObject.onJobsChange()', function () {
  40. it('should set minJobs,maxJobs of filterObject when changing value of filterObject.jobs', function () {
  41. var mainAppsController = App.MainAppsController.create();
  42. mainAppsController.set("filterObject.jobs", ">3");
  43. expect(mainAppsController.get('filterObject.minJobs')).to.equal("3");
  44. expect(mainAppsController.get('filterObject.maxJobs')).to.equal("");
  45. mainAppsController.set("filterObject.jobs", "<3");
  46. expect(mainAppsController.get('filterObject.minJobs')).to.equal("");
  47. expect(mainAppsController.get('filterObject.maxJobs')).to.equal("3");
  48. mainAppsController.set("filterObject.jobs", "3");
  49. expect(mainAppsController.get('filterObject.minJobs')).to.equal("3");
  50. expect(mainAppsController.get('filterObject.maxJobs')).to.equal("3");
  51. mainAppsController.set("filterObject.jobs", "=3");
  52. expect(mainAppsController.get('filterObject.minJobs')).to.equal("3");
  53. expect(mainAppsController.get('filterObject.maxJobs')).to.equal("3");
  54. })
  55. });
  56. describe('#filterObject.onDurationChange()', function () {
  57. it('should set minDuration,maxDuration of filterObject when changing value of filterObject.duration', function () {
  58. var mainAppsController = App.MainAppsController.create();
  59. mainAppsController.set("filterObject.duration", ">3h");
  60. expect(mainAppsController.get('filterObject.minDuration')).to.equal(10799640);
  61. expect(mainAppsController.get('filterObject.maxDuration')).to.equal("");
  62. mainAppsController.set("filterObject.duration", "<6m");
  63. expect(mainAppsController.get('filterObject.minDuration')).to.equal("");
  64. expect(mainAppsController.get('filterObject.maxDuration')).to.equal(360060);
  65. mainAppsController.set("filterObject.duration", "10s");
  66. expect(mainAppsController.get('filterObject.minDuration')).to.equal(9990);
  67. expect(mainAppsController.get('filterObject.maxDuration')).to.equal(10010);
  68. mainAppsController.set("filterObject.duration", "1");
  69. expect(mainAppsController.get('filterObject.minDuration')).to.equal(990);
  70. expect(mainAppsController.get('filterObject.maxDuration')).to.equal(1010);
  71. })
  72. });
  73. describe('#filterObject.onRunDateChange()', function () {
  74. it('should set minStartTime,maxStartTime of filterObject when changing value of filterObject.runDate', function () {
  75. var mainAppsController = App.MainAppsController.create();
  76. mainAppsController.set("filterObject.runDate", "Any");
  77. expect(mainAppsController.get('filterObject.minStartTime')).to.equal("");
  78. mainAppsController.set("filterObject.runDate", "Past 1 Day");
  79. expect(mainAppsController.get('filterObject.minStartTime')).to.be.within(((new Date().getTime())-86400000)-10,((new Date().getTime())-86400000)+10);
  80. mainAppsController.set("filterObject.runDate", "Past 2 Days");
  81. expect(mainAppsController.get('filterObject.minStartTime')).to.be.within(((new Date().getTime())-172800000)-10,((new Date().getTime())-172800000)+10);
  82. mainAppsController.set("filterObject.runDate", "Past 7 Days");
  83. expect(mainAppsController.get('filterObject.minStartTime')).to.be.within(((new Date().getTime())-604800000)-10,((new Date().getTime())-604800000)+10);
  84. mainAppsController.set("filterObject.runDate", "Past 14 Days");
  85. expect(mainAppsController.get('filterObject.minStartTime')).to.be.within(((new Date().getTime())-1209600000)-10,((new Date().getTime())-1209600000)+10);
  86. mainAppsController.set("filterObject.runDate", "Past 30 Days");
  87. expect(mainAppsController.get('filterObject.minStartTime')).to.be.within(((new Date().getTime())-2592000000)-10,((new Date().getTime())-2592000000)+10);
  88. })
  89. });
  90. describe('#filterObject.createAppLink(), #filterObject.valueObserver()', function () {
  91. var mainAppsController = App.MainAppsController.create();
  92. mainAppsController.set('content.length', 20);
  93. it('should set runUrl of filterObject when changing value for any filter', function () {
  94. mainAppsController.set("filterObject.sSearch_0", "0");
  95. mainAppsController.set("filterObject.sSearch_1", "workflowName");
  96. mainAppsController.set("filterObject.sSearch_2", "pig");
  97. mainAppsController.set("filterObject.sSearch_3", "admin");
  98. mainAppsController.set("filterObject.minJobs", "1");
  99. mainAppsController.set("filterObject.maxJobs", "2");
  100. mainAppsController.set("filterObject.minDuration", "1000");
  101. mainAppsController.set("filterObject.maxDuration", "2000");
  102. mainAppsController.set("filterObject.minStartTime", "999");
  103. mainAppsController.set("filterObject.maxStartTime", "1000");
  104. mainAppsController.set("filterObject.sSearch", "searchTerm");
  105. mainAppsController.set("filterObject.iDisplayLength", "10");
  106. mainAppsController.set("filterObject.iDisplayStart", "10");
  107. mainAppsController.set("filterObject.iSortCol_0", "1");
  108. mainAppsController.set("filterObject.sSortDir_0", "ASC");
  109. expect(mainAppsController.get('runUrl')).to.equal("/jobhistory/datatable?" +
  110. "sSearch_0=0" +
  111. "&sSearch_1=workflowName" +
  112. "&sSearch_2=pig" +
  113. "&sSearch_3=admin" +
  114. "&minJobs=1" +
  115. "&maxJobs=2" +
  116. "&minDuration=1000" +
  117. "&maxDuration=2000" +
  118. "&minStartTime=999" +
  119. "&maxStartTime=1000" +
  120. "&sSearch=searchTerm" +
  121. "&iDisplayLength=10" +
  122. "&iDisplayStart=10" +
  123. "&iSortCol_0=1" +
  124. "&sSortDir_0=ASC");
  125. expect(mainAppsController.get('filterObject.viewType')).to.equal('filtered');
  126. });
  127. it('should set viewType to "all" when set iDisplayLength, iDisplayStart, iSortCol_0, sSortDir_0', function () {
  128. mainAppsController.set("filterObject.sSearch_0", "");
  129. mainAppsController.set("filterObject.sSearch_1", "");
  130. mainAppsController.set("filterObject.sSearch_2", "");
  131. mainAppsController.set("filterObject.sSearch_3", "");
  132. mainAppsController.set("filterObject.minJobs", "");
  133. mainAppsController.set("filterObject.maxJobs", "");
  134. mainAppsController.set("filterObject.minDuration", "");
  135. mainAppsController.set("filterObject.maxDuration", "");
  136. mainAppsController.set("filterObject.minStartTime", "");
  137. mainAppsController.set("filterObject.maxStartTime", "");
  138. mainAppsController.set("filterObject.sSearch", "");
  139. mainAppsController.set("filterObject.iDisplayLength", "10");
  140. mainAppsController.set("filterObject.iDisplayStart", "10");
  141. mainAppsController.set("filterObject.iSortCol_0", "1");
  142. mainAppsController.set("filterObject.sSortDir_0", "ASC");
  143. expect(mainAppsController.get('filterObject.viewType')).to.equal('all');
  144. });
  145. });
  146. });