From cd7ad57dde370ecac375a024ffc9299531d3237d Mon Sep 17 00:00:00 2001 From: Sarah Diedrich Date: Fri, 17 May 2019 12:23:22 +0200 Subject: [PATCH 1/4] Add tests for severitylevelsgroup --- .../__snapshots__/severitylevelsgroup.js.snap | 324 ++++++++++++++++++ .../__tests__/severitylevelsgroup.js | 101 ++++++ 2 files changed, 425 insertions(+) create mode 100644 gsa/src/web/components/powerfilter/__tests__/__snapshots__/severitylevelsgroup.js.snap create mode 100644 gsa/src/web/components/powerfilter/__tests__/severitylevelsgroup.js diff --git a/gsa/src/web/components/powerfilter/__tests__/__snapshots__/severitylevelsgroup.js.snap b/gsa/src/web/components/powerfilter/__tests__/__snapshots__/severitylevelsgroup.js.snap new file mode 100644 index 0000000000..dc725d517b --- /dev/null +++ b/gsa/src/web/components/powerfilter/__tests__/__snapshots__/severitylevelsgroup.js.snap @@ -0,0 +1,324 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SeverityLevelsFilterGroup tests should render 1`] = ` +.c3 { + 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; +} + +.c5 { + margin-left: -5px; +} + +.c5 > * { + display: -webkit-inline-box; + display: -webkit-inline-flex; + display: -ms-inline-flexbox; + display: inline-flex; +} + +.c5 > * { + margin-left: 5px; +} + +.c4 { + display: -webkit-inline-box; + display: -webkit-inline-flex; + display: -ms-inline-flexbox; + display: inline-flex; +} + +.c0 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: start; + -webkit-justify-content: start; + -ms-flex-pack: start; + justify-content: start; + padding-bottom: 10px; +} + +.c1 { + display: inline-block; + max-width: 100%; + font-weight: bold; + text-align: right; + padding-left: 10px; + padding-right: 10px; + width: 16.66666667%; + margin-left: 0; +} + +.c2 { + width: 83.33333333%; + padding-left: 10px; + padding-right: 10px; +} + +.c6 { + display: -webkit-inline-box; + display: -webkit-inline-flex; + display: -ms-inline-flexbox; + display: inline-flex; + -webkit-flex-direction: row; + -ms-flex-direction: row; + flex-direction: row; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + font-weight: normal; + cursor: pointer; +} + +.c8 { + font-family: inherit; + font-size: inherit; + padding: 0; + margin: 0; + margin-left: 10px; + line-height: normal; + width: auto; + height: auto; +} + +.c7 { + 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; +} + +.c9 { + text-align: center; + font-weight: normal; + font-style: normal; + color: white; + padding: 1px; + display: inline-block; + width: 60px; + height: 1.5em; + font-size: 0.8em; + background-color: #C83814; + border-color: #C83814; +} + +.c10 { + text-align: center; + font-weight: normal; + font-style: normal; + color: white; + padding: 1px; + display: inline-block; + width: 60px; + height: 1.5em; + font-size: 0.8em; + background-color: #F0A519; + border-color: #F0A519; +} + +.c11 { + text-align: center; + font-weight: normal; + font-style: normal; + color: white; + padding: 1px; + display: inline-block; + width: 60px; + height: 1.5em; + font-size: 0.8em; + background-color: #4F91C7; + border-color: #4F91C7; +} + +.c12 { + text-align: center; + font-weight: normal; + font-style: normal; + color: white; + padding: 1px; + display: inline-block; + width: 60px; + height: 1.5em; + font-size: 0.8em; + background-color: #191919; + border-color: #191919; +} + +
+ +
+
+
+ + + + + +
+
+
+
+`; diff --git a/gsa/src/web/components/powerfilter/__tests__/severitylevelsgroup.js b/gsa/src/web/components/powerfilter/__tests__/severitylevelsgroup.js new file mode 100644 index 0000000000..f7b053b243 --- /dev/null +++ b/gsa/src/web/components/powerfilter/__tests__/severitylevelsgroup.js @@ -0,0 +1,101 @@ +/* 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 {render, fireEvent} from 'web/utils/testing'; + +import SeverityLevelsFilterGroup from '../severitylevelsgroup'; + +import Filter from 'gmp/models/filter'; + +describe('SeverityLevelsFilterGroup tests', () => { + test('should render', () => { + const filter = Filter.fromString('levels=h'); + const handleChange = jest.fn(); + const {element} = render( + , + ); + + expect(element).toMatchSnapshot(); + }); + + test('should call change handler', () => { + const filter = Filter.fromString('levels='); + const handleChange = jest.fn(); + const {element} = render( + , + ); + + const checkbox = element.querySelectorAll('input'); + fireEvent.click(checkbox[0]); + + expect(handleChange).toHaveBeenCalled(); + expect(handleChange).toHaveBeenCalledWith('h', 'levels'); + }); + + test('should check checkbox', () => { + const filter = Filter.fromString('levels=hm'); + const handleChange = jest.fn(); + const {element} = render( + , + ); + + const checkbox = element.querySelectorAll('input'); + + expect(checkbox[0].checked).toEqual(true); + expect(checkbox[1].checked).toEqual(true); + }); + + test('should uncheck checkbox', () => { + const filter1 = Filter.fromString('levels=hm'); + const filter2 = Filter.fromString('levels=m'); + const handleChange = jest.fn(); + const {element, rerender} = render( + , + ); + + const checkbox = element.querySelectorAll('input'); + + expect(checkbox[0].checked).toEqual(true); + expect(checkbox[1].checked).toEqual(true); + + rerender( + , + ); + + expect(checkbox[0].checked).toEqual(false); + expect(checkbox[1].checked).toEqual(true); + }); + + test('should be unchecked by default', () => { + const filter = Filter.fromString(); + const handleChange = jest.fn(); + const {element} = render( + , + ); + + const checkbox = element.querySelectorAll('input'); + + expect(checkbox[0].checked).toEqual(false); + expect(checkbox[1].checked).toEqual(false); + expect(checkbox[2].checked).toEqual(false); + expect(checkbox[3].checked).toEqual(false); + expect(checkbox[4].checked).toEqual(false); + }); +}); From ccce8347d19631b094e8c40fd7e02a4f5bac3ae7 Mon Sep 17 00:00:00 2001 From: Sarah Diedrich Date: Fri, 17 May 2019 12:25:02 +0200 Subject: [PATCH 2/4] Add render with children test for radio button --- .../__tests__/__snapshots__/radio.js.snap | 113 ++++++++++++++++++ .../web/components/form/__tests__/radio.js | 10 ++ 2 files changed, 123 insertions(+) diff --git a/gsa/src/web/components/form/__tests__/__snapshots__/radio.js.snap b/gsa/src/web/components/form/__tests__/__snapshots__/radio.js.snap index c48cc14e15..75f64fb05d 100644 --- a/gsa/src/web/components/form/__tests__/__snapshots__/radio.js.snap +++ b/gsa/src/web/components/form/__tests__/__snapshots__/radio.js.snap @@ -106,3 +106,116 @@ exports[`Radio tests should render radio 1`] = ` `; + +exports[`Radio tests should render radio with children 1`] = ` +.c2 { + 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; +} + +.c3 { + margin-left: -5px; +} + +.c3 > * { + display: -webkit-inline-box; + display: -webkit-inline-flex; + display: -ms-inline-flexbox; + display: inline-flex; +} + +.c3 > * { + margin-left: 5px; +} + +.c1 { + display: -webkit-inline-box; + display: -webkit-inline-flex; + display: -ms-inline-flexbox; + display: inline-flex; +} + +.c0 { + display: -webkit-inline-box; + display: -webkit-inline-flex; + display: -ms-inline-flexbox; + display: inline-flex; + -webkit-flex-direction: row; + -ms-flex-direction: row; + flex-direction: row; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + font-weight: normal; + cursor: pointer; +} + +.c5 { + font-family: inherit; + font-size: inherit; + padding: 0; + margin: 0; + margin-left: 10px; + line-height: normal; + width: auto; + height: auto; +} + +.c4 { + 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: flex-start; + -ms-flex-pack: start; + justify-content: flex-start; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; +} + + +`; diff --git a/gsa/src/web/components/form/__tests__/radio.js b/gsa/src/web/components/form/__tests__/radio.js index 1522051f54..8430c898b4 100644 --- a/gsa/src/web/components/form/__tests__/radio.js +++ b/gsa/src/web/components/form/__tests__/radio.js @@ -68,6 +68,16 @@ describe('Radio tests', () => { expect(element).toMatchSnapshot(); }); + test('should render radio with children', () => { + const {element} = render( + + child1 + child2 + , + ); + expect(element).toMatchSnapshot(); + }); + test('should call change handler', () => { const onChange = jest.fn(); From 7bf8065de1e496041e5005d4a60ad74981a3c0da Mon Sep 17 00:00:00 2001 From: Sarah Diedrich Date: Fri, 17 May 2019 12:25:41 +0200 Subject: [PATCH 3/4] Add tests for task trend --- .../__tests__/__snapshots__/trend.js.snap | 24 +++++++ gsa/src/web/pages/tasks/__tests__/trend.js | 71 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 gsa/src/web/pages/tasks/__tests__/__snapshots__/trend.js.snap create mode 100644 gsa/src/web/pages/tasks/__tests__/trend.js diff --git a/gsa/src/web/pages/tasks/__tests__/__snapshots__/trend.js.snap b/gsa/src/web/pages/tasks/__tests__/__snapshots__/trend.js.snap new file mode 100644 index 0000000000..7c48a60923 --- /dev/null +++ b/gsa/src/web/pages/tasks/__tests__/__snapshots__/trend.js.snap @@ -0,0 +1,24 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Task Trend tests should render 1`] = ` +.c0 { + height: 16px; + width: 16px; + line-height: 16px; +} + +.c0 * { + height: inherit; + width: inherit; +} + + + + trend_up.svg + + +`; diff --git a/gsa/src/web/pages/tasks/__tests__/trend.js b/gsa/src/web/pages/tasks/__tests__/trend.js new file mode 100644 index 0000000000..4edea6d1ab --- /dev/null +++ b/gsa/src/web/pages/tasks/__tests__/trend.js @@ -0,0 +1,71 @@ +/* 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 {render} from 'web/utils/testing'; + +import Trend from '../trend'; + +import {setLocale} from 'gmp/locale/lang'; + +setLocale('en'); + +describe('Task Trend tests', () => { + test('should render', () => { + const {element} = render(); + + expect(element).toMatchSnapshot(); + }); + + test('should render trend up icon', () => { + const {element} = render(); + + expect(element).toHaveAttribute('title', 'Severity increased'); + expect(element).toHaveTextContent('trend_up.svg'); + }); + + test('should render trend down icon', () => { + const {element} = render(); + + expect(element).toHaveAttribute('title', 'Severity decreased'); + expect(element).toHaveTextContent('trend_down.svg'); + }); + + test('should render trend less icon', () => { + const {element} = render(); + + expect(element).toHaveAttribute('title', 'Vulnerability count decreased'); + expect(element).toHaveTextContent('trend_less.svg'); + }); + + test('should render trend more icon', () => { + const {element} = render(); + + expect(element).toHaveAttribute('title', 'Vulnerability count increased'); + expect(element).toHaveTextContent('trend_more.svg'); + }); + + test('should render trend no change icon', () => { + const {element} = render(); + + expect(element).toHaveAttribute('title', 'Vulnerabilities did not change'); + expect(element).toHaveTextContent('trend_nochange.svg'); + }); +}); From ecf4d423674102003e5dd8ed34fbe385bbfd4257 Mon Sep 17 00:00:00 2001 From: Sarah Diedrich Date: Fri, 17 May 2019 12:27:06 +0200 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e666fef452..32006f8db8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [8.0.1] - (unreleased) ### Added +- Add tests for severitylevelsgroup, radio button and task trend [#1413](https://github.com/greenbone/gsa/pull/1413) - Allow to show error details [#1403](https://github.com/greenbone/gsa/pull/1403) - Add test for solution type group [#1402](https://github.com/greenbone/gsa/pull/1402) - Add tests for loginpage and structure components [#1390](https://github.com/greenbone/gsa/pull/1390)