dataset_test.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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');
  21. var dataset,
  22. datasetData = {
  23. id: 'dataset',
  24. name: 'dataset'
  25. },
  26. statusCases = [
  27. {
  28. status: 'RUNNING',
  29. property: 'isRunning'
  30. },
  31. {
  32. status: 'SUSPENDED',
  33. property: 'isSuspended'
  34. },
  35. {
  36. status: 'SUBMITTED',
  37. property: 'isSubmitted'
  38. }
  39. ],
  40. healthCases = [
  41. {
  42. title: 'should be live',
  43. data: {
  44. datasetJobs: [
  45. Em.Object.create({
  46. status: 'SUCCESSFUL'
  47. })
  48. ]
  49. },
  50. className: 'health-status-LIVE',
  51. icon: App.healthIconClassGreen
  52. },
  53. {
  54. title: 'should be dead for failed first job',
  55. data: {
  56. datasetJobs: [
  57. Em.Object.create({
  58. status: 'SUSPENDED',
  59. endDate: 1
  60. }),
  61. Em.Object.create({
  62. status: 'FAILED',
  63. endDate: 0
  64. })
  65. ]
  66. },
  67. className: 'health-status-DEAD-RED',
  68. icon: App.healthIconClassRed
  69. },
  70. {
  71. title: 'should be for no jobs',
  72. data: {
  73. datasetJobs: []
  74. },
  75. className: 'health-status-LIVE',
  76. icon: App.healthIconClassGreen
  77. }
  78. ];
  79. describe('App.Dataset', function () {
  80. beforeEach(function () {
  81. dataset = App.Dataset.createRecord(datasetData);
  82. });
  83. afterEach(function () {
  84. modelSetup.deleteRecord(dataset);
  85. });
  86. describe('#prefixedName', function () {
  87. it('should add mirroring prefix before the name', function () {
  88. dataset.set('name', 'name');
  89. expect(dataset.get('prefixedName')).to.equal(App.mirroringDatasetNamePrefix + 'name');
  90. });
  91. });
  92. describe('#statusFormatted', function () {
  93. it('should be in lower case and capitalized', function () {
  94. dataset.set('status', 'RUNNING');
  95. expect(dataset.get('statusFormatted')).to.equal('Running');
  96. });
  97. });
  98. statusCases.forEach(function (item) {
  99. describe(item.property, function () {
  100. beforeEach(function () {
  101. dataset.set('status', item.status);
  102. });
  103. it('should be true', function () {
  104. expect(dataset.get(item.property)).to.be.true;
  105. });
  106. it('others should be false', function () {
  107. var falseProperties = statusCases.mapProperty('property').without(item.property);
  108. var falseStates = [];
  109. falseProperties.forEach(function (prop) {
  110. falseStates.push(dataset.get(prop));
  111. });
  112. expect(falseStates).to.eql([false, false]);
  113. });
  114. });
  115. });
  116. describe('#healthClass', function () {
  117. healthCases.forEach(function (item) {
  118. it(item.title, function () {
  119. dataset.reopen(item.data);
  120. expect(dataset.get('healthClass')).to.equal(item.className);
  121. });
  122. });
  123. });
  124. describe('#healthIconClass', function () {
  125. healthCases.forEach(function (item) {
  126. it(item.title, function () {
  127. dataset.reopen(item.data);
  128. expect(dataset.get('healthIconClass')).to.equal(item.icon);
  129. });
  130. });
  131. });
  132. });