Skip to content

Commit

Permalink
Merge pull request #3043 from greenbone/mergify/bp/gsa-21.10/pr-3024
Browse files Browse the repository at this point in the history
Add listpage and detailspage tests (backport #3024)
  • Loading branch information
saberlynx authored Jun 29, 2021
2 parents fe9fcf3 + 2dfb158 commit 802c42e
Show file tree
Hide file tree
Showing 32 changed files with 7,735 additions and 125 deletions.
19 changes: 14 additions & 5 deletions gsa/src/web/entity/__tests__/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,27 @@ import React from 'react';

import Date, {setLocale} from 'gmp/models/date';

import {render} from 'web/utils/testing';
import {setTimezone} from 'web/store/usersettings/actions';
import {rendererWith} from 'web/utils/testing';

import EntityBox from '../box';

setLocale('en');

const date = Date('2019-01-01T12:00:00Z');
const date1 = Date('2019-01-01T12:00:00Z');
const date2 = Date('2019-02-02T12:00:00Z');

describe('EntityBox component tests', () => {
test('should render', () => {
const {render, store} = rendererWith({
store: true,
});

store.dispatch(setTimezone('CET'));

const {element} = render(
<EntityBox
end={date}
end={date1}
modified={date2}
text="foo"
title="bar"
Expand All @@ -57,8 +64,10 @@ describe('EntityBox component tests', () => {
expect(element).toHaveTextContent('tool');
expect(element).toHaveTextContent('foo');
expect(element).toHaveTextContent('child');
expect(element).toHaveTextContent('Active untilTue, Jan 1, 2019');
expect(element).toHaveTextContent('ModifiedSat, Feb 2, 2019');
expect(element).toHaveTextContent(
'Active untilTue, Jan 1, 2019 1:00 PM CET',
);
expect(element).toHaveTextContent('ModifiedSat, Feb 2, 2019 1:00 PM CET');
expect(element).toHaveStyleRule('width', '400px');
});
});
Expand Down
22 changes: 16 additions & 6 deletions gsa/src/web/entity/__tests__/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Capabilities from 'gmp/capabilities/capabilities';
import {setLocale} from 'gmp/models/date';
import Note from 'gmp/models/note';

import {setTimezone} from 'web/store/usersettings/actions';
import {rendererWith} from 'web/utils/testing';

import NoteBox from '../note';
Expand All @@ -44,11 +45,14 @@ const note = Note.fromElement({

describe('NoteBox component tests', () => {
test('should render with DetailsLink', () => {
const {render} = rendererWith({
const {render, store} = rendererWith({
capabilities: caps,
router: true,
store: true,
});

store.dispatch(setTimezone('CET'));

const {element, getByTestId} = render(
<NoteBox detailsLink={true} note={note} />,
);
Expand All @@ -59,27 +63,33 @@ describe('NoteBox component tests', () => {
expect(link).toBeDefined();
expect(header).toHaveTextContent('Note');
expect(element).toHaveTextContent('details.svg');
expect(element).toHaveTextContent('ModifiedSat, Feb 2, 2019');
expect(element).toHaveTextContent('Active untilTue, Jan 1, 2019');
expect(element).toHaveTextContent('ModifiedSat, Feb 2, 2019 1:00 PM CET');
expect(element).toHaveTextContent(
'Active untilTue, Jan 1, 2019 1:00 PM CET',
);
expect(element).toHaveTextContent('foo');
});

test('should render without DetailsLink', () => {
const {render} = rendererWith({
const {render, store} = rendererWith({
capabilities: caps,
router: true,
store: true,
});

store.dispatch(setTimezone('CET'));

const {element} = render(<NoteBox detailsLink={false} note={note} />);

const link = element.querySelector('a');

expect(link).toEqual(null);
expect(element).toHaveTextContent('foo');
expect(element).not.toHaveTextContent('details.svg');
expect(element).toHaveTextContent('ModifiedSat, Feb 2, 2019');
expect(element).toHaveTextContent('Active untilTue, Jan 1, 2019');
expect(element).toHaveTextContent('ModifiedSat, Feb 2, 2019 1:00 PM CET');
expect(element).toHaveTextContent(
'Active untilTue, Jan 1, 2019 1:00 PM CET',
);
});
});

Expand Down
22 changes: 16 additions & 6 deletions gsa/src/web/entity/__tests__/override.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Capabilities from 'gmp/capabilities/capabilities';
import {setLocale} from 'gmp/models/date';
import Override from 'gmp/models/override';

import {setTimezone} from 'web/store/usersettings/actions';
import {rendererWith} from 'web/utils/testing';

import OverrideBox from '../override';
Expand All @@ -40,11 +41,14 @@ const override = Override.fromElement({

describe('OverrideBox component tests', () => {
test('should render with DetailsLink', () => {
const {render} = rendererWith({
const {render, store} = rendererWith({
capabilities: caps,
router: true,
store: true,
});

store.dispatch(setTimezone('CET'));

const {element, getByTestId} = render(
<OverrideBox detailsLink={true} override={override} />,
);
Expand All @@ -58,17 +62,21 @@ describe('OverrideBox component tests', () => {
expect(link).toBeDefined();
expect(link.getAttribute('href')).toEqual('/override/123');
expect(element).toHaveTextContent('details.svg');
expect(element).toHaveTextContent('ModifiedSat, Feb 2, 2019');
expect(element).toHaveTextContent('Active untilTue, Jan 1, 2019');
expect(element).toHaveTextContent('ModifiedSat, Feb 2, 2019 1:00 PM CET');
expect(element).toHaveTextContent(
'Active untilTue, Jan 1, 2019 1:00 PM CET',
);
expect(element).toHaveTextContent('foo');
});

test('should render without DetailsLink', () => {
const {render} = rendererWith({
const {render, store} = rendererWith({
capabilities: caps,
router: true,
store: true,
});

store.dispatch(setTimezone('CET'));
const {element} = render(
<OverrideBox detailsLink={false} override={override} />,
);
Expand All @@ -78,8 +86,10 @@ describe('OverrideBox component tests', () => {
expect(link).toEqual(null);
expect(element).toHaveTextContent('foo');
expect(element).not.toHaveTextContent('details.svg');
expect(element).toHaveTextContent('ModifiedSat, Feb 2, 2019');
expect(element).toHaveTextContent('Active untilTue, Jan 1, 2019');
expect(element).toHaveTextContent('ModifiedSat, Feb 2, 2019 1:00 PM CET');
expect(element).toHaveTextContent(
'Active untilTue, Jan 1, 2019 1:00 PM CET',
);
});
});

Expand Down
18 changes: 11 additions & 7 deletions gsa/src/web/entity/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ import React from 'react';
import styled from 'styled-components';

import _ from 'gmp/locale';
import {longDate} from 'gmp/locale/date';
import DateTime from 'web/components/date/datetime';

import {isDefined} from 'gmp/utils/identity';

import PropTypes from 'web/utils/proptypes';

import Theme from 'web/utils/theme';

import Layout from 'web/components/layout/layout';

import InfoTable from 'web/components/table/infotable';
import TableBody from 'web/components/table/body';
import TableData from 'web/components/table/data';
import TableRow from 'web/components/table/row';

import PropTypes from 'web/utils/proptypes';

import Theme from 'web/utils/theme';

const Pre = styled.pre`
white-space: pre-wrap;
word-wrap: break-word;
Expand Down Expand Up @@ -73,12 +73,16 @@ const EntityBox = ({
{isDefined(end) && (
<TableRow>
<TableData>{_('Active until')}</TableData>
<TableData>{longDate(end)}</TableData>
<TableData>
<DateTime date={end} />
</TableData>
</TableRow>
)}
<TableRow>
<TableData>{_('Modified')}</TableData>
<TableData>{longDate(modified)}</TableData>
<TableData>
<DateTime date={modified} />
</TableData>
</TableRow>
</TableBody>
</InfoTable>
Expand Down
Loading

0 comments on commit 802c42e

Please sign in to comment.