Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Fix CC mount filter #28347

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ui/lib/core/addon/utils/client-count-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ export const filteredTotalForMount = (
if (!nsPath || !mountPath || isEmpty(byNamespace)) return emptyCounts();
return (
byNamespace
.find((namespace) => namespace.label === nsPath)
?.mounts.find((mount: MountClients) => mount.label === mountPath) || emptyCounts()
.find((namespace) => sanitizePath(namespace.label) === sanitizePath(nsPath))
?.mounts.find((mount: MountClients) => sanitizePath(mount.label) === sanitizePath(mountPath)) ||
emptyCounts()
);
};

Expand Down
72 changes: 72 additions & 0 deletions ui/tests/integration/utils/client-count-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
destructureClientCounts,
sortMonthsByTimestamp,
filterByMonthDataForMount,
filteredTotalForMount,
} from 'core/utils/client-count-utils';
import clientsHandler from 'vault/mirage/handlers/clients';
import {
Expand Down Expand Up @@ -481,4 +482,75 @@ module('Integration | Util | client count utils', function (hooks) {
assert.deepEqual(result[0], this.getExpected('some-mount', 0), 'works when namespace is not found');
});
});

module('filteredTotalForMount', function (hooks) {
hooks.beforeEach(function () {
this.byNamespace = SERIALIZED_ACTIVITY_RESPONSE.by_namespace;
});

const emptyCounts = {
acme_clients: 0,
clients: 0,
entity_clients: 0,
non_entity_clients: 0,
secret_syncs: 0,
};

[
{
when: 'no namespace filter passed',
result: 'it returns empty counts',
ns: '',
mount: 'auth/authid/0',
expected: emptyCounts,
},
{
when: 'no mount filter passed',
result: 'it returns empty counts',
ns: 'ns1',
mount: '',
expected: emptyCounts,
},
{
when: 'no matching ns/mount exists',
result: 'it returns empty counts',
ns: 'ns1',
mount: 'auth/authid/1',
expected: emptyCounts,
},
{
when: 'mount and label have extra slashes',
result: 'it returns the data sanitized',
ns: 'ns1/',
mount: 'auth/authid/0/',
expected: {
label: 'auth/authid/0',
acme_clients: 0,
clients: 8394,
entity_clients: 4256,
non_entity_clients: 4138,
secret_syncs: 0,
},
},
{
when: 'mount within root',
result: 'it returns the data',
ns: 'root',
mount: 'kvv2-engine-0',
expected: {
label: 'kvv2-engine-0',
acme_clients: 0,
clients: 4290,
entity_clients: 0,
non_entity_clients: 0,
secret_syncs: 4290,
},
},
].forEach((testCase) => {
test(`it returns correct values when ${testCase.when}`, async function (assert) {
const actual = filteredTotalForMount(this.byNamespace, testCase.ns, testCase.mount);
assert.deepEqual(actual, testCase.expected);
});
});
});
});
Loading