Skip to content

Commit d8a8dde

Browse files
authored
fix(SecretLabels): update maxLabels logic (#706)
Update logic to check for "< maxLabels" instead of "<= maxLabels", so at most maxLabels labels are shown (indices 0 to maxLabels-1). Fixes KFLUXUI-1050 Assisted-by: Cursor
1 parent 6ee0ec7 commit d8a8dde

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/components/Secrets/SecretsListView/SecretLabels.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const SecretLabels = ({
2222
) : (
2323
<>
2424
{labels.map((l, i) => {
25-
if (expanded || i <= maxLabels) {
25+
if (expanded || i < maxLabels) {
2626
return (
2727
<Label key={l} className="secret-label">
2828
{l}

src/components/Secrets/__tests___/SecretLabels.spec.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render } from '@testing-library/react';
2+
import { SECRET_MAX_LABELS } from '~/consts/secrets';
23
import { SecretLabels } from '../SecretsListView/SecretLabels';
34

45
describe('SecretLabels', () => {
@@ -25,10 +26,23 @@ describe('SecretLabels', () => {
2526
handleToggle={() => {}}
2627
/>,
2728
);
28-
r.debug();
2929
expect(r.getByText('label1')).toBeInTheDocument();
3030
expect(r.getByText('label2')).toBeInTheDocument();
31-
expect(r.queryByText('label5')).not.toBeInTheDocument();
31+
expect(r.getByText('label3')).toBeInTheDocument();
32+
expect(r.queryByText('label4')).not.toBeInTheDocument();
33+
expect(r.getByText('Show more')).toBeInTheDocument();
34+
});
35+
36+
it('should hide the label at maxLabels index when collapsed', () => {
37+
const labels = Array.from({ length: SECRET_MAX_LABELS + 1 }, (_, i) => `label${i + 1}`);
38+
const r = render(
39+
<SecretLabels labels={labels} index={0} expanded={false} handleToggle={() => {}} />,
40+
);
41+
42+
labels.slice(0, SECRET_MAX_LABELS).forEach((label) => {
43+
expect(r.getByText(label)).toBeInTheDocument();
44+
});
45+
expect(r.queryByText(labels[SECRET_MAX_LABELS])).not.toBeInTheDocument();
3246
expect(r.getByText('Show more')).toBeInTheDocument();
3347
});
3448

0 commit comments

Comments
 (0)