From 87b5dd2ab474586548c940b85f4698a4a9071251 Mon Sep 17 00:00:00 2001 From: EMaksy Date: Fri, 12 Apr 2024 16:59:12 +0200 Subject: [PATCH] Remove sid duplication from view --- assets/js/pages/HostsList/HostsList.jsx | 5 ++-- assets/js/pages/HostsList/HostsList.test.jsx | 31 ++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/assets/js/pages/HostsList/HostsList.jsx b/assets/js/pages/HostsList/HostsList.jsx index 22da87f720..05563bff6f 100644 --- a/assets/js/pages/HostsList/HostsList.jsx +++ b/assets/js/pages/HostsList/HostsList.jsx @@ -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'; @@ -129,8 +130,8 @@ function HostsList() { , ]; }); - - return sidsArray; + const extractSid = (item) => item[1]?.props?.children || null; + return uniqBy(sidsArray, extractSid); }, }, { diff --git a/assets/js/pages/HostsList/HostsList.test.jsx b/assets/js/pages/HostsList/HostsList.test.jsx index e2331f8f2b..fa539be6f0 100644 --- a/assets/js/pages/HostsList/HostsList.test.jsx +++ b/assets/js/pages/HostsList/HostsList.test.jsx @@ -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, @@ -54,7 +58,6 @@ describe('HostsLists component', () => { const [StatefulHostsList] = withDefaultState(); const params = { route: `/hosts?hostname=${host}` }; renderWithRouter(StatefulHostsList, params); - const table = screen.getByRole('table'); expect(table.querySelector('td:nth-child(2)')).toHaveTextContent( host @@ -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(, state); + renderWithRouter(StatefulHostsList); + + expect(screen.getAllByText(duplicateSID).length).toBe(1); + }); }); describe('deregistration', () => {