Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] fixing tests #1218

Merged
merged 17 commits into from
Mar 22, 2023
Merged
Prev Previous commit
Next Next commit
skip ui-tests
  • Loading branch information
viyatb committed Mar 22, 2023
commit 214b5ded9cfbbca57c6f6b611ecd8a96036c1b21
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
POSTGRES_PORT: 5432

- name: node_js
if: "!contains(github.event.commits[0].message, '[skip ui-tests]')"
working-directory: owtf/webapp
run: yarn install --production=false && yarn test

Expand Down
1 change: 1 addition & 0 deletions owtf/webapp/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"presets": [
"@babel/preset-react",
"@babel/preset-env",
"@babel/preset-typescript"
],
"plugins": [
"emotion",
Expand Down
11 changes: 9 additions & 2 deletions owtf/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"redux-saga": "^0.16.0",
"reselect": "^3.0.1",
"save-as": "^0.1.8",
"ts-jest": "^29.0.5",
"typescript": "^4.7.4",
"whatwg-fetch": "^2.0.3"
},
Expand All @@ -87,6 +88,7 @@
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@types/react-redux": "^7.1.24",
"@babel/preset-typescript": "^7.21.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.4.2",
"babel-loader": "^8.0.0",
Expand Down Expand Up @@ -114,12 +116,12 @@
"jest": "^24.3.1",
"jest-enzyme": "^7.0.2",
"json-loader": "^0.5.7",
"sass": "^1.59.3",
"offline-plugin": "^4.9.0",
"prettier": "^1.13.5",
"pretty-quick": "^1.6.0",
"redux-logger": "^3.0.6",
"redux-mock-store": "^1.5.3",
"sass": "^1.59.3",
"sass-loader": "^7.0.3",
"style-loader": "^0.20.3",
"url-loader": "^1.0.1",
Expand All @@ -132,6 +134,11 @@
"moduleNameMapper": {
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/mocks/fileMock.js",
"\\.(css|less|scss)$": "<rootDir>/mocks/fileMock.js"
}
},
"moduleFileExtensions": [
"js",
"ts",
"tsx"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`NotFoundPage Component Should render without errors 1`] = `
<p>
<p
style={
Object {
"fontSize": "40px",
"fontWeight": "bold",
"margin": "150px auto",
"textAlign": "center",
}
}
>
Page Not Found
</p>
`;
70 changes: 30 additions & 40 deletions owtf/webapp/src/containers/Plugins/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Plugin component
* This components manages Plugins and handles the plugin launch on selected targets
*/
import React, {useState, useEffect} from "react";
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
Expand All @@ -24,7 +24,7 @@ import {
import { loadPlugins, postToWorklist } from "./actions";
import PluginsTable from "./PluginsTable";

interface IPlugins{
interface IPlugins {
loading: boolean;
error: object | boolean;
plugins: Array<any> | boolean;
Expand All @@ -38,7 +38,7 @@ interface IPlugins{
resetTargetState: Function;
}

export function Plugins ({
export function Plugins({
loading,
error,
plugins,
Expand All @@ -49,15 +49,14 @@ export function Plugins ({
handlePluginClose,
selectedTargets,
handleAlertMsg,
resetTargetState,
resetTargetState
}: IPlugins) {

const [selectedIndex, setSelectedIndex] = useState(1); //handles individual and group-wise plugins
const [selectedPlugins, setSelectedPlugins] = useState([]); //list of plugins to be launched
const [groupSelectedPlugins, setGroupSelectedPlugins] = useState({}); //list of group-wise selected pugins
const [force_overwrite, setForceOverwrite] = useState(false); //handles force-overwrite checkbox
const [globalSearch, setGlobalSearch] = useState(""); // handles the search query for the main search box

useEffect(() => {
onFetchPlugins();
}, []);
Expand All @@ -69,15 +68,17 @@ export function Plugins ({
setSelectedPlugins([]);
setGroupSelectedPlugins({});
setForceOverwrite(false);
}
};

/**
* Function updates the checked plugins in the plugin table
* @param {array} selectedPlugins list of checked plugins
*/
const updateSelectedPlugins = (selectedPlugins: React.SetStateAction<never[]>) => {
const updateSelectedPlugins = (
selectedPlugins: React.SetStateAction<never[]>
) => {
setSelectedPlugins(selectedPlugins);
}
};

/**
* Function launches the plugins group-wise based on group and type
Expand All @@ -94,15 +95,19 @@ export function Plugins ({
});
}
return [pluginGroupss, pluginTypess];
}
};

/**
* Function handles the list of group-wise checked plugins
* @param {object} e checkbox onchange event
* @param {string} collection_type type of plugin group from ['group', 'type']
* @param {string} collection_name name of plugin group or type
*/
const handleCheckboxChange = (e: { target: { checked: any; }; }, collection_type: string | number, collection_name: any) => {
const handleCheckboxChange = (
e: { target: { checked: any } },
collection_type: string | number,
collection_name: any
) => {
const newArray = groupSelectedPlugins;
if (e.target.checked) {
if (newArray[collection_type] === undefined)
Expand All @@ -115,15 +120,15 @@ export function Plugins ({
delete newArray[collection_type];
}
setGroupSelectedPlugins(newArray);
}
};

/**
* Function updating the state of force_overwrite checkbox
* @param {object} event checkbox onchange event
*/
const forceOverwriteChange = ({ target }) => {
setForceOverwrite(target.checked);
}
};

/**
* Function handles the launch of selected individual and group-wise plugins
Expand All @@ -135,21 +140,19 @@ export function Plugins ({
handlePostToWorklist(pluginDetails);
});
// Then fire off any selected groups
if (
Object.getOwnPropertyNames(groupSelectedPlugins).length !== 0
) {
if (Object.getOwnPropertyNames(groupSelectedPlugins).length !== 0) {
// i.e no checkboxes checked then do not send a request
handlePostToWorklist(groupSelectedPlugins);
}
resetState();
resetTargetState();
}
};

/**
* Function that posts targets to worklist using API call
* @param {object} selectedPluginData array containing the target and plugin launch data
*/
const handlePostToWorklist = (selectedPluginData) => {
const handlePostToWorklist = selectedPluginData => {
selectedPluginData["id"] = selectedTargets;
selectedPluginData["force_overwrite"] = force_overwrite;
const data = Object.keys(selectedPluginData)
Expand All @@ -165,18 +168,12 @@ export function Plugins ({

if (selectedPluginData["id"].length < 1) {
// If no targets selected
handleAlertMsg(
"warning",
"No targets selected to launch plugins"
);
handleAlertMsg("warning", "No targets selected to launch plugins");
} else {
onPostToWorklist(data);
setTimeout(() => {
if (postingError !== false) {
handleAlertMsg(
"danger",
"Unable to add " + postingError
); // on post to worklist saga success
handleAlertMsg("danger", "Unable to add " + postingError); // on post to worklist saga success
} else {
handleAlertMsg(
"success",
Expand All @@ -187,7 +184,7 @@ export function Plugins ({
}

handlePluginClose();
}
};

const PluginsTableProps = {
plugins: plugins,
Expand Down Expand Up @@ -232,9 +229,7 @@ export function Plugins ({
borderRadius={100}
className="search-box"
placeholder="Search"
onChange={e =>
setGlobalSearch(e.target.value))
}
onChange={e => setGlobalSearch(e.target.value)}
value={globalSearch}
/>
) : null}
Expand Down Expand Up @@ -289,13 +284,10 @@ export function Plugins ({
key={index}
label={group}
checked={
groupSelectedPlugins["group"] !==
undefined &&
groupSelectedPlugins["group"] !== undefined &&
groupSelectedPlugins["group"].includes(group)
}
onChange={e =>
handleCheckboxChange(e, "group", group)
}
onChange={e => handleCheckboxChange(e, "group", group)}
/>
);
})}
Expand Down Expand Up @@ -347,11 +339,9 @@ const mapStateToProps = createStructuredSelector({
const mapDispatchToProps = (dispatch: Function) => {
return {
onFetchPlugins: () => dispatch(loadPlugins()),
onPostToWorklist: (plugin_data: object) => dispatch(postToWorklist(plugin_data))
onPostToWorklist: (plugin_data: object) =>
dispatch(postToWorklist(plugin_data))
};
};

export default connect(
mapStateToProps,
mapDispatchToProps
)(Plugins);
export default connect(mapStateToProps, mapDispatchToProps)(Plugins);
Loading