service_config_version_test.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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('models/configs/service_config_version');
  20. var model;
  21. function getModel() {
  22. return App.ServiceConfigVersion.createRecord({});
  23. }
  24. describe('App.ServiceConfigVersion', function () {
  25. beforeEach(function () {
  26. model = getModel();
  27. });
  28. App.TestAliases.testAsComputedAnd(getModel(), 'canBeMadeCurrent', ['isCompatible', '!isCurrent']);
  29. App.TestAliases.testAsComputedTruncate(getModel(), 'authorFormatted', 'author', 15, 15);
  30. App.TestAliases.testAsComputedTruncate(getModel(), 'briefNotes', 'fullNotes', 81, 81, '');
  31. App.TestAliases.testAsComputedNotEqualProperties(getModel(), 'moreNotesExists', 'fullNotes', 'briefNotes');
  32. describe("#configGroupName", function() {
  33. it("not default group", function() {
  34. model.reopen({
  35. groupName: 'g1',
  36. isDefault: false
  37. });
  38. expect(model.get('configGroupName')).to.equal('g1');
  39. });
  40. it("default group", function() {
  41. model.reopen({
  42. isDefault: true
  43. });
  44. expect(model.get('configGroupName')).to.equal(Em.I18n.t('common.default'));
  45. });
  46. });
  47. describe("#fullNotes", function() {
  48. it("notes is null", function() {
  49. model.set('notes', null);
  50. expect(model.get('fullNotes')).to.equal(Em.I18n.t('dashboard.configHistory.table.notes.no'));
  51. });
  52. it("notes is empty", function() {
  53. model.set('notes', "");
  54. expect(model.get('fullNotes')).to.equal(Em.I18n.t('dashboard.configHistory.table.notes.no'));
  55. });
  56. it("notes has value", function() {
  57. model.set('notes', "notes-value");
  58. expect(model.get('fullNotes')).to.equal('notes-value');
  59. });
  60. });
  61. describe("#createdDate", function() {
  62. it("should return created date", function() {
  63. model.set('createTime', 1450267588961);
  64. moment.tz.setDefault('America/Los_Angeles');
  65. expect(model.get('createdDate')).to.equal('Wed, Dec 16, 2015 04:06');
  66. });
  67. });
  68. describe("#timeSinceCreated", function () {
  69. before(function () {
  70. sinon.stub($, 'timeago').returns('timeago');
  71. });
  72. after(function () {
  73. $.timeago.restore()
  74. });
  75. it("should return time since created", function () {
  76. model.set('rawCreateTime', 1450267588961);
  77. expect(model.get('timeSinceCreated')).to.equal('timeago');
  78. });
  79. });
  80. describe("#isRestartRequired", function() {
  81. it("service.isRestartRequired is false", function() {
  82. model.set('service', Em.Object.create({
  83. isRestartRequired: false
  84. }));
  85. expect(model.get('isRestartRequired')).to.be.false;
  86. });
  87. it("non-current version", function() {
  88. model.set('service', Em.Object.create({
  89. isRestartRequired: true
  90. }));
  91. model.set('isCurrent', false);
  92. expect(model.get('isRestartRequired')).to.be.false;
  93. });
  94. it("version has no hosts", function() {
  95. model.setProperties({
  96. service: Em.Object.create({
  97. isRestartRequired: true
  98. }),
  99. isCurrent: true,
  100. hosts: []
  101. });
  102. expect(model.get('isRestartRequired')).to.be.false;
  103. });
  104. it("version hosts don't need restart", function() {
  105. model.setProperties({
  106. service: Em.Object.create({
  107. isRestartRequired: true,
  108. restartRequiredHostsAndComponents: {}
  109. }),
  110. isCurrent: true,
  111. hosts: ['host1']
  112. });
  113. expect(model.get('isRestartRequired')).to.be.false;
  114. });
  115. it("version hosts need restart", function() {
  116. model.setProperties({
  117. service: Em.Object.create({
  118. isRestartRequired: true,
  119. restartRequiredHostsAndComponents: {'host1': {}}
  120. }),
  121. isCurrent: true,
  122. hosts: ['host1']
  123. });
  124. expect(model.get('isRestartRequired')).to.be.true;
  125. });
  126. });
  127. describe("#disabledActionMessages", function() {
  128. var testCases = [
  129. {
  130. input: {
  131. isDisplayed: false,
  132. isCurrent: false
  133. },
  134. expected: {
  135. view: '',
  136. compare: '',
  137. revert: ''
  138. }
  139. },
  140. {
  141. input: {
  142. isDisplayed: true,
  143. isCurrent: false
  144. },
  145. expected: {
  146. view: Em.I18n.t('dashboard.configHistory.info-bar.view.button.disabled'),
  147. compare: Em.I18n.t('dashboard.configHistory.info-bar.compare.button.disabled'),
  148. revert: ''
  149. }
  150. },
  151. {
  152. input: {
  153. isDisplayed: false,
  154. isCurrent: true
  155. },
  156. expected: {
  157. view: '',
  158. compare: '',
  159. revert: Em.I18n.t('dashboard.configHistory.info-bar.revert.button.disabled')
  160. }
  161. },
  162. {
  163. input: {
  164. isDisplayed: true,
  165. isCurrent: true
  166. },
  167. expected: {
  168. view: Em.I18n.t('dashboard.configHistory.info-bar.view.button.disabled'),
  169. compare: Em.I18n.t('dashboard.configHistory.info-bar.compare.button.disabled'),
  170. revert: Em.I18n.t('dashboard.configHistory.info-bar.revert.button.disabled')
  171. }
  172. }
  173. ];
  174. testCases.forEach(function(test) {
  175. it("isDisplayed = " + test.input.isDisplayed + ", isCurrent = " + test.input.isCurrent, function() {
  176. model.setProperties(test.input);
  177. expect(model.get('disabledActionMessages')).to.eql(test.expected);
  178. });
  179. });
  180. });
  181. describe("#disabledActionAttr", function() {
  182. var testCases = [
  183. {
  184. input: {
  185. isDisplayed: false,
  186. isCurrent: false,
  187. isDisabled: false
  188. },
  189. expected: {
  190. view: false,
  191. compare: false,
  192. revert: false
  193. }
  194. },
  195. {
  196. input: {
  197. isDisplayed: true,
  198. isCurrent: false,
  199. isDisabled: false
  200. },
  201. expected: {
  202. view: 'disabled',
  203. compare: 'disabled',
  204. revert: false
  205. }
  206. },
  207. {
  208. input: {
  209. isDisplayed: false,
  210. isCurrent: false,
  211. isDisabled: true
  212. },
  213. expected: {
  214. view: false,
  215. compare: 'disabled',
  216. revert: 'disabled'
  217. }
  218. },
  219. {
  220. input: {
  221. isDisplayed: false,
  222. isCurrent: true,
  223. isDisabled: false
  224. },
  225. expected: {
  226. view: false,
  227. compare: false,
  228. revert: 'disabled'
  229. }
  230. },
  231. {
  232. input: {
  233. isDisplayed: true,
  234. isCurrent: true,
  235. isDisabled: true
  236. },
  237. expected: {
  238. view: 'disabled',
  239. compare: 'disabled',
  240. revert: 'disabled'
  241. }
  242. }
  243. ];
  244. testCases.forEach(function(test) {
  245. it("isDisplayed = " + test.input.isDisplayed + ", isCurrent = " + test.input.isCurrent + ", isDisabled = " + test.input.isDisabled, function() {
  246. model.setProperties(test.input);
  247. expect(model.get('disabledActionAttr')).to.eql(test.expected);
  248. });
  249. });
  250. });
  251. });