Skip to content

Commit

Permalink
Remove sid duplication from view
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksy committed Apr 12, 2024
1 parent c6b63a1 commit 87b5dd2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
5 changes: 3 additions & 2 deletions assets/js/pages/HostsList/HostsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Table from '@common/Table';
import Tags from '@common/Tags';
import Tooltip from '@common/Tooltip';

import { uniqBy } from 'lodash';
import { post, del } from '@lib/network';
import { agentVersionWarning } from '@lib/agent';

Expand Down Expand Up @@ -129,8 +130,8 @@ function HostsList() {
</SapSystemLink>,
];
});

return sidsArray;
const extractSid = (item) => item[1]?.props?.children || null;
return uniqBy(sidsArray, extractSid);
},
},
{
Expand Down
31 changes: 29 additions & 2 deletions assets/js/pages/HostsList/HostsList.test.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from 'react';
import { act, screen, waitFor } from '@testing-library/react';
import { faker } from '@faker-js/faker';
import userEvent from '@testing-library/user-event';
import 'intersection-observer';
import '@testing-library/jest-dom';
import { hostFactory } from '@lib/test-utils/factories';
import {
hostFactory,
sapSystemApplicationInstanceFactory,
} from '@lib/test-utils/factories';

import {
renderWithRouter,
Expand Down Expand Up @@ -54,7 +58,6 @@ describe('HostsLists component', () => {
const [StatefulHostsList] = withDefaultState(<HostsList />);
const params = { route: `/hosts?hostname=${host}` };
renderWithRouter(StatefulHostsList, params);

const table = screen.getByRole('table');
expect(table.querySelector('td:nth-child(2)')).toHaveTextContent(
host
Expand Down Expand Up @@ -121,6 +124,30 @@ describe('HostsLists component', () => {
).toBeVisible()
);
});

it('should show only unique SIDs', async () => {
const host = hostFactory.build();
const duplicateSID = faker.string.alpha({ casing: 'upper', count: 3 });
const sapInstances = sapSystemApplicationInstanceFactory.buildList(2, {
sid: duplicateSID,
host_id: host.id,
});

const state = {
...defaultInitialState,
hostsList: {
hosts: [host],
},
sapSystemsList: {
applicationInstances: [...sapInstances],
},
};

const [StatefulHostsList] = withState(<HostsList />, state);
renderWithRouter(StatefulHostsList);

expect(screen.getAllByText(duplicateSID).length).toBe(1);
});
});

describe('deregistration', () => {
Expand Down

0 comments on commit 87b5dd2

Please sign in to comment.