From a3898ad17c34f35e3f3c4135a8c834fd982974db Mon Sep 17 00:00:00 2001 From: Alessio Biancalana Date: Wed, 7 Aug 2024 13:09:57 +0200 Subject: [PATCH] Add render test to AdvisoryDetailsPage --- .../pages/AdvisoryDetails/AdvisoryDetails.jsx | 2 + .../AdvisoryDetailsPage.test.jsx | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 assets/js/pages/AdvisoryDetails/AdvisoryDetailsPage.test.jsx diff --git a/assets/js/pages/AdvisoryDetails/AdvisoryDetails.jsx b/assets/js/pages/AdvisoryDetails/AdvisoryDetails.jsx index 54baf00281..7ee095d1e9 100644 --- a/assets/js/pages/AdvisoryDetails/AdvisoryDetails.jsx +++ b/assets/js/pages/AdvisoryDetails/AdvisoryDetails.jsx @@ -90,6 +90,7 @@ function AdvisoryDetails({ {fix} @@ -112,6 +113,7 @@ function AdvisoryDetails({ {cve} diff --git a/assets/js/pages/AdvisoryDetails/AdvisoryDetailsPage.test.jsx b/assets/js/pages/AdvisoryDetails/AdvisoryDetailsPage.test.jsx new file mode 100644 index 0000000000..90a493fc15 --- /dev/null +++ b/assets/js/pages/AdvisoryDetails/AdvisoryDetailsPage.test.jsx @@ -0,0 +1,44 @@ +import React from 'react'; +import { screen, act } from '@testing-library/react'; +import MockAdapter from 'axios-mock-adapter'; +import { networkClient } from '@lib/network'; +import '@testing-library/jest-dom'; + +import { faker } from '@faker-js/faker'; + +import { + renderWithRouterMatch, + defaultInitialState, + withState, +} from '@lib/test-utils'; +import { advisoryErrataFactory } from '@lib/test-utils/factories'; + +import AdvisoryDetailsPage from '.'; + +describe('Advisory Details Page', () => { + it('should render correctly', async () => { + const axiosMock = new MockAdapter(networkClient); + + const hostID = faker.string.uuid(); + const advisoryName = faker.string.uuid(); + const errata = advisoryErrataFactory.build(); + + axiosMock + .onGet(`/api/v1/software_updates/errata_details/${advisoryName}`) + .reply(200, errata); + + const [StatefulPage] = withState( + , + defaultInitialState + ); + + await act(async () => { + renderWithRouterMatch(StatefulPage, { + path: 'hosts/:hostID/patches/:advisoryID', + route: `/hosts/${hostID}/patches/${advisoryName}`, + }); + }); + + expect(screen.getByText(advisoryName)).toBeVisible(); + }); +});