From 5477759e1168e6a280f4b65bf9fa4e15b3c76eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 25 Feb 2021 10:55:16 +0100 Subject: [PATCH] Update LoginForm tests Use screen instead of the returned query functions of render. Also remove the snapshot test which is very flacky. --- .../__tests__/__snapshots__/loginform.js.snap | 379 ------------------ .../web/pages/login/__tests__/loginform.js | 49 +-- 2 files changed, 25 insertions(+), 403 deletions(-) delete mode 100644 gsa/src/web/pages/login/__tests__/__snapshots__/loginform.js.snap diff --git a/gsa/src/web/pages/login/__tests__/__snapshots__/loginform.js.snap b/gsa/src/web/pages/login/__tests__/__snapshots__/loginform.js.snap deleted file mode 100644 index 0aa7784a74..0000000000 --- a/gsa/src/web/pages/login/__tests__/__snapshots__/loginform.js.snap +++ /dev/null @@ -1,379 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`LoginForm tests should render full LoginForm 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: center; - -webkit-justify-content: center; - -ms-flex-pack: center; - justify-content: center; -} - -.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-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; -} - -.c2 { - 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; - margin-top: -10px; -} - -.c2 > * { - display: -webkit-inline-box; - display: -webkit-inline-flex; - display: -ms-inline-flexbox; - display: inline-flex; -} - -.c2 > * { - margin-top: 10px; -} - -.c1 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-flex-direction: row; - -ms-flex-direction: row; - flex-direction: row; - -webkit-box-flex: 1; - -webkit-flex-grow: 1; - -ms-flex-positive: 1; - flex-grow: 1; - -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; -} - -.c4 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - height: 180px; -} - -.c0 { - 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; - background: #fff; - box-shadow: 0px 14px 22px #787878; - padding: 4rem; - width: 30rem; -} - -.c9 { - 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; - min-height: 12rem; - -webkit-box-pack: space-evenly; - -webkit-justify-content: space-evenly; - -ms-flex-pack: space-evenly; - justify-content: space-evenly; -} - -.c7 { - color: #d83636; - font-weight: bold; - text-align: center; - margin: 10px; -} - -.c12 { - box-sizing: border-box; - color: white; - background-color: text:white; - background: #4c4c4d; - hover: #212121; - disabled: #c2c2c2; - border: none; - border-radius: 3px; - font-size: 1rem; - font-weight: normal; - min-height: 2.25rem; - margin: 0; - padding-right: 1.25rem; - padding-left: 1.25rem; - margin-top: 2rem; - width: 100%; -} - -.c12:hover { - cursor: pointer; - background-color: #212121; -} - -.c12 + .c11 { - margin-left: 1.25rem; -} - -.c6 { - margin: 5px auto; - padding-bottom: 10px; - font-size: 9pt; - border: 1px solid #c8d3d9; - padding: 10px; - margin-bottom: 10px; - margin-top: 20px; -} - -.c10 { - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-box-flex: 1; - -webkit-flex-grow: 1; - -ms-flex-positive: 1; - flex-grow: 1; -} - - -
-
-
-
-
-
- Greenbone Security Assistant -
-
-
-

- Warning: Connection unencrypted -

-

- The connection to this GSA is not encrypted, allowing anyone listening to the traffic to steal your credentials. -

-

- Please configure a TLS certificate for the HTTPS service or ask your administrator to do so as soon as possible. -

-
-
-
-
-

- Sign in to your account -

-
-
- -
- -
-
-
-
-
- -
- -
-
-
- -
-

- An Error Occurred -

-
- -
-
- - Powered By Greenbone Networks - -
-
-
-
-
- -`; diff --git a/gsa/src/web/pages/login/__tests__/loginform.js b/gsa/src/web/pages/login/__tests__/loginform.js index fe11af4269..307cccd23b 100644 --- a/gsa/src/web/pages/login/__tests__/loginform.js +++ b/gsa/src/web/pages/login/__tests__/loginform.js @@ -17,7 +17,7 @@ */ import React from 'react'; -import {rendererWith, fireEvent} from 'web/utils/testing'; +import {rendererWith, fireEvent, screen} from 'web/utils/testing'; import LoginForm from '../loginform'; @@ -30,7 +30,7 @@ describe('LoginForm tests', () => { const {render} = rendererWith({gmp}); - const {baseElement} = render( + const {getByName} = render( { />, ); - expect(baseElement).toMatchSnapshot(); + expect(getByName('username')).toBeInTheDocument(); + expect(getByName('password')).toBeInTheDocument(); }); test('should display error', () => { @@ -50,7 +51,7 @@ describe('LoginForm tests', () => { const {render} = rendererWith({gmp}); - const {getByTestId} = render( + render( { />, ); - expect(getByTestId('error')).toHaveTextContent('An Error Occurred'); + expect(screen.getByTestId('error')).toHaveTextContent('An Error Occurred'); }); test('should not display error by default', () => { @@ -67,11 +68,11 @@ describe('LoginForm tests', () => { const {render} = rendererWith({gmp}); - const {queryByTestId} = render( + render( , ); - expect(queryByTestId('error')).not.toBeInTheDocument(); + expect(screen.queryByTestId('error')).not.toBeInTheDocument(); }); test('should display insecure protocol message', () => { @@ -80,7 +81,7 @@ describe('LoginForm tests', () => { const {render} = rendererWith({gmp}); - const {getByTestId} = render( + render( { />, ); - expect(getByTestId('protocol-insecure')).toBeInTheDocument(); + expect(screen.getByTestId('protocol-insecure')).toBeInTheDocument(); }); test('should not display insecure protocol message by default', () => { @@ -110,7 +111,7 @@ describe('LoginForm tests', () => { const {render} = rendererWith({gmp}); - const {getByTestId} = render( + render( { />, ); - expect(getByTestId('IE11')).toBeInTheDocument(); + expect(screen.getByTestId('IE11')).toBeInTheDocument(); }); test('should not display IE11 message by default', () => { @@ -140,12 +141,12 @@ describe('LoginForm tests', () => { const {render} = rendererWith({gmp}); - const {queryByName} = render( + const {getByName} = render( , ); - expect(queryByName('username')).toBeInTheDocument(); - expect(queryByName('password')).toBeInTheDocument(); + expect(getByName('username')).toBeInTheDocument(); + expect(getByName('password')).toBeInTheDocument(); }); test('should allow to disable login fields', () => { @@ -172,7 +173,7 @@ describe('LoginForm tests', () => { const {render} = rendererWith({gmp}); - const {getByName, getByTestId} = render( + const {getByName} = render( , ); @@ -182,7 +183,7 @@ describe('LoginForm tests', () => { fireEvent.change(usernameField, {target: {value: 'foo'}}); fireEvent.change(passwordField, {target: {value: 'bar'}}); - const button = getByTestId('login-button'); + const button = screen.getByTestId('login-button'); fireEvent.click(button); expect(handleSubmit).toBeCalledWith('foo', 'bar'); @@ -194,12 +195,12 @@ describe('LoginForm tests', () => { const {render} = rendererWith({gmp}); - const {queryByTestId} = render( + render( , ); - expect(queryByTestId('guest-login')).not.toBeInTheDocument(); - expect(queryByTestId('guest-login-button')).not.toBeInTheDocument(); + expect(screen.queryByTestId('guest-login')).not.toBeInTheDocument(); + expect(screen.queryByTestId('guest-login-button')).not.toBeInTheDocument(); }); test('should allow to display guest login', () => { @@ -208,7 +209,7 @@ describe('LoginForm tests', () => { const {render} = rendererWith({gmp}); - const {getByTestId} = render( + render( { />, ); - expect(getByTestId('guest-login')).toBeInTheDocument(); - expect(getByTestId('guest-login-button')).toBeInTheDocument(); + expect(screen.getByTestId('guest-login')).toBeInTheDocument(); + expect(screen.getByTestId('guest-login-button')).toBeInTheDocument(); }); test('should allow to login as guest', () => { @@ -226,7 +227,7 @@ describe('LoginForm tests', () => { const {render} = rendererWith({gmp}); - const {getByTestId} = render( + render( { />, ); - const button = getByTestId('guest-login-button'); + const button = screen.getByTestId('guest-login-button'); fireEvent.click(button); expect(handleClick).toHaveBeenCalled();