提交 17e20e07 编写于 作者: B bryk

Auto-select namespace in deploy form and add namespace to deamonsetlist

Fixes #853
上级 1c659b22
......@@ -53,12 +53,13 @@ export default function stateConfig($stateProvider) {
/**
* @param {!angular.$resource} $resource
* @param {!./../chrome/chrome_state.StateParams} $stateParams
* @return {!angular.$q.Promise}
* @ngInject
*/
export function resolveDaemonSetList($resource) {
export function resolveDaemonSetList($resource, $stateParams) {
/** @type {!angular.Resource<!backendApi.DaemonSetList>} */
let resource = $resource('api/v1/daemonset');
let resource = $resource(`api/v1/daemonset/${$stateParams.namespace || ''}`);
return resource.get().$promise;
}
......@@ -38,9 +38,10 @@ export default class DeployFromSettingsController {
* @param {!angular.$resource} $resource
* @param {!angular.$q} $q
* @param {!md.$dialog} $mdDialog
* @param {!./../chrome/chrome_state.StateParams} $stateParams
* @ngInject
*/
constructor(namespaces, protocols, $log, $state, $resource, $q, $mdDialog) {
constructor(namespaces, protocols, $log, $state, $resource, $q, $mdDialog, $stateParams) {
/**
* Initialized from the template.
* @export {!angular.FormController}
......@@ -140,7 +141,7 @@ export default class DeployFromSettingsController {
* Currently chosen namespace.
* @export {string}
*/
this.namespace = this.namespaces[0];
this.namespace = $stateParams.namespace || this.namespaces[0];
/**
* @export {?number}
......
......@@ -24,9 +24,21 @@ describe('StateConfig for daemon set list', () => {
let resource = jasmine.createSpy('$resource');
resource.and.returnValue({get: function() { return {$promise: promise}; }});
let actual = resolveDaemonSetList(resource);
let actual = resolveDaemonSetList(resource, {namespace: 'foo'});
expect(resource).toHaveBeenCalledWith('api/v1/daemonset');
expect(resource).toHaveBeenCalledWith('api/v1/daemonset/foo');
expect(actual).toBe(promise);
}));
it('should resolve daemon sets with no namespace', angular.mock.inject(($q) => {
let promise = $q.defer().promise;
let resource = jasmine.createSpy('$resource');
resource.and.returnValue({get: function() { return {$promise: promise}; }});
let actual = resolveDaemonSetList(resource, {});
expect(resource).toHaveBeenCalledWith('api/v1/daemonset/');
expect(actual).toBe(promise);
}));
});
......@@ -66,6 +66,22 @@ describe('DeployFromSettings controller', () => {
expect(result).toEqual('');
});
it('should select initial namespace', angular.mock.inject(($controller) => {
ctrl = $controller(
DeployFromSettingController,
{namespaces: {namespaces: ['foo', 'bar']}, protocols: {protocols: []}, $stateParams: {}});
expect(ctrl.namespace).toBe('foo');
ctrl = $controller(DeployFromSettingController, {
namespaces: {namespaces: ['foo', 'bar']},
protocols: {protocols: []},
$stateParams: {namespace: 'bar'},
});
expect(ctrl.namespace).toBe('bar');
}));
it('should return empty string when containerImage is empty', () => {
// given
ctrl.containerImage = '';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册