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

Remove bind links with site ids #462

Merged
merged 5 commits into from
Sep 18, 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
10 changes: 5 additions & 5 deletions __tests__/pages/Metrics/Filters.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Server } from 'miragejs';
import processesData from '../../../mocks/data/PROCESSES.json';
import siteData from '../../../mocks/data/SITES.json';
import { loadMockServer } from '../../../mocks/server';
import { AvailableProtocols } from '../../../src/API/REST.enum';
import { Protocols } from '../../../src/API/REST.enum';
import { waitForElementToBeRemovedTimeout } from '../../../src/config/config';
import MetricFilters from '../../../src/pages/shared/Metrics/components/Filters';
import { MetricsLabels } from '../../../src/pages/shared/Metrics/Metrics.enum';
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('Metrics component', () => {
{ destinationName: processesData.results[2].name },
{ destinationName: processesData.results[3].name }
]}
availableProtocols={[AvailableProtocols.Http, AvailableProtocols.Http2, AvailableProtocols.Tcp]}
availableProtocols={[Protocols.Http, Protocols.Http2, Protocols.Tcp]}
configFilters={{
destinationProcesses: { disabled: false, placeholder: MetricsLabels.FilterAllDestinationProcesses },
sourceProcesses: { disabled: false, placeholder: MetricsLabels.FilterAllSourceProcesses },
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('Metrics component', () => {
{ destinationName: processesData.results[2].name },
{ destinationName: processesData.results[3].name }
]}
availableProtocols={[AvailableProtocols.Http, AvailableProtocols.Http2, AvailableProtocols.Tcp]}
availableProtocols={[Protocols.Http, Protocols.Http2, Protocols.Tcp]}
configFilters={{
destinationProcesses: { disabled: false, placeholder: MetricsLabels.FilterAllDestinationProcesses },
sourceProcesses: { disabled: false, placeholder: MetricsLabels.FilterAllSourceProcesses },
Expand All @@ -123,11 +123,11 @@ describe('Metrics component', () => {
});

fireEvent.click(screen.getByText(MetricsLabels.FilterProtocolsDefault));
await waitFor(() => expect(screen.getByText(AvailableProtocols.Http2)).toBeInTheDocument(), {
await waitFor(() => expect(screen.getByText(Protocols.Http2)).toBeInTheDocument(), {
timeout: waitForElementToBeRemovedTimeout
});

fireEvent.click(screen.getByText(AvailableProtocols.Http2));
fireEvent.click(screen.getByText(Protocols.Http2));
await waitFor(() => expect(screen.queryByText(MetricsLabels.FilterProtocolsDefault)).not.toBeInTheDocument(), {
timeout: waitForElementToBeRemovedTimeout
});
Expand Down
10 changes: 5 additions & 5 deletions __tests__/pages/Metrics/Metrics.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import { Suspense } from 'react';

import { act, render, renderHook } from '@testing-library/react';

import { AvailableProtocols } from '../../../src/API/REST.enum';
import { Protocols } from '../../../src/API/REST.enum';
import { Wrapper } from '../../../src/core/components/Wrapper';
import LoadingPage from '../../../src/pages/shared/Loading';
import Metrics, { MetricsProps, useMetrics } from '../../../src/pages/shared/Metrics';
import { configDefaultFilters } from '../../../src/pages/shared/Metrics/Metrics.constants';

describe('useMetrics', () => {
const initialProps = {
defaultMetricFilterValues: { protocol: AvailableProtocols.Http },
defaultMetricFilterValues: { protocol: Protocols.Http },
defaultOpenSections: { byterate: true },
onGetMetricFiltersConfig: jest.fn(),
onGetExpandedSectionsConfig: jest.fn()
};

it('initializes with the correct state from props', () => {
const { result } = renderHook(() => useMetrics(initialProps));
expect(result.current.queryParams).toEqual({ protocol: AvailableProtocols.Http });
expect(result.current.queryParams).toEqual({ protocol: Protocols.Http });
expect(result.current.shouldUpdateData).toBe(0);
});

Expand All @@ -32,7 +32,7 @@ describe('useMetrics', () => {

it('updates queryParams and calls onGetMetricFiltersConfig when handleFilterChange is invoked', () => {
const { result } = renderHook(() => useMetrics(initialProps));
const newFilters = { protocol: AvailableProtocols.Tcp };
const newFilters = { protocol: Protocols.Tcp };
act(() => {
result.current.handleFilterChange(newFilters);
});
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Metrics Component', () => {
destSites: [],
sourceProcesses: [],
destProcesses: [],
availableProtocols: [AvailableProtocols.Http, AvailableProtocols.Tcp, AvailableProtocols.Http2],
availableProtocols: [Protocols.Http, Protocols.Tcp, Protocols.Http2],
onGetMetricFiltersConfig: jest.fn(),
onGetExpandedSectionsConfig: jest.fn(),
...overrides
Expand Down
89 changes: 89 additions & 0 deletions __tests__/pages/Metrics/useMetricsSessionHandler.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { act } from 'react';

import { renderHook } from '@testing-library/react';

import { Direction, Protocols } from '@API/REST.enum';
import { getDataFromSession, storeDataToSession } from '@core/utils/persistData';
import { useMetricSessionHandlers } from '@pages/shared/Metrics/hooks/useMetricsSessionHandler';
import { QueryMetricsParams, ExpandedMetricSections } from '@sk-types/Metrics.interfaces';

const mockQueryMetricsParams: QueryMetricsParams = {
sourceSite: 'SiteA',
destSite: 'SiteB',
sourceProcess: 'ProcessA',
destProcess: 'ProcessB',
sourceComponent: 'ComponentA',
destComponent: 'ComponentB',
service: 'ServiceA',
protocol: Protocols.Tcp,
start: 1620000000,
end: 1620003600,
duration: 3600,
direction: Direction.Incoming
};

const mockExpandedMetricSections: ExpandedMetricSections = {
byterate: true,
latency: false,
request: true,
response: true,
connection: false
};

// Mock the utility functions
jest.mock('@core/utils/persistData', () => ({
getDataFromSession: jest.fn(),
storeDataToSession: jest.fn()
}));

describe('useMetricSessionHandlers', () => {
const id = 'test-id';

beforeEach(() => {
jest.clearAllMocks();
});

it('should return undefined for visibleMetrics if session data is missing', () => {
(getDataFromSession as jest.Mock).mockReturnValueOnce(undefined);

const { result } = renderHook(() => useMetricSessionHandlers(id));
expect(result.current.visibleMetrics).toBeUndefined();
});

it('should retrieve selectedFilters and visibleMetrics from session', () => {
const mockFilters: QueryMetricsParams = mockQueryMetricsParams;
const mockVisibleMetrics = mockExpandedMetricSections;

(getDataFromSession as jest.Mock).mockImplementation((key: string) =>
key.includes('metric-filters') ? mockFilters : mockVisibleMetrics
);

const { result } = renderHook(() => useMetricSessionHandlers(id));

expect(result.current.selectedFilters).toEqual(mockFilters);
expect(result.current.visibleMetrics).toEqual(mockVisibleMetrics);
expect(getDataFromSession).toHaveBeenCalledTimes(2);
});

it('should store selectedFilters to session', () => {
const mockFilters: QueryMetricsParams = mockQueryMetricsParams;
const { result } = renderHook(() => useMetricSessionHandlers(id));

act(() => {
result.current.setSelectedFilters(mockFilters);
});

expect(storeDataToSession).toHaveBeenCalledWith(`metric-filters-${id}`, mockFilters);
});

it('should store visibleMetrics to session', () => {
const mockVisibleMetrics = mockExpandedMetricSections;
const { result } = renderHook(() => useMetricSessionHandlers(id));

act(() => {
result.current.setVisibleMetrics(mockVisibleMetrics);
});

expect(storeDataToSession).toHaveBeenCalledWith(`metric-sections-${id}`, mockVisibleMetrics);
});
});
10 changes: 5 additions & 5 deletions __tests__/pages/Processes/ProcessPairs.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { loadMockServer } from '../../../mocks/server';
import { waitForElementToBeRemovedTimeout } from '../../../src/config/config';
import { getTestsIds } from '../../../src/config/testIds';
import { Wrapper } from '../../../src/core/components/Wrapper';
import ProcessPairs, { ProcessPairsContent } from '../../../src/pages/Processes/views/ProcessPairs';
import ProcessPair, { ProcessPairContent } from '../../../src/pages/Processes/views/ProcessPair';
import LoadingPage from '../../../src/pages/shared/Loading';
import { ProcessPairsResponse, SitePairsResponse } from '../../../src/types/REST.interfaces';

Expand All @@ -37,7 +37,7 @@ describe('Begin testing the Processes component', () => {
render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<ProcessPairs />
<ProcessPair />
</Suspense>
</Wrapper>
);
Expand All @@ -54,7 +54,7 @@ describe('Begin testing the Processes component', () => {
render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<ProcessPairsContent id={processPairsResultOpToCart.identity} />
<ProcessPairContent id={processPairsResultOpToCart.identity} />
</Suspense>
</Wrapper>
);
Expand All @@ -70,7 +70,7 @@ describe('Begin testing the Processes component', () => {
const { queryByTestId, getByTestId } = render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<ProcessPairsContent id={processPairsResultDatabaseToPayment.identity} />
<ProcessPairContent id={processPairsResultDatabaseToPayment.identity} />
</Suspense>
</Wrapper>
);
Expand All @@ -86,7 +86,7 @@ describe('Begin testing the Processes component', () => {
const { queryByTestId, getByText, getByTestId } = render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<ProcessPairsContent id={processPairsResultPayment2ToOp.identity} />
<ProcessPairContent id={processPairsResultPayment2ToOp.identity} />
</Suspense>
</Wrapper>
);
Expand Down
6 changes: 3 additions & 3 deletions __tests__/pages/Processes/ProcessPairsList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { loadMockServer } from '../../../mocks/server';
import { waitForElementToBeRemovedTimeout } from '../../../src/config/config';
import { getTestsIds } from '../../../src/config/testIds';
import { Wrapper } from '../../../src/core/components/Wrapper';
import ProcessPairsList from '../../../src/pages/Processes/components/ProcessPairsList';
import PairsList from '../../../src/pages/Processes/components/PairsList';
import { ProcessesLabels, ProcessesRoutesPaths } from '../../../src/pages/Processes/Processes.enum';
import LoadingPage from '../../../src/pages/shared/Loading';
import { ProcessPairsResponse, ProcessResponse, SitePairsResponse } from '../../../src/types/REST.interfaces';
Expand All @@ -29,7 +29,7 @@ describe('Processes Pairs component', () => {
render(
<Wrapper>
<Suspense fallback={<LoadingPage />}>
<ProcessPairsList process={processResult} />
<PairsList process={processResult} />
</Suspense>
</Wrapper>
);
Expand All @@ -45,7 +45,7 @@ describe('Processes Pairs component', () => {
timeout: waitForElementToBeRemovedTimeout
});

expect(screen.getAllByRole('link', { name: 'view pairs' })[1]).toHaveAttribute(
expect(screen.getAllByRole('link', { name: ProcessesLabels.GoToDetailsLink })[1]).toHaveAttribute(
'href',
`#${ProcessesRoutesPaths.Processes}/${processPairsResult.sourceName}@${processPairsResult.sourceId}/${ProcessesLabels.ProcessPairs}@${processPairsResult.identity}?type=${ProcessesLabels.ProcessPairs}`
);
Expand Down
27 changes: 0 additions & 27 deletions __tests__/pages/Sites/SiteController.spec.ts

This file was deleted.

14 changes: 8 additions & 6 deletions __tests__/pages/Topology/DisplayOptions.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { renderHook, render, act } from '@testing-library/react';
import eventUser from '@testing-library/user-event';

import DisplayOptions, { useDisplayOptions } from '../../../src/pages/Topology/components/DisplayOptions';
import { useDisplayOptionsState } from '@pages/Topology/hooks/useDisplayOptionsState';

import DisplayOptions from '../../../src/pages/Topology/components/DisplayOptions';
import { SHOW_DATA_LINKS, SHOW_ROUTER_LINKS } from '../../../src/pages/Topology/Topology.constants';
import { TopologyLabels } from '../../../src/pages/Topology/Topology.enum';

Expand All @@ -21,13 +23,13 @@ const options = {
describe('useDisplayOptions', () => {
it('initializes with defaultSelected values', () => {
const { result } = renderHook(() =>
useDisplayOptions({ defaultSelected: ['option1', 'option2'], onSelected: mockOnSelected })
useDisplayOptionsState({ defaultSelected: ['option1', 'option2'], onSelected: mockOnSelected })
);
expect(result.current.displayOptionsSelected).toEqual(['option1', 'option2']);
});

it('adds and removes options correctly', () => {
const { result } = renderHook(() => useDisplayOptions({ defaultSelected: [], onSelected: mockOnSelected }));
const { result } = renderHook(() => useDisplayOptionsState({ defaultSelected: [], onSelected: mockOnSelected }));
const { selectDisplayOptions } = result.current;

// Add an option
Expand All @@ -41,7 +43,7 @@ describe('useDisplayOptions', () => {

it('toggles between SHOW_DATA_LINKS and SHOW_ROUTER_LINKS correctly', () => {
const { result } = renderHook(() =>
useDisplayOptions({ defaultSelected: [SHOW_DATA_LINKS], onSelected: mockOnSelected })
useDisplayOptionsState({ defaultSelected: [SHOW_DATA_LINKS], onSelected: mockOnSelected })
);

// Initially, SHOW_DATA_LINKS is selected
Expand All @@ -56,7 +58,7 @@ describe('useDisplayOptions', () => {

it('clicks on SHOW_DATA_LINKS already checked and SHOW_ROUTER_LINKS correctly', () => {
const { result } = renderHook(() =>
useDisplayOptions({ defaultSelected: [SHOW_DATA_LINKS], onSelected: mockOnSelected })
useDisplayOptionsState({ defaultSelected: [SHOW_DATA_LINKS], onSelected: mockOnSelected })
);

// Initially, SHOW_DATA_LINKS is selected
Expand All @@ -69,7 +71,7 @@ describe('useDisplayOptions', () => {
});

it('calls onSelect callback with updated options and selected option', () => {
const { result } = renderHook(() => useDisplayOptions({ defaultSelected: [], onSelected: mockOnSelected }));
const { result } = renderHook(() => useDisplayOptionsState({ defaultSelected: [], onSelected: mockOnSelected }));
const { selectDisplayOptions } = result.current;

act(() => selectDisplayOptions('option1'));
Expand Down
Loading
Loading