2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2020-07-24 17:49:42 -04:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2024-11-12 09:27:07 -08:00
|
|
|
import { authenticateSession } from 'ember-simple-auth/test-support';
|
2020-07-24 17:49:42 -04:00
|
|
|
|
2020-07-29 15:47:23 -04:00
|
|
|
module('Unit | Controller | application', function (hooks) {
|
2020-07-24 17:49:42 -04:00
|
|
|
setupTest(hooks);
|
|
|
|
|
|
2024-11-12 09:27:07 -08:00
|
|
|
let controller;
|
|
|
|
|
let featureEdition;
|
|
|
|
|
let featuresService;
|
|
|
|
|
let session;
|
2025-05-22 16:34:40 -07:00
|
|
|
let router;
|
2024-11-12 09:27:07 -08:00
|
|
|
|
|
|
|
|
hooks.beforeEach(async function () {
|
2024-12-03 10:27:27 -08:00
|
|
|
await authenticateSession({});
|
2024-11-12 09:27:07 -08:00
|
|
|
controller = this.owner.lookup('controller:application');
|
|
|
|
|
featureEdition = this.owner.lookup('service:featureEdition');
|
|
|
|
|
featuresService = this.owner.lookup('service:features');
|
|
|
|
|
session = this.owner.lookup('service:session');
|
2025-05-22 16:34:40 -07:00
|
|
|
router = this.owner.lookup('service:router');
|
2024-11-12 09:27:07 -08:00
|
|
|
});
|
|
|
|
|
|
2020-07-29 15:47:23 -04:00
|
|
|
test('it exists', function (assert) {
|
2020-07-24 17:49:42 -04:00
|
|
|
assert.ok(controller);
|
|
|
|
|
});
|
2024-11-12 09:27:07 -08:00
|
|
|
|
|
|
|
|
test('invalidateSession action de-authenticates a user', async function (assert) {
|
|
|
|
|
assert.true(session.isAuthenticated);
|
|
|
|
|
|
|
|
|
|
await controller.invalidateSession();
|
|
|
|
|
|
|
|
|
|
assert.false(session.isAuthenticated);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('toggleTheme action sets theme to specified value', function (assert) {
|
|
|
|
|
assert.notOk(session.data.theme);
|
|
|
|
|
|
|
|
|
|
controller.toggleTheme('light');
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(session.data.theme, 'light');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('toggleEdition action sets edition to specified value', function (assert) {
|
|
|
|
|
assert.notOk(featureEdition.edition);
|
|
|
|
|
|
|
|
|
|
controller.toggleEdition('oss');
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(featureEdition.edition, 'oss');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('toggleFeature action toggles specified feature', function (assert) {
|
|
|
|
|
assert.false(featuresService.isEnabled('ssh-target'));
|
|
|
|
|
|
|
|
|
|
controller.toggleFeature('ssh-target');
|
|
|
|
|
|
|
|
|
|
assert.true(featuresService.isEnabled('ssh-target'));
|
|
|
|
|
});
|
2025-05-22 16:34:40 -07:00
|
|
|
|
|
|
|
|
test.each(
|
|
|
|
|
'customRouteChangeValidator',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
from: '/scopes',
|
|
|
|
|
to: '/scopes',
|
|
|
|
|
expectedResult: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: '/scopes/global/scopes',
|
|
|
|
|
to: '/scopes/global/scopes',
|
|
|
|
|
expectedResult: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: '/scopes/global/scopes?search=xyz',
|
|
|
|
|
to: '/scopes/global/scopes',
|
|
|
|
|
expectedResult: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: '/scopes/global/scopes?search=xyz',
|
|
|
|
|
to: '/scopes/global/scopes?search=xy',
|
|
|
|
|
expectedResult: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
to: '/scopes/global/scopes',
|
|
|
|
|
expectedResult: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: '/scopes/global/scopes',
|
|
|
|
|
expectedResult: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: '/scopes/global/scopes',
|
|
|
|
|
to: '/scopes/global/auth-methods',
|
|
|
|
|
expectedResult: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: '/scopes/global/scopes',
|
|
|
|
|
to: '/scopes/o_12345/scopes',
|
|
|
|
|
expectedResult: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: '/scopes/global/roles/r_123/scopes',
|
|
|
|
|
to: '/scopes/global/roles/r_321/scopes',
|
|
|
|
|
expectedResult: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
async function (assert, input) {
|
|
|
|
|
const transition = {
|
|
|
|
|
from: input.from ? router.recognize(input.from) : undefined,
|
|
|
|
|
to: input.to ? router.recognize(input.to) : undefined,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
|
controller.customRouteChangeValidator(transition),
|
|
|
|
|
input.expectedResult,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
2020-07-24 17:49:42 -04:00
|
|
|
});
|