Skip to content

Commit d5138bf

Browse files
committed
Add test for reducers on client end
1 parent 8259be9 commit d5138bf

45 files changed

Lines changed: 4413 additions & 13 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.DS_Store

0 Bytes
Binary file not shown.

client/enzyme.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** Used in jest.config.js */
2+
import { configure } from "enzyme";
3+
import Adapter from "enzyme-adapter-react-16";
4+
5+
configure({ adapter: new Adapter() });

client/jest.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
4+
module.exports = {
5+
// Automatically clear mock calls and instances between every test
6+
clearMocks: true,
7+
8+
// An array of glob patterns indicating a set of files for which coverage information should be collected
9+
collectCoverageFrom: ["src/**/*.{js,jsx,mjs}"],
10+
11+
// The directory where Jest should output its coverage files
12+
coverageDirectory: "coverage",
13+
14+
// An array of file extensions your modules use
15+
moduleFileExtensions: ["js", "json", "jsx"],
16+
17+
// The paths to modules that run some code to configure or set up the testing environment before each test
18+
setupFiles: ["<rootDir>/enzyme.config.js"],
19+
20+
// The test environment that will be used for testing
21+
testEnvironment: "jsdom",
22+
23+
// The glob patterns Jest uses to detect test files
24+
testMatch: ["**/__tests__/**/*.js?(x)", "**/?(*.)+(spec|test).js?(x)"],
25+
26+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
27+
testPathIgnorePatterns: ["\\\\node_modules\\\\"],
28+
29+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
30+
testURL: "http://localhost",
31+
32+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
33+
transformIgnorePatterns: ["<rootDir>/node_modules/"],
34+
35+
// Indicates whether each individual test should be reported during the run
36+
verbose: false
37+
};

client/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
"scripts": {
1919
"start": "webpack-dev-server --open",
2020
"build": "webpack --mode production",
21-
"test": "react-scripts test",
21+
"test": "jest",
22+
"test:watch": "jest --watch",
23+
"test:coverage": "jest --coverage --colors",
2224
"eject": "react-scripts eject"
2325
},
2426
"eslintConfig": {
@@ -37,16 +39,20 @@
3739
]
3840
},
3941
"devDependencies": {
42+
"@babel/polyfill": "^7.4.4",
4043
"@babel/preset-env": "^7.4.5",
4144
"@babel/preset-react": "^7.0.0",
4245
"@babel/preset-stage-0": "^7.0.0",
4346
"babel-cli": "^6.26.0",
4447
"babel-core": "^7.0.0-bridge.0",
45-
"babel-loader": "^7.1.5",
48+
"babel-loader": "^8.0.5",
4649
"css-loader": "^2.1.1",
50+
"enzyme": "^3.10.0",
51+
"enzyme-adapter-react-16": "^1.14.0",
4752
"extract-text-webpack-plugin": "^4.0.0-beta.0",
4853
"file-loader": "^4.0.0",
4954
"html-webpack-plugin": "^3.2.0",
55+
"jest": "^24.8.0",
5056
"mini-css-extract-plugin": "^0.7.0",
5157
"node-sass": "^4.12.0",
5258
"path": "^0.12.7",

client/src/App/App.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { PrivateRoute } from "../_components/PrivateRoute.js";
88
import { HomePage } from "../HomePage/HomePage.js";
99
import { LoginPage } from "../LoginPage/LoginPage.js";
1010
import { SignupPage } from "../SignupPage/SignupPage.js";
11-
import { VirtualMachine } from "../CreateAzureServices/VirtualMachine.js";
12-
import { VirtualNetwork } from "../CreateAzureServices/VirtualNetwork.js";
13-
import { Database } from "../CreateAzureServices/Database.js";
14-
import { Security } from "../CreateAzureServices/Security.js";
11+
import { VirtualMachine } from "../CreateServices/VirtualMachine.js";
12+
import { VirtualNetwork } from "../CreateServices/VirtualNetwork.js";
13+
import { Database } from "../CreateServices/Database.js";
14+
import { Security } from "../CreateServices/Security.js";
1515
import { PageNotFound } from "../_helpers/PageNotFound.js";
1616

1717
class App extends React.Component {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

client/src/_reducers/users.reducer.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,73 @@ export function users(state = {}, action) {
4646
// return user;
4747
// })
4848
};
49-
case userConstants.CREATE_VM_REQUEST:
49+
case userConstants.CREATE_VIRTUAL_MACHINE_REQUEST:
5050
// add 'deleting:true' property to user being deleted
5151
return {
5252
loading: true
5353
};
54-
case userConstants.CREATE_VM_SUCCESS:
54+
case userConstants.CREATE_VIRTUAL_MACHINE_SUCCESS:
5555
// remove deleted user from state
5656
return {
5757
...state,
5858
loading: false,
5959
items: action.services
6060
};
61-
case userConstants.CREATE_VM_FAILURE:
61+
case userConstants.CREATE_VIRTUAL_MACHINE_FAILURE:
62+
return {
63+
...state,
64+
loading: false,
65+
error: action.error
66+
};
67+
case userConstants.CREATE_VIRTUAL_NETWORK_REQUEST:
68+
// add 'deleting:true' property to user being deleted
69+
return {
70+
loading: true
71+
};
72+
case userConstants.CREATE_VIRTUAL_NETWORK_SUCCESS:
73+
// remove deleted user from state
74+
return {
75+
...state,
76+
loading: false,
77+
items: action.services
78+
};
79+
case userConstants.CREATE_VIRTUAL_NETWORK_FAILURE:
80+
return {
81+
...state,
82+
loading: false,
83+
error: action.error
84+
};
85+
case userConstants.CREATE_DATABASE_REQUEST:
86+
// add 'deleting:true' property to user being deleted
87+
return {
88+
loading: true
89+
};
90+
case userConstants.CREATE_DATABASE_SUCCESS:
91+
// remove deleted user from state
92+
return {
93+
...state,
94+
loading: false,
95+
items: action.services
96+
};
97+
case userConstants.CREATE_DATABASE_FAILURE:
98+
return {
99+
...state,
100+
loading: false,
101+
error: action.error
102+
};
103+
case userConstants.CREATE_SECURITY_REQUEST:
104+
// add 'deleting:true' property to user being deleted
105+
return {
106+
loading: true
107+
};
108+
case userConstants.CREATE_SECURITY_SUCCESS:
109+
// remove deleted user from state
110+
return {
111+
...state,
112+
loading: false,
113+
items: action.services
114+
};
115+
case userConstants.CREATE_SECURITY_FAILURE:
62116
return {
63117
...state,
64118
loading: false,

0 commit comments

Comments
 (0)