mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-15 18:54:36 +00:00
feat(*): recreate package with new name
This commit is contained in:
1
sasjs-tests/.env
Normal file
1
sasjs-tests/.env
Normal file
@@ -0,0 +1 @@
|
||||
SKIP_PREFLIGHT_CHECK=true
|
||||
23
sasjs-tests/.gitignore
vendored
Normal file
23
sasjs-tests/.gitignore
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
68
sasjs-tests/README.md
Normal file
68
sasjs-tests/README.md
Normal file
@@ -0,0 +1,68 @@
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.<br />
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.<br />
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.<br />
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.<br />
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.<br />
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
|
||||
14799
sasjs-tests/package-lock.json
generated
Normal file
14799
sasjs-tests/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
sasjs-tests/package.json
Normal file
47
sasjs-tests/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "sasjs-tests",
|
||||
"version": "0.1.0",
|
||||
"homepage": ".",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.5.0",
|
||||
"@testing-library/user-event": "^7.2.1",
|
||||
"@types/jest": "^26.0.3",
|
||||
"@types/node": "^14.0.14",
|
||||
"@types/react": "^16.9.41",
|
||||
"@types/react-dom": "^16.9.8",
|
||||
"@types/react-router-dom": "^5.1.5",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-scripts": "3.4.1",
|
||||
"sasjs": "file:../build/sasjs-5.0.0.tgz",
|
||||
"typescript": "^3.9.6"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject",
|
||||
"deploy": "rsync -avhe ssh ./build/* --delete kriaco@sas.analytium.co.uk:/var/www/html/kriaco/sasjs-tests"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"node-sass": "^4.14.1"
|
||||
}
|
||||
}
|
||||
11
sasjs-tests/public/config.json
Normal file
11
sasjs-tests/public/config.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"userName": "",
|
||||
"password": "",
|
||||
"sasJsConfig": {
|
||||
"serverUrl": "",
|
||||
"appLoc": "/Public/app",
|
||||
"serverType": "SASVIYA",
|
||||
"debug": false,
|
||||
"contextName": null
|
||||
}
|
||||
}
|
||||
BIN
sasjs-tests/public/favicon.ico
Normal file
BIN
sasjs-tests/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
BIN
sasjs-tests/public/favicon.png
Normal file
BIN
sasjs-tests/public/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
40
sasjs-tests/public/index.html
Normal file
40
sasjs-tests/public/index.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta name="description" content="Tests for SASjs" />
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>SASjs Tests</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
BIN
sasjs-tests/public/logo192.png
Normal file
BIN
sasjs-tests/public/logo192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
BIN
sasjs-tests/public/logo512.png
Normal file
BIN
sasjs-tests/public/logo512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
25
sasjs-tests/public/manifest.json
Normal file
25
sasjs-tests/public/manifest.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
3
sasjs-tests/public/robots.txt
Normal file
3
sasjs-tests/public/robots.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
BIN
sasjs-tests/public/sasjs-logo.png
Normal file
BIN
sasjs-tests/public/sasjs-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
102
sasjs-tests/src/App.scss
Normal file
102
sasjs-tests/src/App.scss
Normal file
@@ -0,0 +1,102 @@
|
||||
.app {
|
||||
padding: 16px;
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
.debug-toggle,
|
||||
.app-loc-input,
|
||||
.submit-button {
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.row {
|
||||
margin: 16px;
|
||||
|
||||
&.app-loc {
|
||||
width: 20vw;
|
||||
}
|
||||
}
|
||||
|
||||
.submit-button {
|
||||
padding: 16px;
|
||||
font-size: 1.25em;
|
||||
}
|
||||
|
||||
.app-loc-input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.debug-toggle {
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.label {
|
||||
padding: 0 8px;
|
||||
font-size: 1.25em;
|
||||
}
|
||||
}
|
||||
|
||||
$height: 40px;
|
||||
$width: 70px;
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
width: $width;
|
||||
height: $height;
|
||||
|
||||
input[type="checkbox"] {
|
||||
display: none;
|
||||
}
|
||||
input:checked + .knob {
|
||||
animation: colorChange 0.4s linear forwards;
|
||||
}
|
||||
input:checked + .knob:before {
|
||||
animation: turnON 0.4s linear forwards;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes colorChange {
|
||||
from {
|
||||
background-color: #ccc;
|
||||
}
|
||||
50% {
|
||||
background-color: #a4d9ad;
|
||||
}
|
||||
to {
|
||||
background-color: #4bd663;
|
||||
}
|
||||
}
|
||||
@keyframes turnON {
|
||||
from {
|
||||
transform: translateX(0px);
|
||||
}
|
||||
to {
|
||||
transform: translateX($width - ($height * 0.99));
|
||||
box-shadow: -10px 0px 44px 0px #434343;
|
||||
}
|
||||
}
|
||||
|
||||
.knob {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #ccc;
|
||||
border-radius: $height;
|
||||
}
|
||||
|
||||
.knob:before {
|
||||
position: absolute;
|
||||
background-color: white;
|
||||
content: "";
|
||||
left: $height * 0.1;
|
||||
top: $height * 0.1;
|
||||
width: ($height * 0.8);
|
||||
height: ($height * 0.8);
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
9
sasjs-tests/src/App.test.js
Normal file
9
sasjs-tests/src/App.test.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
||||
test('renders learn react link', () => {
|
||||
const { getByText } = render(<App />);
|
||||
const linkElement = getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
||||
58
sasjs-tests/src/App.tsx
Normal file
58
sasjs-tests/src/App.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import React, { ReactElement, useState, useContext, useEffect } from "react";
|
||||
import "./App.scss";
|
||||
import TestSuiteRunner from "./TestSuiteRunner";
|
||||
import { AppContext } from "./context/AppContext";
|
||||
|
||||
const App = (): ReactElement<{}> => {
|
||||
const [appLoc, setAppLoc] = useState("");
|
||||
const [debug, setDebug] = useState(false);
|
||||
const { adapter } = useContext(AppContext);
|
||||
|
||||
useEffect(() => {
|
||||
if (adapter) {
|
||||
adapter.setDebugState(debug);
|
||||
}
|
||||
}, [debug, adapter]);
|
||||
|
||||
useEffect(() => {
|
||||
if (appLoc && adapter) {
|
||||
adapter.setSASjsConfig({ ...adapter.getSasjsConfig(), appLoc });
|
||||
}
|
||||
}, [appLoc, adapter]);
|
||||
|
||||
useEffect(() => {
|
||||
setAppLoc(adapter.getSasjsConfig().appLoc);
|
||||
}, [adapter]);
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<div className="controls">
|
||||
<div className="row">
|
||||
<label>Debug</label>
|
||||
<div className="debug-toggle">
|
||||
<label className="switch">
|
||||
<input
|
||||
type="checkbox"
|
||||
onChange={(e) => setDebug(e.target.checked)}
|
||||
/>
|
||||
<span className="knob"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row app-loc">
|
||||
<label>App Loc</label>
|
||||
<input
|
||||
type="text"
|
||||
className="app-loc-input"
|
||||
value={appLoc}
|
||||
onChange={(e) => setAppLoc(e.target.value)}
|
||||
placeholder="AppLoc"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{adapter && <TestSuiteRunner adapter={adapter} />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
34
sasjs-tests/src/Login.scss
Normal file
34
sasjs-tests/src/Login.scss
Normal file
@@ -0,0 +1,34 @@
|
||||
.login-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
img {
|
||||
max-width: 30%;
|
||||
}
|
||||
|
||||
form {
|
||||
width: 33%;
|
||||
margin-top: 3%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.row {
|
||||
input {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
label {
|
||||
font-weight: bold;
|
||||
font-size: 0.9em;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.submit-button {
|
||||
margin-top: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
54
sasjs-tests/src/Login.tsx
Normal file
54
sasjs-tests/src/Login.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
import React, { ReactElement, useState, useCallback, useContext } from "react";
|
||||
import "./Login.scss";
|
||||
import { AppContext } from "./context/AppContext";
|
||||
import { Redirect } from "react-router-dom";
|
||||
|
||||
const Login = (): ReactElement<{}> => {
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const appContext = useContext(AppContext);
|
||||
|
||||
const handleSubmit = useCallback(
|
||||
(e) => {
|
||||
e.preventDefault();
|
||||
appContext.adapter.logIn(username, password).then(() => {
|
||||
appContext.setIsLoggedIn(true);
|
||||
});
|
||||
},
|
||||
[username, password, appContext]
|
||||
);
|
||||
|
||||
return !appContext.isLoggedIn ? (
|
||||
<div className="login-container">
|
||||
<img src="sasjs-logo.png" alt="SASjs Logo" />
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className="row">
|
||||
<label>User Name</label>
|
||||
<input
|
||||
placeholder="User Name"
|
||||
value={username}
|
||||
required
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="row">
|
||||
<label>Password</label>
|
||||
<input
|
||||
placeholder="Password"
|
||||
type="password"
|
||||
value={password}
|
||||
required
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<button type="submit" className="submit-button">
|
||||
Log In
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
) : (
|
||||
<Redirect to="/" />
|
||||
);
|
||||
};
|
||||
|
||||
export default Login;
|
||||
23
sasjs-tests/src/PrivateRoute.tsx
Normal file
23
sasjs-tests/src/PrivateRoute.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
import React, { ReactElement, useContext, FunctionComponent } from "react";
|
||||
import { Redirect, Route } from "react-router-dom";
|
||||
import { AppContext } from "./context/AppContext";
|
||||
|
||||
interface PrivateRouteProps {
|
||||
component: FunctionComponent;
|
||||
exact?: boolean;
|
||||
path: string;
|
||||
}
|
||||
|
||||
const PrivateRoute = (
|
||||
props: PrivateRouteProps
|
||||
): ReactElement<PrivateRouteProps> => {
|
||||
const { component, path, exact } = props;
|
||||
const appContext = useContext(AppContext);
|
||||
return appContext.isLoggedIn ? (
|
||||
<Route component={component} path={path} exact={exact} />
|
||||
) : (
|
||||
<Redirect to="/login" />
|
||||
);
|
||||
};
|
||||
|
||||
export default PrivateRoute;
|
||||
19
sasjs-tests/src/TestSuiteRunner.scss
Normal file
19
sasjs-tests/src/TestSuiteRunner.scss
Normal file
@@ -0,0 +1,19 @@
|
||||
.button-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 16px;
|
||||
|
||||
.loading-spinner {
|
||||
margin: 0 8px;
|
||||
}
|
||||
|
||||
.submit-button {
|
||||
padding: 10px;
|
||||
min-height: 80px;
|
||||
font-size: 2em;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
126
sasjs-tests/src/TestSuiteRunner.tsx
Normal file
126
sasjs-tests/src/TestSuiteRunner.tsx
Normal file
@@ -0,0 +1,126 @@
|
||||
import React, { useEffect, useState, ReactElement, useContext } from "react";
|
||||
import TestSuiteComponent from "./components/TestSuite";
|
||||
import TestSuiteCard from "./components/TestSuiteCard";
|
||||
import { TestSuite, Test } from "./types";
|
||||
import { basicTests } from "./testSuites/Basic";
|
||||
import "./TestSuiteRunner.scss";
|
||||
import SASjs from "sasjs";
|
||||
import { AppContext } from "./context/AppContext";
|
||||
import { sendArrTests, sendObjTests } from "./testSuites/RequestData";
|
||||
import { specialCaseTests } from "./testSuites/SpecialCases";
|
||||
import { sasjsRequestTests } from "./testSuites/SasjsRequests";
|
||||
|
||||
interface TestSuiteRunnerProps {
|
||||
adapter: SASjs;
|
||||
}
|
||||
const TestSuiteRunner = (
|
||||
props: TestSuiteRunnerProps
|
||||
): ReactElement<TestSuiteRunnerProps> => {
|
||||
const { adapter } = props;
|
||||
const { config } = useContext(AppContext);
|
||||
const [testSuites, setTestSuites] = useState<TestSuite[]>([]);
|
||||
const [runTests, setRunTests] = useState(false);
|
||||
const [completedTestSuites, setCompletedTestSuites] = useState<
|
||||
{
|
||||
name: string;
|
||||
completedTests: {
|
||||
test: Test;
|
||||
result: boolean;
|
||||
error: Error | null;
|
||||
executionTime: number;
|
||||
}[];
|
||||
}[]
|
||||
>([]);
|
||||
const [currentTestSuite, setCurrentTestSuite] = useState<TestSuite | null>(
|
||||
(null as unknown) as TestSuite
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (adapter) {
|
||||
setTestSuites([
|
||||
// basicTests(adapter, config.userName, config.password),
|
||||
// sendArrTests(adapter),
|
||||
// sendObjTests(adapter),
|
||||
specialCaseTests(adapter),
|
||||
// sasjsRequestTests(adapter),
|
||||
]);
|
||||
setCompletedTestSuites([]);
|
||||
}
|
||||
}, [adapter]);
|
||||
|
||||
useEffect(() => {
|
||||
if (testSuites.length) {
|
||||
setCurrentTestSuite(testSuites[0]);
|
||||
}
|
||||
}, [testSuites]);
|
||||
|
||||
useEffect(() => {
|
||||
if (runTests) {
|
||||
setCompletedTestSuites([]);
|
||||
setCurrentTestSuite(testSuites[0]);
|
||||
}
|
||||
}, [runTests, testSuites]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="button-container">
|
||||
<button
|
||||
className={runTests ? "submit-button disabled" : "submit-button"}
|
||||
onClick={() => setRunTests(true)}
|
||||
disabled={runTests}
|
||||
>
|
||||
{runTests ? (
|
||||
<>
|
||||
<div className="loading-spinner"></div>Running tests...
|
||||
</>
|
||||
) : (
|
||||
"Run tests!"
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
{completedTestSuites.map((completedTestSuite, index) => {
|
||||
return (
|
||||
<TestSuiteCard
|
||||
key={index}
|
||||
tests={completedTestSuite.completedTests}
|
||||
name={completedTestSuite.name}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{currentTestSuite && runTests && (
|
||||
<TestSuiteComponent
|
||||
{...currentTestSuite}
|
||||
onCompleted={(
|
||||
name,
|
||||
completedTests: {
|
||||
test: Test;
|
||||
result: boolean;
|
||||
error: Error | null;
|
||||
executionTime: number;
|
||||
}[]
|
||||
) => {
|
||||
const currentIndex = testSuites.indexOf(currentTestSuite);
|
||||
const nextIndex =
|
||||
currentIndex < testSuites.length - 1 ? currentIndex + 1 : -1;
|
||||
if (nextIndex >= 0) {
|
||||
setCurrentTestSuite(testSuites[nextIndex]);
|
||||
} else {
|
||||
setCurrentTestSuite(null);
|
||||
}
|
||||
const newCompletedTestSuites = [
|
||||
...completedTestSuites,
|
||||
{ name, completedTests },
|
||||
];
|
||||
setCompletedTestSuites(newCompletedTestSuites);
|
||||
|
||||
if (newCompletedTestSuites.length === testSuites.length) {
|
||||
setRunTests(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default TestSuiteRunner;
|
||||
79
sasjs-tests/src/components/Test.tsx
Normal file
79
sasjs-tests/src/components/Test.tsx
Normal file
@@ -0,0 +1,79 @@
|
||||
import React, { ReactElement, useEffect, useState } from "react";
|
||||
import TestCard from "./TestCard";
|
||||
import { start } from "repl";
|
||||
|
||||
interface TestProps {
|
||||
title: string;
|
||||
description: string;
|
||||
beforeTest?: (...args: any) => Promise<any>;
|
||||
afterTest?: (...args: any) => Promise<any>;
|
||||
test: (context: any) => Promise<any>;
|
||||
assertion: (...args: any) => boolean;
|
||||
onCompleted: (payload: {
|
||||
result: boolean;
|
||||
error: Error | null;
|
||||
executionTime: number;
|
||||
}) => void;
|
||||
context: any;
|
||||
}
|
||||
|
||||
const getStatus = (isRunning: boolean, isPassed: boolean): string => {
|
||||
return isRunning ? "running" : isPassed ? "passed" : "failed";
|
||||
};
|
||||
|
||||
const Test = (props: TestProps): ReactElement<TestProps> => {
|
||||
const {
|
||||
title,
|
||||
description,
|
||||
test,
|
||||
beforeTest,
|
||||
afterTest,
|
||||
assertion,
|
||||
onCompleted,
|
||||
context,
|
||||
} = props;
|
||||
const beforeTestFunction = beforeTest ? beforeTest : () => Promise.resolve();
|
||||
const afterTestFunction = afterTest ? afterTest : () => Promise.resolve();
|
||||
const [isRunning, setIsRunning] = useState(false);
|
||||
const [isPassed, setIsPassed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (test && assertion) {
|
||||
const startTime = new Date().valueOf();
|
||||
setIsRunning(true);
|
||||
setIsPassed(false);
|
||||
beforeTestFunction()
|
||||
.then(() => test(context))
|
||||
.then((res) => {
|
||||
setIsRunning(false);
|
||||
setIsPassed(assertion(res, context));
|
||||
return Promise.resolve(assertion(res, context));
|
||||
})
|
||||
.then((testResult) => {
|
||||
afterTestFunction();
|
||||
const endTime = new Date().valueOf();
|
||||
const executionTime = (endTime - startTime) / 1000;
|
||||
onCompleted({ result: testResult, error: null, executionTime });
|
||||
})
|
||||
.catch((e) => {
|
||||
setIsRunning(false);
|
||||
setIsPassed(false);
|
||||
console.error(e);
|
||||
const endTime = new Date().valueOf();
|
||||
const executionTime = (endTime - startTime) / 1000;
|
||||
onCompleted({ result: false, error: e, executionTime });
|
||||
});
|
||||
}
|
||||
}, [test, assertion]);
|
||||
|
||||
return (
|
||||
<TestCard
|
||||
title={title}
|
||||
description={description}
|
||||
status={getStatus(isRunning, isPassed)}
|
||||
error={null}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default Test;
|
||||
62
sasjs-tests/src/components/TestCard.scss
Normal file
62
sasjs-tests/src/components/TestCard.scss
Normal file
@@ -0,0 +1,62 @@
|
||||
.test {
|
||||
display: inline-flex;
|
||||
padding: 8px;
|
||||
margin: 8px;
|
||||
flex-direction: column;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
width: 20%;
|
||||
|
||||
.title {
|
||||
font-weight: bold;
|
||||
color: #eee;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.description,
|
||||
.execution-time {
|
||||
color: #c6c0c0;
|
||||
padding: 8px 0;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.description {
|
||||
min-height: 50px;
|
||||
}
|
||||
|
||||
.execution-time {
|
||||
color: #f9e804;
|
||||
}
|
||||
|
||||
.icon {
|
||||
border-radius: 50%;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
margin-right: 8px;
|
||||
display: inline-block;
|
||||
|
||||
&.running {
|
||||
background-color: yellow;
|
||||
}
|
||||
|
||||
&.passed {
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
&.failed {
|
||||
background-color: red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 900px) {
|
||||
.test {
|
||||
width: 90%;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 901px) and (max-width: 1280px) {
|
||||
.test {
|
||||
width: 30%;
|
||||
}
|
||||
}
|
||||
43
sasjs-tests/src/components/TestCard.tsx
Normal file
43
sasjs-tests/src/components/TestCard.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import React, { ReactElement } from "react";
|
||||
import "./TestCard.scss";
|
||||
|
||||
interface TestCardProps {
|
||||
title: string;
|
||||
description: string;
|
||||
status: string;
|
||||
error: Error | null;
|
||||
executionTime?: number;
|
||||
}
|
||||
const TestCard = (props: TestCardProps): ReactElement<TestCardProps> => {
|
||||
const { title, description, status, error, executionTime } = props;
|
||||
|
||||
return (
|
||||
<div className="test">
|
||||
<code className="title">{title}</code>
|
||||
<span className="description">{description}</span>
|
||||
<span className="execution-time">
|
||||
{executionTime ? executionTime.toFixed(2) + "s" : ""}
|
||||
</span>
|
||||
{status === "running" && (
|
||||
<div>
|
||||
<span className="icon running"></span>Running...
|
||||
</div>
|
||||
)}
|
||||
{status === "passed" && (
|
||||
<div>
|
||||
<span className="icon passed"></span>Passed
|
||||
</div>
|
||||
)}
|
||||
{status === "failed" && (
|
||||
<>
|
||||
<div>
|
||||
<span className="icon failed"></span>Failed
|
||||
</div>
|
||||
{!!error && <code>{error.message}</code>}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TestCard;
|
||||
106
sasjs-tests/src/components/TestSuite.tsx
Normal file
106
sasjs-tests/src/components/TestSuite.tsx
Normal file
@@ -0,0 +1,106 @@
|
||||
import React, { ReactElement, useState, useEffect } from "react";
|
||||
import "./TestSuiteCard.scss";
|
||||
import { Test } from "../types";
|
||||
import TestComponent from "./Test";
|
||||
import TestCard from "./TestCard";
|
||||
|
||||
interface TestSuiteProps {
|
||||
name: string;
|
||||
tests: Test[];
|
||||
beforeAll?: (...args: any) => Promise<any>;
|
||||
afterAll?: (...args: any) => Promise<any>;
|
||||
onCompleted: (
|
||||
name: string,
|
||||
completedTests: {
|
||||
test: Test;
|
||||
result: boolean;
|
||||
error: Error | null;
|
||||
executionTime: number;
|
||||
}[]
|
||||
) => void;
|
||||
}
|
||||
const TestSuite = (props: TestSuiteProps): ReactElement<TestSuiteProps> => {
|
||||
const { name, tests, beforeAll, afterAll, onCompleted } = props;
|
||||
const [context, setContext] = useState<any>(null);
|
||||
const [completedTests, setCompletedTests] = useState<
|
||||
{
|
||||
test: Test;
|
||||
result: boolean;
|
||||
error: Error | null;
|
||||
executionTime: number;
|
||||
}[]
|
||||
>([]);
|
||||
const [currentTest, setCurrentTest] = useState<Test | null>(
|
||||
(null as unknown) as Test
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (beforeAll) {
|
||||
beforeAll().then((data) => setContext({ data }));
|
||||
}
|
||||
}, [beforeAll]);
|
||||
|
||||
useEffect(() => {
|
||||
if (tests.length) {
|
||||
setCurrentTest(tests[0]);
|
||||
}
|
||||
setCompletedTests([]);
|
||||
setContext(null);
|
||||
}, [tests]);
|
||||
|
||||
return (!!beforeAll && !!context) || !beforeAll ? (
|
||||
<div className="test-suite">
|
||||
<div className="test-suite-name running">{name}</div>
|
||||
{currentTest && (
|
||||
<TestComponent
|
||||
{...currentTest}
|
||||
context={context}
|
||||
onCompleted={(completedTest) => {
|
||||
const newCompleteTests = [
|
||||
...completedTests,
|
||||
{
|
||||
test: currentTest,
|
||||
result: completedTest.result,
|
||||
error: completedTest.error,
|
||||
executionTime: completedTest.executionTime,
|
||||
},
|
||||
];
|
||||
setCompletedTests(newCompleteTests);
|
||||
const currentIndex = tests.indexOf(currentTest);
|
||||
const nextIndex =
|
||||
currentIndex < tests.length - 1 ? currentIndex + 1 : -1;
|
||||
if (nextIndex >= 0) {
|
||||
setCurrentTest(tests[nextIndex]);
|
||||
} else {
|
||||
setCurrentTest(null);
|
||||
}
|
||||
if (newCompleteTests.length === tests.length) {
|
||||
if (afterAll) {
|
||||
afterAll().then(() => onCompleted(name, newCompleteTests));
|
||||
} else {
|
||||
onCompleted(name, newCompleteTests);
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{completedTests.map((completedTest, index) => {
|
||||
const { test, result, error } = completedTest;
|
||||
const { title, description } = test;
|
||||
return (
|
||||
<TestCard
|
||||
key={index}
|
||||
title={title}
|
||||
description={description}
|
||||
status={result === true ? "passed" : "failed"}
|
||||
error={error}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
};
|
||||
|
||||
export default TestSuite;
|
||||
19
sasjs-tests/src/components/TestSuiteCard.scss
Normal file
19
sasjs-tests/src/components/TestSuiteCard.scss
Normal file
@@ -0,0 +1,19 @@
|
||||
.test-suite {
|
||||
.test-suite-name {
|
||||
font-size: 1.5em;
|
||||
font-weight: bold;
|
||||
color: #1f2027;
|
||||
|
||||
&.passed {
|
||||
color: green;
|
||||
}
|
||||
|
||||
&.failed {
|
||||
color: red;
|
||||
}
|
||||
|
||||
&.running {
|
||||
color: yellow;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
sasjs-tests/src/components/TestSuiteCard.tsx
Normal file
44
sasjs-tests/src/components/TestSuiteCard.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import React, { ReactElement } from "react";
|
||||
import "./TestSuiteCard.scss";
|
||||
import { Test } from "../types";
|
||||
import TestCard from "./TestCard";
|
||||
|
||||
interface TestSuiteCardProps {
|
||||
name: string;
|
||||
tests: {
|
||||
test: Test;
|
||||
result: boolean;
|
||||
error: Error | null;
|
||||
executionTime: number;
|
||||
}[];
|
||||
}
|
||||
const TestSuiteCard = (
|
||||
props: TestSuiteCardProps
|
||||
): ReactElement<TestSuiteCardProps> => {
|
||||
const { name, tests } = props;
|
||||
const overallStatus = tests.map((t) => t.result).reduce((x, y) => x && y);
|
||||
|
||||
return (
|
||||
<div className="test-suite">
|
||||
<div className={`test-suite-name ${overallStatus ? "passed" : "failed"}`}>
|
||||
{name}
|
||||
</div>
|
||||
{tests.map((completedTest, index) => {
|
||||
const { test, result, error, executionTime } = completedTest;
|
||||
const { title, description } = test;
|
||||
return (
|
||||
<TestCard
|
||||
key={index}
|
||||
title={title}
|
||||
description={description}
|
||||
status={result === true ? "passed" : "failed"}
|
||||
error={error}
|
||||
executionTime={executionTime}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TestSuiteCard;
|
||||
53
sasjs-tests/src/context/AppContext.tsx
Normal file
53
sasjs-tests/src/context/AppContext.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import React, { createContext, useState, useEffect, ReactNode } from "react";
|
||||
import SASjs from "sasjs";
|
||||
|
||||
export const AppContext = createContext<{
|
||||
config: any;
|
||||
sasJsConfig: any;
|
||||
isLoggedIn: boolean;
|
||||
setIsLoggedIn: (value: boolean) => void;
|
||||
adapter: SASjs;
|
||||
}>({
|
||||
config: null,
|
||||
sasJsConfig: null,
|
||||
isLoggedIn: false,
|
||||
setIsLoggedIn: (null as unknown) as (value: boolean) => void,
|
||||
adapter: (null as unknown) as SASjs,
|
||||
});
|
||||
|
||||
export const AppProvider = (props: { children: ReactNode }) => {
|
||||
const [config, setConfig] = useState<{ sasJsConfig: any }>({
|
||||
sasJsConfig: null,
|
||||
});
|
||||
|
||||
const [adapter, setAdapter] = useState<SASjs>((null as unknown) as SASjs);
|
||||
|
||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("config.json")
|
||||
.then((res) => res.json())
|
||||
.then((configJson: any) => {
|
||||
setConfig(configJson);
|
||||
const sasjs = new SASjs(configJson.sasJsConfig);
|
||||
setAdapter(sasjs);
|
||||
sasjs.checkSession().then((response) => {
|
||||
setIsLoggedIn(response.isLoggedIn);
|
||||
});
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AppContext.Provider
|
||||
value={{
|
||||
config,
|
||||
sasJsConfig: config.sasJsConfig,
|
||||
isLoggedIn,
|
||||
setIsLoggedIn,
|
||||
adapter,
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</AppContext.Provider>
|
||||
);
|
||||
};
|
||||
63
sasjs-tests/src/index.scss
Normal file
63
sasjs-tests/src/index.scss
Normal file
@@ -0,0 +1,63 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
|
||||
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
background-color: #1f2027;
|
||||
color: #eee;
|
||||
}
|
||||
|
||||
* {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
|
||||
monospace;
|
||||
}
|
||||
|
||||
input {
|
||||
padding: 8px;
|
||||
border-radius: 3px;
|
||||
border: none;
|
||||
font-size: 1.125em;
|
||||
}
|
||||
|
||||
.submit-button {
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
padding: 8px;
|
||||
background-color: #f9e804;
|
||||
color: black;
|
||||
font-size: 0.8em;
|
||||
|
||||
&.disabled {
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
display: inline-block;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
border-top-color: #fff;
|
||||
animation: spin 1s ease-in-out infinite;
|
||||
-webkit-animation: spin 1s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
-webkit-transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@-webkit-keyframes spin {
|
||||
to {
|
||||
-webkit-transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
26
sasjs-tests/src/index.tsx
Normal file
26
sasjs-tests/src/index.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { Route, HashRouter, Switch } from "react-router-dom";
|
||||
import "./index.scss";
|
||||
import * as serviceWorker from "./serviceWorker";
|
||||
import { AppProvider } from "./context/AppContext";
|
||||
import PrivateRoute from "./PrivateRoute";
|
||||
import Login from "./Login";
|
||||
import App from "./App";
|
||||
|
||||
ReactDOM.render(
|
||||
<AppProvider>
|
||||
<HashRouter>
|
||||
<Switch>
|
||||
<PrivateRoute exact path="/" component={App} />
|
||||
<Route exact path="/login" component={Login} />
|
||||
</Switch>
|
||||
</HashRouter>
|
||||
</AppProvider>,
|
||||
document.getElementById("root")
|
||||
);
|
||||
|
||||
// If you want your app to work offline and load faster, you can change
|
||||
// unregister() to register() below. Note this comes with some pitfalls.
|
||||
// Learn more about service workers: https://bit.ly/CRA-PWA
|
||||
serviceWorker.unregister();
|
||||
1
sasjs-tests/src/react-app-env.d.ts
vendored
Normal file
1
sasjs-tests/src/react-app-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="react-scripts" />
|
||||
141
sasjs-tests/src/serviceWorker.js
Normal file
141
sasjs-tests/src/serviceWorker.js
Normal file
@@ -0,0 +1,141 @@
|
||||
// This optional code is used to register a service worker.
|
||||
// register() is not called by default.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on subsequent visits to a page, after all the
|
||||
// existing tabs open on the page have been closed, since previously cached
|
||||
// resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model and instructions on how to
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
);
|
||||
|
||||
export function register(config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl, config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl, config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl, {
|
||||
headers: { 'Service-Worker': 'script' },
|
||||
})
|
||||
.then(response => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
.then(registration => {
|
||||
registration.unregister();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
5
sasjs-tests/src/setupTests.js
Normal file
5
sasjs-tests/src/setupTests.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom/extend-expect';
|
||||
97
sasjs-tests/src/testSuites/Basic.ts
Normal file
97
sasjs-tests/src/testSuites/Basic.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import SASjs, { ServerType, SASjsConfig } from "sasjs";
|
||||
import { TestSuite } from "../types";
|
||||
|
||||
const defaultConfig: SASjsConfig = {
|
||||
serverUrl: window.location.origin,
|
||||
pathSAS9: "/SASStoredProcess/do",
|
||||
pathSASViya: "/SASJobExecution",
|
||||
appLoc: "/Public/seedapp",
|
||||
serverType: ServerType.SASViya,
|
||||
debug: true,
|
||||
contextName: "SAS Job Execution compute context",
|
||||
};
|
||||
|
||||
const customConfig = {
|
||||
serverUrl: "url",
|
||||
pathSAS9: "sas9",
|
||||
pathSASViya: "viya",
|
||||
appLoc: "/Public/seedapp",
|
||||
serverType: ServerType.SAS9,
|
||||
debug: false,
|
||||
};
|
||||
|
||||
export const basicTests = (
|
||||
adapter: SASjs,
|
||||
userName: string,
|
||||
password: string
|
||||
): TestSuite => ({
|
||||
name: "Basic Tests",
|
||||
tests: [
|
||||
{
|
||||
title: "Log in",
|
||||
description: "Should log the user in",
|
||||
test: async () => {
|
||||
return adapter.logIn(userName, password);
|
||||
},
|
||||
assertion: (response: any) =>
|
||||
response && response.isLoggedIn && response.userName === userName,
|
||||
},
|
||||
{
|
||||
title: "Default config",
|
||||
description:
|
||||
"Should instantiate with default config when none is provided",
|
||||
test: async () => {
|
||||
return Promise.resolve(new SASjs());
|
||||
},
|
||||
assertion: (sasjsInstance: SASjs) => {
|
||||
const sasjsConfig = sasjsInstance.getSasjsConfig();
|
||||
return (
|
||||
sasjsConfig.serverUrl === defaultConfig.serverUrl &&
|
||||
sasjsConfig.pathSAS9 === defaultConfig.pathSAS9 &&
|
||||
sasjsConfig.pathSASViya === defaultConfig.pathSASViya &&
|
||||
sasjsConfig.appLoc === defaultConfig.appLoc &&
|
||||
sasjsConfig.serverType === defaultConfig.serverType &&
|
||||
sasjsConfig.debug === defaultConfig.debug
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Custom config",
|
||||
description: "Should use fully custom config whenever supplied",
|
||||
test: async () => {
|
||||
return Promise.resolve(new SASjs(customConfig));
|
||||
},
|
||||
assertion: (sasjsInstance: SASjs) => {
|
||||
const sasjsConfig = sasjsInstance.getSasjsConfig();
|
||||
return (
|
||||
sasjsConfig.serverUrl === customConfig.serverUrl &&
|
||||
sasjsConfig.pathSAS9 === customConfig.pathSAS9 &&
|
||||
sasjsConfig.pathSASViya === customConfig.pathSASViya &&
|
||||
sasjsConfig.appLoc === customConfig.appLoc &&
|
||||
sasjsConfig.serverType === customConfig.serverType &&
|
||||
sasjsConfig.debug === customConfig.debug
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Config overrides",
|
||||
description: "Should override default config with supplied properties",
|
||||
test: async () => {
|
||||
return Promise.resolve(
|
||||
new SASjs({ serverUrl: "http://test.com", debug: false })
|
||||
);
|
||||
},
|
||||
assertion: (sasjsInstance: SASjs) => {
|
||||
const sasjsConfig = sasjsInstance.getSasjsConfig();
|
||||
return (
|
||||
sasjsConfig.serverUrl === "http://test.com" &&
|
||||
sasjsConfig.pathSAS9 === defaultConfig.pathSAS9 &&
|
||||
sasjsConfig.pathSASViya === defaultConfig.pathSASViya &&
|
||||
sasjsConfig.appLoc === defaultConfig.appLoc &&
|
||||
sasjsConfig.serverType === defaultConfig.serverType &&
|
||||
sasjsConfig.debug === false
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
308
sasjs-tests/src/testSuites/RequestData.ts
Normal file
308
sasjs-tests/src/testSuites/RequestData.ts
Normal file
@@ -0,0 +1,308 @@
|
||||
import SASjs from "sasjs";
|
||||
import { TestSuite } from "../types";
|
||||
|
||||
const stringData: any = { table1: [{ col1: "first col value" }] };
|
||||
const numericData: any = { table1: [{ col1: 3.14159265 }] };
|
||||
const multiColumnData: any = {
|
||||
table1: [{ col1: 42, col2: 1.618, col3: "x", col4: "x" }],
|
||||
};
|
||||
const multipleRowsWithNulls: any = {
|
||||
table1: [
|
||||
{ col1: 42, col2: null, col3: "x", col4: "" },
|
||||
{ col1: 42, col2: null, col3: "x", col4: "" },
|
||||
{ col1: 42, col2: null, col3: "x", col4: "" },
|
||||
{ col1: 42, col2: 1.62, col3: "x", col4: "x" },
|
||||
{ col1: 42, col2: 1.62, col3: "x", col4: "x" },
|
||||
],
|
||||
};
|
||||
const multipleColumnsWithNulls: any = {
|
||||
table1: [
|
||||
{ col1: 42, col2: null, col3: "x", col4: null },
|
||||
{ col1: 42, col2: null, col3: "x", col4: null },
|
||||
{ col1: 42, col2: null, col3: "x", col4: null },
|
||||
{ col1: 42, col2: null, col3: "x", col4: "" },
|
||||
{ col1: 42, col2: null, col3: "x", col4: "" },
|
||||
],
|
||||
};
|
||||
|
||||
const getLongStringData = (length = 32764) => {
|
||||
let x = "X";
|
||||
for (let i = 1; i <= length; i++) {
|
||||
x = x + "X";
|
||||
}
|
||||
const data: any = { table1: [{ col1: x }] };
|
||||
return data;
|
||||
};
|
||||
|
||||
const getLargeObjectData = () => {
|
||||
const data = { table1: [{ big: "data" }] };
|
||||
|
||||
for (let i = 1; i < 10000; i++) {
|
||||
data.table1.push(data.table1[0]);
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export const sendArrTests = (adapter: SASjs): TestSuite => ({
|
||||
name: "sendArr",
|
||||
tests: [
|
||||
{
|
||||
title: "Single string value",
|
||||
description: "Should send an array with a single string value",
|
||||
test: () => {
|
||||
return adapter.request("common/sendArr", stringData);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
return res.table1[0][0] === stringData.table1[0].col1;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Long string value",
|
||||
description:
|
||||
"Should send an array with a long string value under 32765 characters",
|
||||
test: () => {
|
||||
return adapter.request("common/sendArr", getLongStringData());
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
const longStringData = getLongStringData();
|
||||
return res.table1[0][0] === longStringData.table1[0].col1;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Overly long string value",
|
||||
description:
|
||||
"Should error out with long string values over 32765 characters",
|
||||
test: () => {
|
||||
return adapter
|
||||
.request("common/sendArr", getLongStringData(32767))
|
||||
.catch((e) => e);
|
||||
},
|
||||
assertion: (error: any) => {
|
||||
return !!error && !!error.MESSAGE;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Single numeric value",
|
||||
description: "Should send an array with a single numeric value",
|
||||
test: () => {
|
||||
return adapter.request("common/sendArr", numericData);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
return res.table1[0][0] === numericData.table1[0].col1;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Multiple columns",
|
||||
description: "Should handle data with multiple columns",
|
||||
test: () => {
|
||||
return adapter.request("common/sendArr", multiColumnData);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
return (
|
||||
res.table1[0][0] === multiColumnData.table1[0].col1 &&
|
||||
res.table1[0][1] === multiColumnData.table1[0].col2 &&
|
||||
res.table1[0][2] === multiColumnData.table1[0].col3 &&
|
||||
res.table1[0][3] === multiColumnData.table1[0].col4
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Multiple rows with nulls",
|
||||
description: "Should handle data with multiple rows with null values",
|
||||
test: () => {
|
||||
return adapter.request("common/sendArr", multipleRowsWithNulls);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
let result = true;
|
||||
multipleRowsWithNulls.table1.forEach((_: any, index: number) => {
|
||||
result =
|
||||
result &&
|
||||
res.table1[index][0] === multipleRowsWithNulls.table1[index].col1;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index][1] === multipleRowsWithNulls.table1[index].col2;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index][2] === multipleRowsWithNulls.table1[index].col3;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index][3] === multipleRowsWithNulls.table1[index].col4;
|
||||
});
|
||||
return result;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Multiple columns with nulls",
|
||||
description: "Should handle data with multiple columns with null values",
|
||||
test: () => {
|
||||
return adapter.request("common/sendArr", multipleColumnsWithNulls);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
let result = true;
|
||||
multipleColumnsWithNulls.table1.forEach((_: any, index: number) => {
|
||||
result =
|
||||
result &&
|
||||
res.table1[index][0] ===
|
||||
multipleColumnsWithNulls.table1[index].col1;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index][1] ===
|
||||
multipleColumnsWithNulls.table1[index].col2;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index][2] ===
|
||||
multipleColumnsWithNulls.table1[index].col3;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index][3] ===
|
||||
(multipleColumnsWithNulls.table1[index].col4 || "");
|
||||
});
|
||||
return result;
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export const sendObjTests = (adapter: SASjs): TestSuite => ({
|
||||
name: "sendObj",
|
||||
tests: [
|
||||
{
|
||||
title: "Invalid column name",
|
||||
description: "Should throw an error",
|
||||
test: async () => {
|
||||
const invalidData: any = {
|
||||
"1 invalid table": [{ col1: 42 }],
|
||||
};
|
||||
return adapter.request("common/sendObj", invalidData).catch((e) => e);
|
||||
},
|
||||
assertion: (error: any) => !!error && !!error.MESSAGE,
|
||||
},
|
||||
{
|
||||
title: "Single string value",
|
||||
description: "Should send an object with a single string value",
|
||||
test: () => {
|
||||
return adapter.request("common/sendObj", stringData);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
return res.table1[0].COL1 === stringData.table1[0].col1;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Long string value",
|
||||
description:
|
||||
"Should send an object with a long string value under 32765 characters",
|
||||
test: () => {
|
||||
return adapter.request("common/sendObj", getLongStringData());
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
const longStringData = getLongStringData();
|
||||
return res.table1[0].COL1 === longStringData.table1[0].col1;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Overly long string value",
|
||||
description:
|
||||
"Should error out with long string values over 32765 characters",
|
||||
test: () => {
|
||||
return adapter
|
||||
.request("common/sendObj", getLongStringData(32767))
|
||||
.catch((e) => e);
|
||||
},
|
||||
assertion: (error: any) => {
|
||||
return !!error && !!error.MESSAGE;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Single numeric value",
|
||||
description: "Should send an object with a single numeric value",
|
||||
test: () => {
|
||||
return adapter.request("common/sendObj", numericData);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
return res.table1[0].COL1 === numericData.table1[0].col1;
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
title: "Large data volume",
|
||||
description: "Should send an object with a large amount of data",
|
||||
test: () => {
|
||||
return adapter.request("common/sendObj", getLargeObjectData());
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
const data = getLargeObjectData();
|
||||
return res.table1[9000].BIG === data.table1[9000].big;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Multiple columns",
|
||||
description: "Should handle data with multiple columns",
|
||||
test: () => {
|
||||
return adapter.request("common/sendObj", multiColumnData);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
return (
|
||||
res.table1[0].COL1 === multiColumnData.table1[0].col1 &&
|
||||
res.table1[0].COL2 === multiColumnData.table1[0].col2 &&
|
||||
res.table1[0].COL3 === multiColumnData.table1[0].col3 &&
|
||||
res.table1[0].COL4 === multiColumnData.table1[0].col4
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Multiple rows with nulls",
|
||||
description: "Should handle data with multiple rows with null values",
|
||||
test: () => {
|
||||
return adapter.request("common/sendObj", multipleRowsWithNulls);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
let result = true;
|
||||
multipleRowsWithNulls.table1.forEach((_: any, index: number) => {
|
||||
result =
|
||||
result &&
|
||||
res.table1[index].COL1 === multipleRowsWithNulls.table1[index].col1;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index].COL2 === multipleRowsWithNulls.table1[index].col2;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index].COL3 === multipleRowsWithNulls.table1[index].col3;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index].COL4 === multipleRowsWithNulls.table1[index].col4;
|
||||
});
|
||||
return result;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Multiple columns with nulls",
|
||||
description: "Should handle data with multiple columns with null values",
|
||||
test: () => {
|
||||
return adapter.request("common/sendObj", multipleColumnsWithNulls);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
let result = true;
|
||||
multipleColumnsWithNulls.table1.forEach((_: any, index: number) => {
|
||||
result =
|
||||
result &&
|
||||
res.table1[index].COL1 ===
|
||||
multipleColumnsWithNulls.table1[index].col1;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index].COL2 ===
|
||||
multipleColumnsWithNulls.table1[index].col2;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index].COL3 ===
|
||||
multipleColumnsWithNulls.table1[index].col3;
|
||||
result =
|
||||
result &&
|
||||
res.table1[index].COL4 ===
|
||||
(multipleColumnsWithNulls.table1[index].col4 || "");
|
||||
});
|
||||
return result;
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
25
sasjs-tests/src/testSuites/SasjsRequests.ts
Normal file
25
sasjs-tests/src/testSuites/SasjsRequests.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import SASjs from "sasjs";
|
||||
import { TestSuite } from "../types";
|
||||
|
||||
const data: any = { table1: [{ col1: "first col value" }] };
|
||||
|
||||
export const sasjsRequestTests = (adapter: SASjs): TestSuite => ({
|
||||
name: "SASjs Requests",
|
||||
tests: [
|
||||
{
|
||||
title: "WORK tables",
|
||||
description: "Should get WORK tables after request",
|
||||
test: async () => {
|
||||
return adapter.request("common/sendArr", data);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
const requests = adapter.getSasRequests();
|
||||
if (adapter.getSasjsConfig().debug) {
|
||||
return requests[0].SASWORK !== null;
|
||||
} else {
|
||||
return requests[0].SASWORK === null;
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
235
sasjs-tests/src/testSuites/SpecialCases.ts
Normal file
235
sasjs-tests/src/testSuites/SpecialCases.ts
Normal file
@@ -0,0 +1,235 @@
|
||||
import SASjs from "sasjs";
|
||||
import { TestSuite } from "../types";
|
||||
|
||||
const specialCharData: any = {
|
||||
table1: [
|
||||
{
|
||||
tab: "\t",
|
||||
lf: "\n",
|
||||
cr: "\r",
|
||||
semicolon: ";semi",
|
||||
percent: "%",
|
||||
singleQuote: "'",
|
||||
doubleQuote: '"',
|
||||
crlf: "\r\n",
|
||||
euro: "€euro",
|
||||
banghash: "!#banghash",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const moreSpecialCharData: any = {
|
||||
table1: [
|
||||
{
|
||||
speech0: '"speech',
|
||||
pct: "%percent",
|
||||
speech: '"speech',
|
||||
slash: "\\slash",
|
||||
slashWithSpecial: "\\\tslash",
|
||||
macvar: "&sysuserid",
|
||||
chinese: "传/傳chinese",
|
||||
sigma: "Σsigma",
|
||||
at: "@at",
|
||||
serbian: "Српски",
|
||||
dollar: "$",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const getWideData = () => {
|
||||
const cols: any = {};
|
||||
for (let i = 1; i <= 10000; i++) {
|
||||
cols["col" + i] = "test" + i;
|
||||
}
|
||||
|
||||
const data: any = {
|
||||
table1: [cols],
|
||||
};
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
const getTables = () => {
|
||||
const tables: any = {};
|
||||
|
||||
for (let i = 1; i <= 100; i++) {
|
||||
tables["table" + i] = [{ col1: "x", col2: "x", col3: "x", col4: "x" }];
|
||||
}
|
||||
return tables;
|
||||
};
|
||||
|
||||
const getLargeDataset = () => {
|
||||
const rows: any = [];
|
||||
const colData: string =
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||
for (let i = 1; i <= 10000; i++) {
|
||||
rows.push({ col1: colData, col2: colData, col3: colData, col4: colData });
|
||||
}
|
||||
|
||||
const data: any = {
|
||||
table1: rows,
|
||||
};
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
const errorAndCsrfData: any = {
|
||||
error: [{ col1: "q", col2: "w", col3: "e", col4: "r" }],
|
||||
_csrf: [{ col1: "q", col2: "w", col3: "e", col4: "r" }],
|
||||
};
|
||||
|
||||
export const specialCaseTests = (adapter: SASjs): TestSuite => ({
|
||||
name: "Special Cases",
|
||||
tests: [
|
||||
{
|
||||
title: "Common special characters",
|
||||
description: "Should handle common special characters",
|
||||
test: () => {
|
||||
return adapter.request("common/sendArr", specialCharData);
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
return (
|
||||
res.table1[0][0] === specialCharData.table1[0].tab &&
|
||||
res.table1[0][1] === specialCharData.table1[0].lf &&
|
||||
res.table1[0][2] === specialCharData.table1[0].cr &&
|
||||
res.table1[0][3] === specialCharData.table1[0].semicolon &&
|
||||
res.table1[0][4] === specialCharData.table1[0].percent &&
|
||||
res.table1[0][5] === specialCharData.table1[0].singleQuote &&
|
||||
res.table1[0][6] === specialCharData.table1[0].doubleQuote &&
|
||||
res.table1[0][7] === "\n" &&
|
||||
res.table1[0][8] === specialCharData.table1[0].euro &&
|
||||
res.table1[0][9] === specialCharData.table1[0].banghash
|
||||
);
|
||||
},
|
||||
},
|
||||
// {
|
||||
// title: "Other special characters",
|
||||
// description: "Should handle other special characters",
|
||||
// test: () => {
|
||||
// return adapter.request("common/sendArr", moreSpecialCharData);
|
||||
// },
|
||||
// assertion: (res: any) => {
|
||||
// return (
|
||||
// res.table1[0][0] === moreSpecialCharData.table1[0].speech0 &&
|
||||
// res.table1[0][1] === moreSpecialCharData.table1[0].pct &&
|
||||
// res.table1[0][2] === moreSpecialCharData.table1[0].speech &&
|
||||
// res.table1[0][3] === moreSpecialCharData.table1[0].slash &&
|
||||
// res.table1[0][4] === moreSpecialCharData.table1[0].slashWithSpecial &&
|
||||
// res.table1[0][5] === moreSpecialCharData.table1[0].macvar &&
|
||||
// res.table1[0][6] === moreSpecialCharData.table1[0].chinese &&
|
||||
// res.table1[0][7] === moreSpecialCharData.table1[0].sigma &&
|
||||
// res.table1[0][8] === moreSpecialCharData.table1[0].at &&
|
||||
// res.table1[0][9] === moreSpecialCharData.table1[0].serbian &&
|
||||
// res.table1[0][10] === moreSpecialCharData.table1[0].dollar
|
||||
// );
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// title: "Wide table with sendArr",
|
||||
// description: "Should handle data with 10000 columns",
|
||||
// test: () => {
|
||||
// return adapter.request("common/sendArr", getWideData());
|
||||
// },
|
||||
// assertion: (res: any) => {
|
||||
// const data = getWideData();
|
||||
// let result = true;
|
||||
// for (let i = 0; i <= 10; i++) {
|
||||
// result =
|
||||
// result && res.table1[0][i] === data.table1[0]["col" + (i + 1)];
|
||||
// }
|
||||
// return result;
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// title: "Wide table with sendObj",
|
||||
// description: "Should handle data with 10000 columns",
|
||||
// test: () => {
|
||||
// return adapter.request("common/sendObj", getWideData());
|
||||
// },
|
||||
// assertion: (res: any) => {
|
||||
// const data = getWideData();
|
||||
// let result = true;
|
||||
// for (let i = 0; i <= 10; i++) {
|
||||
// result =
|
||||
// result &&
|
||||
// res.table1[0]["COL" + (i + 1)] === data.table1[0]["col" + (i + 1)];
|
||||
// }
|
||||
// return result;
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// title: "Multiple tables",
|
||||
// description: "Should handle data with 100 tables",
|
||||
// test: () => {
|
||||
// return adapter.request("common/sendArr", getTables());
|
||||
// },
|
||||
// assertion: (res: any) => {
|
||||
// const data = getTables();
|
||||
// return (
|
||||
// res.table1[0][0] === data.table1[0].col1 &&
|
||||
// res.table1[0][1] === data.table1[0].col2 &&
|
||||
// res.table1[0][2] === data.table1[0].col3 &&
|
||||
// res.table1[0][3] === data.table1[0].col4 &&
|
||||
// res.table50[0][0] === data.table50[0].col1 &&
|
||||
// res.table50[0][1] === data.table50[0].col2 &&
|
||||
// res.table50[0][2] === data.table50[0].col3 &&
|
||||
// res.table50[0][3] === data.table50[0].col4
|
||||
// );
|
||||
// },
|
||||
// },
|
||||
{
|
||||
title: "Large dataset",
|
||||
description: "Should handle 5mb of data",
|
||||
test: () => {
|
||||
return adapter.request("common/sendArr", getLargeDataset());
|
||||
},
|
||||
assertion: (res: any) => {
|
||||
const data = getLargeDataset();
|
||||
let result = true;
|
||||
for (let i = 0; i <= 10; i++) {
|
||||
result = result && res.table1[i][0] === data.table1[i][0];
|
||||
}
|
||||
return result;
|
||||
},
|
||||
},
|
||||
|
||||
// {
|
||||
// title: "Error and _csrf tables with sendArr",
|
||||
// description: "Should handle error and _csrf tables",
|
||||
// test: () => {
|
||||
// return adapter.request("common/sendArr", errorAndCsrfData);
|
||||
// },
|
||||
// assertion: (res: any) => {
|
||||
// return (
|
||||
// res.error[0][0] === errorAndCsrfData.error[0].col1 &&
|
||||
// res.error[0][1] === errorAndCsrfData.error[0].col2 &&
|
||||
// res.error[0][2] === errorAndCsrfData.error[0].col3 &&
|
||||
// res.error[0][3] === errorAndCsrfData.error[0].col4 &&
|
||||
// res._csrf[0][0] === errorAndCsrfData._csrf[0].col1 &&
|
||||
// res._csrf[0][1] === errorAndCsrfData._csrf[0].col2 &&
|
||||
// res._csrf[0][2] === errorAndCsrfData._csrf[0].col3 &&
|
||||
// res._csrf[0][3] === errorAndCsrfData._csrf[0].col4
|
||||
// );
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// title: "Error and _csrf tables with sendObj",
|
||||
// description: "Should handle error and _csrf tables",
|
||||
// test: () => {
|
||||
// return adapter.request("common/sendObj", errorAndCsrfData);
|
||||
// },
|
||||
// assertion: (res: any) => {
|
||||
// return (
|
||||
// res.error[0].COL1 === errorAndCsrfData.error[0].col1 &&
|
||||
// res.error[0].COL2 === errorAndCsrfData.error[0].col2 &&
|
||||
// res.error[0].COL3 === errorAndCsrfData.error[0].col3 &&
|
||||
// res.error[0].COL4 === errorAndCsrfData.error[0].col4 &&
|
||||
// res._csrf[0].COL1 === errorAndCsrfData._csrf[0].col1 &&
|
||||
// res._csrf[0].COL2 === errorAndCsrfData._csrf[0].col2 &&
|
||||
// res._csrf[0].COL3 === errorAndCsrfData._csrf[0].col3 &&
|
||||
// res._csrf[0].COL4 === errorAndCsrfData._csrf[0].col4
|
||||
// );
|
||||
// },
|
||||
// },
|
||||
],
|
||||
});
|
||||
15
sasjs-tests/src/types/index.ts
Normal file
15
sasjs-tests/src/types/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export interface Test {
|
||||
title: string;
|
||||
description: string;
|
||||
beforeTest?: (...args: any) => Promise<any>;
|
||||
afterTest?: (...args: any) => Promise<any>;
|
||||
test: (context?: any) => Promise<any>;
|
||||
assertion: (...args: any) => boolean;
|
||||
}
|
||||
|
||||
export interface TestSuite {
|
||||
name: string;
|
||||
tests: Test[];
|
||||
beforeAll?: (...args: any) => Promise<any>;
|
||||
afterAll?: (...args: any) => Promise<any>;
|
||||
}
|
||||
22
sasjs-tests/src/utils/Assert.ts
Normal file
22
sasjs-tests/src/utils/Assert.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export const assert = (
|
||||
expression: boolean | (() => boolean),
|
||||
message = "Assertion failed"
|
||||
) => {
|
||||
let result;
|
||||
try {
|
||||
if (typeof expression === "boolean") {
|
||||
result = expression;
|
||||
} else {
|
||||
result = expression();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
if (!!result) {
|
||||
return;
|
||||
} else {
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
};
|
||||
23
sasjs-tests/src/utils/UploadFile.ts
Normal file
23
sasjs-tests/src/utils/UploadFile.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export const uploadFile = (file: File, fileName: string, url: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const data = new FormData();
|
||||
data.append("file", file);
|
||||
data.append("filename", fileName);
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.withCredentials = true;
|
||||
xhr.addEventListener("readystatechange", function () {
|
||||
if (this.readyState === 4) {
|
||||
let response: any;
|
||||
try {
|
||||
response = JSON.parse(this.responseText);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
xhr.open("POST", url);
|
||||
xhr.setRequestHeader("cache-control", "no-cache");
|
||||
xhr.send(data);
|
||||
});
|
||||
};
|
||||
25
sasjs-tests/tsconfig.json
Normal file
25
sasjs-tests/tsconfig.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user