1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048 |
- /**
- * 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');
- function getController() {
- return App.ManageAlertNotificationsController.create({});
- }
- var createEditPopupView = getController().showCreateEditPopup();
- describe('App.ManageAlertNotificationsController', function () {
- beforeEach(function () {
- controller = getController();
- });
- 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;
- });
- });
- 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 () {
- var inputFields = Em.Object.create({
- a: {
- value: '',
- defaultValue: 'a'
- },
- b: {
- value: '',
- defaultValue: 'b'
- },
- c: {
- value: '',
- defaultValue: 'c'
- },
- severityFilter: {
- value: [],
- defaultValue: ['OK', 'WARNING', 'CRITICAL', 'UNKNOWN']
- },
- global: {
- value: false
- },
- allGroups: Em.Object.create({
- value: 'custom'
- })
- });
- beforeEach(function () {
- sinon.stub(controller, 'showCreateEditPopup');
- controller.set('inputFields', inputFields);
- controller.addAlertNotification();
- });
- afterEach(function () {
- controller.showCreateEditPopup.restore();
- });
- Object.keys(inputFields).forEach(function (key) {
- it(key, function () {
- expect(controller.get('inputFields.' + key + '.value')).to.be.eql(controller.get('inputFields.' + key + '.defaultValue'));
- });
- });
- it("should call showCreateEditPopup", function () {
- 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) - EMAIL", function () {
- controller.set('selectedAlertNotification', Em.Object.create({
- name: 'test_name',
- global: true,
- description: 'test_description',
- groups: ['test1', 'test2'],
- type: 'EMAIL',
- alertStates: ['OK', 'UNKNOWN'],
- properties: {
- 'ambari.dispatch.recipients': [
- 'test1@test.test',
- 'test2@test.test'
- ],
- 'customName': 'customValue',
- "mail.smtp.from" : "from",
- "ambari.dispatch.credential.username" : "user",
- "mail.smtp.host" : "s1",
- "mail.smtp.port" : "25",
- "mail.smtp.auth" : "true",
- "ambari.dispatch.credential.password" : "pass",
- "mail.smtp.starttls.enable" : "true"
- }
- }));
- controller.set('inputFields', Em.Object.create({
- name: {
- value: ''
- },
- groups: {
- value: []
- },
- global: {
- value: false
- },
- allGroups: {
- value: false
- },
- method: {
- value: ''
- },
- email: {
- value: ''
- },
- severityFilter: {
- value: []
- },
- description: {
- value: ''
- },
- SMTPServer: {
- value: ''
- },
- SMTPPort: {
- value: ''
- },
- SMTPUseAuthentication: {
- value: ''
- },
- SMTPUsername: {
- value: ''
- },
- SMTPPassword: {
- value: ''
- },
- retypeSMTPPassword: {
- value: ''
- },
- SMTPSTARTTLS: {
- value: ''
- },
- emailFrom: {
- value: ''
- },
- version: {
- value: ''
- },
- OIDs: {
- value: ''
- },
- community: {
- value: ''
- },
- host: {
- value: ''
- },
- port: {
- 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: ['test1', 'test2']
- },
- global: {
- value: true,
- disabled: true
- },
- allGroups: {
- value: 'all'
- },
- method: {
- value: 'EMAIL'
- },
- email: {
- value: 'test1@test.test, test2@test.test'
- },
- severityFilter: {
- value: ['OK', 'UNKNOWN']
- },
- description: {
- value: 'test_description'
- },
- SMTPServer: {
- value: 's1'
- },
- SMTPPort: {
- value: '25'
- },
- SMTPUseAuthentication: {
- value: true
- },
- SMTPUsername: {
- value: 'user'
- },
- SMTPPassword: {
- value: 'pass'
- },
- retypeSMTPPassword: {
- value: 'pass'
- },
- SMTPSTARTTLS: {
- value: true
- },
- emailFrom: {
- value: 'from'
- },
- version: {},
- OIDs: {},
- community: {},
- host: {
- value: 'test1@test.test, test2@test.test'
- },
- port: {},
- customProperties: [
- {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
- ]
- }));
- });
- it("should map properties from selectedAlertNotification to inputFields (ambari.dispatch.recipients ignored) - SNMP", function () {
- controller.set('selectedAlertNotification', Em.Object.create({
- name: 'test_SNMP_name',
- global: true,
- description: 'test_description',
- groups: ['test1', 'test2'],
- type: 'SNMP',
- alertStates: ['OK', 'UNKNOWN'],
- properties: {
- 'ambari.dispatch.recipients': [
- 'c6401.ambari.apache.org',
- 'c6402.ambari.apache.org'
- ],
- 'customName': 'customValue',
- 'ambari.dispatch.snmp.version': 'SNMPv1',
- 'ambari.dispatch.snmp.oids.trap': '1',
- 'ambari.dispatch.snmp.community': 'snmp',
- 'ambari.dispatch.snmp.port': 161
- }
- }));
- controller.set('inputFields', Em.Object.create({
- name: {
- value: ''
- },
- groups: {
- value: []
- },
- global: {
- value: false
- },
- allGroups: {
- value: false
- },
- method: {
- value: ''
- },
- email: {
- value: ''
- },
- severityFilter: {
- value: []
- },
- description: {
- value: ''
- },
- SMTPServer: {
- value: ''
- },
- SMTPPort: {
- value: ''
- },
- SMTPUseAuthentication: {
- value: ''
- },
- SMTPUsername: {
- value: ''
- },
- SMTPPassword: {
- value: ''
- },
- retypeSMTPPassword: {
- value: ''
- },
- SMTPSTARTTLS: {
- value: ''
- },
- emailFrom: {
- value: ''
- },
- version: {
- value: ''
- },
- OIDs: {
- value: ''
- },
- community: {
- value: ''
- },
- host: {
- value: ''
- },
- port: {
- 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_SNMP_name'
- },
- groups: {
- value: ['test1', 'test2']
- },
- global: {
- value: true,
- disabled: true
- },
- allGroups: {
- value: 'all'
- },
- method: {
- value: 'SNMP'
- },
- email: {
- value: 'c6401.ambari.apache.org, c6402.ambari.apache.org'
- },
- severityFilter: {
- value: ['OK', 'UNKNOWN']
- },
- description: {
- value: 'test_description'
- },
- SMTPServer: {},
- SMTPPort: {},
- SMTPUseAuthentication: {
- value: true
- },
- SMTPUsername: {},
- SMTPPassword: {},
- retypeSMTPPassword: {},
- SMTPSTARTTLS: {
- value: true
- },
- emailFrom: {},
- version: {
- value:'SNMPv1'
- },
- OIDs: {
- value: '1'
- },
- community: {
- value: 'snmp'
- },
- host: {
- value: 'c6401.ambari.apache.org, c6402.ambari.apache.org'
- },
- port: {
- value: 161
- },
- customProperties: [
- {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
- ]
- }));
- })
- });
- describe("#showCreateEditPopup()", function () {
- beforeEach(function () {
- sinon.spy(App.ModalPopup, 'show');
- });
- afterEach(function () {
- App.ModalPopup.show.restore();
- });
- it("should open popup and set popup object to createEditPopup", function () {
- controller.showCreateEditPopup();
- expect(App.ModalPopup.show.calledOnce).to.be.true;
- });
- App.TestAliases.testAsComputedOr(getController().showCreateEditPopup(), 'disablePrimary', ['isSaving', 'hasErrors']);
- describe('#bodyClass', function () {
- function getBodyClass() {
- return createEditPopupView.get('bodyClass').create({
- controller: Em.Object.create({
- inputFields: {
- name: {},
- global: {},
- allGroups: {},
- SMTPPassword: {},
- retypeSMTPPassword: {},
- method: {}
- }
- }),
- groupSelect: Em.Object.create({
- selection: [],
- content: [{}, {}]
- }),
- parentView: Em.Object.create({
- hasErrors: false
- })
- });
- }
- var view;
- beforeEach(function () {
- view = getBodyClass();
- });
- App.TestAliases.testAsComputedOr(getBodyClass(), 'someErrorExists', ['nameError', 'emailToError', 'emailFromError', 'smtpPortError', 'hostError', 'portError', 'passwordError']);
- describe('#selectAllGroups', function () {
- it('should check inputFields.allGroups.value', function () {
- view.set('controller.inputFields.allGroups.value', 'all');
- view.selectAllGroups();
- expect(view.get('groupSelect.selection')).to.eql([]);
- view.set('controller.inputFields.allGroups.value', 'custom');
- view.selectAllGroups();
- expect(view.get('groupSelect.selection')).to.eql([{}, {}]);
- });
- });
- describe('#clearAllGroups', function () {
- it('should check inputFields.allGroups.value', function () {
- view.set('controller.inputFields.allGroups.value', 'custom');
- view.selectAllGroups();
- view.set('controller.inputFields.allGroups.value', 'all');
- view.clearAllGroups();
- expect(view.get('groupSelect.selection')).to.eql([{}, {}]);
- view.set('controller.inputFields.allGroups.value', 'custom');
- view.clearAllGroups();
- expect(view.get('groupSelect.selection')).to.eql([]);
- });
- });
- describe('#nameValidation', function () {
- it('should check inputFields.name.value', function () {
- view.set('controller.inputFields.name.value', '');
- expect(view.get('controller.inputFields.name.errorMsg')).to.equal(Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.empty'));
- expect(view.get('parentView.hasErrors')).to.be.true;
- });
- it('should check inputFields.name.value (2)', function () {
- view.set('controller.inputFields.name.errorMsg', 'error');
- view.set('controller.inputFields.name.value', 'test');
- expect(view.get('controller.inputFields.name.errorMsg')).to.equal('');
- });
- it('should check inputFields.name.value (3)', function () {
- view.set('isEdit', true);
- view.set('controller.inputFields.name.value', '');
- expect(view.get('controller.inputFields.name.errorMsg')).to.equal(Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.empty'));
- expect(view.get('parentView.hasErrors')).to.be.true;
- });
- it('should check inputFields.name.value (4)', function () {
- view.set('isEdit', true);
- view.set('controller.inputFields.name.errorMsg', 'error');
- view.set('controller.inputFields.name.value', 'test');
- expect(view.get('controller.inputFields.name.errorMsg')).to.equal('');
- });
- });
- describe('#retypePasswordValidation', function () {
- it('should check inputFields.retypeSMTPPassword.value', function () {
- view.set('controller.inputFields.retypeSMTPPassword.errorMsg', null);
- view.set('controller.inputFields.SMTPPassword.value', 'pass');
- view.set('controller.inputFields.retypeSMTPPassword.value', 'pas');
- expect(view.get('controller.inputFields.retypeSMTPPassword.errorMsg')).to.equal(Em.I18n.t('alerts.notifications.error.retypePassword'));
- expect(view.get('parentView.hasErrors')).to.be.true;
- });
- it('should check inputFields.retypeSMTPPassword.value (2)', function () {
- view.set('parentView.hasErrors', true);
- view.set('controller.inputFields.retypeSMTPPassword.errorMsg', 'error');
- view.set('controller.inputFields.SMTPPassword.value', 'pass');
- view.set('controller.inputFields.retypeSMTPPassword.value', 'pass');
- expect(view.get('controller.inputFields.retypeSMTPPassword.errorMsg')).to.equal(null);
- expect(view.get('parentView.hasErrors')).to.be.false;
- });
- });
- describe('#methodObserver', function () {
- var cases = [
- {
- method: 'EMAIL',
- errors: ['portError', 'hostError'],
- validators: ['emailToValidation', 'emailFromValidation', 'smtpPortValidation', 'retypePasswordValidation']
- },
- {
- method: 'SNMP',
- errors: ['emailToError', 'emailFromError', 'smtpPortError', 'passwordError'],
- validators: ['portValidation', 'hostsValidation']
- }
- ],
- validators = [];
- before(function () {
- cases.forEach(function (item) {
- validators.pushObjects(item.validators);
- });
- });
- beforeEach(function () {
- validators.forEach(function (item) {
- sinon.stub(view, item, Em.K);
- });
- });
- afterEach(function () {
- validators.forEach(function (item) {
- view.get(item).restore();
- });
- });
- cases.forEach(function (item) {
- describe(item.method, function () {
- beforeEach(function () {
- item.errors.forEach(function (errorName) {
- view.set(errorName, true);
- });
- view.set('controller.inputFields.method.value', item.method);
- });
- item.errors.forEach(function (errorName) {
- it(errorName + ' is false', function () {
- expect(view.get(errorName)).to.be.false;
- });
- });
- validators.forEach(function (validatorName) {
- var called = item.validators.contains(validatorName);
- it(validatorName + ' ' + (called ? '' : 'not') + ' called', function () {
- expect(view.get(validatorName).calledOnce).to.equal(called);
- });
- });
- });
- });
- });
- });
- });
- describe("#formatNotificationAPIObject()", function () {
- var inputFields = Em.Object.create({
- name: {
- value: 'test_name'
- },
- groups: {
- value: [{id: 1}, {id: 2}, {id: 3}]
- },
- allGroups: {
- value: 'custom'
- },
- global: {
- value: false
- },
- method: {
- value: 'EMAIL'
- },
- email: {
- value: 'test1@test.test, test2@test.test,test3@test.test , test4@test.test'
- },
- severityFilter: {
- value: ['OK', 'CRITICAL']
- },
- SMTPServer: {
- value: 's1'
- },
- SMTPPort: {
- value: '25'
- },
- SMTPUseAuthentication: {
- value: "true"
- },
- SMTPUsername: {
- value: 'user'
- },
- SMTPPassword: {
- value: 'pass'
- },
- SMTPSTARTTLS: {
- value: "true"
- },
- emailFrom: {
- value: 'from'
- },
- description: {
- value: 'test_description'
- },
- customProperties: [
- {name: 'n1', value: 'v1'},
- {name: 'n2', value: 'v2'}
- ]
- });
- it("should create object with properties from inputFields values", function () {
- controller.set('inputFields', inputFields);
- var result = controller.formatNotificationAPIObject();
- expect(JSON.stringify(result)).to.eql(JSON.stringify({
- AlertTarget: {
- name: 'test_name',
- description: 'test_description',
- global: false,
- notification_type: 'EMAIL',
- alert_states: ['OK', 'CRITICAL'],
- properties: {
- 'ambari.dispatch.recipients': [
- 'test1@test.test',
- 'test2@test.test',
- 'test3@test.test',
- 'test4@test.test'
- ],
- "mail.smtp.host" : "s1",
- "mail.smtp.port" : "25",
- "mail.smtp.from" : "from",
- "mail.smtp.auth" : "true",
- "ambari.dispatch.credential.username" : "user",
- "ambari.dispatch.credential.password" : "pass",
- "mail.smtp.starttls.enable" : "true",
- 'n1': 'v1',
- 'n2': 'v2'
- },
- groups: [1,2,3]
- }
- }));
- });
- it('should ignore groups if global is true', function () {
- controller.set('inputFields', inputFields);
- controller.set('inputFields.allGroups.value', 'all');
- var result = controller.formatNotificationAPIObject();
- expect(Em.keys(result.AlertTarget)).to.not.contain('groups');
- });
- });
- describe('#createAlertNotification()', function () {
- it("should send ajax request", function () {
- controller.createAlertNotification();
- var args = helpers.findAjaxRequest('name', 'alerts.create_alert_notification');
- expect(args[0]).to.exists;
- });
- });
- 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.updateAlertNotification();
- var args = helpers.findAjaxRequest('name', 'alerts.update_alert_notification');
- expect(args[0]).to.exists;
- });
- });
- 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();
- var args = helpers.findAjaxRequest('name', 'alerts.delete_alert_notification');
- expect(args[0]).to.exists;
- });
- });
- describe('#deleteAlertNotificationSuccessCallback()', function () {
- var mockSelectedAlertNotification;
- beforeEach(function () {
- mockSelectedAlertNotification = {
- deleteRecord: Em.K
- };
- controller.set('selectedAlertNotification', mockSelectedAlertNotification);
- sinon.stub(controller, 'loadAlertNotifications', Em.K);
- sinon.spy(mockSelectedAlertNotification, 'deleteRecord');
- controller.deleteAlertNotificationSuccessCallback();
- });
- afterEach(function () {
- controller.loadAlertNotifications.restore();
- mockSelectedAlertNotification.deleteRecord.restore();
- });
- it("should call loadAlertNotifications", function () {
- expect(controller.loadAlertNotifications.calledOnce).to.be.true;
- });
- it("should call selectedAlertNotification.deleteRecord", function () {
- expect(mockSelectedAlertNotification.deleteRecord.calledOnce).to.be.true;
- });
- it("should set null to selectedAlertNotification", function () {
- expect(controller.get('selectedAlertNotification')).to.equal(null);
- });
- });
- 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', []);
- });
- /*eslint-disable mocha-cleanup/asserts-limit */
- 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'));
- });
- /*eslint-enable mocha-cleanup/asserts-limit */
- });
- 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'}
- ]);
- });
- /*eslint-disable mocha-cleanup/asserts-limit */
- 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')
- );
- });
- /*eslint-enable mocha-cleanup/asserts-limit */
- });
- 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;
- });
- });
- });
- });
- });
|