提交 efd24e64 编写于 作者: P Piotr Bryk 提交者: GitHub

Fix namespace selector for _all namespaces (#1197)

* Fix namespace selector for _all namespaces
上级 a0ff17e5
...@@ -95,7 +95,7 @@ export class NamespaceSelectController { ...@@ -95,7 +95,7 @@ export class NamespaceSelectController {
let newNamespace = toParams[namespaceParam]; let newNamespace = toParams[namespaceParam];
if (newNamespace) { if (newNamespace) {
if (this.namespacesInitialized_) { if (this.namespacesInitialized_) {
if (this.namespaces.indexOf(newNamespace) >= 0) { if (this.namespaces.indexOf(newNamespace) >= 0 || newNamespace === ALL_NAMESPACES) {
this.selectedNamespace = newNamespace; this.selectedNamespace = newNamespace;
} else { } else {
this.selectedNamespace = DEFAULT_NAMESPACE; this.selectedNamespace = DEFAULT_NAMESPACE;
...@@ -141,8 +141,9 @@ export class NamespaceSelectController { ...@@ -141,8 +141,9 @@ export class NamespaceSelectController {
return resource.get().$promise.then((/** !backendApi.NamespaceList */ namespaceList) => { return resource.get().$promise.then((/** !backendApi.NamespaceList */ namespaceList) => {
this.namespaces = namespaceList.namespaces.map((n) => n.objectMeta.name); this.namespaces = namespaceList.namespaces.map((n) => n.objectMeta.name);
this.namespacesInitialized_ = true; this.namespacesInitialized_ = true;
if (this.namespaces.indexOf(this.selectedNamespace) === -1) { if (this.namespaces.indexOf(this.selectedNamespace) === -1 &&
this.selectedNamespace = ALL_NAMESPACES; this.selectedNamespace !== ALL_NAMESPACES) {
this.selectedNamespace = DEFAULT_NAMESPACE;
this.changeNamespace(); this.changeNamespace();
} }
}); });
......
...@@ -100,10 +100,29 @@ describe('Namespace select component ', () => { ...@@ -100,10 +100,29 @@ describe('Namespace select component ', () => {
scope.$digest(); scope.$digest();
expect(ctrl.selectedNamespace).toBe('default'); expect(ctrl.selectedNamespace).toBe('default');
state.go('fakeState', {namespace: '_all'});
scope.$digest();
expect(ctrl.selectedNamespace).toBe('_all');
// Do not init twice. Nothing happens. // Do not init twice. Nothing happens.
ctrl.loadNamespacesIfNeeded(); ctrl.loadNamespacesIfNeeded();
}); });
it('should initialize from all namespaces', () => {
ctrl.$onInit();
state.go('fakeState', new StateParams('_all'));
scope.$digest();
expect(ctrl.selectedNamespace).toBe('_all');
ctrl.loadNamespacesIfNeeded();
httpBackend.whenGET('api/v1/namespace').respond({
namespaces: [{objectMeta: {name: 'a'}}],
});
httpBackend.flush();
expect(ctrl.namespaces).toEqual(['a']);
expect(ctrl.selectedNamespace).toBe('_all');
});
it('should format namespace', () => { it('should format namespace', () => {
ctrl.selectedNamespace = '_all'; ctrl.selectedNamespace = '_all';
expect(ctrl.formatNamespace()).toBe('All namespaces'); expect(ctrl.formatNamespace()).toBe('All namespaces');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册