2018-09-25 16:28:26 +00:00
|
|
|
import { later, run } from '@ember/runloop';
|
2018-12-12 22:53:45 +00:00
|
|
|
import { module, test } from 'qunit';
|
2018-09-25 16:28:26 +00:00
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render, settled } from '@ember/test-helpers';
|
2018-11-05 16:56:59 +00:00
|
|
|
import apiStub from 'vault/tests/helpers/noop-all-api-requests';
|
2018-04-03 14:16:57 +00:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
|
|
|
import { create } from 'ember-cli-page-object';
|
|
|
|
import mountBackendForm from '../../pages/components/mount-backend-form';
|
|
|
|
|
|
|
|
import sinon from 'sinon';
|
|
|
|
|
|
|
|
const component = create(mountBackendForm);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Component | mount backend form', function (hooks) {
|
2018-09-25 16:28:26 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(function () {
|
2018-09-25 16:28:26 +00:00
|
|
|
this.owner.lookup('service:flash-messages').registerTypes(['success', 'danger']);
|
2018-12-12 22:53:45 +00:00
|
|
|
this.server = apiStub();
|
2018-09-25 16:28:26 +00:00
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.afterEach(function () {
|
2018-04-03 14:16:57 +00:00
|
|
|
this.server.shutdown();
|
2018-09-25 16:28:26 +00:00
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
await render(hbs`{{mount-backend-form}}`);
|
2019-03-30 17:07:52 +00:00
|
|
|
assert.equal(component.header, 'Enable an Authentication Method', 'renders auth header in default state');
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.ok(component.types.length > 0, 'renders type picker');
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it changes path when type is changed', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
await render(hbs`{{mount-backend-form}}`);
|
|
|
|
await component.selectType('aws');
|
|
|
|
await component.next();
|
|
|
|
assert.equal(component.pathValue, 'aws', 'sets the value of the type');
|
|
|
|
await component.back();
|
|
|
|
await component.selectType('approle');
|
|
|
|
await component.next();
|
|
|
|
assert.equal(component.pathValue, 'approle', 'updates the value of the type');
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it keeps path value if the user has changed it', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
await render(hbs`{{mount-backend-form}}`);
|
|
|
|
await component.selectType('approle');
|
|
|
|
await component.next();
|
|
|
|
assert.equal(component.pathValue, 'approle', 'defaults to approle (first in the list)');
|
|
|
|
await component.path('newpath');
|
|
|
|
await component.back();
|
|
|
|
await component.selectType('aws');
|
|
|
|
await component.next();
|
|
|
|
assert.equal(component.pathValue, 'newpath', 'updates to the value of the type');
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it calls mount success', async function (assert) {
|
2018-12-12 22:53:45 +00:00
|
|
|
this.server.post('/v1/sys/auth/foo', () => {
|
|
|
|
return [204, { 'Content-Type': 'application/json' }];
|
|
|
|
});
|
2018-09-25 16:28:26 +00:00
|
|
|
const spy = sinon.spy();
|
|
|
|
this.set('onMountSuccess', spy);
|
|
|
|
await render(hbs`{{mount-backend-form onMountSuccess=onMountSuccess}}`);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await component.mount('approle', 'foo');
|
2018-12-12 22:53:45 +00:00
|
|
|
|
|
|
|
later(() => run.cancelTimers(), 50);
|
|
|
|
await settled();
|
|
|
|
let enableRequest = this.server.handledRequests.findBy('url', '/v1/sys/auth/foo');
|
|
|
|
assert.ok(enableRequest, 'it calls enable on an auth method');
|
2018-04-03 14:16:57 +00:00
|
|
|
assert.ok(spy.calledOnce, 'calls the passed success method');
|
|
|
|
});
|
|
|
|
});
|