Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add listpage and detailspage tests #3024

Merged
merged 17 commits into from
Jun 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions gsa/src/web/entity/__tests__/box.js
Original file line number Diff line number Diff line change
@@ -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"
@@ -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');
});
});
22 changes: 16 additions & 6 deletions gsa/src/web/entity/__tests__/note.js
Original file line number Diff line number Diff line change
@@ -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';
@@ -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} />,
);
@@ -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',
);
});
});

22 changes: 16 additions & 6 deletions gsa/src/web/entity/__tests__/override.js
Original file line number Diff line number Diff line change
@@ -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';
@@ -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} />,
);
@@ -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} />,
);
@@ -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',
);
});
});

18 changes: 11 additions & 7 deletions gsa/src/web/entity/box.js
Original file line number Diff line number Diff line change
@@ -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;
@@ -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>
Loading