123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var App = require('app');
- var controller;
- var helpers = require('test/helpers');
- describe('App.ManageAlertNotificationsController', function () {
- beforeEach(function () {
- controller = App.ManageAlertNotificationsController.create({});
- sinon.spy(App.ajax, 'send');
- });
- afterEach(function () {
- App.ajax.send.restore();
- });
- describe('#alertNotifications', function () {
- beforeEach(function () {
- sinon.stub(App.AlertNotification, 'find', function () {
- return [1, 2, 3];
- });
- });
- afterEach(function () {
- App.AlertNotification.find.restore();
- });
- it("should return all alert notifications if controller isLoaded", function () {
- controller.set('isLoaded', true);
- expect(controller.get('alertNotifications')).to.eql([1, 2, 3]);
- });
- it("should return [] if controller isLoaded=false", function () {
- controller.set('isLoaded', false);
- expect(controller.get('alertNotifications')).to.eql([]);
- });
- });
- describe('#loadAlertNotifications()', function () {
- it("should send ajax request and set isLoaded to false", function () {
- controller.set('isLoaded', true);
- controller.loadAlertNotifications();
- expect(controller.get('isLoaded')).to.be.false;
- expect(App.ajax.send.calledOnce).to.be.true;
- });
- });
- describe('#getAlertNotificationsSuccessCallback()', function () {
- beforeEach(function () {
- sinon.spy(App.alertNotificationMapper, 'map');
- });
- afterEach(function () {
- App.alertNotificationMapper.map.restore();
- });
- it("should call mapper and set isLoaded to true", function () {
- controller.set('isLoaded', false);
- controller.getAlertNotificationsSuccessCallback('test');
- expect(controller.get('isLoaded')).to.be.true;
- expect(App.alertNotificationMapper.map.calledWith('test')).to.be.true;
- });
- });
- describe('#getAlertNotificationsErrorCallback()', function () {
- it("should set isLoaded to true", function () {
- controller.set('isLoaded', false);
- controller.getAlertNotificationsSuccessCallback('test');
- expect(controller.get('isLoaded')).to.be.true;
- });
- });
- describe('#addAlertNotification()', function () {
- beforeEach(function () {
- sinon.spy(controller, 'showCreateEditPopup');
- });
- afterEach(function () {
- controller.showCreateEditPopup.restore();
- });
- it("should set value for inputFields and call showCreateEditPopup", function () {
- controller.set('inputFields', Em.Object.create({
- a: {
- value: '',
- defaultValue: 'a'
- },
- b: {
- value: '',
- defaultValue: 'b'
- },
- c: {
- value: '',
- defaultValue: 'c'
- },
- severityFilter: {
- value: [],
- defaultValue: [true, true, true, true]
- }
- }));
- controller.addAlertNotification();
- Em.keys(controller.get('inputFields')).forEach(function (key) {
- expect(controller.get('inputFields.' + key + '.value')).to.equal(controller.get('inputFields.' + key + '.defaultValue'));
- });
- expect(controller.showCreateEditPopup.calledOnce).to.be.true;
- });
- });
- describe('#editAlertNotification()', function () {
- beforeEach(function () {
- sinon.stub(controller, 'showCreateEditPopup', Em.K);
- sinon.stub(controller, 'fillEditCreateInputs', Em.K);
- });
- afterEach(function () {
- controller.showCreateEditPopup.restore();
- controller.fillEditCreateInputs.restore();
- });
- it("should call fillEditCreateInputs and showCreateEditPopup", function () {
- controller.editAlertNotification();
- expect(controller.fillEditCreateInputs.calledOnce).to.be.true;
- expect(controller.showCreateEditPopup.calledWith(true)).to.be.true;
- });
- });
- describe('#fillEditCreateInputs()', function () {
- it("should map properties from selectedAlertNotification to inputFields (ambari.dispatch.recipients ignored)", function () {
- controller.set('selectedAlertNotification', Em.Object.create({
- name: 'test_name',
- global: true,
- description: 'test_description',
- type: 'EMAIL',
- alertStates: ['OK', 'UNKNOWN'],
- properties: {
- 'ambari.dispatch.recipients': [
- 'test1@test.test',
- 'test2@test.test'
- ],
- 'customName': 'customValue'
- }
- }));
- controller.set('inputFields', Em.Object.create({
- name: {
- value: ''
- },
- groups: {
- value: ''
- },
- global: {
- value: false
- },
- method: {
- value: ''
- },
- email: {
- value: ''
- },
- severityFilter: {
- value: []
- },
- description: {
- value: ''
- },
- customProperties: [
- {name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
- {name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
- ]
- }));
- controller.fillEditCreateInputs();
- expect(JSON.stringify(controller.get('inputFields'))).to.equal(JSON.stringify({
- name: {
- value: 'test_name'
- },
- groups: {
- value: ''
- },
- global: {
- value: true
- },
- method: {
- value: 'EMAIL'
- },
- email: {
- value: 'test1@test.test, test2@test.test'
- },
- severityFilter: {
- value: [true, false, false, true]
- },
- description: {
- value: 'test_description'
- },
- customProperties: [
- {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
- ]
- }));
- });
- });
- describe("#showCreateEditPopup()", function () {
- before(function () {
- sinon.stub(App.ModalPopup, 'show', function () {
- return 'popup';
- });
- });
- after(function () {
- App.ModalPopup.show.restore();
- });
- it("should open popup and set popup object to createEditPopup", function () {
- controller.set('createEditPopup', null);
- controller.showCreateEditPopup();
- expect(App.ModalPopup.show.calledOnce).to.be.true;
- expect(controller.get('createEditPopup')).to.equal('popup');
- });
- });
- describe("#formatNotificationAPIObject()", function () {
- it("should create object with properties from inputFields values", function () {
- controller.set('inputFields', Em.Object.create({
- name: {
- value: 'test_name'
- },
- groups: {
- value: ''
- },
- global: {
- value: false
- },
- method: {
- value: 'EMAIL'
- },
- email: {
- value: 'test1@test.test, test2@test.test,test3@test.test , test4@test.test'
- },
- severityFilter: {
- value: [true, false, true, false]
- },
- description: {
- value: 'test_description'
- },
- customProperties: [
- {name: 'n1', value: 'v1'},
- {name: 'n2', value: 'v2'}
- ]
- }));
- var result = controller.formatNotificationAPIObject();
- expect(result).to.eql({
- AlertTarget: {
- name: 'test_name',
- global: false,
- description: 'test_description',
- notification_type: 'EMAIL',
- alert_states: ['OK', 'CRITICAL'],
- properties: {
- 'ambari.dispatch.recipients': [
- 'test1@test.test',
- 'test2@test.test',
- 'test3@test.test',
- 'test4@test.test'
- ],
- 'n1': 'v1',
- 'n2': 'v2'
- }
- }
- });
- });
- });
- describe('#createAlertNotification()', function () {
- it("should send ajax request", function () {
- controller.createAlertNotification();
- expect(App.ajax.send.calledOnce).to.be.true;
- });
- });
- describe('#createAlertNotificationSuccessCallback()', function () {
- beforeEach(function () {
- controller.set('createEditPopup', {
- hide: Em.K
- });
- sinon.stub(controller, 'loadAlertNotifications', Em.K);
- sinon.spy(controller.createEditPopup, 'hide');
- });
- afterEach(function () {
- controller.loadAlertNotifications.restore();
- controller.createEditPopup.hide.restore();
- });
- it("should call loadAlertNotifications and createEditPopup.hide", function () {
- controller.createAlertNotificationSuccessCallback();
- expect(controller.loadAlertNotifications.calledOnce).to.be.true;
- expect(controller.createEditPopup.hide.calledOnce).to.be.true;
- });
- });
- describe('#updateAlertNotification()', function () {
- it("should send ajax request", function () {
- controller.createAlertNotification();
- expect(App.ajax.send.calledOnce).to.be.true;
- });
- });
- describe('#updateAlertNotificationSuccessCallback()', function () {
- beforeEach(function () {
- controller.set('createEditPopup', {
- hide: Em.K
- });
- sinon.stub(controller, 'loadAlertNotifications', Em.K);
- sinon.spy(controller.createEditPopup, 'hide');
- });
- afterEach(function () {
- controller.loadAlertNotifications.restore();
- controller.createEditPopup.hide.restore();
- });
- it("should call loadAlertNotifications and createEditPopup.hide", function () {
- controller.updateAlertNotificationSuccessCallback();
- expect(controller.loadAlertNotifications.calledOnce).to.be.true;
- expect(controller.createEditPopup.hide.calledOnce).to.be.true;
- });
- });
- describe('#deleteAlertNotification()', function () {
- beforeEach(function () {
- sinon.spy(App, 'showConfirmationPopup');
- });
- afterEach(function () {
- App.showConfirmationPopup.restore();
- });
- it("should show popup and send request on confirmation", function () {
- var popup = controller.deleteAlertNotification();
- expect(App.showConfirmationPopup.calledOnce).to.be.true;
- popup.onPrimary();
- expect(App.ajax.send.calledOnce).to.be.true;
- });
- });
- describe('#deleteAlertNotificationSuccessCallback()', function () {
- it("should call loadAlertNotifications, selectedAlertNotification.deleteRecord and set null to selectedAlertNotification", function () {
- var mockSelectedAlertNotification = {
- deleteRecord: Em.K
- };
- controller.set('selectedAlertNotification', mockSelectedAlertNotification);
- sinon.stub(controller, 'loadAlertNotifications', Em.K);
- sinon.spy(mockSelectedAlertNotification, 'deleteRecord');
- controller.deleteAlertNotificationSuccessCallback();
- expect(controller.loadAlertNotifications.calledOnce).to.be.true;
- expect(mockSelectedAlertNotification.deleteRecord.calledOnce).to.be.true;
- expect(controller.get('selectedAlertNotification')).to.equal(null);
- controller.loadAlertNotifications.restore();
- mockSelectedAlertNotification.deleteRecord.restore();
- });
- });
- describe('#duplicateAlertNotification()', function () {
- beforeEach(function () {
- sinon.stub(controller, 'fillEditCreateInputs', Em.K);
- sinon.stub(controller, 'showCreateEditPopup', Em.K);
- });
- afterEach(function () {
- controller.fillEditCreateInputs.restore();
- controller.showCreateEditPopup.restore();
- });
- it("should call fillEditCreateInputs and showCreateEditPopup", function () {
- controller.duplicateAlertNotification();
- expect(controller.fillEditCreateInputs.calledWith(true)).to.be.true;
- expect(controller.showCreateEditPopup.calledOnce).to.be.true;
- });
- });
- describe('#addCustomProperty', function () {
- beforeEach(function () {
- controller.set('inputFields.customProperties', []);
- });
- it('should add custom Property to customProperties', function () {
- controller.set('newCustomProperty', {name: 'n1', value: 'v1'});
- controller.addCustomProperty();
- helpers.nestedExpect([{name: 'n1', value: 'v1', defaultValue: 'v1'}], controller.get('inputFields.customProperties'));
- });
- });
- describe('#removeCustomPropertyHandler', function () {
- var c = {name: 'n2', value: 'v2', defaultValue: 'v2'};
- beforeEach(function () {
- controller.set('inputFields.customProperties', [
- {name: 'n1', value: 'v1', defaultValue: 'v1'},
- c,
- {name: 'n3', value: 'v3', defaultValue: 'v3'}
- ]);
- });
- it('should remove selected custom property', function () {
- controller.removeCustomPropertyHandler({context: c});
- helpers.nestedExpect(
- [
- {name: 'n1', value: 'v1', defaultValue: 'v1'},
- {name: 'n3', value: 'v3', defaultValue: 'v3'}
- ],
- controller.get('inputFields.customProperties')
- );
- });
- });
- describe('#addCustomPropertyHandler', function () {
- it('should clean up newCustomProperty on primary click', function () {
- controller.set('newCustomProperty', {name: 'n1', value: 'v1'});
- controller.addCustomPropertyHandler().onPrimary();
- expect(controller.get('newCustomProperty')).to.eql({name: '', value: ''});
- });
- describe('#bodyClass', function () {
- var view;
- beforeEach(function () {
- view = controller.addCustomPropertyHandler().get('bodyClass').create({
- parentView: Em.View.create(),
- controller: Em.Object.create({
- inputFields: Em.Object.create({
- customProperties: [
- {name: 'n1', value: 'v1', defaultValue: 'v1'}
- ]
- }),
- newCustomProperty: {name: '', value: ''}
- })
- });
- });
- describe('#errorHandler', function () {
- it('should fire invalid name', function () {
- view.set('controller.newCustomProperty.name', '!!');
- view.errorsHandler();
- expect(view.get('isError')).to.be.true;
- expect(view.get('parentView.disablePrimary')).to.be.true;
- expect(view.get('errorMessage.length') > 0).to.be.true;
- });
- it('should fire existing property name', function () {
- view.set('controller.newCustomProperty.name', 'n1');
- view.errorsHandler();
- expect(view.get('isError')).to.be.true;
- expect(view.get('parentView.disablePrimary')).to.be.true;
- expect(view.get('errorMessage.length') > 0).to.be.true;
- });
- });
- });
- });
- });
|