Skip to content

Commit

Permalink
Merge pull request #909 from AllenBW/hotfix/service-failed-tag-filter
Browse files Browse the repository at this point in the history
[Finishes #150828440] Reconfigures tag query to prevent explorer filter failure
  • Loading branch information
chriskacerguis authored Sep 6, 2017
2 parents 7996b1a + 99a012f commit 3ba2bdb
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 44 deletions.
24 changes: 16 additions & 8 deletions client/app/services/service-explorer/service-explorer.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const ServiceExplorerComponent = {

/** @ngInject */
function ComponentController ($state, ServicesState, Language, ListView, Chargeback, TaggingService, TagEditorModal,
EventNotifications, ModalService, PowerOperations, lodash, Polling, POLLING_INTERVAL) {
EventNotifications, ModalService, PowerOperations, lodash, Polling, POLLING_INTERVAL) {
const vm = this

vm.$onDestroy = function () {
Expand All @@ -22,9 +22,10 @@ function ComponentController ($state, ServicesState, Language, ListView, Chargeb
$state.params.filter ? ServicesState.services.setFilters($state.params.filter) : ServicesState.services.setFilters([])
ServicesState.services.setSort({id: 'created_at', title: 'Created', sortType: 'numeric'}, false)

TaggingService.queryAvailableTags().then((response) => {
vm.toolbarConfig.filterConfig.fields = getServiceFilterFields(response)
})
TaggingService.queryAvailableTags().then(
(response) => { vm.toolbarConfig.filterConfig.fields = getServiceFilterFields(response) },
() => { vm.toolbarConfig.filterConfig.fields = defaultFilterFields() }
)

angular.extend(vm, {
loading: false,
Expand All @@ -47,6 +48,7 @@ function ComponentController ($state, ServicesState, Language, ListView, Chargeb
stopService: stopService,
suspendService: suspendService,
paginationUpdate: paginationUpdate,
defaultFilterFields: defaultFilterFields,
// Config setup
viewType: 'listView',
cardConfig: getCardConfig(),
Expand Down Expand Up @@ -289,6 +291,7 @@ function ComponentController ($state, ServicesState, Language, ListView, Chargeb
]

angular.forEach(menuOptions, hasPermission)

function hasPermission (item) {
if (item.permission) {
menu.push(item)
Expand Down Expand Up @@ -323,6 +326,11 @@ function ComponentController ($state, ServicesState, Language, ListView, Chargeb
resolveServices(vm.limit, 0)
}

function defaultFilterFields () {
return [ListView.createFilterField('name', __('Name'), __('Filter by Name'), 'text'),
ListView.createFilterField('description', __('Description'), __('Filter by Description'), 'text')]
}

function getServiceFilterFields (tags) {
const filterValues = []
const filterCategories = {}
Expand All @@ -348,9 +356,8 @@ function ComponentController ($state, ServicesState, Language, ListView, Chargeb
}
})

return [
ListView.createFilterField('name', __('Name'), __('Filter by Name'), 'text'),
ListView.createFilterField('description', __('Description'), __('Filter by Description'), 'text'),
const filterFields = defaultFilterFields()
filterFields.push(
ListView.createGenericField(
{
id: 'tags.name',
Expand All @@ -364,7 +371,8 @@ function ComponentController ($state, ServicesState, Language, ListView, Chargeb
filterCategories: filterCategories
}
)
]
)
return filterFields
}

function getServiceSortFields () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
describe('Component: serviceExplorer', () => {
let scope, ctrl, collectionsApiMock;
let scope, ctrl, collectionsApiMock

beforeEach(() => {
module('app.core', 'app.states', 'app.services');
bard.inject('$componentController', 'EventNotifications', 'ListView', 'ServicesState', '$state', 'CollectionsApi');
ctrl = $componentController('serviceExplorer', {$scope: scope}, {});
ctrl.$onInit();
collectionsApiMock = sinon.mock(CollectionsApi);
});
module('app.core', 'app.states', 'app.services')
bard.inject('$componentController', 'EventNotifications', 'ListView', 'ServicesState', '$state', 'CollectionsApi')
ctrl = $componentController('serviceExplorer', {$scope: scope}, {})
ctrl.$onInit()
collectionsApiMock = sinon.mock(CollectionsApi)
})

it('is defined', () => expect(ctrl).to.be.defined);
it('is defined', () => expect(ctrl).to.be.defined)

it('should set permissions', () => {
const expectedPermissions = {
Expand Down Expand Up @@ -38,53 +38,79 @@ describe('Component: serviceExplorer', () => {
instance_show: false,
vm_drift: false,
vm_check_compliance: false
};
}

expect(ctrl.permissions).to.eql(expectedPermissions);
});
expect(ctrl.permissions).to.eql(expectedPermissions)
})

it('should allow pagination to be updated', () => {
const limit = 40;
const offset = 10;
ctrl.paginationUpdate(limit, offset);
const limit = 40
const offset = 10
ctrl.paginationUpdate(limit, offset)

expect(ctrl.limit).to.eq(limit);
expect(ctrl.offset).to.eq(offset);
});
expect(ctrl.limit).to.eq(limit)
expect(ctrl.offset).to.eq(offset)
})

it('should set toolbar', () => {

expect(ctrl.toolbarConfig.sortConfig.fields).to.have.lengthOf(3);
expect(ctrl.toolbarConfig.sortConfig.fields).to.have.lengthOf(3)
expect(ctrl.toolbarConfig.sortConfig.currentField).to.eql({
id: 'created_at',
title: 'Created',
sortType: 'numeric'
});
});
})
})

it('should allow for sorting to be able to be updated', () => {
const catalogSpy = sinon.spy(ServicesState.services, 'setSort');
ctrl.toolbarConfig.sortConfig.onSortChange('name', true);
const catalogSpy = sinon.spy(ServicesState.services, 'setSort')
ctrl.toolbarConfig.sortConfig.onSortChange('name', true)

expect(catalogSpy).to.have.been.called.once;
});
expect(catalogSpy).to.have.been.called.once
})

