Skip to content

Commit

Permalink
Merge pull request #22 from ademuk/bug-fixes
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
ademuk authored Dec 23, 2020
2 parents dfae4c3 + d5c47b1 commit b1c5a71
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 13 deletions.
2 changes: 1 addition & 1 deletion server/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ window.result = getWrapperComponent().then(
render(WrapperComponent).then(
() =>
new Promise((resolve, reject) =>
setTimeout(() => (window.error ? reject(window.error) : resolve()), 0)
setTimeout(() => (window.error ? reject(window.error) : resolve()))
)
)
);
4 changes: 3 additions & 1 deletion server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ const runEventStep = (
);
});

return Promise.resolve(["success", context]);
return new Promise((resolve) =>
setTimeout(() => resolve(["success", context]), 10)
);
};

const runAssertionStep = (
Expand Down
184 changes: 184 additions & 0 deletions src/Components.tsx.tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,190 @@
}
],
"name": "Render project components"
},
{
"id": "0837dde0-453e-11eb-8435-8385c7863d38",
"steps": [
{
"type": "mock",
"definition": {
"name": "fetch",
"args": ["/module-component"],
"return": [
{
"file": "App.tsx",
"components": [
{
"exportName": "default",
"name": "App"
}
]
},
{
"file": "Components.tsx",
"components": [
{
"exportName": "default",
"name": "Components"
}
]
}
]
}
},
{
"type": "mock",
"definition": {
"name": "fetch",
"args": ["/module-test"],
"return": [
{
"file": "App.tsx",
"components": [
{
"name": "App",
"tests": [
{
"id": "c34b2f30-1c83-11eb-a8c1-1da52322ddf8",
"steps": [
{
"type": "mock",
"definition": {
"name": "fetch",
"args": ["/module-component"],
"return": []
}
},
{
"type": "render",
"definition": {
"props": {}
}
},
{
"type": "event",
"definition": {
"type": "click",
"target": "Look for other components"
}
}
]
}
],
"exportName": "default"
}
]
}
]
}
},
{
"type": "render",
"definition": {
"props": {},
"wrapper": {
"file": "react-router-dom",
"exportName": "MemoryRouter",
"props": {}
}
}
},
{
"type": "event",
"definition": {
"type": "click",
"target": "Look for other components"
}
},
{
"type": "assertion",
"definition": {
"type": "text",
"target": "Components.tsx"
}
},
{
"type": "assertion",
"definition": {
"type": "text",
"target": "Components"
}
}
],
"name": "Look for other components"
},
{
"id": "6e725e50-453e-11eb-8435-8385c7863d38",
"steps": [
{
"type": "mock",
"definition": {
"name": "fetch",
"args": ["/module-component"],
"return": [
{
"file": "App.tsx",
"components": [
{
"exportName": "default",
"name": "App"
}
]
},
{
"file": "Components.tsx",
"components": [
{
"exportName": "default",
"name": "Components"
}
]
}
]
}
},
{
"type": "mock",
"definition": {
"name": "fetch",
"args": ["/module-test"],
"return": []
}
},
{
"type": "render",
"definition": {
"props": {},
"wrapper": {
"file": "react-router-dom",
"exportName": "MemoryRouter",
"props": {}
}
}
},
{
"type": "assertion",
"definition": {
"type": "text",
"target": "App.tsx"
}
},
{
"type": "assertion",
"definition": {
"type": "text",
"target": "App"
}
},
{
"type": "assertion",
"definition": {
"type": "text",
"target": "Components.tsx"
}
}
],
"name": "Load components if no tests found"
}
]
}
Expand Down
10 changes: 6 additions & 4 deletions src/Test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Fragment, useEffect, useRef, useState } from "react";
import { Fragment, useEffect, useRef, useState } from "react";
import * as React from "react";
import { Link as RouterLink, RouteComponentProps } from "react-router-dom";
import type { History } from "history";
import queryString from "query-string";
Expand Down Expand Up @@ -111,7 +112,7 @@ const Test = ({ history, file, exportName, test, step }: TestProps) => {
if (test && step > steps.length - 1) {
history.replace(
`/tests/${test.id}?file=${file}&exportName=${exportName}&step=${
test.steps.length - 1
(steps.length ? steps.length : test.steps.length) - 1
}`
);
}
Expand Down Expand Up @@ -245,6 +246,7 @@ const Test = ({ history, file, exportName, test, step }: TestProps) => {
}}
onKeyPress={handleUpdateTestNameKeyPress}
ref={editableTestNameRef}
suppressContentEditableWarning={true}
>
{testName}
</h1>{" "}
Expand Down Expand Up @@ -289,7 +291,7 @@ const Test = ({ history, file, exportName, test, step }: TestProps) => {
<h3 className="text-xl p-2">{capitalise(type)}</h3>
{regions.map((r) => (
<button
className={`text-gray-700 hover:text-gray-600 hover:bg-gray-100 p-2 px-4 my-2 rounded-full focus:rounded-full w-full text-left`}
className={`text-gray-700 hover:text-gray-600 hover:bg-gray-100 py-2 px-4 my-2 rounded-full focus:rounded-full w-full text-left`}
key={`${r.xpath}${r.text}`}
onClick={() => setSelectedRegion(r)}
>
Expand All @@ -311,7 +313,7 @@ const Test = ({ history, file, exportName, test, step }: TestProps) => {
<h3 className="text-xl p-2">{label(name)}</h3>
{calls.map((args, i) => (
<button
className={`text-gray-700 hover:text-gray-600 hover:bg-gray-100 p-2 my-2 rounded-full focus:rounded-full text-left`}
className={`text-gray-700 hover:text-gray-600 hover:bg-gray-100 py-2 px-4 my-2 rounded-full focus:rounded-full w-full text-left`}
key={[i, ...args].join("")}
onClick={() => setSelectedMockCall([name, args])}
>
Expand Down
12 changes: 5 additions & 7 deletions src/test/EditMockModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useState } from "react";
import * as React from "react";
// @ts-ignore
import JSONInput from "react-json-editor-ajrm";
Expand All @@ -21,13 +21,11 @@ const EditMockModal: React.FC<EditStepProps> = ({
onClose,
onUpdateStep,
}) => {
const [returnValue, setReturnValue] = useState({});
const [returnValue, setReturnValue] = useState(
step.definition.return ? step.definition.return : {}
);
const [isValidJson, setIsValidJson] = useState(true);

useEffect(() => {
setReturnValue(step.definition.return ? step.definition.return : {});
}, [step.definition.return]);

const handleReturnValueChange = ({
error,
jsObject,
Expand Down Expand Up @@ -62,7 +60,7 @@ const EditMockModal: React.FC<EditStepProps> = ({
<div className="mt-2 flex">
<JSONInput
id="id"
placeholder={isValidJson ? returnValue : {}}
placeholder={step.definition.return}
theme="light_mitsuketa_tribute"
locale={locale}
width="100%"
Expand Down

0 comments on commit b1c5a71

Please sign in to comment.