mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-15 01:55:56 +08:00
test: metrics table test case is added (#2554)
This commit is contained in:
parent
a3bc2ff24e
commit
813eeb6d5a
@ -1,5 +1,20 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable object-shorthand */
|
||||||
|
/* eslint-disable func-names */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds custom matchers from the react testing library to all tests
|
* Adds custom matchers from the react testing library to all tests
|
||||||
*/
|
*/
|
||||||
import '@testing-library/jest-dom';
|
import '@testing-library/jest-dom';
|
||||||
import 'jest-styled-components';
|
import 'jest-styled-components';
|
||||||
|
|
||||||
|
// Mock window.matchMedia
|
||||||
|
window.matchMedia =
|
||||||
|
window.matchMedia ||
|
||||||
|
function (): any {
|
||||||
|
return {
|
||||||
|
matches: false,
|
||||||
|
addListener: function () {},
|
||||||
|
removeListener: function () {},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
70
frontend/src/container/MetricsTable/Metrics.test.tsx
Normal file
70
frontend/src/container/MetricsTable/Metrics.test.tsx
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import { render, RenderResult, screen, waitFor } from '@testing-library/react';
|
||||||
|
import React from 'react';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
|
import {
|
||||||
|
combineReducers,
|
||||||
|
legacy_createStore as createStore,
|
||||||
|
Store,
|
||||||
|
} from 'redux';
|
||||||
|
|
||||||
|
import { InitialValue } from '../../store/reducers/metric';
|
||||||
|
import Metrics from './index';
|
||||||
|
|
||||||
|
const rootReducer = combineReducers({
|
||||||
|
metrics: (state = InitialValue) => state,
|
||||||
|
});
|
||||||
|
|
||||||
|
const mockStore = createStore(rootReducer);
|
||||||
|
|
||||||
|
const renderWithReduxAndRouter = (mockStore: Store) => (
|
||||||
|
component: React.ReactElement,
|
||||||
|
): RenderResult =>
|
||||||
|
render(
|
||||||
|
<BrowserRouter>
|
||||||
|
<Provider store={mockStore}>{component}</Provider>
|
||||||
|
</BrowserRouter>,
|
||||||
|
);
|
||||||
|
|
||||||
|
describe('Metrics Component', () => {
|
||||||
|
it('renders without errors', async () => {
|
||||||
|
renderWithReduxAndRouter(mockStore)(<Metrics />);
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText(/application/i)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/p99 latency \(in ms\)/i)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/error rate \(% of total\)/i)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/operations per second/i)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders loading when required conditions are met', async () => {
|
||||||
|
const customStore = createStore(rootReducer, {
|
||||||
|
metrics: {
|
||||||
|
services: [],
|
||||||
|
loading: true,
|
||||||
|
error: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { container } = renderWithReduxAndRouter(customStore)(<Metrics />);
|
||||||
|
|
||||||
|
const spinner = container.querySelector('.ant-spin-nested-loading');
|
||||||
|
|
||||||
|
expect(spinner).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders no data when required conditions are met', async () => {
|
||||||
|
const customStore = createStore(rootReducer, {
|
||||||
|
metrics: {
|
||||||
|
services: [],
|
||||||
|
loading: false,
|
||||||
|
error: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
renderWithReduxAndRouter(customStore)(<Metrics />);
|
||||||
|
|
||||||
|
expect(screen.getByText('No data')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
@ -10,7 +10,7 @@ import {
|
|||||||
} from 'types/actions/metrics';
|
} from 'types/actions/metrics';
|
||||||
import InitialValueTypes from 'types/reducer/metrics';
|
import InitialValueTypes from 'types/reducer/metrics';
|
||||||
|
|
||||||
const InitialValue: InitialValueTypes = {
|
export const InitialValue: InitialValueTypes = {
|
||||||
error: false,
|
error: false,
|
||||||
errorMessage: '',
|
errorMessage: '',
|
||||||
loading: true,
|
loading: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user