You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2019/01/25 13:16:11 UTC
[ambari] branch trunk updated: AMBARI-25128 Cover widget mixin with
unit tests
This is an automated email from the ASF dual-hosted git repository.
atkach pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new 9e22cc9 AMBARI-25128 Cover widget mixin with unit tests
9e22cc9 is described below
commit 9e22cc9087c91f9cc8f6968c68c2744d8a8bc4d6
Author: Andrii Tkach <at...@apache.org>
AuthorDate: Fri Jan 25 14:18:10 2019 +0200
AMBARI-25128 Cover widget mixin with unit tests
---
.../app/mixins/common/widgets/widget_section.js | 265 ++++---
.../mixins/common/widgets/widget_section_test.js | 854 ++++++++++++++++++++-
.../modal_popups/select_groups_popup_test.js | 8 +-
3 files changed, 1003 insertions(+), 124 deletions(-)
diff --git a/ambari-web/app/mixins/common/widgets/widget_section.js b/ambari-web/app/mixins/common/widgets/widget_section.js
index 173ee2c..70639a8 100644
--- a/ambari-web/app/mixins/common/widgets/widget_section.js
+++ b/ambari-web/app/mixins/common/widgets/widget_section.js
@@ -19,6 +19,16 @@
var App = require('app');
App.WidgetSectionMixin = Ember.Mixin.create({
+
+ /**
+ * @Type {App.WidgetLayout}
+ */
+ activeWidgetLayout: {},
+
+ activeNSWidgetLayouts: [],
+
+ selectedNSWidgetLayout: {},
+
/**
* UI default layout name
*/
@@ -74,7 +84,7 @@ App.WidgetSectionMixin = Ember.Mixin.create({
var isServiceWithWidgetdescriptor;
var serviceName = this.get('content.serviceName');
if (serviceName) {
- isServiceWithWidgetdescriptor = App.StackService.find().findProperty('serviceName', serviceName).get('isServiceWithWidgets');
+ isServiceWithWidgetdescriptor = App.StackService.find(serviceName).get('isServiceWithWidgets');
} else if (this.get('sectionName') === 'SYSTEM_HEATMAPS') {
isServiceWithWidgetdescriptor = true;
}
@@ -86,11 +96,6 @@ App.WidgetSectionMixin = Ember.Mixin.create({
}.property('content.serviceName', 'sectionNameSuffix', 'App.hasNameNodeFederation'),
/**
- * @Type {App.WidgetLayout}
- */
- activeWidgetLayout: {},
-
- /**
* @type {Em.A}
*/
widgets: function () {
@@ -100,10 +105,6 @@ App.WidgetSectionMixin = Ember.Mixin.create({
return [];
}.property('isWidgetsLoaded', 'activeWidgetLayout.widgets'),
- activeNSWidgetLayouts: [],
-
- selectedNSWidgetLayout: {},
-
isAmbariMetricsInstalled: function () {
return App.Service.find().someProperty('serviceName', 'AMBARI_METRICS');
}.property('App.router.mainServiceController.content.length'),
@@ -144,44 +145,54 @@ App.WidgetSectionMixin = Ember.Mixin.create({
* @param {object|null} data
*/
getActiveWidgetLayoutSuccessCallback: function (data) {
- var self = this;
if (this.get('isHDFSFederatedSummary')) {
- this.getNameNodeWidgets().done(function (widgets) {
+ this.getNameNodeWidgets().done((widgets) => {
widgets = widgets.items;
var widgetsNamespaces = widgets.mapProperty('WidgetInfo.tag').uniq().without(null);
- var namespaces = App.HDFSService.find().objectAt(0).get('masterComponentGroups').mapProperty('name');
+ var namespaces = App.HDFSService.find('HDFS').get('masterComponentGroups').mapProperty('name');
var defaultNNWidgets = widgets.filterProperty('WidgetInfo.tag', null);
var widgetsToCreateCount;
if (namespaces.length > widgetsNamespaces.length) {
widgetsToCreateCount = (namespaces.length - widgetsNamespaces.length) * defaultNNWidgets.length;
- namespaces.forEach(function (namespace) {
+ namespaces.forEach((namespace) => {
if (!widgetsNamespaces.contains(namespace)) {
- defaultNNWidgets.forEach(function (widget) {
- if (widget.href) {
- delete widget.href;
- delete widget.WidgetInfo.id;
- delete widget.WidgetInfo.cluster_name;
- delete widget.WidgetInfo.author;
- widget.WidgetInfo.metrics = JSON.parse(widget.WidgetInfo.metrics);
- widget.WidgetInfo.values = JSON.parse(widget.WidgetInfo.values);
- }
- widget.WidgetInfo.tag = namespace;
- self.postWidget(widget).done(function () {
- if (!--widgetsToCreateCount) {
- self.createLayouts(data);
- }
- });
+ defaultNNWidgets.forEach((widget) => {
+ this.postNNWidgets(widget, widgetsToCreateCount, data, namespace);
});
}
});
} else {
- self.createLayouts(data);
+ this.createLayouts(data);
}
})
} else {
this.createLayouts(data);
}
},
+
+ /**
+ *
+ * @param widget
+ * @param widgetsToCreateCount
+ * @param data
+ * @param namespace
+ */
+ postNNWidgets: function(widget, widgetsToCreateCount, data, namespace) {
+ if (widget.href) {
+ delete widget.href;
+ delete widget.WidgetInfo.id;
+ delete widget.WidgetInfo.cluster_name;
+ delete widget.WidgetInfo.author;
+ widget.WidgetInfo.metrics = JSON.parse(widget.WidgetInfo.metrics);
+ widget.WidgetInfo.values = JSON.parse(widget.WidgetInfo.values);
+ }
+ widget.WidgetInfo.tag = namespace;
+ this.postWidget(widget).done(() => {
+ if (!--widgetsToCreateCount) {
+ this.createLayouts(data);
+ }
+ });
+ },
getNameNodeWidgets: function () {
return App.ajax.send({
@@ -206,39 +217,48 @@ App.WidgetSectionMixin = Ember.Mixin.create({
createLayouts: function (data) {
var self = this;
if (data.items[0]) {
- var hdfs = App.HDFSService.find().objectAt(0);
- if (hdfs && this.get('isHDFSFederatedSummary') && hdfs.get('masterComponentGroups').length + 2 !== data.items.length) {
+ var hdfs = App.HDFSService.find('HDFS');
+ if (hdfs.get('isLoaded') && this.get('isHDFSFederatedSummary') && hdfs.get('masterComponentGroups').length + 2 !== data.items.length) {
this.createFederationWidgetLayouts(data);
} else {
- self.getWidgetLayoutSuccessCallback(data);
+ this.getWidgetLayoutSuccessCallback(data);
}
} else {
- self.getAllActiveWidgetLayouts().done(function (activeWidgetLayoutsData) {
+ this.getAllActiveWidgetLayouts().done(function (activeWidgetLayoutsData) {
self.getDefaultWidgetLayoutByName(self.get('defaultLayoutName')).done(function (defaultWidgetLayoutData) {
defaultWidgetLayoutData = defaultWidgetLayoutData.items[0].WidgetLayoutInfo;
defaultWidgetLayoutData.layout_name = self.get('userLayoutName');
self.createUserWidgetLayout(defaultWidgetLayoutData).done(function (userLayoutIdData) {
- var activeWidgetLayouts;
- var widgetLayouts = [];
- if (!!activeWidgetLayoutsData.items.length) {
- widgetLayouts = activeWidgetLayoutsData.items.map(function (item) {
- return {
- "id": item.WidgetLayoutInfo.id
- }
- });
- }
- widgetLayouts.push({id: userLayoutIdData.resources[0].WidgetLayoutInfo.id});
- activeWidgetLayouts = {
- "WidgetLayouts": widgetLayouts
- };
- self.saveActiveWidgetLayouts(activeWidgetLayouts).done(function () {
- self.getActiveWidgetLayout();
- });
+ self.createUserWidgetLayoutCallback(userLayoutIdData, activeWidgetLayoutsData);
});
});
});
}
},
+
+ /**
+ *
+ * @param userLayoutIdData
+ * @param activeWidgetLayoutsData
+ */
+ createUserWidgetLayoutCallback: function(userLayoutIdData, activeWidgetLayoutsData) {
+ var activeWidgetLayouts;
+ var widgetLayouts = [];
+ if (!!activeWidgetLayoutsData.items.length) {
+ widgetLayouts = activeWidgetLayoutsData.items.map(function (item) {
+ return {
+ "id": item.WidgetLayoutInfo.id
+ }
+ });
+ }
+ widgetLayouts.push({id: userLayoutIdData.resources[0].WidgetLayoutInfo.id});
+ activeWidgetLayouts = {
+ "WidgetLayouts": widgetLayouts
+ };
+ this.saveActiveWidgetLayouts(activeWidgetLayouts).done(() => {
+ this.getActiveWidgetLayout();
+ });
+ },
getAllActiveWidgetLayouts: function () {
return App.ajax.send({
@@ -385,20 +405,14 @@ App.WidgetSectionMixin = Ember.Mixin.create({
},
createFederationWidgetLayouts: function (data) {
- var self = this;
var currentLayouts = data.items;
- self.getDefaultWidgetLayoutByName(self.get('defaultLayoutName')).done(function (defaultWidgetLayoutData) {
- self.getNameNodeWidgets().done(function (widgets) {
- var newNameServices = [];
- var newWidgets = [];
- var currentLayoutsNames = [];
+
+ this.getDefaultWidgetLayoutByName(this.get('defaultLayoutName')).done((defaultWidgetLayoutData) => {
+ this.getNameNodeWidgets().done((widgets) => {
var newLayout = defaultWidgetLayoutData.items[0].WidgetLayoutInfo;
- var newLayoutsIds = [];
var nameServiceToWidgetMap = {all: []};
- var namespaces = App.HDFSService.find().objectAt(0).get('masterComponentGroups').mapProperty('name');
var nonNameServiceSpecific = newLayout.widgets.slice();
- var userLayoutName = self.get('userLayoutName');
- widgets.items.forEach(function (widget) {
+ widgets.items.forEach((widget) => {
var tag = widget.WidgetInfo.tag;
nonNameServiceSpecific = nonNameServiceSpecific.without(nonNameServiceSpecific.findProperty('WidgetInfo.id', widget.WidgetInfo.id));
if (tag) {
@@ -410,61 +424,90 @@ App.WidgetSectionMixin = Ember.Mixin.create({
}
});
if (currentLayouts.length === 1) {
- self.removeWidgetLayout(currentLayouts[0].WidgetLayoutInfo.id).done(function () {
- newLayout.layout_name = userLayoutName;
- newLayout.widgets = nonNameServiceSpecific;
- self.createUserWidgetLayout(newLayout).done(function (data) {
- newLayoutsIds.push(data.resources[0].WidgetLayoutInfo.id);
- Em.keys(nameServiceToWidgetMap).forEach(function (nameService) {
- newLayout.layout_name = userLayoutName + '_nameservice_' + nameService;
- newLayout.display_name = nameService === 'all' ? 'All' : nameService;
- newLayout.widgets = nameServiceToWidgetMap[nameService];
- self.createUserWidgetLayout(newLayout).done(function (data) {
- newLayoutsIds.push(data.resources[0].WidgetLayoutInfo.id);
- if (newLayoutsIds.length >= Em.keys(nameServiceToWidgetMap).length + 1) {
- self.saveActiveWidgetLayouts({
- "WidgetLayouts": newLayoutsIds.map(function (layout) {
- return {id: layout};
- })
- }).done(function () {
- self.getActiveWidgetLayout();
- });
- }
- });
- })
- });
- });
+ this.createSingleLayout(currentLayouts, newLayout, nonNameServiceSpecific, nameServiceToWidgetMap);
} else {
- currentLayoutsNames = currentLayouts.map(function (l) {
- return l.WidgetLayoutInfo.layout_name.split('_nameservice_')[1];
- }).without(undefined).without('all');
- namespaces.forEach(function (n) {
- if (!currentLayoutsNames.contains(n)) {
- newNameServices.push(n);
+ this.createMultipleLayouts(currentLayouts, newLayout, nameServiceToWidgetMap);
+ }
+ });
+ });
+ },
+
+ /**
+ *
+ * @param currentLayouts
+ * @param newLayout
+ * @param nonNameServiceSpecific
+ * @param nameServiceToWidgetMap
+ */
+ createSingleLayout: function(currentLayouts, newLayout, nonNameServiceSpecific, nameServiceToWidgetMap) {
+ const userLayoutName = this.get('userLayoutName');
+ const newLayoutsIds = [];
+
+ this.removeWidgetLayout(currentLayouts[0].WidgetLayoutInfo.id).done(() => {
+ newLayout.layout_name = userLayoutName;
+ newLayout.widgets = nonNameServiceSpecific;
+ this.createUserWidgetLayout(newLayout).done((data) => {
+ newLayoutsIds.push(data.resources[0].WidgetLayoutInfo.id);
+ Em.keys(nameServiceToWidgetMap).forEach((nameService) => {
+ newLayout.layout_name = userLayoutName + '_nameservice_' + nameService;
+ newLayout.display_name = nameService === 'all' ? 'All' : nameService;
+ newLayout.widgets = nameServiceToWidgetMap[nameService];
+ this.createUserWidgetLayout(newLayout).done((data) => {
+ newLayoutsIds.push(data.resources[0].WidgetLayoutInfo.id);
+ if (newLayoutsIds.length >= Em.keys(nameServiceToWidgetMap).length + 1) {
+ this.saveActiveWidgetLayouts({
+ "WidgetLayouts": newLayoutsIds.map(function (layout) {
+ return {id: layout};
+ })
+ }).done(() => {
+ this.getActiveWidgetLayout();
+ });
}
});
- newNameServices.forEach(function (nameService) {
- newLayout.layout_name = userLayoutName + '_nameservice_' + nameService;
- newLayout.display_name = nameService;
- newLayout.widgets = nameServiceToWidgetMap[nameService];
- newWidgets = newWidgets.concat(nameServiceToWidgetMap[nameService]);
- self.createUserWidgetLayout(newLayout).done(function (data) {
- newLayoutsIds.push(data.resources[0].WidgetLayoutInfo.id);
- if (newLayoutsIds.length >= newNameServices.length) {
- self.saveActiveWidgetLayouts({
- "WidgetLayouts": newLayoutsIds.concat(currentLayouts.mapProperty('WidgetLayoutInfo.id')).map(function (layout) {
- return {id: layout};
- })
- }).done(function () {
- var allNSLayout = currentLayouts.findProperty('WidgetLayoutInfo.display_name', 'All').WidgetLayoutInfo;
- allNSLayout.widgets = allNSLayout.widgets.concat(newWidgets);
- self.updateUserWidgetLayout(allNSLayout).done(function() {
- self.getActiveWidgetLayout();
- });
- });
- }
+ })
+ });
+ });
+ },
+
+ /**
+ *
+ * @param currentLayouts
+ * @param newLayout
+ * @param nameServiceToWidgetMap
+ */
+ createMultipleLayouts: function(currentLayouts, newLayout, nameServiceToWidgetMap) {
+ const newNameServices = [];
+ const newLayoutsIds = [];
+ let newWidgets = [];
+ const userLayoutName = this.get('userLayoutName');
+ const namespaces = App.HDFSService.find('HDFS').get('masterComponentGroups').mapProperty('name');
+ const currentLayoutsNames = currentLayouts.map((l) => {
+ return l.WidgetLayoutInfo.layout_name.split('_nameservice_')[1];
+ }).without(undefined).without('all');
+ namespaces.forEach(function (n) {
+ if (!currentLayoutsNames.contains(n)) {
+ newNameServices.push(n);
+ }
+ });
+ newNameServices.forEach((nameService) => {
+ newLayout.layout_name = userLayoutName + '_nameservice_' + nameService;
+ newLayout.display_name = nameService;
+ newLayout.widgets = nameServiceToWidgetMap[nameService];
+ newWidgets = newWidgets.concat(nameServiceToWidgetMap[nameService]);
+ this.createUserWidgetLayout(newLayout).done((data) => {
+ newLayoutsIds.push(data.resources[0].WidgetLayoutInfo.id);
+ if (newLayoutsIds.length >= newNameServices.length) {
+ this.saveActiveWidgetLayouts({
+ "WidgetLayouts": newLayoutsIds.concat(currentLayouts.mapProperty('WidgetLayoutInfo.id')).map(function (layout) {
+ return {id: layout};
+ })
+ }).done(() => {
+ var allNSLayout = currentLayouts.findProperty('WidgetLayoutInfo.display_name', 'All').WidgetLayoutInfo;
+ allNSLayout.widgets = allNSLayout.widgets.concat(newWidgets);
+ this.updateUserWidgetLayout(allNSLayout).done(() => {
+ this.getActiveWidgetLayout();
});
- })
+ });
}
});
});
diff --git a/ambari-web/test/mixins/common/widgets/widget_section_test.js b/ambari-web/test/mixins/common/widgets/widget_section_test.js
index e6b8bf4..e7c110e 100644
--- a/ambari-web/test/mixins/common/widgets/widget_section_test.js
+++ b/ambari-web/test/mixins/common/widgets/widget_section_test.js
@@ -19,29 +19,34 @@
var App = require('app');
require('mixins/common/widgets/widget_section');
+var testHelpers = require('test/helpers');
describe('App.WidgetSectionMixin', function () {
- var obj;
+ var mixin;
beforeEach(function () {
- obj = Em.Object.create(App.WidgetSectionMixin);
+ mixin = Em.Object.create(App.WidgetSectionMixin, {
+ layoutNameSuffix: '_suffix',
+ sectionNameSuffix: '_section_suffix',
+ content: Em.Object.create()
+ });
});
describe('#isAmbariMetricsInstalled', function () {
var cases = [
{
- services: [],
+ services: Em.A([]),
isAmbariMetricsInstalled: false,
title: 'Ambari Metrics not installed'
},
{
- services: [
+ services: Em.A([
{
serviceName: 'AMBARI_METRICS'
}
- ],
+ ]),
isAmbariMetricsInstalled: true,
title: 'Ambari Metrics installed'
}
@@ -58,10 +63,841 @@ describe('App.WidgetSectionMixin', function () {
cases.forEach(function (item) {
it(item.title, function () {
this.stub.returns(item.services);
- expect(obj.get('isAmbariMetricsInstalled')).to.equal(item.isAmbariMetricsInstalled);
+ expect(mixin.get('isAmbariMetricsInstalled')).to.equal(item.isAmbariMetricsInstalled);
});
});
-
});
-
-});
\ No newline at end of file
+
+ describe('#defaultLayoutName', function() {
+
+ it('should return service layout name', function() {
+ mixin.set('content.serviceName', 'S1');
+ mixin.propertyDidChange('defaultLayoutName');
+ expect(mixin.get('defaultLayoutName')).to.be.equal("default_s1_suffix");
+ });
+
+ it('should return system layout name', function() {
+ mixin.set('content.serviceName', null);
+ mixin.propertyDidChange('defaultLayoutName');
+ expect(mixin.get('defaultLayoutName')).to.be.equal("default_system_suffix");
+ });
+ });
+
+ describe('#userLayoutName', function() {
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns('admin');
+ });
+ afterEach(function() {
+ App.router.get.restore();
+ });
+
+ it('should return service layout name', function() {
+ mixin.set('content.serviceName', 'S1');
+ mixin.propertyDidChange('userLayoutName');
+ expect(mixin.get('userLayoutName')).to.be.equal("admin_s1_suffix");
+ });
+
+ it('should return system layout name', function() {
+ mixin.set('content.serviceName', null);
+ mixin.propertyDidChange('userLayoutName');
+ expect(mixin.get('userLayoutName')).to.be.equal("admin_system_suffix");
+ });
+ });
+
+ describe('#sectionName', function() {
+
+ it('should return service layout name', function() {
+ mixin.set('content.serviceName', 'S1');
+ mixin.propertyDidChange('sectionName');
+ expect(mixin.get('sectionName')).to.be.equal("S1_section_suffix");
+ });
+
+ it('should return system layout name', function() {
+ mixin.set('content.serviceName', null);
+ mixin.propertyDidChange('sectionName');
+ expect(mixin.get('sectionName')).to.be.equal("SYSTEM_section_suffix");
+ });
+ });
+
+ describe('#isServiceWithEnhancedWidgets', function() {
+ beforeEach(function() {
+ sinon.stub(App.StackService, 'find').returns(Em.Object.create({
+ isServiceWithWidgets: false
+ }));
+ });
+ afterEach(function() {
+ App.StackService.find.restore();
+ });
+
+ it('should return false', function() {
+ mixin.set('content.serviceName', 'S1');
+ mixin.propertyDidChange('isServiceWithEnhancedWidgets');
+ expect(mixin.get('isServiceWithEnhancedWidgets')).to.be.false;
+ });
+
+ it('should return true', function() {
+ mixin.reopen({
+ sectionName: 'SYSTEM_HEATMAPS'
+ });
+ mixin.propertyDidChange('isServiceWithEnhancedWidgets');
+ expect(mixin.get('isServiceWithEnhancedWidgets')).to.be.true;
+ });
+ });
+
+ describe('#isHDFSFederatedSummary', function() {
+ beforeEach(function() {
+ sinon.stub(App, 'get').returns(true);
+ });
+ afterEach(function() {
+ App.get.restore();
+ });
+
+ it('should be true', function() {
+ mixin.set('content.serviceName', 'HDFS');
+ mixin.set('sectionNameSuffix', '_SUMMARY');
+ mixin.propertyDidChange('isHDFSFederatedSummary');
+ expect(mixin.get('isHDFSFederatedSummary')).to.be.true;
+ });
+ });
+
+ describe('#widgets', function() {
+
+ it('should return no widgets when not loaded', function() {
+ mixin.set('isWidgetsLoaded', false);
+ mixin.propertyDidChange('widgets');
+ expect(mixin.get('widgets')).to.be.empty;
+ });
+
+ it('should return widgets', function() {
+ mixin.set('isWidgetsLoaded', true);
+ mixin.set('activeWidgetLayout', {
+ widgets: [{}]
+ });
+ mixin.propertyDidChange('widgets');
+ expect(mixin.get('widgets')).to.be.eql([{}]);
+ });
+ });
+
+ describe('#switchNameServiceLayout', function() {
+
+ it('should set selectedNSWidgetLayout', function() {
+ mixin.switchNameServiceLayout({context: {}});
+ expect(mixin.get('selectedNSWidgetLayout')).to.be.eql({});
+ });
+ });
+
+ describe('#getActiveWidgetLayout', function() {
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns('admin');
+ });
+ afterEach(function() {
+ App.router.get.restore();
+ });
+
+ it('activeWidgetLayout should be empty', function() {
+ mixin.getActiveWidgetLayout();
+ expect(mixin.get('activeWidgetLayout')).to.be.empty;
+ });
+
+ it('activeNSWidgetLayouts should be empty', function() {
+ mixin.getActiveWidgetLayout();
+ expect(mixin.get('activeNSWidgetLayouts')).to.be.empty;
+ });
+
+ it('isWidgetsLoaded should be empty', function() {
+ mixin.reopen({
+ isServiceWithEnhancedWidgets: false
+ });
+ mixin.getActiveWidgetLayout();
+ expect(mixin.get('isWidgetsLoaded')).to.be.true;
+ });
+
+ it('App.ajax.send should be called', function() {
+ mixin.reopen({
+ isServiceWithEnhancedWidgets: true,
+ sectionName: 'section1'
+ });
+ mixin.getActiveWidgetLayout();
+ expect(testHelpers.findAjaxRequest('name', 'widgets.layouts.active.get')[0].data).to.be.eql({
+ userName: 'admin',
+ sectionName: 'section1',
+ urlParams: 'WidgetLayoutInfo/section_name=section1'
+ });
+ });
+ });
+
+ describe('#getActiveWidgetLayoutSuccessCallback', function() {
+ beforeEach(function() {
+ sinon.stub(mixin, 'createLayouts');
+ sinon.stub(mixin, 'getNameNodeWidgets').returns({
+ done: function(callback) {
+ callback({
+ items: [
+ {
+ WidgetInfo: {
+ tag: 'space1'
+ }
+ },
+ {
+ WidgetInfo: {
+ tag: null
+ }
+ }
+ ]
+ });
+ }
+ });
+ sinon.stub(App.HDFSService, 'find').returns(Em.Object.create({
+ masterComponentGroups: [
+ {
+ name: 'space1'
+ },
+ {
+ name: 'space2'
+ }
+ ]
+ }));
+ sinon.stub(mixin, 'postNNWidgets');
+ });
+ afterEach(function() {
+ mixin.createLayouts.restore();
+ mixin.getNameNodeWidgets.restore();
+ App.HDFSService.find.restore();
+ mixin.postNNWidgets.restore();
+ });
+
+ it('createLayouts should be called when isHDFSFederatedSummary=false', function() {
+ mixin.reopen({
+ isHDFSFederatedSummary: false
+ });
+ mixin.getActiveWidgetLayoutSuccessCallback({items: []});
+ expect(mixin.createLayouts.calledWith({items: []})).to.be.true;
+ });
+
+ it('postNNWidgets should be called when isHDFSFederatedSummary=true', function() {
+ mixin.reopen({
+ isHDFSFederatedSummary: true
+ });
+ mixin.getActiveWidgetLayoutSuccessCallback({items: []});
+ expect(mixin.postNNWidgets.calledWith({
+ WidgetInfo: {
+ tag: null
+ }
+ }, 1, {items: []})).to.be.true;
+ });
+ });
+
+ describe('#postNNWidgets', function() {
+ beforeEach(function() {
+ sinon.stub(mixin, 'postWidget').returns({
+ done: Em.clb
+ });
+ sinon.stub(mixin, 'createLayouts');
+ });
+ afterEach(function() {
+ mixin.postWidget.restore();
+ mixin.createLayouts.restore();
+ });
+
+ it('createLayouts should be called', function() {
+ mixin.postNNWidgets({
+ href: '',
+ WidgetInfo: {
+ id: 1,
+ cluster_name: 'cl1',
+ author: 'me',
+ metrics: JSON.stringify({metrics: []}),
+ values: JSON.stringify({values: []})
+ }
+ }, 1, {});
+ expect(mixin.createLayouts.calledWith({})).to.be.true;
+ });
+ });
+
+ describe('#getNameNodeWidgets', function() {
+
+ it('App.ajax.send should be called', function() {
+ mixin.getNameNodeWidgets();
+ expect(testHelpers.findAjaxRequest('name', 'widgets.get')[0].data).to.be.eql({
+ urlParams: 'WidgetInfo/widget_type.in(GRAPH,NUMBER,GAUGE)&WidgetInfo/scope=CLUSTER&WidgetInfo/metrics.matches(.*\"component_name\":\"NAMENODE\".*)&fields=*'
+ });
+ });
+ });
+
+ describe('#postWidget', function() {
+
+ it('App.ajax.send should be called', function() {
+ mixin.postWidget({data: []});
+ expect(testHelpers.findAjaxRequest('name', 'widgets.wizard.add')[0].data).to.be.eql({
+ data: {data: []}
+ });
+ });
+ });
+
+ describe('#getAllActiveWidgetLayouts', function() {
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns('admin');
+ });
+ afterEach(function() {
+ App.router.get.restore();
+ });
+
+ it('App.ajax.send should be called', function() {
+ mixin.getAllActiveWidgetLayouts();
+ expect(testHelpers.findAjaxRequest('name', 'widgets.layouts.all.active.get')[0].data).to.be.eql({
+ userName: 'admin'
+ });
+ });
+ });
+
+ describe('#createLayouts', function() {
+ beforeEach(function() {
+ sinon.stub(App.HDFSService, 'find').returns(Em.Object.create({
+ isLoaded: true,
+ masterComponentGroups: [{}, {}]
+ }));
+ sinon.stub(mixin, 'createFederationWidgetLayouts');
+ sinon.stub(mixin, 'getWidgetLayoutSuccessCallback');
+ sinon.stub(mixin, 'createUserWidgetLayoutCallback');
+ sinon.stub(mixin, 'getAllActiveWidgetLayouts').returns({
+ done: Em.clb
+ });
+ sinon.stub(mixin, 'getDefaultWidgetLayoutByName').returns({
+ done: function(callback) {
+ callback({
+ items: [
+ {
+ WidgetLayoutInfo: {}
+ }
+ ]
+ });
+ }
+ });
+ sinon.stub(mixin, 'createUserWidgetLayout').returns({
+ done: Em.clb
+ });
+ });
+ afterEach(function() {
+ App.HDFSService.find.restore();
+ mixin.createFederationWidgetLayouts.restore();
+ mixin.getWidgetLayoutSuccessCallback.restore();
+ mixin.createUserWidgetLayoutCallback.restore();
+ mixin.getAllActiveWidgetLayouts.restore();
+ mixin.createUserWidgetLayout.restore();
+ });
+
+ it('createFederationWidgetLayouts should be called', function() {
+ mixin.reopen({
+ isHDFSFederatedSummary: true
+ });
+ mixin.createLayouts({items: [{}]});
+ expect(mixin.createFederationWidgetLayouts.calledWith({items: [{}]})).to.be.true;
+ });
+
+ it('getWidgetLayoutSuccessCallback should be called', function() {
+ mixin.reopen({
+ isHDFSFederatedSummary: false
+ });
+ mixin.createLayouts({items: [{}]});
+ expect(mixin.getWidgetLayoutSuccessCallback.calledWith({items: [{}]})).to.be.true;
+ });
+
+ it('createUserWidgetLayoutCallback should be called', function() {
+ mixin.createLayouts({items: []});
+ expect(mixin.createUserWidgetLayoutCallback.calledOnce).to.be.true;
+ });
+ });
+
+ describe('#createUserWidgetLayoutCallback', function() {
+ beforeEach(function() {
+ sinon.stub(mixin, 'saveActiveWidgetLayouts').returns({
+ done: Em.clb
+ });
+ sinon.stub(mixin, 'getActiveWidgetLayout');
+ });
+ afterEach(function() {
+ mixin.saveActiveWidgetLayouts.restore();
+ mixin.getActiveWidgetLayout.restore();
+ });
+
+ it('saveActiveWidgetLayouts should be called', function() {
+ mixin.createUserWidgetLayoutCallback(
+ {resources: [{WidgetLayoutInfo: {id: 1}}]},
+ {items: [{WidgetLayoutInfo: {id: 2}}]});
+ expect(mixin.saveActiveWidgetLayouts.calledWith(
+ {
+ "WidgetLayouts": [
+ {id: 2},
+ {id: 1}
+ ]
+ }
+ )).to.be.true;
+ });
+
+ it('getActiveWidgetLayout should be called', function() {
+ mixin.createUserWidgetLayoutCallback(
+ {resources: [{WidgetLayoutInfo: {id: 1}}]},
+ {items: [{WidgetLayoutInfo: {id: 2}}]});
+ expect(mixin.getActiveWidgetLayout.calledOnce).to.be.true;
+ });
+ });
+
+ describe('#getWidgetLayoutSuccessCallback', function() {
+ beforeEach(function() {
+ sinon.stub(App.widgetMapper, 'map');
+ sinon.stub(App.widgetLayoutMapper, 'map');
+ sinon.stub(App.WidgetLayout, 'find').returns([
+ {
+ layoutName: 'layout1',
+ sectionName: 'section1'
+ },
+ {
+ layoutName: 'layout2',
+ sectionName: 'section1'
+ }
+ ]);
+ mixin.reopen({
+ isHDFSFederatedSummary: true,
+ userLayoutName: 'layout1',
+ sectionName: 'section1'
+ });
+ mixin.getWidgetLayoutSuccessCallback({items: [{WidgetLayoutInfo: {id: 1}}]});
+ });
+ afterEach(function() {
+ App.widgetMapper.map.restore();
+ App.widgetLayoutMapper.map.restore();
+ App.WidgetLayout.find.restore();
+ });
+
+ it('App.widgetMapper.map should be called', function() {
+ expect(App.widgetMapper.map.calledWith({id: 1})).to.be.true;
+ });
+
+ it('App.widgetLayoutMapper.map should be called', function() {
+ expect(App.widgetLayoutMapper.map.calledWith({items: [{WidgetLayoutInfo: {id: 1}}]})).to.be.true;
+ });
+
+ it('activeWidgetLayout should be set', function() {
+ expect(mixin.get('activeWidgetLayout')).to.be.eql({
+ layoutName: 'layout1',
+ sectionName: 'section1'
+ });
+ });
+
+ it('activeNSWidgetLayouts should be set', function() {
+ expect(mixin.get('activeNSWidgetLayouts')).to.be.eql([{
+ layoutName: 'layout2',
+ sectionName: 'section1'
+ }]);
+ });
+
+ it('selectedNSWidgetLayout should be set', function() {
+ expect(mixin.get('selectedNSWidgetLayout')).to.be.eql({
+ layoutName: 'layout2',
+ sectionName: 'section1'
+ });
+ });
+
+ it('isWidgetsLoaded should be true', function() {
+ expect(mixin.get('isWidgetsLoaded')).to.be.true;
+ });
+ });
+
+ describe('#getDefaultWidgetLayoutByName', function() {
+
+ it('App.ajax.send should be called', function() {
+ mixin.getDefaultWidgetLayoutByName('layout1');
+ expect(testHelpers.findAjaxRequest('name', 'widget.layout.get')[0].data).to.be.eql({
+ urlParams: 'WidgetLayoutInfo/layout_name=layout1'
+ });
+ });
+ });
+
+ describe('#createUserWidgetLayout', function() {
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns('admin');
+ });
+ afterEach(function() {
+ App.router.get.restore();
+ });
+
+ it('App.ajax.send should be called', function() {
+ mixin.createUserWidgetLayout({
+ display_name: 'l1',
+ layout_name: 'L1',
+ section_name: 's1',
+ widgets: [{
+ WidgetInfo: {
+ id: 1
+ }
+ }]
+ });
+ expect(testHelpers.findAjaxRequest('name', 'widget.layout.create')[0].data).to.be.eql({
+ data: {
+ "WidgetLayoutInfo": {
+ "display_name": 'l1',
+ "layout_name": 'L1',
+ "scope": "USER",
+ "section_name": 's1',
+ "user_name": 'admin',
+ "widgets": [{
+ id: 1
+ }]
+ }
+ }
+ });
+ });
+ });
+
+ describe('#updateUserWidgetLayout', function() {
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns('admin');
+ });
+ afterEach(function() {
+ App.router.get.restore();
+ });
+
+ it('App.ajax.send should be called', function() {
+ mixin.updateUserWidgetLayout({
+ display_name: 'l1',
+ layout_name: 'L1',
+ section_name: 's1',
+ id: 1,
+ widgets: [{
+ WidgetInfo: {
+ id: 1
+ }
+ }]
+ });
+ expect(testHelpers.findAjaxRequest('name', 'widget.layout.edit')[0].data).to.be.eql({
+ data: {
+ "WidgetLayoutInfo": {
+ "display_name": 'l1',
+ "layout_name": 'L1',
+ "id": 1,
+ "scope": "USER",
+ "section_name": 's1',
+ "user_name": 'admin',
+ "widgets": [{
+ id: 1
+ }]
+ }
+ },
+ layoutId: 1
+ });
+ });
+ });
+
+ describe('#saveActiveWidgetLayouts', function() {
+
+ beforeEach(function() {
+ sinon.stub(App.router, 'get').returns('admin');
+ });
+ afterEach(function() {
+ App.router.get.restore();
+ });
+
+
+ it('App.ajax.send should be called', function() {
+ mixin.saveActiveWidgetLayouts([]);
+ expect(testHelpers.findAjaxRequest('name', 'widget.activelayouts.edit')[0].data).to.be.eql({
+ data: [],
+ userName: 'admin'
+ });
+ });
+ });
+
+ describe('#removeWidgetLayout', function() {
+
+ it('App.ajax.send should be called', function() {
+ mixin.removeWidgetLayout(1);
+ expect(testHelpers.findAjaxRequest('name', 'widget.layout.delete')[0].data).to.be.eql({
+ layoutId: 1
+ });
+ });
+ });
+
+ describe('#saveWidgetLayout', function() {
+
+ it('App.ajax.send should be called', function() {
+ mixin.saveWidgetLayout(
+ [Em.Object.create({id: 1})],
+ Em.Object.create({
+ displayName: 'l1',
+ layoutName: 'L1',
+ sectionName: 's1',
+ scope: 'USER',
+ id: 1
+ })
+ );
+ expect(testHelpers.findAjaxRequest('name', 'widget.layout.edit')[0].data).to.be.eql({
+ data: {
+ "WidgetLayoutInfo": {
+ "display_name": 'l1',
+ "layout_name": 'L1',
+ "id": 1,
+ "scope": "USER",
+ "section_name": 's1',
+ "widgets": [{
+ id: 1
+ }]
+ }
+ },
+ layoutId: 1
+ });
+ });
+ });
+
+ describe('#clearActiveWidgetLayout', function() {
+
+ it('activeWidgetLayout should be empty', function() {
+ mixin.clearActiveWidgetLayout();
+ expect(mixin.get('activeWidgetLayout')).to.be.empty;
+ });
+
+ it('activeNSWidgetLayouts should be empty', function() {
+ mixin.clearActiveWidgetLayout();
+ expect(mixin.get('activeNSWidgetLayouts')).to.be.empty;
+ });
+ });
+
+ describe('#createFederationWidgetLayouts', function() {
+ var newLayout = {
+ widgets: [
+ {
+ WidgetInfo: {
+ id: 1
+ }
+ },
+ {
+ WidgetInfo: {
+ id: 2
+ }
+ }
+ ]
+ };
+ beforeEach(function() {
+ sinon.stub(mixin, 'getDefaultWidgetLayoutByName').returns({
+ done: function(callback) {
+ callback({
+ items: [{
+ WidgetLayoutInfo: newLayout
+ }]
+ });
+ }
+ });
+ sinon.stub(mixin, 'getNameNodeWidgets').returns({
+ done: function(callback) {
+ callback({
+ items: [
+ {
+ WidgetInfo: {
+ tag: 'tag1',
+ id: 2
+ }
+ }
+ ]
+ });
+ }
+ });
+ sinon.stub(mixin, 'createSingleLayout');
+ sinon.stub(mixin, 'createMultipleLayouts');
+ });
+ afterEach(function() {
+ mixin.getDefaultWidgetLayoutByName.restore();
+ mixin.getNameNodeWidgets.restore();
+ mixin.createSingleLayout.restore();
+ mixin.createMultipleLayouts.restore();
+ });
+
+ it('createSingleLayout should be called', function() {
+ mixin.createFederationWidgetLayouts({items: [{}]});
+ expect(mixin.createSingleLayout.calledWith(
+ [{}],
+ newLayout,
+ [{
+ WidgetInfo: {
+ id: 1
+ }
+ }],
+ {
+ all: [{
+ WidgetInfo: {
+ tag: 'tag1',
+ id: 2
+ }
+ }],
+ tag1: [
+ {
+ WidgetInfo: {
+ tag: 'tag1',
+ id: 2
+ }
+ }
+ ]
+ }
+ )).to.be.true;
+ });
+
+ it('createMultipleLayouts should be called', function() {
+ mixin.createFederationWidgetLayouts({items: [{}, {}]});
+ expect(mixin.createMultipleLayouts.calledWith(
+ [{}, {}],
+ newLayout,
+ {
+ all: [{
+ WidgetInfo: {
+ tag: 'tag1',
+ id: 2
+ }
+ }],
+ tag1: [
+ {
+ WidgetInfo: {
+ tag: 'tag1',
+ id: 2
+ }
+ }
+ ]
+ }
+ )).to.be.true;
+ });
+ });
+
+ describe('#createSingleLayout', function() {
+ beforeEach(function() {
+ sinon.stub(mixin, 'removeWidgetLayout').returns({done: Em.clb});
+ sinon.stub(mixin, 'createUserWidgetLayout').returns({done: function(callback) {
+ return callback({
+ resources: [
+ {
+ WidgetLayoutInfo: {
+ id: 1
+ }
+ }
+ ]
+ });
+ }
+ });
+ sinon.stub(mixin, 'saveActiveWidgetLayouts').returns({done: Em.clb});
+ sinon.stub(mixin, 'getActiveWidgetLayout');
+ mixin.createSingleLayout(
+ [{
+ WidgetLayoutInfo: {
+ id: 1
+ }
+ }],
+ {},
+ [],
+ {space1: []}
+ );
+ });
+ afterEach(function() {
+ mixin.removeWidgetLayout.restore();
+ mixin.createUserWidgetLayout.restore();
+ mixin.saveActiveWidgetLayouts.restore();
+ mixin.getActiveWidgetLayout.restore();
+ });
+
+ it('removeWidgetLayout should be called', function() {
+ expect(mixin.removeWidgetLayout.calledWith(1)).to.be.true;
+ });
+
+ it('createUserWidgetLayout should be called', function() {
+ expect(mixin.createUserWidgetLayout.calledTwice).to.be.true;
+ });
+
+ it('saveActiveWidgetLayouts should be called', function() {
+ expect(mixin.saveActiveWidgetLayouts.calledWith({
+ "WidgetLayouts": [{id: 1}, {id: 1}]
+ })).to.be.true;
+ });
+
+ it('getActiveWidgetLayout should be called', function() {
+ expect(mixin.getActiveWidgetLayout.calledOnce).to.be.true;
+ });
+ });
+
+ describe('#createMultipleLayouts', function() {
+ beforeEach(function() {
+ sinon.stub(App.HDFSService, 'find').returns(Em.Object.create({
+ masterComponentGroups: [{name: 'C1'}, {name: 'C2'}]
+ }));
+ sinon.stub(mixin, 'createUserWidgetLayout').returns({
+ done: function(callback) {
+ callback({
+ resources: [{
+ WidgetLayoutInfo: {
+ id: 1
+ }
+ }]
+ });
+ }
+ });
+ sinon.stub(mixin, 'saveActiveWidgetLayouts').returns({
+ done: Em.clb
+ });
+ sinon.stub(mixin, 'updateUserWidgetLayout').returns({
+ done: Em.clb
+ });
+ sinon.stub(mixin, 'getActiveWidgetLayout');
+ mixin.reopen({
+ userLayoutName: 'layout1'
+ });
+ mixin.createMultipleLayouts(
+ [
+ {
+ WidgetLayoutInfo: {
+ layout_name: 'prefix_nameservice_C2',
+ id: 2
+ }
+ },
+ {
+ WidgetLayoutInfo: {
+ layout_name: 'prefix_nameservice_all',
+ display_name: 'All',
+ widgets: [],
+ id: 3
+ }
+ }
+ ],
+ {},
+ {C2: []}
+ );
+ });
+ afterEach(function() {
+ App.HDFSService.find.restore();
+ mixin.createUserWidgetLayout.restore();
+ mixin.saveActiveWidgetLayouts.restore();
+ mixin.updateUserWidgetLayout.restore();
+ mixin.getActiveWidgetLayout.restore();
+ });
+
+ it('createUserWidgetLayout should be called', function() {
+ expect(mixin.createUserWidgetLayout.calledOnce).to.be.true;
+ });
+
+ it('saveActiveWidgetLayouts should be called', function() {
+ expect(mixin.saveActiveWidgetLayouts.calledWith({
+ "WidgetLayouts": [
+ {id: 1},
+ {id: 2},
+ {id: 3}
+ ]
+ })).to.be.true;
+ });
+
+ it('updateUserWidgetLayout should be called', function() {
+ expect(mixin.updateUserWidgetLayout.calledOnce).to.be.true;
+ });
+
+ it('getActiveWidgetLayout should be called', function() {
+ expect(mixin.getActiveWidgetLayout.calledOnce).to.be.true;
+ });
+ });
+
+});
diff --git a/ambari-web/test/views/common/modal_popups/select_groups_popup_test.js b/ambari-web/test/views/common/modal_popups/select_groups_popup_test.js
index 78be0b8..9d84c20 100644
--- a/ambari-web/test/views/common/modal_popups/select_groups_popup_test.js
+++ b/ambari-web/test/views/common/modal_popups/select_groups_popup_test.js
@@ -133,7 +133,7 @@ describe('App.showSelectGroupsPopup', function () {
});
it('App.config.createOverride should be called when no overrides', function () {
- view = App.showSelectGroupsPopup('', {}, dependentStepConfigs, configs);
+ view = App.showSelectGroupsPopup('', Em.Object.create(), dependentStepConfigs, configs);
view.applyOverridesToConfigGroups('S1', {}, 'g2', 'g1');
expect(App.config.createOverride.calledWith(
Em.Object.create({
@@ -157,7 +157,7 @@ describe('App.showSelectGroupsPopup', function () {
recommendedValue: 'val1'
});
dependentStepConfigs[0].get('configs')[0].set('overrides', [override]);
- view = App.showSelectGroupsPopup('', {}, dependentStepConfigs, configs);
+ view = App.showSelectGroupsPopup('', Em.Object.create(), dependentStepConfigs, configs);
view.applyOverridesToConfigGroups('S1', {}, 'g2', 'g1');
expect(override.get('value')).to.be.equal('val1');
});
@@ -171,7 +171,7 @@ describe('App.showSelectGroupsPopup', function () {
recommendedValue: 'val1'
});
dependentStepConfigs[0].get('configs')[0].set('overrides', [override]);
- view = App.showSelectGroupsPopup('', {}, dependentStepConfigs, configs);
+ view = App.showSelectGroupsPopup('', Em.Object.create(), dependentStepConfigs, configs);
view.applyOverridesToConfigGroups('S1', Em.Object.create({name: 'g1'}), 'g2', 'g1');
expect(App.config.createOverride.calledWith(
Em.Object.create({
@@ -196,7 +196,7 @@ describe('App.showSelectGroupsPopup', function () {
recommendedValue: 'val1'
});
dependentStepConfigs[0].get('configs')[0].set('overrides', [override]);
- view = App.showSelectGroupsPopup('', {}, dependentStepConfigs, configs);
+ view = App.showSelectGroupsPopup('', Em.Object.create(), dependentStepConfigs, configs);
view.applyOverridesToConfigGroups('S1', Em.Object.create({name: 'g2'}), 'g2', 'g1');
expect(override.get('value')).to.be.equal('val1');
});