-
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.
test(Metrics): ✅ Request and response unit test empty case
- Loading branch information
Showing
3 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
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
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,79 @@ | ||
import { Suspense } from 'react'; | ||
|
||
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react'; | ||
import { Server } from 'miragejs'; | ||
|
||
import * as PrometheusAPIModule from '@API/Prometheus.api'; | ||
import { ProcessResponse } from '@API/REST.interfaces'; | ||
import { waitForElementToBeRemovedTimeout } from '@config/config'; | ||
import { getTestsIds } from '@config/testIds'; | ||
import { Wrapper } from '@core/components/Wrapper'; | ||
import processesData from '@mocks/data/PROCESSES.json'; | ||
import { loadMockServer } from '@mocks/server'; | ||
import LoadingPage from '@pages/shared/Loading'; | ||
|
||
import Response from '../components/Response'; | ||
import { MetricsLabels } from '../Metrics.enum'; | ||
|
||
const processResult = processesData.results[0] as ProcessResponse; | ||
|
||
describe('Response component', () => { | ||
let server: Server; | ||
beforeEach(() => { | ||
server = loadMockServer() as Server; | ||
server.logging = false; | ||
}); | ||
|
||
afterEach(() => { | ||
server.shutdown(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render the Reponse section of the metric', async () => { | ||
render( | ||
<Wrapper> | ||
<Suspense fallback={<LoadingPage />}> | ||
<Response | ||
selectedFilters={{ | ||
sourceProcess: processResult.name | ||
}} | ||
openSections={true} | ||
forceUpdate={1} | ||
/> | ||
</Suspense> | ||
</Wrapper> | ||
); | ||
|
||
await waitForElementToBeRemoved(() => screen.queryByTestId(getTestsIds.loadingView()), { | ||
timeout: waitForElementToBeRemovedTimeout | ||
}); | ||
|
||
expect(screen.getByText(MetricsLabels.ResposeTitle)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render the Response section', async () => { | ||
jest | ||
.spyOn(PrometheusAPIModule.PrometheusApi, 'fetchResponseCountsByPartialCodeInTimeRange') | ||
.mockImplementation(jest.fn().mockReturnValue({ data: null })); | ||
|
||
render( | ||
<Wrapper> | ||
<Suspense fallback={<LoadingPage />}> | ||
<Response | ||
selectedFilters={{ | ||
sourceProcess: processResult.name | ||
}} | ||
openSections={true} | ||
forceUpdate={1} | ||
/> | ||
</Suspense> | ||
</Wrapper> | ||
); | ||
|
||
await waitForElementToBeRemoved(() => screen.queryByTestId(getTestsIds.loadingView()), { | ||
timeout: waitForElementToBeRemovedTimeout | ||
}); | ||
|
||
expect(screen.queryByText(MetricsLabels.ResposeTitle)).not.toBeInTheDocument(); | ||
}); | ||
}); |