Added a simple UI cypress test, improvements to ui menu

This commit is contained in:
Jamie Curnow
2021-07-14 09:37:49 +10:00
parent 4fbb354d54
commit 76a170b50b
7 changed files with 151 additions and 95 deletions

View File

@@ -47,7 +47,7 @@
"styled-components": "5.3.0", "styled-components": "5.3.0",
"tabler-icons-react": "^1.35.0", "tabler-icons-react": "^1.35.0",
"tabler-react": "^2.0.0-alpha.1", "tabler-react": "^2.0.0-alpha.1",
"tabler-react-typescript": "^0.0.4", "tabler-react-typescript": "0.0.5",
"typescript": "^4.3.5" "typescript": "^4.3.5"
}, },
"scripts": { "scripts": {
@@ -83,10 +83,10 @@
], ],
"coverageThreshold": { "coverageThreshold": {
"global": { "global": {
"branches": 1, "branches": 0,
"functions": 1, "functions": 0,
"lines": 1, "lines": 0,
"statements": 1 "statements": 0
} }
} }
} }

View File

@@ -0,0 +1,60 @@
import React from "react";
import {
Book,
DeviceDesktop,
Home,
Lock,
Settings,
Shield,
Users,
} from "tabler-icons-react";
import { Navigation } from "tabler-react-typescript";
function NavMenu() {
return (
<Navigation.Menu
theme="light"
className="mb-3"
items={[
{
title: "Home",
icon: <Home />,
to: "/",
},
{
title: "Hosts",
icon: <DeviceDesktop />,
to: "/hosts",
},
{
title: "Access Lists",
icon: <Lock />,
to: "/access-lists",
},
{
title: "Certificates",
icon: <Shield />,
to: "/certificates",
},
{
title: "Users",
icon: <Users />,
to: "/users",
},
{
title: "Audit Log",
icon: <Book />,
to: "/audit-log",
},
{
title: "Settings",
icon: <Settings />,
to: "/settings",
},
]}
/>
);
}
export { NavMenu };

View File

@@ -3,17 +3,10 @@ import React, { ReactNode } from "react";
import { Footer } from "components"; import { Footer } from "components";
import { useAuthState, useUserState } from "context"; import { useAuthState, useUserState } from "context";
import styled from "styled-components"; import styled from "styled-components";
import {
Book,
DeviceDesktop,
Home,
Lock,
Settings,
Shield,
Users,
} from "tabler-icons-react";
import { Avatar, Dropdown, Navigation } from "tabler-react-typescript"; import { Avatar, Dropdown, Navigation } from "tabler-react-typescript";
import { NavMenu } from "./NavMenu";
const StyledContainer = styled.div` const StyledContainer = styled.div`
padding-bottom: 30px; padding-bottom: 30px;
`; `;
@@ -45,52 +38,14 @@ function SiteWrapper({ children }: Props) {
user.roles.includes("admin") ? "Administrator" : "Standard User" user.roles.includes("admin") ? "Administrator" : "Standard User"
} }
profileItems={[ profileItems={[
<Dropdown.Item key="m1-1">Set status</Dropdown.Item>, <Dropdown.Item key="m1-2">Profile settings</Dropdown.Item>,
<Dropdown.Item key="m1-2">Profile &amp; account</Dropdown.Item>,
<Dropdown.Item key="m1-3">Feedback</Dropdown.Item>,
<Dropdown.Item divider key="m1-4" />, <Dropdown.Item divider key="m1-4" />,
<Dropdown.Item key="m1-5">Settings</Dropdown.Item>,
<Dropdown.Item key="m1-6" onClick={logout}> <Dropdown.Item key="m1-6" onClick={logout}>
Logout Logout
</Dropdown.Item>, </Dropdown.Item>,
]} ]}
/> />
<Navigation.Menu <NavMenu />
theme="light"
className="mb-3"
items={[
{
title: "Home",
icon: <Home />,
active: true,
},
{
title: "Hosts",
icon: <DeviceDesktop />,
},
{
title: "Access Lists",
icon: <Lock />,
},
{
title: "Certificates",
icon: <Shield />,
},
{
title: "Users",
icon: <Users />,
},
{
title: "Audit Log",
icon: <Book />,
},
{
title: "Settings",
icon: <Settings />,
},
]}
/>
<div className="content"> <div className="content">
<div className="container-xl"> <div className="container-xl">
<StyledContainer>{children}</StyledContainer> <StyledContainer>{children}</StyledContainer>

