vault/ui/tests/unit/utils/ldap-breadcrumbs-test.js
claire bontempo 6e3ae793f5
UI: LDAP Hierarchical Library names (#29293)
* refactor crumbs

* add subdirectory library route and hierarchical nav

* update library breadcrumbs;

* fix role popup menus

* add getter to library model for full path

* cleanup model getters

* add changelog

* add bug fix note

* add transition after deleting

* fix function definition

* update adapter test

* add test coverage

* fix crumb typo
2025-01-07 12:54:36 -06:00

80 lines
3.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { ldapBreadcrumbs, roleRoutes } from 'ldap/utils/ldap-breadcrumbs';
import { module, test } from 'qunit';
module('Unit | Utility | ldap breadcrumbs', function (hooks) {
hooks.beforeEach(async function () {
this.mountPath = 'my-engine';
this.roleType = 'static';
const routeParams = (childResource) => {
return [this.mountPath, this.roleType, childResource];
};
this.testCrumbs = (path, { lastItemCurrent }) => {
return ldapBreadcrumbs(path, routeParams, roleRoutes, lastItemCurrent);
};
});
test('it generates crumbs when the path is a directory', function (assert) {
const path = 'prod/org/';
let actual = this.testCrumbs(path, { lastItemCurrent: true });
let expected = [
{ label: 'prod', route: 'roles.subdirectory', models: [this.mountPath, this.roleType, 'prod/'] },
{ label: 'org' },
];
assert.propEqual(actual, expected, 'crumbs are correct when lastItemCurrent = true');
actual = this.testCrumbs(path, { lastItemCurrent: false });
expected = [
{ label: 'prod', route: 'roles.subdirectory', models: [this.mountPath, this.roleType, 'prod/'] },
{ label: 'org', route: 'roles.subdirectory', models: [this.mountPath, this.roleType, 'prod/org/'] },
];
assert.propEqual(actual, expected, 'crumbs are correct when lastItemCurrent = false');
});
test('it generates crumbs when the path is not a directory', function (assert) {
const path = 'prod/org/admin';
let actual = this.testCrumbs(path, { lastItemCurrent: true });
let expected = [
{ label: 'prod', route: 'roles.subdirectory', models: [this.mountPath, this.roleType, 'prod/'] },
{ label: 'org', route: 'roles.subdirectory', models: [this.mountPath, this.roleType, 'prod/org/'] },
{ label: 'admin' },
];
assert.propEqual(actual, expected, 'crumbs are correct when lastItemCurrent = true');
actual = this.testCrumbs(path, { lastItemCurrent: false });
expected = [
{ label: 'prod', route: 'roles.subdirectory', models: [this.mountPath, this.roleType, 'prod/'] },
{ label: 'org', route: 'roles.subdirectory', models: [this.mountPath, this.roleType, 'prod/org/'] },
{
label: 'admin',
route: 'roles.role.details',
models: [this.mountPath, this.roleType, 'prod/org/admin'],
},
];
assert.propEqual(actual, expected, 'crumbs are correct when lastItemCurrent = false');
});
test('it generates crumbs when the path is the top-level', function (assert) {
const path = 'prod/';
let actual = this.testCrumbs(path, { lastItemCurrent: true });
let expected = [{ label: 'prod' }];
assert.propEqual(actual, expected, 'crumbs are correct when lastItemCurrent = true');
actual = this.testCrumbs(path, { lastItemCurrent: false });
expected = [
{ label: 'prod', route: 'roles.subdirectory', models: [this.mountPath, this.roleType, 'prod/'] },
];
assert.propEqual(actual, expected, 'crumbs are correct when lastItemCurrent = false');
});
test('it fails gracefully when no path', function (assert) {
const path = undefined;
const actual = this.testCrumbs(path, { lastItemCurrent: false });
assert.propEqual(actual, [], 'returns empty array when path is null');
});
});