dataset_job_test.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. var modelSetup = require('test/init_model_test');
  20. require('models/dataset_job');
  21. var dataSetJob,
  22. dataSetJobData = {
  23. id: 'job',
  24. name: 'job'
  25. },
  26. timeCases = [
  27. {
  28. property: 'startFormatted',
  29. dateProperty: 'startDate'
  30. },
  31. {
  32. property: 'endFormatted',
  33. dateProperty: 'endDate'
  34. }
  35. ],
  36. timeTestData = [
  37. {
  38. title: 'should calculate time period',
  39. time: function () {
  40. return App.dateTime();
  41. },
  42. result: 'a moment ago'
  43. },
  44. {
  45. title: 'should be empty',
  46. time: function () {
  47. return 0;
  48. },
  49. result: ''
  50. }
  51. ],
  52. healthCases = [
  53. {
  54. status: 'SUCCEEDED',
  55. className: 'icon-ok'
  56. },
  57. {
  58. status: 'SUSPENDED',
  59. className: 'icon-cog'
  60. },
  61. {
  62. status: 'WAITING',
  63. className: 'icon-time'
  64. },
  65. {
  66. status: 'RUNNING',
  67. className: 'icon-play'
  68. },
  69. {
  70. status: 'KILLED',
  71. className: 'icon-exclamation-sign'
  72. },
  73. {
  74. status: 'FAILED',
  75. className: 'icon-warning-sign'
  76. },
  77. {
  78. status: 'ERROR',
  79. className: 'icon-remove'
  80. },
  81. {
  82. status: '',
  83. className: 'icon-question-sign'
  84. }
  85. ];
  86. describe('App.DataSetJob', function () {
  87. beforeEach(function () {
  88. dataSetJob = App.DataSetJob.createRecord(dataSetJobData);
  89. });
  90. afterEach(function () {
  91. modelSetup.deleteRecord(dataSetJob);
  92. });
  93. describe('#statusFormatted', function () {
  94. it('should be in lower case and capitalized', function () {
  95. dataSetJob.set('status', 'RUNNING');
  96. expect(dataSetJob.get('statusFormatted')).to.equal('Running');
  97. });
  98. });
  99. describe('#isSuspended', function () {
  100. it('should be false', function () {
  101. dataSetJob.set('status', 'RUNNING');
  102. expect(dataSetJob.get('isSuspended')).to.be.false;
  103. });
  104. it('should be true', function () {
  105. dataSetJob.set('status', 'SUSPENDED');
  106. expect(dataSetJob.get('isSuspended')).to.be.true;
  107. });
  108. });
  109. timeCases.forEach(function (item) {
  110. describe('#' + item.property, function () {
  111. timeTestData.forEach(function (test) {
  112. it(test.title, function () {
  113. dataSetJob.set(item.dateProperty, test.time());
  114. expect(dataSetJob.get(item.property)).to.equal(test.result);
  115. });
  116. });
  117. });
  118. });
  119. describe('#healthClass', function () {
  120. healthCases.forEach(function (item) {
  121. it('should be ' + item.className, function () {
  122. dataSetJob.set('status', item.status);
  123. expect(dataSetJob.get('healthClass')).to.equal(item.className);
  124. });
  125. });
  126. });
  127. });