From 73b7bd8b18899ad0749f078961af213aaca4c71b Mon Sep 17 00:00:00 2001 From: RomanDavlyatshin Date: Mon, 24 May 2021 13:42:34 +0400 Subject: [PATCH] feat: add isRealtime option --- src/background/backend-api.ts | 4 ++-- src/background/index.ts | 12 ++++++------ src/background/types.d.ts | 4 ++-- src/common/background-interop/index.ts | 4 ++-- .../pages/start-new-manual-test/index.tsx | 13 +++++++++++-- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/background/backend-api.ts b/src/background/backend-api.ts index 454cbb1..6d9cb2f 100644 --- a/src/background/backend-api.ts +++ b/src/background/backend-api.ts @@ -73,7 +73,7 @@ export default async (backendUrl: string, errorCb: any, completeCb: any) => { getMethods(baseUrl: string) { return { - async startTest(testName: string) { // TODO add isRealTime param + async startTest(testName: string, isRealtime: boolean) { const sessionId = uuid(); await sendSessionAction(baseUrl, { type: 'START', @@ -81,7 +81,7 @@ export default async (backendUrl: string, errorCb: any, completeCb: any) => { sessionId, testName, testType: 'MANUAL', - isRealtime: true, + isRealtime, }, }); return sessionId; diff --git a/src/background/index.ts b/src/background/index.ts index c7c317a..1a0d55d 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -226,11 +226,11 @@ async function init() { const router = createMessageRouter(); - router.add('START_TEST', async (sender: chrome.runtime.MessageSender, testName: string) => { + router.add('START_TEST', async (sender: chrome.runtime.MessageSender, { testName, isRealtime }) => { const host = transformHost(sender.url); const adapter = adapters[host]; if (!adapter) throw new Error('Backend connection unavailable'); - const sessionId = await adapter.startTest(testName, sender); + const sessionId = await adapter.startTest(testName, isRealtime, sender); sessionsData[host] = { testName, sessionId, @@ -455,8 +455,8 @@ function createAdapter(adapterInfo: AdapterInfo, backend: BackendCreator): Agent if (!adapterInfo.mustRecordJsCoverage) { return { - startTest: async (testName) => { - const sessionId = await backendApi.startTest(testName); + startTest: async (testName, isRealtime) => { + const sessionId = await backendApi.startTest(testName, isRealtime); return sessionId; }, stopTest: async (sessionId: string) => { @@ -468,10 +468,10 @@ function createAdapter(adapterInfo: AdapterInfo, backend: BackendCreator): Agent }; } return { - startTest: async (testName, sender) => { + startTest: async (testName, isRealtime, sender) => { if (!sender) throw new Error('START_TEST_NO_SENDER'); await jsCoverageRecorder.start(sender); - const sessionId = await backendApi.startTest(testName); + const sessionId = await backendApi.startTest(testName, isRealtime); return sessionId; }, stopTest: async (sessionId, testName, sender) => { diff --git a/src/background/types.d.ts b/src/background/types.d.ts index 5a7b58f..38f53b2 100644 --- a/src/background/types.d.ts +++ b/src/background/types.d.ts @@ -17,7 +17,7 @@ export interface Routes { } export interface AgentAdapter { - startTest: (testName: string, sender?: chrome.runtime.MessageSender) => Promise; + startTest: (testName: string, isRealtime: boolean, sender?: chrome.runtime.MessageSender) => Promise; stopTest: (sessionId: string, testName?: string, sender?: chrome.runtime.MessageSender) => Promise; cancelTest: (sessionId: string, sender?: chrome.runtime.MessageSender) => Promise; } @@ -47,7 +47,7 @@ export interface AdapterInfo { } export interface BackendApi { - startTest: (testName: string) => Promise; + startTest: (testName: string, isRealtime: boolean) => Promise; stopTest: (sessionId: string) => Promise; cancelTest: (sessionId: string) => Promise; addSessionData: (sessionId: string, data: unknown) => Promise; diff --git a/src/common/background-interop/index.ts b/src/common/background-interop/index.ts index fe56b9d..66d1d14 100644 --- a/src/common/background-interop/index.ts +++ b/src/common/background-interop/index.ts @@ -59,8 +59,8 @@ async function sendMessage(message: unknown): Promise { }); } -export async function startTest(testName: string) { - return sendMessage({ type: 'START_TEST', payload: testName }); +export async function startTest(testName: string, isRealtime: boolean) { + return sendMessage({ type: 'START_TEST', payload: { testName, isRealtime } }); } export async function stopTest() { diff --git a/src/content-script/pages/start-new-manual-test/index.tsx b/src/content-script/pages/start-new-manual-test/index.tsx index b4cfbc9..665c7f3 100644 --- a/src/content-script/pages/start-new-manual-test/index.tsx +++ b/src/content-script/pages/start-new-manual-test/index.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Button } from '@drill4j/ui-kit'; +import { Button, Checkbox } from '@drill4j/ui-kit'; import { AgentContext } from '../../context'; import * as bgInterop from '../../../common/background-interop'; @@ -9,6 +9,7 @@ import { ManualTestError } from '../manual-test-error'; export const StartNewManualTest = () => { const [submitError, setSubmitError] = React.useState(''); const [testName, setTestName] = React.useState(''); + const [isRealtime, setIsRealTime] = React.useState(true); const [isFormSubmitting, setIsFormSubmitting] = React.useState(false); const agent = React.useContext(AgentContext); @@ -42,6 +43,14 @@ export const StartNewManualTest = () => { onChange={({ currentTarget: { value } }) => setTestName(value)} disabled={isFormSubmitting} /> + + Realtime + setIsRealTime(el.target.checked)} + /> +