Skip to content

Commit

Permalink
add tests for policy details
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahd93 committed Aug 29, 2019
1 parent 958ddcb commit 82f9330
Show file tree
Hide file tree
Showing 2 changed files with 271 additions and 0 deletions.
213 changes: 213 additions & 0 deletions gsa/src/web/pages/policies/__tests__/__snapshots__/details.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Policy Details tests should render full Details 1`] = `
.c0 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
flex-grow: 1;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-align-items: stretch;
-webkit-box-align: stretch;
-ms-flex-align: stretch;
align-items: stretch;
}
.c5 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-align-items: stretch;
-webkit-box-align: stretch;
-ms-flex-align: stretch;
align-items: stretch;
}
.c8 {
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
}
.c7 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: start;
-webkit-justify-content: start;
-ms-flex-pack: start;
justify-content: start;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin-left: -5px;
}
.c7 > * {
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
}
.c7 > * {
margin-left: 5px;
}
.c6 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-pack: start;
-webkit-justify-content: start;
-ms-flex-pack: start;
justify-content: start;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
}
.c2 {
border: 0;
border-spacing: 0px;
font-size: 12px;
text-align: left;
table-layout: auto;
}
.c1 td {
padding: 4px 4px 4px 0;
}
.c1 tr td:first-child {
padding-right: 5px;
}
.c3 {
width: 10%;
}
.c4 {
width: 90%;
}
@media print {
.c2 {
border-collapse: collapse;
}
}
<div
class="c0"
>
<table
class="c1 c2"
>
<colgroup>
<col
class="c3"
width="10%"
/>
<col
class="c4"
width="90%"
/>
</colgroup>
<tbody
class=""
>
<tr>
<td>
<div
class="c5"
>
Comment
</div>
</td>
<td>
<div
class="c5"
>
bar
</div>
</td>
</tr>
<tr>
<td>
<div
class="c5"
>
Audits using this Policy
</div>
</td>
<td>
<div
class="c5"
>
<div
class="c6"
>
<div
class="c7"
margin="5px"
>
<a
class="c8"
data-testid="details-link"
href="/audit/1234"
>
audit1
</a>
,
<a
class="c8"
data-testid="details-link"
href="/audit/5678"
>
audit2
</a>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
`;
58 changes: 58 additions & 0 deletions gsa/src/web/pages/policies/__tests__/details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Copyright (C) 2019 Greenbone Networks GmbH
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import React from 'react';

import Capabilities from 'gmp/capabilities/capabilities';

import Policy from 'gmp/models/policy';
import {OPENVAS_SCAN_CONFIG_TYPE} from 'gmp/models/scanconfig';

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

import Details from '../details';

describe('Policy Details tests', () => {
test('should render full Details', () => {
const policy = new Policy({
name: 'foo',
comment: 'bar',
scanner: {name: 'scanner', type: '42'},
policy_type: OPENVAS_SCAN_CONFIG_TYPE,
tasks: {
task: [{id: '1234', name: 'audit1'}, {id: '5678', name: 'audit2'}],
},
});
const caps = new Capabilities(['everything']);

const {render} = rendererWith({capabilities: caps, router: true});

const {element, getAllByTestId} = render(<Details entity={policy} />);

expect(element).toMatchSnapshot();
expect(element).toHaveTextContent('bar');
expect(element).toHaveTextContent('audit1');
expect(element).toHaveTextContent('audit2');
expect(element).not.toHaveTextContent('scanner');

const detailslinks = getAllByTestId('details-link');

expect(detailslinks[0]).toHaveAttribute('href', '/audit/1234');
expect(detailslinks[1]).toHaveAttribute('href', '/audit/5678');
});
});

0 comments on commit 82f9330

Please sign in to comment.