Skip to content

Commit

Permalink
Merge pull request #2 from Andrea-gli/play
Browse files Browse the repository at this point in the history
add testing snippet area
  • Loading branch information
konradkop authored Feb 23, 2021
2 parents 921890f + d04dba9 commit 9b8640f
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 77 deletions.
108 changes: 51 additions & 57 deletions src/client/components/composer/NewRequest/TestEntryForm.jsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,73 @@
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import React, { useState } from "react";
import WWWForm from "./WWWForm.jsx";
import BodyTypeSelect from "./BodyTypeSelect.jsx";
import JSONTextArea from "./JSONTextArea.jsx";
import RawBodyTypeSelect from "./RawBodyTypeSelect.jsx"
import JSONPrettify from "./JSONPrettify.jsx"
import TextCodeAreaEditable from "./TextCodeAreaEditable.jsx"
import RawBodyTypeSelect from "./RawBodyTypeSelect.jsx";
import JSONPrettify from "./JSONPrettify.jsx";
import TextCodeAreaEditable from "./TextCodeAreaEditable.jsx";
import dropDownArrow from "../../../../assets/icons/caret-down-tests.svg";
import dropDownArrowUp from "../../../../assets/icons/caret-up-tests.svg";
import { isAbsolute, relative } from "path";
import RestTestSnippetsContainer from "./TestSnippets/RestTestSnippetsContainer";

