123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- /**
- * 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 view;
- describe('App.ManageAlertNotificationsView', function () {
- beforeEach(function () {
- view = App.ManageAlertNotificationsView.create({
- controller: Em.Object.create()
- });
- });
- describe('#buttonObserver', function () {
- Em.A([
- {
- isOperator: false,
- selectedAlertNotification: {id: 1},
- m: 'some alert notification is selected and user is an admin',
- p: {
- isAddButtonDisabled: true,
- isEditButtonDisabled: true,
- isRemoveButtonDisabled: true,
- isDuplicateButtonDisabled: true
- },
- e: {
- isAddButtonDisabled: false,
- isEditButtonDisabled: false,
- isRemoveButtonDisabled: false,
- isDuplicateButtonDisabled: false
- }
- },
- {
- isOperator: true,
- selectedAlertNotification: {id: 1},
- m: 'some alert notification is selected and user is a non-admin operator',
- p: {
- isAddButtonDisabled: true,
- isEditButtonDisabled: true,
- isRemoveButtonDisabled: true,
- isDuplicateButtonDisabled: true
- },
- e: {
- isAddButtonDisabled: true,
- isEditButtonDisabled: true,
- isRemoveButtonDisabled: true,
- isDuplicateButtonDisabled: true
- }
- },
- {
- isOperator: false,
- selectedAlertNotification: null,
- m: 'some alert notification is not selected and user is an admin',
- p: {
- isAddButtonDisabled: true,
- isEditButtonDisabled: false,
- isRemoveButtonDisabled: false,
- isDuplicateButtonDisabled: false
- },
- e: {
- isAddButtonDisabled: true,
- isEditButtonDisabled: true,
- isRemoveButtonDisabled: true,
- isDuplicateButtonDisabled: true
- }
- },
- {
- isOperator: true,
- selectedAlertNotification: null,
- m: 'some alert notification is not selected and user is a non-admin operator',
- p: {
- isAddButtonDisabled: true,
- isEditButtonDisabled: false,
- isRemoveButtonDisabled: false,
- isDuplicateButtonDisabled: false
- },
- e: {
- isAddButtonDisabled: true,
- isEditButtonDisabled: true,
- isRemoveButtonDisabled: true,
- isDuplicateButtonDisabled: true
- }
- }
- ]).forEach(function (test) {
- describe(test.m, function () {
- beforeEach(function () {
- view.setProperties(test.p);
- view.set('controller.selectedAlertNotification', test.selectedAlertNotification);
- App.isOperator = test.isOperator;
- view.buttonObserver();
- });
- Em.keys(test.e).forEach(function (k) {
- it(k, function () {
- expect(view.get(k)).to.equal(test.e[k]);
- });
- });
- });
- });
- });
- describe('#showEmailDetails', function () {
- Em.A([
- {
- selectedAlertNotification: {type: 'SNMP'},
- e: false
- },
- {
- selectedAlertNotification: {type: 'EMAIL'},
- e: true
- }
- ]).forEach(function (test, i) {
- it('test ' + (i + 1), function () {
- view.set('controller.selectedAlertNotification', test.selectedAlertNotification);
- expect(view.get('showEmailDetails')).to.equal(test.e);
- });
- });
- });
- describe('#showSNMPDetails', function () {
- Em.A([
- {
- selectedAlertNotification: {type: 'SNMP'},
- e: true
- },
- {
- selectedAlertNotification: {type: 'EMAIL'},
- e: false
- }
- ]).forEach(function (test, i) {
- it('test ' + (i + 1), function () {
- view.set('controller.selectedAlertNotification', test.selectedAlertNotification);
- expect(view.get('showSNMPDetails')).to.equal(test.e);
- });
- });
- });
- describe("#selectedAlertNotificationGroups", function () {
- it("should contain group names", function () {
- view.set('controller', Em.Object.create({
- selectedAlertNotification: Em.Object.create({
- groups: [
- Em.Object.create({
- displayName: 'g1'
- }),
- Em.Object.create({
- displayName: 'g2'
- })
- ]
- })
- }));
- expect(view.get('selectedAlertNotificationGroups')).to.equal('g1, g2');
- });
- });
- describe("#email", function () {
- it("should return ambari.dispatch.recipients", function () {
- view.set('controller', Em.Object.create({
- selectedAlertNotification: Em.Object.create({
- properties: {
- 'ambari.dispatch.recipients': 1
- }
- })
- }));
- expect(view.get('email')).to.equal(1);
- });
- });
- describe("#severities", function () {
- it("should return list of states", function () {
- view.set('controller', Em.Object.create({
- selectedAlertNotification: Em.Object.create({
- alertStates: ['st1', 'st2']
- })
- }));
- expect(view.get('severities')).to.equal('st1, st2');
- });
- });
- describe("#onAlertNotificationSelect()", function () {
- beforeEach(function () {
- view.removeObserver('selectedAlertNotification', view, 'onAlertNotificationSelect');
- view.set('controller', Em.Object.create({selectedAlertNotification: null}));
- });
- it("selectedAlertNotification is null", function () {
- view.set('selectedAlertNotification', null);
- view.onAlertNotificationSelect();
- expect(view.get('selectedAlertNotification')).to.be.null;
- expect(view.get('controller.selectedAlertNotification')).to.be.null;
- });
- it("selectedAlertNotification is empty array", function () {
- view.set('selectedAlertNotification', []);
- view.onAlertNotificationSelect();
- expect(view.get('selectedAlertNotification')).to.be.empty;
- expect(view.get('controller.selectedAlertNotification')).to.be.null;
- });
- it("selectedAlertNotification is array with single element", function () {
- view.set('selectedAlertNotification', [1]);
- view.onAlertNotificationSelect();
- expect(view.get('selectedAlertNotification')).to.eql([1]);
- expect(view.get('controller.selectedAlertNotification')).to.equal(1);
- });
- it("selectedAlertNotification is array with two elements", function () {
- view.set('selectedAlertNotification', [1, 2]);
- view.onAlertNotificationSelect();
- expect(view.get('selectedAlertNotification')).to.equal(2);
- expect(view.get('controller.selectedAlertNotification')).to.equal(2);
- });
- });
- describe("#willInsertElement()", function () {
- beforeEach(function () {
- view.set('controller', Em.Object.create({loadAlertNotifications: Em.K}));
- sinon.spy(view.get('controller'), 'loadAlertNotifications');
- });
- afterEach(function () {
- view.get('controller').loadAlertNotifications.restore();
- });
- it("loadAlertNotifications should be called", function () {
- view.willInsertElement();
- expect(view.get('controller').loadAlertNotifications.calledOnce).to.be.true;
- });
- });
- describe("#didInsertElement()", function () {
- beforeEach(function () {
- sinon.stub(view, 'onLoad');
- });
- afterEach(function () {
- view.onLoad.restore();
- });
- it("loadAlertNotifications should be called", function () {
- view.didInsertElement();
- expect(view.onLoad.calledOnce).to.be.true;
- });
- });
- describe("#onLoad()", function () {
- beforeEach(function () {
- view.removeObserver('controller.isLoaded', view, 'onLoad');
- view.set('controller', Em.Object.create());
- sinon.stub(view, 'buttonObserver');
- sinon.stub(Em.run, 'later', function (context, callback) {
- callback();
- });
- sinon.stub(App, 'tooltip');
- this.clock = sinon.useFakeTimers();
- });
- afterEach(function () {
- view.buttonObserver.restore();
- Em.run.later.restore();
- App.tooltip.restore();
- this.clock.restore();
- });
- it("controller.isLoaded is false", function () {
- view.set('controller.isLoaded', false);
- view.onLoad();
- expect(Em.run.later.called).to.be.false;
- });
- describe("controller.isLoaded is true, alertNotifications is null", function () {
- beforeEach(function () {
- view.set('controller.isLoaded', true);
- view.set('controller.alertNotifications', null);
- });
- it("Em.run.later should be called", function () {
- view.onLoad();
- expect(Em.run.later.calledOnce).to.be.true;
- });
- it("App.tooltip should be called twice", function () {
- view.onLoad();
- this.clock.tick(50);
- expect(App.tooltip.calledTwice).to.be.true;
- });
- it("selectedAlertNotification should be null", function () {
- view.onLoad();
- expect(view.get('selectedAlertNotification')).to.be.null;
- });
- it("isAddButtonDisabled should be true", function () {
- view.set('isAddButtonDisabled', true);
- App.isOperator = true;
- view.onLoad();
- expect(view.get('isAddButtonDisabled')).to.be.true;
- });
- it("isAddButtonDisabled should be false", function () {
- view.set('isAddButtonDisabled', true);
- App.isOperator = false;
- view.onLoad();
- expect(view.get('isAddButtonDisabled')).to.be.false;
- });
- });
- describe("controller.isLoaded is true, alertNotifications is array", function () {
- beforeEach(function () {
- view.set('controller.isLoaded', true);
- view.set('controller.alertNotifications', [{}]);
- });
- it("Em.run.later should be called", function () {
- view.onLoad();
- expect(Em.run.later.calledOnce).to.be.true;
- });
- it("App.tooltip should be called twice", function () {
- view.onLoad();
- this.clock.tick(50);
- expect(App.tooltip.calledTwice).to.be.true;
- });
- it("selectedAlertNotification should be object", function () {
- view.onLoad();
- expect(view.get('selectedAlertNotification')).to.eql({});
- });
- it("buttonObserver should be called", function () {
- view.onLoad();
- expect(view.buttonObserver.calledOnce).to.be.true;
- });
- });
- });
- });
|