123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- /**
- * 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.
- */
- App = require('app');
- require('controllers/main/service/widgets/create/step3_controller');
- describe('App.WidgetWizardStep3Controller', function () {
- var controller = App.WidgetWizardStep3Controller.create({
- content: Em.Object.create()
- });
- App.TestAliases.testAsComputedEqual(controller, 'isEditController', 'content.controllerName', 'widgetEditController');
- App.TestAliases.testAsComputedIfThenElse(controller, 'widgetScope', 'isSharedChecked', 'Cluster', 'User');
- App.TestAliases.testAsComputedGte(controller, 'isNameInvalid', 'widgetName.length', 129);
- App.TestAliases.testAsComputedGte(controller, 'isDescriptionInvalid', 'widgetDescription.length', 2049);
- describe("#isSubmitDisabled", function () {
- it("widgetName - null", function () {
- controller.set('widgetName', null);
- controller.propertyDidChange('isSubmitDisabled');
- expect(controller.get('isSubmitDisabled')).to.be.true;
- });
- it("widgetName empty ", function () {
- controller.set('widgetName', '');
- controller.propertyDidChange('isSubmitDisabled');
- expect(controller.get('isSubmitDisabled')).to.be.true;
- });
- it("widgetName contains only whitespace", function () {
- controller.set('widgetName', ' ');
- controller.propertyDidChange('isSubmitDisabled');
- expect(controller.get('isSubmitDisabled')).to.be.true;
- });
- it("widgetName correct", function () {
- controller.set('widgetName', 'w1');
- controller.propertyDidChange('isSubmitDisabled');
- expect(controller.get('isSubmitDisabled')).to.be.false;
- });
- });
- describe("#initPreviewData()", function () {
- beforeEach(function () {
- sinon.stub(controller, 'addObserver');
- });
- afterEach(function () {
- controller.addObserver.restore();
- });
- it("", function () {
- controller.set('content', Em.Object.create({
- widgetProperties: 'widgetProperties',
- widgetValues: 'widgetValues',
- widgetMetrics: 'widgetMetrics',
- widgetAuthor: 'widgetAuthor',
- widgetName: 'widgetName',
- widgetDescription: 'widgetDescription',
- widgetScope: 'CLUSTER',
- controllerName: 'widgetEditController'
- }));
- controller.initPreviewData();
- controller.get('isSharedCheckboxDisabled') ? expect(controller.addObserver.calledWith('isSharedChecked')).to.be.false:
- expect(controller.addObserver.calledWith('isSharedChecked')).to.be.true;
- expect(controller.get('widgetProperties')).to.equal('widgetProperties');
- expect(controller.get('widgetValues')).to.equal('widgetValues');
- expect(controller.get('widgetMetrics')).to.equal('widgetMetrics');
- expect(controller.get('widgetAuthor')).to.equal('widgetAuthor');
- expect(controller.get('widgetName')).to.equal('widgetName');
- expect(controller.get('widgetDescription')).to.equal('widgetDescription');
- expect(controller.get('isSharedChecked')).to.be.true;
- expect(controller.get('isSharedCheckboxDisabled')).to.be.true;
- });
- });
- describe("#showConfirmationOnSharing()", function () {
- beforeEach(function () {
- sinon.spy(App, 'showConfirmationFeedBackPopup');
- });
- afterEach(function () {
- App.showConfirmationFeedBackPopup.restore();
- });
- it("isSharedChecked - false", function () {
- controller.set('isSharedChecked', false);
- controller.showConfirmationOnSharing();
- expect(App.showConfirmationFeedBackPopup.called).to.be.false;
- });
- it("isSharedChecked - true", function () {
- controller.set('isSharedChecked', true);
- var popup = controller.showConfirmationOnSharing();
- expect(App.showConfirmationFeedBackPopup.calledOnce).to.be.true;
- popup.onSecondary();
- expect(controller.get('isSharedChecked')).to.be.false;
- popup.onPrimary();
- expect(controller.get('isSharedChecked')).to.be.true;
- });
- });
- describe("#collectWidgetData()", function () {
- it("", function () {
- controller.setProperties({
- widgetName: 'widgetName',
- content: Em.Object.create({widgetType: 'T1'}),
- widgetDescription: 'widgetDescription',
- widgetScope: 'Cluster',
- widgetAuthor: 'widgetAuthor',
- widgetMetrics: [{data: 'data', name: 'm1'}],
- widgetValues: [{computedValue: 'cv', value: 'v'}],
- widgetProperties: 'widgetProperties'
- });
- expect(controller.collectWidgetData()).to.eql({
- "WidgetInfo": {
- "widget_name": "widgetName",
- "widget_type": "T1",
- "description": "widgetDescription",
- "scope": "CLUSTER",
- "author": "widgetAuthor",
- "metrics": [
- {
- "name": "m1"
- }
- ],
- "values": [
- {
- "value": "v"
- }
- ],
- "properties": "widgetProperties"
- }
- });
- });
- });
- describe("#cancel()", function () {
- var mock = {
- cancel: Em.K
- };
- beforeEach(function () {
- sinon.spy(mock, 'cancel');
- sinon.stub(App.router, 'get').returns(mock);
- });
- afterEach(function () {
- App.router.get.restore();
- mock.cancel.restore();
- });
- it("", function () {
- controller.cancel();
- expect(mock.cancel.calledOnce).to.be.true;
- });
- });
- describe("#complete()", function () {
- var mock = {
- finishWizard: Em.K
- };
- beforeEach(function () {
- sinon.spy(mock, 'finishWizard');
- sinon.stub(controller, 'collectWidgetData');
- sinon.stub(App.router, 'get').returns(mock);
- sinon.stub(App.router, 'send');
- });
- afterEach(function () {
- App.router.get.restore();
- App.router.send.restore();
- controller.collectWidgetData.restore();
- mock.finishWizard.restore();
- });
- it("", function () {
- controller.complete();
- expect(controller.collectWidgetData.calledOnce).to.be.true;
- expect(App.router.send.calledWith('complete')).to.be.true;
- expect(mock.finishWizard.calledOnce).to.be.true;
- });
- });
- });
|