View File

@@ -1829,13 +1829,6 @@
dependencies: dependencies:
"@babel/types" "^7.3.0" "@babel/types" "^7.3.0"
"@types/classnames@^2.2.11":
version "2.3.1"
resolved "https://registry.yarnpkg.com/@types/classnames/-/classnames-2.3.1.tgz#3c2467aa0f1a93f1f021e3b9bcf938bd5dfdc0dd"
integrity sha512-zeOWb0JGBoVmlQoznvqXbE0tEC/HONsnoUNH19Hc96NFsTAwTXbTqb8FMYkru1F/iqp7a18Ws3nWJvtA1sHD1A==
dependencies:
classnames "*"
"@types/eslint@^7.2.6": "@types/eslint@^7.2.6":
version "7.2.6" version "7.2.6"
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.2.6.tgz#5e9aff555a975596c03a98b59ecd103decc70c3c" resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.2.6.tgz#5e9aff555a975596c03a98b59ecd103decc70c3c"
@@ -3646,7 +3639,7 @@ class-utils@^0.3.5:
isobject "^3.0.0" isobject "^3.0.0"
static-extend "^0.1.1" static-extend "^0.1.1"
classnames@*, classnames@^2.2.6: classnames@^2.2.6:
version "2.3.1" version "2.3.1"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.3.1.tgz#dfcfa3891e306ec1dad105d0e88f4417b8535e8e" resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.3.1.tgz#dfcfa3891e306ec1dad105d0e88f4417b8535e8e"
integrity sha512-OlQdbZ7gLfGarSqxesMesDa5uz7KFbID8Kpq/SxIoNGDqY8lSYs0D+hhtBXhcdB3rcbXArFr7vlHheLk1voeNA== integrity sha512-OlQdbZ7gLfGarSqxesMesDa5uz7KFbID8Kpq/SxIoNGDqY8lSYs0D+hhtBXhcdB3rcbXArFr7vlHheLk1voeNA==
@@ -11784,13 +11777,13 @@ tabler-icons-react@^1.35.0:
resolved "https://registry.yarnpkg.com/tabler-icons-react/-/tabler-icons-react-1.35.0.tgz#b4e7f8da632314d002aa5e34931f2f824395b77c" resolved "https://registry.yarnpkg.com/tabler-icons-react/-/tabler-icons-react-1.35.0.tgz#b4e7f8da632314d002aa5e34931f2f824395b77c"
integrity sha512-WiJ+dYQ71HCsxKAQpCfPrFVwSfqE6CByYFjq9Gzikmp2RijJBsNpj0sE/T5G0H+nERS9odjAWJoSryvr4FymFg== integrity sha512-WiJ+dYQ71HCsxKAQpCfPrFVwSfqE6CByYFjq9Gzikmp2RijJBsNpj0sE/T5G0H+nERS9odjAWJoSryvr4FymFg==
tabler-react-typescript@^0.0.4: tabler-react-typescript@0.0.5:
version "0.0.4" version "0.0.5"
resolved "https://registry.yarnpkg.com/tabler-react-typescript/-/tabler-react-typescript-0.0.4.tgz#b40ee7faef743f5d5af6cdf098d3376cdb71989e" resolved "https://registry.yarnpkg.com/tabler-react-typescript/-/tabler-react-typescript-0.0.5.tgz#ab14ebada6f0524e13e3c6e60d2739a0f34f617d"
integrity sha512-l/OoB4zQ3+u4xVxARw+1HqaHO13wDYlQIvjFyvs6Sdk7Vdys0sAc/EzN9hxWg5ywRNM+mGwt5+fVHXiuYAcD7g== integrity sha512-PIov0LMSZWQzQ0OnlyITTzVdgBOKuc6HzgNLttP6Uz3/evGDBFl/Owl7wcP6niy7varzx4SttzFNXfJyhC3zcg==
dependencies: dependencies:
"@types/classnames" "^2.2.11"
classnames "^2.2.6" classnames "^2.2.6"
react-router-dom "^5.2.0"
tabler-react@^2.0.0-alpha.1: tabler-react@^2.0.0-alpha.1:
version "2.0.0-alpha.1" version "2.0.0-alpha.1"

View File

