2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-24 18:02:15 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render, click, fillIn } from '@ember/test-helpers';
|
|
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
|
|
|
|
module('Integration | Component | mount-accessor-select', function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function () {
|
|
|
|
this.store = this.owner.lookup('service:store');
|
|
|
|
this.server.get('/sys/auth', () => ({
|
|
|
|
data: {
|
|
|
|
'userpass/': { type: 'userpass', accessor: 'auth_userpass_1234' },
|
|
|
|
'token/': { type: 'token', accessor: 'auth_token' },
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
this.set('onChange', sinon.spy());
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders', async function (assert) {
|
2022-10-18 15:46:02 +00:00
|
|
|
await render(hbs`<MountAccessorSelect @onChange={{this.onChange}}/>`);
|
2022-05-24 18:02:15 +00:00
|
|
|
assert.dom('[data-test-mount-accessor-select]').exists();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it filters token', async function (assert) {
|
2022-10-18 15:46:02 +00:00
|
|
|
await render(hbs`<MountAccessorSelect @onChange={{this.onChange}} @filterToken={{true}}/>`);
|
2022-05-24 18:02:15 +00:00
|
|
|
await click('[data-test-mount-accessor-select]');
|
2022-11-09 23:15:31 +00:00
|
|
|
const options = document.querySelector('[data-test-mount-accessor-select]').options;
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(options.length, 1, 'only the auth option, no token');
|
2022-05-24 18:02:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it shows token', async function (assert) {
|
2022-10-18 15:46:02 +00:00
|
|
|
await render(hbs`<MountAccessorSelect @onChange={{this.onChange}}/>`);
|
2022-05-24 18:02:15 +00:00
|
|
|
await click('[data-test-mount-accessor-select]');
|
2022-11-09 23:15:31 +00:00
|
|
|
const options = document.querySelector('[data-test-mount-accessor-select]').options;
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(options.length, 2, 'both auth and token show');
|
2022-05-24 18:02:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it sends value to parent onChange', async function (assert) {
|
2022-10-18 15:46:02 +00:00
|
|
|
await render(hbs`<MountAccessorSelect @onChange={{this.onChange}}/>`);
|
2022-05-24 18:02:15 +00:00
|
|
|
await fillIn('[data-test-mount-accessor-select]', 'auth_userpass_1234');
|
|
|
|
assert.ok(
|
|
|
|
this.onChange.calledWith('auth_userpass_1234'),
|
|
|
|
'Passes the auth method selected to the parent'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it selects the first option if no default', async function (assert) {
|
2022-10-18 15:46:02 +00:00
|
|
|
await render(hbs`<MountAccessorSelect @onChange={{this.onChange}} />`);
|
2022-11-09 23:15:31 +00:00
|
|
|
const defaultSelection = document.querySelector('[data-test-mount-accessor-select]').options[0].innerHTML;
|
2022-05-24 18:02:15 +00:00
|
|
|
// remove all non letters
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(defaultSelection.replace(/\W/g, ''), 'userpassuserpass');
|
2022-05-24 18:02:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it shows Select one if yes default', async function (assert) {
|
2022-10-18 15:46:02 +00:00
|
|
|
await render(hbs`<MountAccessorSelect @onChange={{this.onChange}} @noDefault={{true}} />`);
|
2022-11-09 23:15:31 +00:00
|
|
|
const defaultSelection = document.querySelector('[data-test-mount-accessor-select]').options[0].innerHTML;
|
2022-05-24 18:02:15 +00:00
|
|
|
// remove all non letters
|
2022-10-18 15:46:02 +00:00
|
|
|
assert.strictEqual(defaultSelection.replace(/\W/g, ''), 'Selectone');
|
2022-05-24 18:02:15 +00:00
|
|
|
});
|
|
|
|
});
|