Skip to content

Commit 78eca82

Browse files
Grid UI Unit Tests (#8865)
Co-authored-by: David Burns <david.burns@theautomatedtester.co.uk>
1 parent 44b7ba4 commit 78eca82

16 files changed

Lines changed: 13973 additions & 7170 deletions

javascript/grid-ui/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SKIP_PREFLIGHT_CHECK=true

javascript/grid-ui/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load("@bazel_skylib//rules:write_file.bzl", "write_file")
22
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
33
load("@npm//react-scripts:index.bzl", "react_scripts")
4+
load("@npm//jest-cli:index.bzl", "jest_test")
45
load("//common:defs.bzl", "zip_file")
56

67
_RUNTIME_DEPS = [
@@ -78,3 +79,20 @@ zip_file(
7879
"//java/server/src/org/openqa/selenium/grid:__pkg__",
7980
],
8081
)
82+
83+
jest_test(
84+
name = "test",
85+
size = "small",
86+
args = [
87+
"--no-cache",
88+
"--no-watchman",
89+
"--ci",
90+
"--colors",
91+
"--config",
92+
"$(location jest.config.js)"
93+
],
94+
data = [
95+
":build",
96+
"jest.config.js"
97+
]
98+
)

javascript/grid-ui/jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
roots: [
3+
"<rootDir>/../../../../src"
4+
],
5+
testMatch: [
6+
"<rootDir>/../../../../src/tests/**/*.test.tsx"
7+
],
8+
transform: {
9+
"^.+\\.(ts|tsx)$": "ts-jest"
10+
},
11+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
12+
snapshotSerializers: ["enzyme-to-json/serializer"],
13+
setupFilesAfterEnv: ["<rootDir>/../../../../src/setupTests.tsx"],
14+
testEnvironment: "jsdom",
15+
moduleNameMapper: {
16+
".+\\.(svg|png|jpg|css)$": "identity-obj-proxy"
17+
}
18+
}

javascript/grid-ui/package.json

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
{
2-
"name": "grid_ui",
3-
"version": "0.1.0",
4-
"private": true,
5-
"type": "module",
6-
"dependencies": {
7-
"@apollo/react-hooks": "^3.1.5",
8-
"@babel/preset-react": "^7.10.4",
9-
"@emotion/core": "^10.0.28",
10-
"@material-ui/core": "^4.10.2",
11-
"@material-ui/icons": "^4.9.1",
12-
"@testing-library/jest-dom": "^4.2.4",
13-
"@testing-library/react": "^9.5.0",
14-
"@testing-library/user-event": "^7.2.1",
15-
"@types/react-modal": "^3.10.6",
16-
"@types/react-router-dom": "^5.1.5",
17-
"@tippyjs/react": "^4.1.0",
18-
"@types/jest": "^26.0.0",
19-
"@types/keyboardjs": "^2.5.0",
20-
"@types/react": "^16.9.38",
21-
"@types/react-dom": "^16.9.8",
22-
"@types/react-router": "^5.1.8",
23-
"apollo-boost": "^0.4.9",
24-
"findandreplacedomtext": "^0.4.6",
25-
"graphql": "^15.1.0",
26-
"graphql.macro": "^1.4.2",
27-
"historyjs": "^1.8.0-b2",
28-
"keyboardjs": "^2.6.3",
29-
"materialize-css": "^1.0.0-rc.2",
30-
"progressbar.js": "^1.1.0",
31-
"rc-pagination": "^2.4.1",
32-
"react": "^16.13.1",
33-
"react-apollo": "^3.1.5",
34-
"react-dom": "^16.13.1",
35-
"react-json-view": "^1.19.1",
36-
"react-modal": "^3.11.2",
37-
"react-router-dom": "^5.2.0",
38-
"react-scripts": "3.4.3",
39-
"source-map-explorer": "^2.4.2",
40-
"typescript": "^3.9.5"
41-
},
42-
"scripts": {
43-
"start": "node node_modules/react-scripts/bin/react-scripts start",
44-
"build": "node node_modules/react-scripts/bin/react-scripts build && python scripts/rmSourcemaps.py",
45-
"analyze": "source-map-explorer 'build/static/js/*.js'",
46-
"test": "node node_modules/react-scripts/bin/react-scripts test",
47-
"eject": "node node_modules/react-scripts/bin/react-scripts eject"
48-
},
49-
"eslintConfig": {
50-
"extends": "react-app"
51-
},
2+
"name": "grid_ui",
3+
"version": "0.1.0",
4+
"private": true,
5+
"type": "module",
6+
"dependencies": {
7+
"@apollo/react-hooks": "^3.1.5",
8+
"@babel/preset-react": "^7.10.4",
9+
"@emotion/core": "^10.0.28",
10+
"@material-ui/core": "^4.10.2",
11+
"@material-ui/icons": "^4.9.1",
12+
"@testing-library/jest-dom": "^4.2.4",
13+
"@testing-library/react": "^9.5.0",
14+
"@testing-library/user-event": "^7.2.1",
15+
"@tippyjs/react": "^4.1.0",
16+
"@types/enzyme-adapter-react-16": "^1.0.6",
17+
"@types/keyboardjs": "^2.5.0",
18+
"@types/react": "^16.9.38",
19+
"@types/react-dom": "^16.9.8",
20+
"@types/react-modal": "^3.10.6",
21+
"@types/react-router": "^5.1.8",
22+
"@types/react-router-dom": "^5.1.5",
23+
"apollo-boost": "^0.4.9",
24+
"findandreplacedomtext": "^0.4.6",
25+
"graphql": "^15.1.0",
26+
"graphql.macro": "^1.4.2",
27+
"historyjs": "^1.8.0-b2",
28+
"keyboardjs": "^2.6.3",
29+
"materialize-css": "^1.0.0-rc.2",
30+
"node-fetch": "^2.6.1",
31+
"progressbar.js": "^1.1.0",
32+
"rc-pagination": "^2.4.1",
33+
"react": "^16.13.1",
34+
"react-apollo": "^3.1.5",
35+
"react-dom": "^16.13.1",
36+
"react-json-view": "^1.19.1",
37+
"react-modal": "^3.11.2",
38+
"react-router-dom": "^5.2.0",
39+
"react-scripts": "3.4.3",
40+
"source-map-explorer": "^2.4.2"
41+
},
42+
"scripts": {
43+
"start": "node node_modules/react-scripts/bin/react-scripts start",
44+
"build": "node node_modules/react-scripts/bin/react-scripts build && python scripts/rmSourcemaps.py",
45+
"analyze": "source-map-explorer 'build/static/js/*.js'",
46+
"test": "node node_modules/react-scripts/bin/react-scripts test --watchAll=false",
47+
"eject": "node node_modules/react-scripts/bin/react-scripts eject"
48+
},
49+
"eslintConfig": {
50+
"extends": "react-app"
51+
},
5252
"homepage": "/ui",
53-
"browserslist": {
54-
"production": [
55-
">0.2%",
56-
"not dead",
57-
"not op_mini all"
58-
],
59-
"development": [
60-
"last 1 chrome version",
61-
"last 1 firefox version",
62-
"last 1 safari version"
63-
]
64-
}
53+
"browserslist": {
54+
"production": [
55+
">0.2%",
56+
"not dead",
57+
"not op_mini all"
58+
],
59+
"development": [
60+
"last 1 chrome version",
61+
"last 1 firefox version",
62+
"last 1 safari version"
63+
]
64+
}
6565
}