it('should make a query for services', () => {
collectionsApiMock
.expects('query')
.withArgs('services', { filter: ["ancestry=null"] })
.returns(Promise.resolve());
.withArgs('services', {filter: ['ancestry=null']})
.returns(Promise.resolve())

ctrl.resolveServices(20, 0);
ctrl.resolveServices(20, 0)

collectionsApiMock.verify();
ctrl.$onDestroy();
collectionsApiMock.verify()
ctrl.$onDestroy()

});
})

it('should had default filter fields', () => {
const defaultFields = [{
id: 'name',
title: 'Name',
placeholder: 'Filter by Name',
filterType: 'text',
filterValues: undefined
},
{
id: 'description',
title: 'Description',
placeholder: 'Filter by Description',
filterType: 'text',
filterValues: undefined
}]

expect(ctrl.defaultFilterFields()).to.eql(defaultFields)
})

it('should test service type is ansible', () => {
const isAnsible = ctrl.isAnsibleService({type: 'ansible', name: 'ansible'})
expect(isAnsible).to.be.true
const isNotAnsible = ctrl.isAnsibleService({type: 'vm'})
expect(isNotAnsible).to.be.false
})

it('should change view type', () => {
expect(ctrl.viewType).to.equal("listView");
ctrl.viewSelected("tableView");
expect(ctrl.viewType).to.equal("tableView");
});
});
expect(ctrl.viewType).to.equal('listView')
ctrl.viewSelected('tableView')
expect(ctrl.viewType).to.equal('tableView')
})
})
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ babel-plugin-transform-es2015-literals@^6.22.0:
dependencies:
babel-runtime "^6.22.0"

babel-plugin-transform-es2015-modules-amd@^6.22.0:
babel-plugin-transform-es2015-modules-amd@^6.22.0, babel-plugin-transform-es2015-modules-amd@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-amd/-/babel-plugin-transform-es2015-modules-amd-6.24.1.tgz#3b3e54017239842d6d19c3011c4bd2f00a00d154"
dependencies:
Expand Down

0 comments on commit 3ba2bdb

Please sign in to comment.