const TestEntryForm = (props) => {
const {
testContent,
setNewTestContent
} = props;
const { testContent, setNewTestContent } = props;

const [showTests, setShowTests] = useState(false);
const handleShowTests = () => setShowTests(!showTests);

return (
<div className='mt-4 mb-4'>
<div className="mt-4 mb-4">
<RestTestSnippetsContainer
testContent={testContent}
setNewTestContent={setNewTestContent}
setShowTests={setShowTests}
/>
<div
className="is-rest-invert show-hide-tests cards-dropdown minimize-card is-flex is-align-items-center is-justify-content-center"
onClick={() => {
handleShowTests();
}}
onClick={handleShowTests}
>
{showTests === true &&
<>
<span>Hide Tests</span>
<span className="icon is-medium is-align-self-center show-hide-tests-icon">
<img
alt=''
src={dropDownArrowUp}
className="is-awesome-icon"
aria-hidden="false"
/>
</span>
</>
}
{showTests === false &&
<>
<span>View Tests</span>
<span className="icon is-medium is-align-self-center show-hide-tests-icon">
<img
alt=''
src={dropDownArrow}
className="is-awesome-icon"
aria-hidden="false"
/>
</span>
</>
}


</div>
{showTests === true &&
<div id="test-script-entry">
<TextCodeAreaEditable
mode="javascript"
value={testContent}
onChange={(editor, data, value) => {
setNewTestContent(value);
}}
/>
{showTests === true && (
<>
<span>Hide Tests</span>
<span className="icon is-medium is-align-self-center show-hide-tests-icon">
<img
alt=""
src={dropDownArrowUp}
className="is-awesome-icon"
aria-hidden="false"
/>
</span>
</>
)}
{showTests === false && (
<>
<span>View Tests</span>
<span className="icon is-medium is-align-self-center show-hide-tests-icon">
<img
alt=""
src={dropDownArrow}
className="is-awesome-icon"
aria-hidden="false"
/>
</span>
</>
)}
</div>
}
{showTests === true && (
<div id="test-script-entry">
<TextCodeAreaEditable
mode="javascript"
value={testContent}
onChange={(editor, data, value) => {
setNewTestContent(value);
}}
/>
</div>
)}
</div>







);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import React from "react";

export default function RestTestSnippets(props) {
const { setNewTestContent, setShowTests } = props;

const snippets = {
"Status code: Code is 200":
"assert.strictEqual(response.status, 200, 'response is 200')",

"Access the cookies from the response object":
"assert.exists(response.cookies, 'cookies exists on response object')",
};

const handleClickOne = () => {
setShowTests(true);
setNewTestContent(snippets["Status code: Code is 200"]);
};

const handleClickTwo = () => {
setShowTests(true);
setNewTestContent(snippets["Access the cookies from the response object"]);
};

return (
<div>
<span onClick={handleClickOne}>Status code: Code is 200</span>;
<br />
<span onClick={handleClickTwo}>
Access the cookies from the response object
</span>
;
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import React, { useState } from "react";
import dropDownArrow from "../../../../../assets/icons/caret-down-tests.svg";

import dropDownArrowUp from "../../../../../assets/icons/caret-up-tests.svg";

import RestTestSnippets from "./RestTestSnippets";

export default function RestTestSnippetsContainer(props) {
console.log("propsssss=>", props);
const { setShowTests, testContent, setNewTestContent } = props;
const [showSnippets, setShowSnippets] = useState(false);

const handleShowSnippets = () => {
setShowSnippets(!showSnippets);
};
return (
<div>
<div
className="is-rest-invert show-hide-tests cards-dropdown minimize-card is-flex is-align-items-center is-justify-content-center"
onClick={handleShowSnippets}
>
{showSnippets === true && (
<>
<span>Test Snippets</span>
<span className="icon is-medium is-align-self-center show-hide-tests-icon">
<img
alt=""
src={dropDownArrowUp}
className="is-awesome-icon"
aria-hidden="false"
/>
</span>
</>
)}

{showSnippets === false && (
<>
<span>Test Snippets</span>
<span className="icon is-medium is-align-self-center show-hide-tests-icon">
<img
alt=""
src={dropDownArrow}
className="is-awesome-icon"
aria-hidden="false"
/>
</span>
</>
)}
</div>

{showSnippets === true && (
<div id="test-snippets">
<RestTestSnippets
testContent={testContent}
setNewTestContent={setNewTestContent}
setShowTests={setShowTests}
/>
</div>
)}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { POINT_CONVERSION_UNCOMPRESSED } from "constants";
import React, { useState, useEffect, useRef } from "react";
import {UnControlled as CodeMirror} from 'react-codemirror2';
import 'codemirror/theme/neat.css';
import { UnControlled as CodeMirror } from "react-codemirror2";
import "codemirror/theme/neat.css";


export default function TextCodeAreaEditable ({ value, mode, onChange, theme }) {
export default function TextCodeAreaEditable({ value, mode, onChange, theme }) {
console.log("value=>", value, "mode=>", mode, "theme=>", theme);
return (
<div className='is-neutral-200-box'>
<div className="is-neutral-200-box">
<CodeMirror
value={value}
autoCursor={false}
options={{
mode,
theme: theme || 'neat',
theme: theme || "neat",
lineNumbers: true,
tabSize: 4,
lineWrapping: true,
Expand All @@ -23,4 +23,4 @@ export default function TextCodeAreaEditable ({ value, mode, onChange, theme })
/>
</div>
);
}
}
1 change: 0 additions & 1 deletion src/client/components/composer/RestContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export default function RestContainer({
minimized: false,
tab: currentTab,
};
console.log("reqRes--->", reqRes);
}

// add request to history
Expand Down
2 changes: 2 additions & 0 deletions src/client/components/display/WebSocketMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const WebSocketMessage:React.SFC<WebSocketMessageProps> = ({
console.log('Data=>>>> ',data)
console.log('type of data', typeof data)


return (
<div>
<div className={webSocketMessageClassNames} id={`ws-msg-${index}`}>
Expand All @@ -42,6 +43,7 @@ console.log('type of data', typeof data)

typeof data==='object'?

//decode buffer to dataURI
<img src={new TextDecoder("utf-8").decode(data)} alt="img"/> :

<div id={webSocketMessageIDNames}>{data}</div>
Expand Down
14 changes: 14 additions & 0 deletions src/client/components/display/WebSocketWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { api } = window;
const WebSocketWindow :React.SFC<WebSocketWindowProps> = ({ content, outgoingMessages, incomingMessages, connection }) => {

const [inputMessage, setInputMessage] = useState('');
const [showWarning, setShowWarning] =useState(false)

//updates the outgoing message when it changes
const updateOutgoingMessage = (value: any) => {
Expand All @@ -28,6 +29,13 @@ const WebSocketWindow :React.SFC<WebSocketWindowProps> = ({ content, outgoingMes

const file = event.target.files[0]
console.log('file===>',file)
console.log('size==>', file.size)
file.size>100000 ?
setShowWarning(true):
setShowWarning(false)



//const imageSrc = URL.createObjectURL(file)

const dataURL = (file:any) => new Promise((resolve, reject) => {
Expand All @@ -38,6 +46,7 @@ const WebSocketWindow :React.SFC<WebSocketWindowProps> = ({ content, outgoingMes
});

const data:any = await dataURL(file);

// const buffer = Buffer.from(data, "utf8");
// console.log(buffer)

Expand Down Expand Up @@ -120,6 +129,11 @@ const WebSocketWindow :React.SFC<WebSocketWindowProps> = ({ content, outgoingMes
>
Send image
</button>


{showWarning?
<p >file size is large, may cause errors</p>: null}

</div>
{/* only show the ws messages when connection is open */}
{connection === "open" && (
Expand Down
12 changes: 6 additions & 6 deletions test/pageObjects/ComposerObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class ComposerObj {
return app.client.$("button=Add New Request");
}

// get closeConnectionBtn() {
// return app.client.$("button=Close Connection");
// }
get closeConnectionBtn() {
return app.client.$("button=Close Connection");
}

// get reopenConnectionBtn() {
// return app.client.$("button=Re-Open Connection");
// }
get reopenConnectionBtn() {
return app.client.$("button=Re-Open Connection");
}

get testScriptCode() {
const codeMirror = app.client.$("#test-script-entry");
Expand Down
Loading

0 comments on commit 9b8640f

Please sign in to comment.