javascript/grid-ui/src/App.test.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

javascript/grid-ui/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { HttpLink } from "apollo-link-http";
55
import ReactModal from "react-modal";
66
import { ApolloProvider } from "react-apollo";
77
import { HashRouter as Router, Route, Switch } from "react-router-dom";
8+
import fetch from 'node-fetch';
89

910
// css import order is important
1011
/* 1 */ import "./css/theme.css";
@@ -21,6 +22,7 @@ import NodeType from "./models/node";
2122
const cache = new InMemoryCache();
2223
const link = new HttpLink({
2324
uri: GridConfig.serverUri,
25+
fetch: fetch
2426
});
2527

2628
export const client = new ApolloClient({
@@ -38,7 +40,7 @@ declare global {
3840
}
3941
}
4042

41-
ReactModal.setAppElement("#root");
43+
if (process.env.NODE_ENV !== 'test') ReactModal.setAppElement("#root");
4244

4345
function App() {
4446
return (

javascript/grid-ui/src/setupTests.js

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { configure } from 'enzyme';
2+
import EnzymeAdapter from 'enzyme-adapter-react-16';
3+
configure({ adapter: new EnzymeAdapter() });
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { shallow, mount } from 'enzyme';
3+
import ColorInfo from '../../components/RingSystem/ColorInfo/ColorInfo';
4+
5+
test('ColorInfo with no progress', () => {
6+
const colorInfo = shallow(
7+
<ColorInfo
8+
color={"#00000"}
9+
text={"Random text"}
10+
id={"1"}
11+
progress={0}
12+
/>
13+
)
14+
15+
expect(colorInfo.getElements()[0].props.children.props).toEqual({});
16+
});
17+
18+
test('ColorInfo with progress', () => {
19+
const colorInfo = shallow(
20+
<ColorInfo
21+
color={"#00000"}
22+
text={"Random text"}
23+
id={"1"}
24+
progress={10}
25+
/>
26+
)
27+
28+
const items = colorInfo.getElements()[0].props.children.props.children;
29+
30+
expect(items[0].props.content).toEqual('10%');
31+
expect(items[1].props.children).toEqual('Random text')
32+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import { shallow, mount } from 'enzyme';
3+
import NavBar from '../../components/NavBar/NavBar';
4+
5+
test('NavBar', () => {
6+
const navBar = shallow(<NavBar />)
7+
8+
const linkProp = navBar.getElements()[0].props.children.props.children[0].props.children[0].props.children.props;
9+
10+
expect(linkProp.id).toEqual('logo');
11+
expect(linkProp.to).toEqual('/home');
12+
});

0 commit comments

Comments
 (0)