@@ -3,19 +3,15 @@
describe('Setup Phase', () => { describe('Setup Phase', () => {
before(() => { before(() => {
cy.task('backendApiDelete', { cy.resetUsers();
path: '/api/users'
}).then((data) => {
expect(data).to.have.property('result', true);
});
}); });
it('Should not be able to get a token', function() { it('Should NOT be able to get a token', function() {
cy.task('backendApiPost', { cy.task('backendApiPost', {
path: '/api/tokens', path: '/api/tokens',
data: { data: {
type: 'password', type: 'password',
identity: 'jc@jc21.com', identity: 'cypress@example.com',
secret: 'changeme' secret: 'changeme'
}, },
returnOnError: true returnOnError: true

View File

@@ -0,0 +1,20 @@
/// <reference types="Cypress" />
describe('UI Setup and Login', () => {
// Clear the users before runing this test
before(() => {
cy.resetUsers();
});
it('Should be able to setup a new user', function() {
cy.visit('/');
cy.get('input[name="name"]').type('Cypress McGee');
cy.get('input[name="nickname"]').type('Cypress');
cy.get('input[name="email"]').type('cypress@example.com');
cy.get('input[name="password"]').type('changeme');
cy.get('form button:first').click();
cy.get('.navbar-nav .avatar').should('be.visible');
});
});

View File

@@ -28,7 +28,18 @@ Cypress.Commands.add('validateSwaggerSchema', (method, code, path, data) => {
}).should('equal', null); }).should('equal', null);
}); });
Cypress.Commands.add('getToken', () => { /**
* @param {object} defaultUser
* @param {object} defaultAuth
*/
Cypress.Commands.add('getToken', (defaultUser, defaultAuth) => {
if (typeof defaultAuth === 'object' && defaultAuth) {
if (!defaultUser) {
defaultUser = {};
}
defaultUser.auth = defaultAuth;
}
cy.task('backendApiGet', { cy.task('backendApiGet', {
path: '/api/', path: '/api/',
}).then((data) => { }).then((data) => {
@@ -38,40 +49,52 @@ Cypress.Commands.add('getToken', () => {
if (!data.result.setup) { if (!data.result.setup) {
cy.log('Setup = false'); cy.log('Setup = false');
// create a new user // create a new user
cy.createInitialUser().then(() => { cy.createInitialUser(defaultUser).then(() => {
return cy.getToken(); return cy.getToken(defaultUser);
}); });
} else { } else {
let auth = {
type: 'password',
identity: 'cypress@example.com',
secret: 'changeme',
};
if (typeof defaultUser === 'object' && defaultUser && typeof defaultUser.auth === 'object' && defaultUser.auth) {
auth = Object.assign({}, auth, defaultUser.auth);
}
cy.log('Setup = true'); cy.log('Setup = true');
// login with existing user // login with existing user
cy.task('backendApiPost', { cy.task('backendApiPost', {
path: '/api/tokens', path: '/api/tokens',
data: { data: auth,
type: 'password', }).then((res) => {
identity: 'jc@jc21.com',
secret: 'changeme'
}
}).then(res => {
cy.wrap(res.result.token); cy.wrap(res.result.token);
}); });
} }
}); });
}); });
Cypress.Commands.add('createInitialUser', () => { Cypress.Commands.add('createInitialUser', (defaultUser) => {
return cy.task('backendApiPost', { let user = {
path: '/api/users', name: 'Cypress McGee',
data: { nickname: 'Cypress',
name: 'Jamie Curnow', email: 'cypress@example.com',
nickname: 'James',
email: 'jc@jc21.com',
roles: [], roles: [],
is_disabled: false, is_disabled: false,
auth: { auth: {
type: 'password', type: 'password',
secret: 'changeme' secret: 'changeme'
} }
};
if (typeof defaultUser === 'object' && defaultUser) {
user = Object.assign({}, user, defaultUser);
} }
return cy.task('backendApiPost', {
path: '/api/users',
data: user,
}).then((data) => { }).then((data) => {
// Check the swagger schema: // Check the swagger schema:
cy.validateSwaggerSchema('post', 201, '/users', data); cy.validateSwaggerSchema('post', 201, '/users', data);
@@ -80,3 +103,12 @@ Cypress.Commands.add('createInitialUser', () => {
cy.wrap(data.result); cy.wrap(data.result);
}); });
}); });
Cypress.Commands.add('resetUsers', () => {
cy.task('backendApiDelete', {
path: '/api/users'
}).then((data) => {
expect(data).to.have.property('result', true);
cy.wrap(data.result);
});
});