From 85e62e20f57d2d0413e6757aef83518e09874291 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Wed, 5 Sep 2018 14:12:07 -0500 Subject: [PATCH] fix auth form so that it will preference path'd auth methods instead of token --- ui/app/components/auth-form.js | 5 ++++- ui/tests/integration/components/auth-form-test.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ui/app/components/auth-form.js b/ui/app/components/auth-form.js index 409318715df5..7f9fcb5a2199 100644 --- a/ui/app/components/auth-form.js +++ b/ui/app/components/auth-form.js @@ -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: { diff --git a/ui/tests/integration/components/auth-form-test.js b/ui/tests/integration/components/auth-form-test.js index ae2d612527bd..834ac117601e 100644 --- a/ui/tests/integration/components/auth-form-test.js +++ b/ui/tests/integration/components/auth-form-test.js @@ -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(); }); });