Skip to content

Commit

Permalink
feat(TestRun): start test and download when user clicks start button
Browse files Browse the repository at this point in the history
  • Loading branch information
xianshenglu committed Apr 27, 2022
1 parent 7b53089 commit 9e5b09b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
25 changes: 22 additions & 3 deletions screens/TestRunScreen/components/TestPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StyleSheet, Button, TextInput } from "react-native";
import { Text, View } from "@/components/Themed";
import { useState } from "react";
import { useEffect, useState } from "react";
import { responseTestService } from "@/services/ResponseTest.service";
import { downloadTestService } from "@/services/DownloadTest.service";
import { TableHeader } from "@/components/Table/TableHeader";
Expand All @@ -9,7 +9,7 @@ import { useTableData } from "../hooks/useTableData";
import { useTestIpCount } from "../hooks/useTestIpCount";
import { TableRows } from "@/components/Table/TableRows";
import { initialTestPageTableHeaderCols, MyTableHeaderColumn } from "../model";
import { RequestStatus } from "@/typings";
import { useTestRunningStatus } from "../hooks/useTestRunningStatus";

export default function TestPage({ path }: { path: string }) {
const { testIpCount, setTestIpCount, getIpList } = useTestIpCount();
Expand Down Expand Up @@ -37,13 +37,32 @@ export default function TestPage({ path }: { path: string }) {
changeTableHeadersSortType,
} = useTableHeader<MyTableHeaderColumn>(initialTestPageTableHeaderCols);

const { testRunningStatus, nextTestRunningStatus } = useTestRunningStatus();

function onReset() {
responseTestService.stop();
downloadTestService.stop();
resetTableData();
resetTableHeader();
initTableData(getIpList());
const newIpList = getIpList();
initTableData(newIpList);
nextTestRunningStatus();
}

useEffect(() => {
// in the future may need to add a status check
startResponseSpeedTest(
getSelectedIpList(),
Number(testIpCoCurrentCount),
testUrl
);
startDownloadSpeedTest(
getSelectedIpList(),
Number(testIpCoCurrentCount),
testUrl
);
}, [testRunningStatus]);

function onSort(
colId: MyTableHeaderColumn["id"],
sortType: MyTableHeaderColumn["sort"]
Expand Down
24 changes: 24 additions & 0 deletions screens/TestRunScreen/hooks/useTestRunningStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useState } from "react";
export enum TestRunningStatus {
Uninitialized = "Uninitialized",
Running = "Running",
}
const nextTestRunningStatusMap = {
[TestRunningStatus.Uninitialized]: TestRunningStatus.Running as const,
[TestRunningStatus.Running]: TestRunningStatus.Uninitialized as const,
};
export function useTestRunningStatus() {
const [testRunningStatus, setTestRunningStatus] =
useState<`${TestRunningStatus}`>(TestRunningStatus.Uninitialized);

function nextTestRunningStatus() {
setTestRunningStatus((prev) => {
return nextTestRunningStatusMap[prev];
});
}

return {
testRunningStatus,
nextTestRunningStatus,
};
}

0 comments on commit 9e5b09b

Please sign in to comment.