Skip to content

Commit

Permalink
refactor(General): ♻️ Refactor overview pages
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoval committed Sep 15, 2024
1 parent 99aca42 commit 59a23ee
Show file tree
Hide file tree
Showing 48 changed files with 407 additions and 483 deletions.
22 changes: 3 additions & 19 deletions __tests__/pages/Services/HttpRequests.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import flowPairsData from '../../../mocks/data/FLOW_PAIRS.json';
import processesData from '../../../mocks/data/PROCESSES.json';
import servicesData from '../../../mocks/data/SERVICES.json';
import { loadMockServer } from '../../../mocks/server';
import { AvailableProtocols } from '../../../src/API/REST.enum';
import { waitForElementToBeRemovedTimeout } from '../../../src/config/config';
import { getTestsIds } from '../../../src/config/testIds';
import { Wrapper } from '../../../src/core/components/Wrapper';
Expand Down Expand Up @@ -38,12 +37,7 @@ describe('Begin testing the Http requests component', () => {
const { getByText } = render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<HttpRequests
serviceId={servicesResults[0].identity}
serviceName={servicesResults[0].name}
protocol={AvailableProtocols.Http2}
viewSelected={TAB_0_KEY}
/>
<HttpRequests id={servicesResults[0].identity} name={servicesResults[0].name} viewSelected={TAB_0_KEY} />
</Suspense>
</Wrapper>
);
Expand All @@ -58,12 +52,7 @@ describe('Begin testing the Http requests component', () => {
const { getByText } = render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<HttpRequests
serviceId={servicesResults[0].identity}
serviceName={servicesResults[0].name}
protocol={AvailableProtocols.Http2}
viewSelected={TAB_1_KEY}
/>
<HttpRequests id={servicesResults[0].identity} name={servicesResults[0].name} viewSelected={TAB_1_KEY} />
</Suspense>
</Wrapper>
);
Expand All @@ -78,12 +67,7 @@ describe('Begin testing the Http requests component', () => {
render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<HttpRequests
serviceId={servicesResults[0].identity}
serviceName={servicesResults[0].name}
protocol={AvailableProtocols.Http2}
viewSelected={TAB_2_KEY}
/>
<HttpRequests id={servicesResults[0].identity} name={servicesResults[0].name} viewSelected={TAB_2_KEY} />
</Suspense>
</Wrapper>
);
Expand Down
31 changes: 5 additions & 26 deletions __tests__/pages/Services/TcpConnections.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import flowPairsData from '../../../mocks/data/FLOW_PAIRS.json';
import processesData from '../../../mocks/data/PROCESSES.json';
import servicesData from '../../../mocks/data/SERVICES.json';
import { loadMockServer } from '../../../mocks/server';
import { AvailableProtocols } from '../../../src/API/REST.enum';
import { waitForElementToBeRemovedTimeout } from '../../../src/config/config';
import { getTestsIds } from '../../../src/config/testIds';
import { Wrapper } from '../../../src/core/components/Wrapper';
import { TAB_0_KEY, TAB_1_KEY, TAB_2_KEY, TAB_3_KEY } from '../../../src/pages/Services/Services.constants';
import { TAB_0_KEY, TAB_1_KEY, TAB_3_KEY, TAB_4_KEY } from '../../../src/pages/Services/Services.constants';
import LoadingPage from '../../../src/pages/shared/Loading';
import { MetricsLabels } from '../../../src/pages/shared/Metrics/Metrics.enum';

Expand All @@ -39,12 +38,7 @@ describe('Begin testing the TCP connections component', () => {
const { getByText } = render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<TcpConnections
serviceId={servicesResults[5].identity}
serviceName={servicesResults[5].name}
protocol={AvailableProtocols.Tcp}
viewSelected={TAB_0_KEY}
/>
<TcpConnections id={servicesResults[5].identity} name={servicesResults[5].name} viewSelected={TAB_0_KEY} />
</Suspense>
</Wrapper>
);
Expand All @@ -59,12 +53,7 @@ describe('Begin testing the TCP connections component', () => {
const { getByText } = render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<TcpConnections
serviceId={servicesResults[2].identity}
serviceName={servicesResults[2].name}
protocol={AvailableProtocols.Tcp}
viewSelected={TAB_1_KEY}
/>
<TcpConnections id={servicesResults[2].identity} name={servicesResults[2].name} viewSelected={TAB_1_KEY} />
</Suspense>
</Wrapper>
);
Expand All @@ -79,12 +68,7 @@ describe('Begin testing the TCP connections component', () => {
render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<TcpConnections
serviceId={servicesResults[4].identity}
serviceName={servicesResults[4].name}
protocol={AvailableProtocols.Tcp}
viewSelected={TAB_2_KEY}
/>
<TcpConnections id={servicesResults[4].identity} name={servicesResults[4].name} viewSelected={TAB_3_KEY} />
</Suspense>
</Wrapper>
);
Expand All @@ -100,12 +84,7 @@ describe('Begin testing the TCP connections component', () => {
const { queryByTestId, getByText, getAllByText } = render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<TcpConnections
serviceId={servicesResults[4].identity}
serviceName={servicesResults[4].name}
protocol={AvailableProtocols.Tcp}
viewSelected={TAB_3_KEY}
/>
<TcpConnections id={servicesResults[4].identity} name={servicesResults[4].name} viewSelected={TAB_4_KEY} />
</Suspense>
</Wrapper>
);
Expand Down
12 changes: 7 additions & 5 deletions __tests__/pages/Topology/useTopologyComponentData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ describe('useTopologyComponentData', () => {
});

const components = { results: [{ identity: 'component1' }, { identity: 'component2' }, { identity: 'component3' }] };
const componentPairs = [
{ sourceId: 'component1', destinationId: 'component2' },
{ sourceId: 'component2', destinationId: 'component3' }
];
const componentPairs = {
results: [
{ sourceId: 'component1', destinationId: 'component2' },
{ sourceId: 'component2', destinationId: 'component3' }
]
};

it('should call useTopologyComponentData', async () => {
(useSuspenseQueries as jest.Mock).mockReturnValue([{ data: components }, { data: componentPairs }]);
Expand All @@ -25,7 +27,7 @@ describe('useTopologyComponentData', () => {

await waitFor(() => {
expect(result.current.components).toEqual(components.results);
expect(result.current.componentsPairs).toEqual(componentPairs);
expect(result.current.componentsPairs).toEqual(componentPairs.results);
});
});
});
18 changes: 9 additions & 9 deletions __tests__/pages/Topology/useTopologySiteData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ describe('useTopologySiteData', () => {

(useSuspenseQueries as jest.Mock).mockReturnValue([
{ data: { results: mockSites } },
{ data: null },
{ data: mockSitesPairs },
{ data: undefined },
{ data: { results: mockSitesPairs } },
{ data: mockMetrics }
]);

Expand All @@ -35,7 +35,7 @@ describe('useTopologySiteData', () => {

await waitFor(() => {
expect(result.current.sites).toEqual(mockSites);
expect(result.current.routerLinks).toEqual(null);
expect(result.current.routerLinks).toBeUndefined();
expect(result.current.sitesPairs).toEqual(mockSitesPairs);
expect(result.current.metrics).toEqual(mockMetrics);
});
Expand All @@ -54,8 +54,8 @@ describe('useTopologySiteData', () => {

(useSuspenseQueries as jest.Mock).mockReturnValue([
{ data: { results: mockSites } },
{ data: mockRouterLinks },
{ data: null },
{ data: { results: mockRouterLinks } },
{ data: undefined },
{ data: null }
]);

Expand All @@ -71,7 +71,7 @@ describe('useTopologySiteData', () => {
await waitFor(() => {
expect(result.current.sites).toEqual(mockSites);
expect(result.current.routerLinks).toBe(mockRouterLinks);
expect(result.current.sitesPairs).toBeNull();
expect(result.current.sitesPairs).toBeUndefined();
expect(result.current.metrics).toBeNull();
});
});
Expand All @@ -82,8 +82,8 @@ describe('useTopologySiteData', () => {

(useSuspenseQueries as jest.Mock).mockReturnValue([
{ data: { results: mockSites } },
{ data: null },
{ data: mockSitesPairs },
{ data: undefined },
{ data: { results: mockSitesPairs } },
{ data: null }
]);

Expand All @@ -98,7 +98,7 @@ describe('useTopologySiteData', () => {

await waitFor(() => {
expect(result.current.sites).toEqual(mockSites);
expect(result.current.routerLinks).toBeNull();
expect(result.current.routerLinks).toBeUndefined();
expect(result.current.sitesPairs).toEqual(mockSitesPairs);
expect(result.current.metrics).toBeNull();
});
Expand Down
28 changes: 13 additions & 15 deletions mocks/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const processGroupPairs: ResponseWrapper<ComponentPairsResponse[]> = require(`${
const processes: ResponseWrapper<ProcessResponse[]> = require(`${path}/PROCESSES.json`);
const sitePairs: ResponseWrapper<SitePairsResponse[]> = require(`${path}/SITE_PAIRS.json`);
const processPairs: ResponseWrapper<ProcessPairsResponse[]> = require(`${path}/PROCESS_PAIRS.json`);
const services = require(`${path}/SERVICES.json`);
const flowPairs = require(`${path}/FLOW_PAIRS.json`);
const services: ResponseWrapper<ServiceResponse[]> = require(`${path}/SERVICES.json`);
const flowPairs: ResponseWrapper<FlowPairsResponse[]> = require(`${path}/FLOW_PAIRS.json`);
const links: ResponseWrapper<LinkResponse[]> = require(`${path}/LINKS.json`);

interface ApiProps {
Expand Down Expand Up @@ -257,7 +257,7 @@ export const MockApi = {

if (queryParams.name || queryParams.protocol) {
results = results.filter(
({ name, protocol }: ServiceResponse) =>
({ name, protocol }) =>
name.startsWith(queryParams.name as string) || protocol.startsWith(queryParams.protocol as string)
);
}
Expand All @@ -283,8 +283,7 @@ export const MockApi = {
}

const resultsFiltered = results.filter(
({ sourceId, destinationId }: SitePairsResponse) =>
sourceId === queryParams.sourceId || destinationId === queryParams.destinationId
({ sourceId, destinationId }) => sourceId === queryParams.sourceId || destinationId === queryParams.destinationId
);

return { ...processPairs, results: resultsFiltered };
Expand All @@ -299,8 +298,7 @@ export const MockApi = {
}

const resultsFiltered = results.filter(
({ sourceId, destinationId }: ProcessPairsResponse) =>
sourceId === queryParams.sourceId || destinationId === queryParams.destinationId
({ sourceId, destinationId }) => sourceId === queryParams.sourceId || destinationId === queryParams.destinationId
);

return { ...processPairs, results: resultsFiltered };
Expand All @@ -311,7 +309,7 @@ export const MockApi = {
}),

getService: (_: unknown, { params: { id } }: ApiProps) => {
const results = services.results.find(({ identity }: ServiceResponse) => identity === id);
const results = services.results.find(({ identity }) => identity === id);

return { results };
},
Expand Down Expand Up @@ -439,17 +437,17 @@ export function loadMockServer() {
this.get(`${prefix}/processgrouppairs`, () => processGroupPairs);

this.get(`${prefix}/processgrouppairs/:id`, (_, { params: { id } }) => ({
results: processGroupPairs.results.find(({ identity }: ProcessPairsResponse) => identity === id)
results: processGroupPairs.results.find(({ identity }) => identity === id)
}));

this.get(`${prefix}/processes/:id`, (_, { params: { id } }) => ({
results: MockApi.getProcesses(null, { params: {}, queryParams: {} }).results.find(
({ identity }: ProcessResponse) => identity === id
({ identity }) => identity === id
)
}));

this.get(`${prefix}/processes/:id/addresses`, (_, { params: { id } }): { results: ProcessResponse[] } => {
const process = processes.results.find(({ identity }: ProcessResponse) => identity === id);
this.get(`${prefix}/processes/:id/addresses`, (_, { params: { id } }): { results: ServiceResponse[] } => {
const process = processes.results.find(({ identity }) => identity === id);

if (!process) {
return { results: [] };
Expand All @@ -458,7 +456,7 @@ export function loadMockServer() {
const processNamePrefix = process.name.split('-')[0];

return {
results: services.results.filter(({ name }: ServiceResponse) => name.includes(processNamePrefix))
results: services.results.filter(({ name }) => name.includes(processNamePrefix))
};
});

Expand All @@ -467,7 +465,7 @@ export function loadMockServer() {
const queryRoutingKey = queryParams.routingKey;

const results = flowPairs.results.filter(
({ protocol, routingKey, endTime }: FlowPairsResponse) =>
({ protocol, routingKey, endTime }) =>
(queryProtocol ? protocol === queryProtocol : true) &&
(queryRoutingKey ? routingKey === queryRoutingKey : true) &&
(queryParams.state === 'active' ? endTime === 0 : endTime > 0)
Expand All @@ -477,7 +475,7 @@ export function loadMockServer() {
});

this.get(`${prefix}/connections/:id`, (_, { params: { id } }) => ({
results: flowPairs.results.find(({ identity }: ServiceResponse) => identity === id)
results: flowPairs.results.find(({ identity }) => identity === id)
}));

this.get(`${prefix}/addresses/:id/processpairs`, () => processPairs);
Expand Down
Loading

0 comments on commit 59a23ee

Please sign in to comment.