ui - fix auth form so that it will preference path'd auth methods instead of token (#5281)

This commit is contained in:
Matthew Irish 2018-09-05 14:28:10 -05:00 committed by GitHub
parent cdd08cba58
commit 6dfba3bab3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -57,7 +57,10 @@ export default Ember.Component.extend(DEFAULTS, {
}
// this is here because we're changing the `with` attr and there's no way to short-circuit rendering,
// so we'll just nav -> get new attrs -> re-render
if (!this.get('selectedAuth') || (this.get('selectedAuth') && !this.get('selectedAuthBackend'))) {
if (
(this.get('fetchMethods.isIdle') && !this.get('selectedAuth')) ||
(this.get('selectedAuth') && !this.get('selectedAuthBackend'))
) {
this.set('selectedAuth', this.firstMethod());
this.get('router').replaceWith({
queryParams: {

View File

@ -104,11 +104,21 @@ test('it renders AdapterError style errors', function(assert) {
});
test('it renders all the supported tabs when no methods are passed', function(assert) {
let replaceSpy = sinon.spy(this.get('router'), 'replaceWith');
this.render(hbs`{{auth-form cluster=cluster}}`);
assert.equal(component.tabs.length, BACKENDS.length, 'renders a tab for every backend');
return wait().then(() => {
assert.equal(component.tabs.length, BACKENDS.length, 'renders a tab for every backend');
assert.equal(
replaceSpy.getCall(0).args[0].queryParams.with,
'token',
'calls router replaceWith properly'
);
});
});
test('it renders all the supported methods and Other tab when methods are present', function(assert) {
let replaceSpy = sinon.spy(this.get('router'), 'replaceWith');
let methods = {
'foo/': {
type: 'userpass',
@ -128,7 +138,9 @@ test('it renders all the supported methods and Other tab when methods are presen
assert.equal(component.tabs.length, 2, 'renders a tab for userpass and Other');
assert.equal(component.tabs.objectAt(0).name, 'foo', 'uses the path in the label');
assert.equal(component.tabs.objectAt(1).name, 'Other', 'second tab is the Other tab');
assert.equal(replaceSpy.getCall(0).args[0].queryParams.with, 'foo/', 'calls router replaceWith properly');
server.shutdown();
replaceSpy.restore();
});
});