From 5104b32d60433f13b2527825f3cbf5eb133b3d5e Mon Sep 17 00:00:00 2001 From: Adem Gaygusuz Date: Wed, 23 Dec 2020 17:15:32 +0000 Subject: [PATCH 1/3] fix(events): Add setTimeout after events to allow of async side effects to take place --- server/render.ts | 2 +- server/server.ts | 4 +- src/Components.tsx.tests.json | 208 ++++++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+), 2 deletions(-) diff --git a/server/render.ts b/server/render.ts index bc436c2..dd759fc 100644 --- a/server/render.ts +++ b/server/render.ts @@ -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())) ) ) ); diff --git a/server/server.ts b/server/server.ts index 7b5824c..58f8e8d 100644 --- a/server/server.ts +++ b/server/server.ts @@ -683,7 +683,9 @@ const runEventStep = ( ); }); - return Promise.resolve(["success", context]); + return new Promise((resolve) => + setTimeout(() => resolve(["success", context]), 10) + ); }; const runAssertionStep = ( diff --git a/src/Components.tsx.tests.json b/src/Components.tsx.tests.json index 581eaaa..de85ba4 100644 --- a/src/Components.tsx.tests.json +++ b/src/Components.tsx.tests.json @@ -141,6 +141,214 @@ } ], "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": "mock", + "target": { + "name": "fetch", + "args": ["/module-component"] + } + } + }, + { + "type": "assertion", + "definition": { + "type": "text", + "target": "App.tsx" + } + }, + { + "type": "assertion", + "definition": { + "type": "text", + "target": "App" + } + }, + { + "type": "assertion", + "definition": { + "type": "text", + "target": "Components.tsx" + } + }, + { + "type": "assertion", + "definition": { + "type": "text", + "target": "Components" + } + }, + { + "type": "assertion", + "definition": { + "type": "text", + "target": "You don't have any tests yet" + } + } + ], + "name": "Load components if no tests found" } ] } From e64cb5ef808dce1875960492c75ed2c0490c2bbd Mon Sep 17 00:00:00 2001 From: Adem Gaygusuz Date: Wed, 23 Dec 2020 17:16:51 +0000 Subject: [PATCH 2/3] fix(mocks): Fix JSON editor losing focus --- src/test/EditMockModal.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/test/EditMockModal.tsx b/src/test/EditMockModal.tsx index edfdd1e..fa9742a 100644 --- a/src/test/EditMockModal.tsx +++ b/src/test/EditMockModal.tsx @@ -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"; @@ -21,13 +21,11 @@ const EditMockModal: React.FC = ({ 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, @@ -62,7 +60,7 @@ const EditMockModal: React.FC = ({
Date: Wed, 23 Dec 2020 17:17:44 +0000 Subject: [PATCH 3/3] fix: Fix incorrect step selected after deleting last step --- src/Components.tsx.tests.json | 24 ------------------------ src/Test.tsx | 10 ++++++---- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/Components.tsx.tests.json b/src/Components.tsx.tests.json index de85ba4..30947b1 100644 --- a/src/Components.tsx.tests.json +++ b/src/Components.tsx.tests.json @@ -302,16 +302,6 @@ } } }, - { - "type": "assertion", - "definition": { - "type": "mock", - "target": { - "name": "fetch", - "args": ["/module-component"] - } - } - }, { "type": "assertion", "definition": { @@ -332,20 +322,6 @@ "type": "text", "target": "Components.tsx" } - }, - { - "type": "assertion", - "definition": { - "type": "text", - "target": "Components" - } - }, - { - "type": "assertion", - "definition": { - "type": "text", - "target": "You don't have any tests yet" - } } ], "name": "Load components if no tests found" diff --git a/src/Test.tsx b/src/Test.tsx index f876dd8..eae2544 100644 --- a/src/Test.tsx +++ b/src/Test.tsx @@ -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"; @@ -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 }` ); } @@ -245,6 +246,7 @@ const Test = ({ history, file, exportName, test, step }: TestProps) => { }} onKeyPress={handleUpdateTestNameKeyPress} ref={editableTestNameRef} + suppressContentEditableWarning={true} > {testName} {" "} @@ -289,7 +291,7 @@ const Test = ({ history, file, exportName, test, step }: TestProps) => {

{capitalise(type)}

{regions.map((r) => (