alert_instances_controller_test.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. expect(App.ajax.send.args[0][0].name).to.equal('alerts.instances.by_host');
  35. expect(App.ajax.send.args[0][0].data.hostName).to.equal('host');
  36. });
  37. it('should load by AlertDefinition id', function () {
  38. controller.loadAlertInstancesByAlertDefinition('1');
  39. expect(App.ajax.send.args[0][0].name).to.equal('alerts.instances.by_definition');
  40. expect(App.ajax.send.args[0][0].data.definitionId).to.equal('1');
  41. });
  42. it('should load all', function () {
  43. controller.loadAlertInstances();
  44. expect(App.ajax.send.args[0][0].name).to.equal('alerts.instances');
  45. });
  46. });
  47. });
  48. describe('#showPopup', function () {
  49. describe('#bodyClass', function () {
  50. var bodyView;
  51. beforeEach(function () {
  52. controller.reopen({unhealthyAlertInstances: [
  53. App.AlertInstance.createRecord({state: 'CRITICAL'}),
  54. App.AlertInstance.createRecord({state: 'WARNING'}),
  55. App.AlertInstance.createRecord({state: 'WARNING'}),
  56. App.AlertInstance.createRecord({state: 'CRITICAL'})
  57. ]});
  58. bodyView = controller.showPopup().get('bodyClass').create();
  59. });
  60. it('#content', function () {
  61. expect(bodyView.get('content.length')).to.equal(4);
  62. });
  63. it('#isLoaded', function () {
  64. expect(bodyView.get('isLoaded')).to.be.true;
  65. });
  66. it('#isAlertEmptyList', function () {
  67. expect(bodyView.get('isAlertEmptyList')).to.be.false;
  68. });
  69. });
  70. });
  71. });