Skip to content

Commit

Permalink
Make suggested updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Johnson committed Feb 27, 2024
1 parent eaed2bb commit ff48006
Show file tree
Hide file tree
Showing 28 changed files with 683 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import configureStore from 'redux-mock-store';
import { initialState } from '../../../Store/Reducers/CVEDetailsPageStore';
import { CVEPageContext } from '../../SmartComponents/CVEDetailsPage/CVEDetailsPage';
import TestWrapper from '../../../Utilities/TestWrapper';
import '@testing-library/jest-dom';

const customMiddleWare = store => next => action => {
useSelector.mockImplementation(callback => {
Expand Down Expand Up @@ -40,7 +41,7 @@ describe('CVEDetailsPageSummary component', () => {
</TestWrapper>
);

expect(screen.getByText(data.data.description)).toBeTruthy();
expect(screen.getByText(data.data.description)).toBeVisible();
});

it('should render with long description', () => {
Expand All @@ -67,6 +68,6 @@ describe('CVEDetailsPageSummary component', () => {
</TestWrapper>
);

expect(screen.getByText(data.data.description)).toBeTruthy();
expect(screen.getByText(data.data.description)).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import CvssVector, { parseVector } from './CvssVector';
import { V3names, V2names } from './vectorNames';
import { render, screen } from '@testing-library/react';
import TestWrapper from '../../../Utilities/TestWrapper';
import '@testing-library/jest-dom';

describe('CvssVector', () => {
it('Should render with CVSSv2', () => {
Expand All @@ -11,7 +12,7 @@ describe('CvssVector', () => {
</TestWrapper>
);

expect(screen.getByText('CVSS 2.0 base score')).toBeTruthy();
expect(screen.getByText('CVSS 2.0 base score')).toBeVisible();
});

it('Should render with CVSSv3', () => {
Expand All @@ -21,7 +22,7 @@ describe('CvssVector', () => {
</TestWrapper>
);

expect(screen.getByText('CVSS 3.0 base score')).toBeTruthy();
expect(screen.getByText('CVSS 3.0 base score')).toBeVisible();
});

it('Should render CVSSv3 when given both', () => {
Expand All @@ -30,7 +31,7 @@ describe('CvssVector', () => {
<CvssVector cvss2_metrics="AV:L/AC:H/Au:N/C:N/I:N/A:P" cvss3_metrics="CVSS:3.0/AV:A/AC:L/PR:L/UI:R/S:U/C:L/I:N/A:N"/>
</TestWrapper>
);
expect(screen.getByText('CVSS 3.0 base score')).toBeTruthy();
expect(screen.getByText('CVSS 3.0 base score')).toBeVisible();
expect(screen.queryAllByText('CVSS 2.0 base score')).toHaveLength(0);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import TestWrapper from '../../../Utilities/TestWrapper';
import messages from '../../../Messages'
import '@testing-library/jest-dom';

describe('Empty states', () => {
it('should render EmptyStateNoCVEs', () => {
const { asFragment } = render(<TestWrapper><EmptyStateNoCVEs secondParagraph={messages.emptyStateThereShouldBeCVEs}/></TestWrapper>);
expect(asFragment()).toMatchSnapshot();

expect(screen.getByTestId('prod-sec-link')).toBeTruthy();
expect(screen.getByTestId('prod-sec-link')).toBeVisible();
})

it('should render EmptyStateNoSystems', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/Components/PresentationalComponents/Header/Header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import { BrowserRouter as Router } from 'react-router-dom';
import Header from './Header';
import '@testing-library/jest-dom';

describe('VulnerabilityHeader component', () => {
it('should render with title Hello world', () => {
const title = 'Hello world'
render(<Header title={title} />);

expect(screen.getByText(title)).toBeTruthy();
expect(screen.getByText(title)).toBeVisible();
});

it('should render default title', () => {
render(<Header />);
expect(screen.getByText('CVEs')).toBeTruthy();
expect(screen.getByText('CVEs')).toBeVisible();
});

it('should not render Breadcrumb', () => {
Expand All @@ -37,7 +38,7 @@ describe('VulnerabilityHeader component', () => {
</Router>
);

expect(screen.getByTestId('PfBreadcrumb')).toBeTruthy();
expect(screen.getByTestId('PfBreadcrumb')).toBeVisible();
expect(screen.getAllByTestId('breadcrumb-skeleton')).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { InsightsSystemRule } from './InsightsSystemRule';
import { render, screen } from '@testing-library/react';
import TestWrapper from '../../../Utilities/TestWrapper';
import '@testing-library/jest-dom';

const rule = {
"details": {
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('InsightsSystemRule', () => {
</TestWrapper>
);

expect(screen.getByText("This system is affected by CVE_2018_12130, but is not affected by any security rules associated with this CVE.")).toBeTruthy();
expect(screen.getByText("This system is affected by CVE_2018_12130, but is not affected by any security rules associated with this CVE.")).toBeVisible();
});

it('Should render with rule', () => {
Expand All @@ -96,7 +97,7 @@ describe('InsightsSystemRule', () => {
</TestWrapper>
);

expect(screen.getByText("CVE-2018-12126, CVE-2018-12127, CVE-2018-12130, CVE-2019-11091: \"MDS\" CPU side-channel reported by kernel")).toBeTruthy();
expect(screen.getByText("CVE-2018-12126, CVE-2018-12127, CVE-2018-12130, CVE-2019-11091: \"MDS\" CPU side-channel reported by kernel")).toBeVisible();
});

it('Should render rule ruleID ', () => {
Expand All @@ -112,6 +113,6 @@ describe('InsightsSystemRule', () => {
</TestWrapper>
);

expect(screen.getByText("CVE_2018_12130_cpu_kernel|CVE_2018_12130_CPU_KERNEL_VULNERABLE_2")).toBeTruthy()
expect(screen.getByText("CVE_2018_12130_cpu_kernel|CVE_2018_12130_CPU_KERNEL_VULNERABLE_2")).toBeVisible()
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render, screen } from '@testing-library/react';
import TestWrapper from '../../../Utilities/TestWrapper';
import messages from '../../../Messages';
import { intl } from '../../../Utilities/IntlProvider';
import '@testing-library/jest-dom';

describe('ReadOnlyBanner component', () => {
it('Should match snapshot.', () => {
Expand All @@ -12,6 +13,6 @@ describe('ReadOnlyBanner component', () => {
</TestWrapper>
);

expect(screen.getByText(intl.formatMessage(messages.learnMore))).toBeTruthy();
expect(screen.getByText(intl.formatMessage(messages.learnMore))).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import SnippetWithPopover from './SnippetWithPopover';
import { render, screen } from '@testing-library/react';
import TestWrapper from '../../../Utilities/TestWrapper';
import '@testing-library/jest-dom';

describe('SnippetWithPopover component', () => {
it('should render with business risk', () => {
Expand Down Expand Up @@ -55,7 +56,7 @@ describe('SnippetWithPopover component', () => {
</TestWrapper>
);

expect(screen.getByText('Not reviewed')).toBeTruthy();
expect(screen.getByText('Not reviewed')).toBeVisible();
});

it('should render with non-default status and -- in place of missing or invalid data', () => {
Expand All @@ -82,6 +83,6 @@ describe('SnippetWithPopover component', () => {
</TestWrapper>
);

expect(screen.getByText('--')).toBeTruthy();
expect(screen.getByText('--')).toBeVisible();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import userEvent from '@testing-library/user-event';
import SelectCustomSorter from './SelectCustomSorter';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';

const selectProps = null
const options = [
Expand All @@ -18,12 +19,12 @@ describe('SelectCustomSorter component', () => {
<SelectCustomSorter sorterData={sorterData} setSorterData={setSorterData} selectProps={selectProps} options={options} />
);

expect(screen.getByText('option 2')).toBeTruthy(); // should be selected sorter by default
expect(screen.getByText('option 2')).toBeVisible(); // should be selected sorter by default
expect(screen.queryAllByText('option 1')).toHaveLength(0); // shouldn't be visible until menu is opened
userEvent.click(screen.getByLabelText('Options menu'));

expect(screen.getByRole('option', { name: 'option 1' })).toBeTruthy();
expect(screen.getByRole('option', { name: 'option 2' })).toBeTruthy();
expect(screen.getByRole('option', { name: 'option 3' })).toBeTruthy();
expect(screen.getByRole('option', { name: 'option 1' })).toBeVisible();
expect(screen.getByRole('option', { name: 'option 2' })).toBeVisible();
expect(screen.getByRole('option', { name: 'option 3' })).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import configureStore from 'redux-mock-store';
import { intl } from '../../../Utilities/IntlProvider';
import { render, screen } from '@testing-library/react';
import TestWrapper from '../../../Utilities/TestWrapper';
import '@testing-library/jest-dom';

const mockStore = configureStore([store => next => action => {}]);
let store = mockStore({ });
Expand All @@ -15,7 +16,7 @@ describe('NoAccessPage component', () => {
</TestWrapper>
);

expect(screen.getByText('Go to landing page')).toBeTruthy();
expect(screen.getByText('Go to landing page')).toBeVisible();
expect(screen.queryByText('Return to previous page')).toBeFalsy();

Object.defineProperty(document, 'referrer', { value: 'Referrer Test', configurable: true });
Expand All @@ -26,6 +27,6 @@ describe('NoAccessPage component', () => {
</TestWrapper>
);

expect(screen.getByText('Return to previous page')).toBeTruthy();
expect(screen.getByText('Return to previous page')).toBeVisible();
})
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import StatusColumn from './StatusColumn'
import { render, screen } from '@testing-library/react';
import TestWrapper from '../../../Utilities/TestWrapper';
import '@testing-library/jest-dom';

describe('StatusColumn', () => {
it('Should render icon', () => {
Expand All @@ -10,7 +11,7 @@ describe('StatusColumn', () => {
</TestWrapper>
);

expect(screen.getByTestId('status-column-server-icon')).toBeTruthy();
expect(screen.getByTestId('status-column-server-icon')).toBeVisible();
});

it('Should not render icon and status should be Not reviewed', () => {
Expand All @@ -21,7 +22,7 @@ describe('StatusColumn', () => {
);

expect(screen.queryByTestId('status-column-server-icon')).toBeFalsy();
expect(screen.getByText('Not reviewed')).toBeTruthy();
expect(screen.getByText('Not reviewed')).toBeVisible();
});

it('Status should be In review', () => {
Expand All @@ -31,7 +32,7 @@ describe('StatusColumn', () => {
</TestWrapper>
);

expect(screen.getByText('In review')).toBeTruthy();
expect(screen.getByText('In review')).toBeVisible();
});

it('Status should be On-hold', () => {
Expand All @@ -41,7 +42,7 @@ describe('StatusColumn', () => {
</TestWrapper>
);

expect(screen.getByText('On-hold')).toBeTruthy();
expect(screen.getByText('On-hold')).toBeVisible();
});

it('Status should be Scheduled for patch', () => {
Expand All @@ -51,7 +52,7 @@ describe('StatusColumn', () => {
</TestWrapper>
);

expect(screen.getByText('Scheduled for patch')).toBeTruthy();
expect(screen.getByText('Scheduled for patch')).toBeVisible();
});

it('Status should be Resolved', () => {
Expand All @@ -61,7 +62,7 @@ describe('StatusColumn', () => {
</TestWrapper>
);

expect(screen.getByText('Resolved')).toBeTruthy();
expect(screen.getByText('Resolved')).toBeVisible();
});

it('Status should be No action - risk accepted', () => {
Expand All @@ -71,7 +72,7 @@ describe('StatusColumn', () => {
</TestWrapper>
);

expect(screen.getByText('No action - risk accepted')).toBeTruthy();
expect(screen.getByText('No action - risk accepted')).toBeVisible();
});

it('Status should be Resolved via mitigation ', () => {
Expand All @@ -81,7 +82,7 @@ describe('StatusColumn', () => {
</TestWrapper>
);

expect(screen.getByText('Resolved via mitigation')).toBeTruthy();
expect(screen.getByText('Resolved via mitigation')).toBeVisible();
});

})
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import SystemNameColumn from './SystemNameColumn'
import { render, screen } from '@testing-library/react';
import { intl } from '../../../Utilities/IntlProvider';
import messages from '../../../Messages';
import '@testing-library/jest-dom';

describe('SystemNameColumn', () => {
it('Should match snapshot when not opt out', () => {
render(<SystemNameColumn item={{ title: "Some system" }}/>)

expect(screen.getByText('Some system')).toBeTruthy();
expect(screen.getByText('Some system')).toBeVisible();
expect(screen.queryByText(intl.formatMessage(messages.systemsTableDisabled))).toBeFalsy();
});

it('Should match snapshot when opt out', () => {
render(<SystemNameColumn optOut item={{ title: "Some opt-out system" }}/>)

expect(screen.getByText(intl.formatMessage(messages.systemsTableDisabled))).toBeTruthy();
expect(screen.getByText(intl.formatMessage(messages.systemsTableDisabled))).toBeVisible();
});
})
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { render, screen } from '@testing-library/react';
import TestWrapper from '../../../Utilities/TestWrapper';
import { getAffectedSystemsByCVE } from '../../../Helpers/APIHelper';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom';

jest.mock('../../../Helpers/Hooks', () => ({
...jest.requireActual('../../../Helpers/Hooks'),
Expand Down Expand Up @@ -97,7 +98,7 @@ describe('CVE details:', () => {
expect(asFragment()).toMatchSnapshot();
});

it.skip('Should dispatch actions to fetch data', () => {
it('Should dispatch actions to fetch data', () => {
render(
<TestWrapper store={ store }>
<CveDetailsPage {...props} />
Expand All @@ -119,7 +120,7 @@ describe('CVE details:', () => {

userEvent.click(screen.getByRole('button', { name: 'Actions' }));
userEvent.click(screen.getByRole('menuitem', { name: 'Edit business risk' }));
expect(screen.getByRole('dialog', { name: 'Edit business risk' })).toBeTruthy();
expect(screen.getByRole('dialog', { name: 'Edit business risk' })).toBeVisible();
});

it('Should set StatusModal', () => {
Expand All @@ -133,7 +134,7 @@ describe('CVE details:', () => {

userEvent.click(screen.getByRole('button', { name: 'Actions' }));
userEvent.click(screen.getByRole('menuitem', { name: 'Edit status' }));
expect(screen.getByRole('dialog', { name: 'Edit status for this CVE' })).toBeTruthy();
expect(screen.getByRole('dialog', { name: 'Edit status for this CVE' })).toBeVisible();
});
});

Expand All @@ -160,7 +161,7 @@ describe('CVE details:', () => {
</TestWrapper>
);

expect(screen.getByRole('heading', { name: 'Something went wrong' })).toBeTruthy();
expect(screen.getByRole('heading', { name: 'Something went wrong' })).toBeVisible();
});

it('Should process filterRulevalues and send as a prop to SystemsExposedPage', () => {
Expand Down Expand Up @@ -214,10 +215,10 @@ describe('CVE details:', () => {
</TestWrapper>
);

expect(screen.getByRole('button', { name: 'Security rule testDescription Filter by affected systems' })).toBeTruthy();
expect(screen.getByRole('button', { name: 'Security rule testDescription Filter by affected systems' })).toBeVisible();
});

it('Should show total number of affected systems when there is an edge device in an account', async () => {
it('Should render skeleton table', async () => {
getAffectedSystemsByCVE.mockImplementation(() => Promise.resolve({ meta: { total_items: 1 }}))
render(
<TestWrapper store={ store }>
Expand All @@ -227,7 +228,7 @@ describe('CVE details:', () => {
</TestWrapper>
);

expect(screen.getByLabelText('Table title skeleton')).toBeTruthy();
expect(screen.getByLabelText('Table title skeleton')).toBeVisible();
});

it('Should count only advisory available cves in the table title by filter the API with "advisory_available: true"', async () => {
Expand Down
Loading

0 comments on commit ff48006

Please sign in to comment.