Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng committed Sep 23, 2024
1 parent 28cac79 commit 60f2739
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 93 deletions.
12 changes: 8 additions & 4 deletions src/web/pages/audits/__tests__/listpage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,18 @@ describe('AuditPage tests', () => {
const icons = getBulkActionItems();

expect(deleteByFilter).not.toHaveBeenCalled();
expect(icons[0]).toHaveAttribute('title', 'Move page contents to trashcan');
await clickElement(icons[0]);
const deleteIcon = icons[1];
expect(deleteIcon).toHaveAttribute(
'title',
'Move page contents to trashcan',
);
await clickElement(deleteIcon);

testBulkTrashcanDialog(screen, deleteByFilter);

expect(exportByFilter).not.toHaveBeenCalled();
expect(icons[1]).toHaveAttribute('title', 'Export page contents');
await clickElement(icons[1]);
expect(icons[2]).toHaveAttribute('title', 'Export page contents');
await clickElement(icons[2]);
expect(exportByFilter).toHaveBeenCalled();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/web/pages/policies/__tests__/listpage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('PoliciesPage tests', () => {

await wait();

expect(baseElement).toBeVisible();
expect(element).toBeVisible();
});

test('should call commands for bulk actions', async () => {
Expand Down
37 changes: 23 additions & 14 deletions src/web/pages/reports/__tests__/auditdeltadetailspage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import Filter from 'gmp/models/filter';

import {setTimezone, setUsername} from 'web/store/usersettings/actions';

import {rendererWith} from 'web/utils/testing';
import {getByRole, rendererWith} from 'web/utils/testing';
import {getPowerFilter, getTextInputs} from 'web/components/testing';

import {getMockAuditDeltaReport} from 'web/pages/reports/__mocks__/mockauditdeltareport';

Expand Down Expand Up @@ -91,7 +92,7 @@ describe('Audit Detla Report Details Content tests', () => {
store.dispatch(setTimezone('CET'));
store.dispatch(setUsername('admin'));

const {baseElement, getAllByTestId} = render(
const {baseElement, getAllByTestId, within} = render(
<DeltaDetailsContent
audit={true}
activeTab={0}
Expand Down Expand Up @@ -129,19 +130,21 @@ describe('Audit Detla Report Details Content tests', () => {
);

const icons = baseElement.querySelectorAll('svg');
const inputs = baseElement.querySelectorAll('input');
const links = baseElement.querySelectorAll('a');
const tableData = baseElement.querySelectorAll('td');
const selects = getAllByTestId('select-selected-value');
const powerFilter = getPowerFilter();
const inputs = getTextInputs(powerFilter);
const select = getByRole(powerFilter, 'combobox');
const bars = getAllByTestId('progressbar-box');

// Toolbar Icons
expect(icons.length).toEqual(14)
expect(icons.length).toEqual(15);

// Powerfilter
// Powerilter
expect(inputs[0]).toHaveAttribute('name', 'userFilterString');
expect(selects[0]).toHaveAttribute('title', 'Loaded filter');
expect(selects[0]).toHaveTextContent('foo');

const input = within(select).getByTitle('Loaded filter');
expect(input).toHaveValue('foo');

// Header
expect(baseElement).toHaveTextContent(
Expand Down Expand Up @@ -266,7 +269,7 @@ describe('Audit Detla Report Details Content tests', () => {
store.dispatch(setTimezone('CET'));
store.dispatch(setUsername('admin'));

const {baseElement, getAllByTestId} = render(
const {baseElement, getAllByTestId, within} = render(
<DeltaDetailsContent
activeTab={1}
audit={true}
Expand Down Expand Up @@ -303,19 +306,25 @@ describe('Audit Detla Report Details Content tests', () => {
);

const icons = baseElement.querySelectorAll('svg');
const inputs = baseElement.querySelectorAll('input');
const header = baseElement.querySelectorAll('th');
const rows = baseElement.querySelectorAll('tr');
const selects = getAllByTestId('select-selected-value');
const powerFilter = getPowerFilter();
const inputs = getTextInputs(powerFilter);
const select = getByRole(powerFilter, 'combobox');

// PowerFilter
expect(inputs[0]).toHaveAttribute('name', 'userFilterString');

const input = within(select).getByTitle('Loaded filter');
expect(input).toHaveValue('--');

const bars = getAllByTestId('progressbar-box');

// Toolbar Icons
expect(icons.length).toEqual(24)
expect(icons.length).toEqual(25);

// Powerfilter
expect(inputs[0]).toHaveAttribute('name', 'userFilterString');
expect(selects[0]).toHaveAttribute('title', 'Loaded filter');
expect(selects[0]).toHaveTextContent('--');

// Header
expect(baseElement).toHaveTextContent(
Expand Down
30 changes: 17 additions & 13 deletions src/web/pages/reports/__tests__/auditdetailscontent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import Filter from 'gmp/models/filter';

import {setTimezone, setUsername} from 'web/store/usersettings/actions';

import {rendererWith} from 'web/utils/testing';
import {getByRole, rendererWith} from 'web/utils/testing';

import {getMockAuditReport} from 'web/pages/reports/__mocks__/mockauditreport';
import {getPowerFilter, getTextInputs} from 'web/components/testing';

import DetailsContent from 'web/pages/reports/auditdetailscontent';

Expand Down Expand Up @@ -95,7 +96,7 @@ describe('Audit Report Details Content tests', () => {
store.dispatch(setTimezone('CET'));
store.dispatch(setUsername('admin'));

const {baseElement, getAllByTestId} = render(
const {baseElement, getAllByTestId, within} = render(
<DetailsContent
activeTab={0}
applicationsCounts={{all: 4, filtered: 4}}
Expand Down Expand Up @@ -145,19 +146,21 @@ describe('Audit Report Details Content tests', () => {
const inputs = baseElement.querySelectorAll('input');
const links = baseElement.querySelectorAll('a');
const tableData = baseElement.querySelectorAll('td');
const selects = getAllByTestId('select-selected-value');
const powerFilter = getPowerFilter();

const select = getByRole(powerFilter, 'combobox');
const bars = getAllByTestId('progressbar-box');

// Toolbar Icons
expect(icons.length).toEqual(16)
expect(icons.length).toEqual(17);

// Powerfilter
expect(inputs[0]).toHaveAttribute('name', 'userFilterString');
expect(selects[0]).toHaveAttribute('title', 'Loaded filter');
expect(selects[0]).toHaveTextContent('Loading...');
const input = within(select).getByTitle('Loaded filter');
expect(input).toHaveAttribute('placeholder', 'Loading...');

// Header
expect(baseElement).toHaveTextContent(
expect(baseElement).toHaveTextContent(
'Report:Mon, Jun 3, 2019 1:00 PM CEST',
);
expect(bars[0]).toHaveAttribute('title', 'Done');
Expand Down Expand Up @@ -261,7 +264,7 @@ describe('Audit Report Details Content tests', () => {
store.dispatch(setTimezone('CET'));
store.dispatch(setUsername('admin'));

const {baseElement, getAllByTestId} = render(
const {baseElement, getAllByTestId, within} = render(
<DetailsContent
activeTab={2}
applicationsCounts={{all: 4, filtered: 4}}
Expand Down Expand Up @@ -308,17 +311,18 @@ describe('Audit Report Details Content tests', () => {
);

const icons = baseElement.querySelectorAll('svg');
const inputs = baseElement.querySelectorAll('input');
const selects = getAllByTestId('select-selected-value');
const powerFilter = getPowerFilter();
const inputs = getTextInputs(powerFilter);
const select = getByRole(powerFilter, 'combobox');
const bars = getAllByTestId('progressbar-box');

// Toolbar Icons
expect(icons.length).toEqual(20)
expect(icons.length).toEqual(21);

// Powerfilter
expect(inputs[0]).toHaveAttribute('name', 'userFilterString');
expect(selects[0]).toHaveAttribute('title', 'Loaded filter');
expect(selects[0]).toHaveTextContent('Loading...');
const input = within(select).getByTitle('Loaded filter');
expect(input).toHaveAttribute('placeholder', 'Loading...');

// Header
expect(baseElement).toHaveTextContent(
Expand Down
36 changes: 21 additions & 15 deletions src/web/pages/reports/__tests__/auditfilterdialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Filter Dialog for Audit report', () => {
capabilities: caps,
});

const {getAllByTestId} = render(
const {baseElement, getByLabelText} = render(
<AuditReportFilter
filter={filter}
delta={false}
Expand All @@ -48,19 +48,25 @@ describe('Filter Dialog for Audit report', () => {
/>,
);

const formgroups = getAllByTestId('formgroup-title');
const content = getAllByTestId('formgroup-content');
const radioTitles = getAllByTestId('radio-title');

expect(formgroups[0]).toHaveTextContent('Filter');
expect(formgroups[1]).toHaveTextContent('Compliance');
expect(content[1]).toHaveTextContent('YesNoIncompleteUndefined');
expect(formgroups[2]).toHaveTextContent('QoD');
expect(formgroups[3]).toHaveTextContent('From Task (name)');
expect(formgroups[4]).toHaveTextContent('First result');
expect(formgroups[5]).toHaveTextContent('Results per page');
expect(formgroups[6]).toHaveTextContent('Sort by');
expect(radioTitles[0]).toHaveTextContent('Ascending');
expect(radioTitles[1]).toHaveTextContent('Descending');
const formGroups = baseElement.querySelectorAll(
'[class*="mantine-Text-root"]',
);

expect(formGroups[0]).toHaveTextContent('Filter');
expect(formGroups[1]).toHaveTextContent('Compliance');
expect(formGroups[2]).toHaveTextContent('QoD');
expect(formGroups[3]).toHaveTextContent('From Task (name)');
expect(formGroups[4]).toHaveTextContent('First result');
expect(formGroups[5]).toHaveTextContent('Results per page');
expect(formGroups[6]).toHaveTextContent('Sort by');

const ascendingRadio = getByLabelText('Ascending');
const descendingRadio = getByLabelText('Descending');

expect(ascendingRadio).toBeInTheDocument();
expect(descendingRadio).toBeInTheDocument();

expect(ascendingRadio).toBeChecked();
expect(descendingRadio).not.toBeChecked();
});
});
43 changes: 27 additions & 16 deletions src/web/pages/reports/__tests__/auditreportslistpage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
*/

import {describe, test, expect, testing} from '@gsa/testing';
import {
getPowerFilter,
getTextInputs,
getSelectElement,
testBulkDeleteDialog,
} from 'web/components/testing';
import React from 'react';
import {act} from 'react-dom/test-utils';

import CollectionCounts from 'gmp/collection/collectioncounts';

Expand All @@ -16,7 +21,13 @@ import {entitiesActions} from 'web/store/entities/auditreports';
import {loadingActions} from 'web/store/usersettings/defaults/actions';
import {defaultFilterLoadingActions} from 'web/store/usersettings/defaultfilters/actions';

import {rendererWith, waitFor, fireEvent} from 'web/utils/testing';
import {
rendererWith,
waitFor,
fireEvent,
screen,
wait,
} from 'web/utils/testing';
import {getMockAuditReport} from 'web/pages/reports/__mocks__/mockauditreport';
import AuditReportsPage from '../auditreportslistpage';

Expand Down Expand Up @@ -135,17 +146,17 @@ describe('AuditReportsPage tests', () => {
entitiesActions.success([entity], filter, loadedFilter, counts),
);

const {baseElement, getAllByTestId} = render(<AuditReportsPage />);
const {baseElement, getAllByTestId, within} = render(<AuditReportsPage />);

await waitFor(() => baseElement.querySelectorAll('table'));

const display = getAllByTestId('grid-item');
const icons = getAllByTestId('svg-icon');
const inputs = baseElement.querySelectorAll('input');
const header = baseElement.querySelectorAll('th');
const row = baseElement.querySelectorAll('tr');
const selects = getAllByTestId('select-selected-value');

const powerFilter = getPowerFilter();
const select = getSelectElement(powerFilter);
const inputs = getTextInputs(powerFilter);
// Toolbar Icons
expect(icons[0]).toHaveAttribute('title', 'Help: Audit Reports');

Expand All @@ -156,8 +167,8 @@ describe('AuditReportsPage tests', () => {
expect(icons[3]).toHaveAttribute('title', 'Reset to Default Filter');
expect(icons[4]).toHaveAttribute('title', 'Help: Powerfilter');
expect(icons[5]).toHaveAttribute('title', 'Edit Filter');
expect(selects[0]).toHaveAttribute('title', 'Loaded filter');
expect(selects[0]).toHaveTextContent('--');
const input = within(select).getByTitle('Loaded filter');
expect(input).toHaveValue('--');

// // Dashboard
expect(icons[7]).toHaveAttribute('title', 'Add new Dashboard Display');
Expand Down Expand Up @@ -254,14 +265,14 @@ describe('AuditReportsPage tests', () => {

const icons = getAllByTestId('svg-icon');

await act(async () => {
expect(icons[19]).toHaveAttribute('title', 'Add tag to page contents');
fireEvent.click(icons[19]);
expect(getAll).toHaveBeenCalled();
expect(icons[19]).toHaveAttribute('title', 'Add tag to page contents');
fireEvent.click(icons[19]);
expect(getAll).toHaveBeenCalled();

expect(icons[20]).toHaveAttribute('title', 'Delete page contents');
fireEvent.click(icons[20]);
expect(deleteByFilter).toHaveBeenCalled();
});
fireEvent.click(screen.getAllByTitle('Delete page contents')[0]);

await wait();

testBulkDeleteDialog(screen, deleteByFilter);
});
});
Loading

0 comments on commit 60f2739

Please sign in to comment.