alert_instances_controller_test.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 controller;
  20. describe('App.MainAlertInstancesController', function () {
  21. beforeEach(function () {
  22. controller = App.MainAlertInstancesController.create({});
  23. });
  24. describe('#fetchAlertInstances', function () {
  25. describe('loading instances from correct endpoint', function () {
  26. beforeEach(function () {
  27. sinon.stub(App.ajax, 'send', Em.K);
  28. });
  29. afterEach(function () {
  30. App.ajax.send.restore();
  31. });
  32. it('should load by Host name', function () {
  33. controller.loadAlertInstancesByHost('host');
  34. console.log(App.ajax.send.args[0]);
  35. expect(App.ajax.send.args[0][0].name).to.equal('alerts.instances.by_host');
  36. expect(App.ajax.send.args[0][0].data.hostName).to.equal('host');
  37. });
  38. it('should load by AlertDefinition id', function () {
  39. controller.loadAlertInstancesByAlertDefinition('1');
  40. console.log(App.ajax.send.args[0]);
  41. expect(App.ajax.send.args[0][0].name).to.equal('alerts.instances.by_definition');
  42. expect(App.ajax.send.args[0][0].data.definitionId).to.equal('1');
  43. });
  44. it('should load all', function () {
  45. controller.loadAlertInstances();
  46. console.log(App.ajax.send.args[0]);
  47. expect(App.ajax.send.args[0][0].name).to.equal('alerts.instances');
  48. });
  49. });
  50. });
  51. describe('#showPopup', function () {
  52. describe('#bodyClass', function () {
  53. var bodyView;
  54. beforeEach(function () {
  55. controller.reopen({unhealthyAlertInstances: [
  56. App.AlertInstance.createRecord({state: 'CRITICAL'}),
  57. App.AlertInstance.createRecord({state: 'WARNING'}),
  58. App.AlertInstance.createRecord({state: 'WARNING'}),
  59. App.AlertInstance.createRecord({state: 'CRITICAL'})
  60. ]});
  61. bodyView = controller.showPopup().get('bodyClass').create();
  62. });
  63. it('#content', function () {
  64. expect(bodyView.get('content.length')).to.equal(4);
  65. });
  66. it('#isLoaded', function () {
  67. expect(bodyView.get('isLoaded')).to.be.true;
  68. });
  69. it('#isAlertEmptyList', function () {
  70. expect(bodyView.get('isAlertEmptyList')).to.be.false;
  71. });
  72. });
  73. });
  74. });