2018-09-25 16:28:26 +00:00
|
|
|
import Service from '@ember/service';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render } from '@ember/test-helpers';
|
2018-04-03 14:16:57 +00:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2018-09-25 16:28:26 +00:00
|
|
|
import waitForError from 'vault/tests/helpers/wait-for-error';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
const versionStub = Service.extend({
|
2018-04-03 14:16:57 +00:00
|
|
|
features: null,
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('helper:has-feature', function (hooks) {
|
2018-09-25 16:28:26 +00:00
|
|
|
setupRenderingTest(hooks);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(function () {
|
2018-09-25 16:28:26 +00:00
|
|
|
this.owner.register('service:version', versionStub);
|
|
|
|
this.versionService = this.owner.lookup('service:version');
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it asserts on unknown features', async function (assert) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const promise = waitForError();
|
2018-09-25 16:28:26 +00:00
|
|
|
render(hbs`{{has-feature 'New Feature'}}`);
|
2022-11-09 23:15:31 +00:00
|
|
|
const err = await promise;
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.ok(
|
|
|
|
err.message.includes('New Feature is not one of the available values for Vault Enterprise features.'),
|
|
|
|
'asserts when an unknown feature is passed as an arg'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it is true with existing features', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
this.set('versionService.features', ['HSM']);
|
|
|
|
await render(hbs`{{if (has-feature 'HSM') 'It works' null}}`);
|
|
|
|
assert.dom(this.element).hasText('It works', 'present features evaluate to true');
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it is false with missing features', async function (assert) {
|
2018-09-25 16:28:26 +00:00
|
|
|
this.set('versionService.features', ['MFA']);
|
|
|
|
await render(hbs`{{if (has-feature 'HSM') 'It works' null}}`);
|
|
|
|
assert.dom(this.element).hasText('', 'missing features evaluate to false');
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|