-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #465 from bartoval/refactor_metric_filters
Refactor metric filters
- Loading branch information
Showing
28 changed files
with
974 additions
and
811 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { Server } from 'miragejs'; | ||
|
||
import { Protocols } from '@API/REST.enum'; | ||
import { getTestsIds } from '@config/testIds'; | ||
import { BiFlowLabels } from '@core/components/SkBiFlowDetails/BiFlow.enum'; | ||
|
||
import biFlowData from '../../mocks/data/FLOW_PAIRS.json'; | ||
import { loadMockServer } from '../../mocks/server'; | ||
import SkBiFlowDetails from '../../src/core/components/SkBiFlowDetails'; | ||
import { Wrapper } from '../../src/core/components/Wrapper'; | ||
import { BiFlowResponse } from '../../src/types/REST.interfaces'; | ||
|
||
describe('BiFlowDetails component', () => { | ||
let server: Server; | ||
|
||
beforeEach(() => { | ||
server = loadMockServer() as Server; | ||
server.logging = false; | ||
}); | ||
|
||
afterEach(() => { | ||
server.shutdown(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render the http/2 Open Request', () => { | ||
render( | ||
<Wrapper> | ||
<SkBiFlowDetails biflow={biFlowData.results[0] as BiFlowResponse} /> | ||
</Wrapper> | ||
); | ||
|
||
expect(screen.getByTestId(getTestsIds.biFlowView(biFlowData.results[0].identity))).toBeInTheDocument(); | ||
expect(screen.getByText(BiFlowLabels.Terminated)).toBeInTheDocument(); | ||
expect(screen.getByText(biFlowData.results[0].protocol)).toHaveTextContent(Protocols.Http2); | ||
expect(screen.getByText(BiFlowLabels.Method)).toBeInTheDocument(); | ||
expect(screen.getByText(BiFlowLabels.Status)).toBeInTheDocument(); | ||
expect(screen.queryByText(BiFlowLabels.Host)).not.toBeInTheDocument(); | ||
expect(screen.queryByText(BiFlowLabels.ProxyHost)).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render a Terminated Connection', () => { | ||
render( | ||
<Wrapper> | ||
<SkBiFlowDetails biflow={biFlowData.results[4] as BiFlowResponse} /> | ||
</Wrapper> | ||
); | ||
|
||
expect(screen.getByText(BiFlowLabels.Closed)).toBeInTheDocument(); | ||
expect(screen.getByText(biFlowData.results[4].protocol)).toHaveTextContent(Protocols.Tcp); | ||
expect(screen.getByText(BiFlowLabels.Trace)).toBeInTheDocument(); | ||
expect(screen.getByText(BiFlowLabels.Duration)).toBeInTheDocument(); | ||
expect(screen.getAllByText(BiFlowLabels.Host)[0]).toBeInTheDocument(); | ||
expect(screen.getByText(BiFlowLabels.ProxyHost)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render an Open Connection', () => { | ||
render( | ||
<Wrapper> | ||
<SkBiFlowDetails biflow={biFlowData.results[3] as BiFlowResponse} /> | ||
</Wrapper> | ||
); | ||
|
||
expect(screen.getByText(BiFlowLabels.Open)).toBeInTheDocument(); | ||
expect(screen.getByText(biFlowData.results[3].protocol)).toHaveTextContent(Protocols.Tcp); | ||
expect(screen.getByText(BiFlowLabels.Trace)).toBeInTheDocument(); | ||
expect(screen.getAllByText(BiFlowLabels.Host)[0]).toBeInTheDocument(); | ||
expect(screen.getByText(BiFlowLabels.ProxyHost)).toBeInTheDocument(); | ||
expect(screen.queryByText(BiFlowLabels.Duration)).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import SkDurationCell from '../../src/core/components/SKDurationCell'; | ||
import { formatLatency } from '../../src/core/utils/formatLatency'; | ||
|
||
jest.mock('@core/utils/formatLatency', () => ({ | ||
formatLatency: jest.fn() | ||
})); | ||
|
||
describe('SkDurationCell', () => { | ||
it('renders the formatted duration when value is provided', () => { | ||
const value = 123456; // microseconds | ||
const formattedLatency = '123 ms'; | ||
|
||
(formatLatency as jest.Mock).mockReturnValue(formattedLatency); | ||
|
||
render(<SkDurationCell value={value} data={{}} />); | ||
|
||
expect(formatLatency).toHaveBeenCalledWith(value); | ||
expect(screen.getByText(formattedLatency)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders null when value is falsy', () => { | ||
const { container } = render(<SkDurationCell value={null} data={{}} />); | ||
expect(container.firstChild).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.