Skip to content

Commit 9e5b09b

Browse files
committed
feat(TestRun): start test and download when user clicks start button
1 parent 7b53089 commit 9e5b09b

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

screens/TestRunScreen/components/TestPage.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StyleSheet, Button, TextInput } from "react-native";
22
import { Text, View } from "@/components/Themed";
3-
import { useState } from "react";
3+
import { useEffect, useState } from "react";
44
import { responseTestService } from "@/services/ResponseTest.service";
55
import { downloadTestService } from "@/services/DownloadTest.service";
66
import { TableHeader } from "@/components/Table/TableHeader";
@@ -9,7 +9,7 @@ import { useTableData } from "../hooks/useTableData";
99
import { useTestIpCount } from "../hooks/useTestIpCount";
1010
import { TableRows } from "@/components/Table/TableRows";
1111
import { initialTestPageTableHeaderCols, MyTableHeaderColumn } from "../model";
12-
import { RequestStatus } from "@/typings";
12+
import { useTestRunningStatus } from "../hooks/useTestRunningStatus";
1313

1414
export default function TestPage({ path }: { path: string }) {
1515
const { testIpCount, setTestIpCount, getIpList } = useTestIpCount();
@@ -37,13 +37,32 @@ export default function TestPage({ path }: { path: string }) {
3737
changeTableHeadersSortType,
3838
} = useTableHeader<MyTableHeaderColumn>(initialTestPageTableHeaderCols);
3939

40+
const { testRunningStatus, nextTestRunningStatus } = useTestRunningStatus();
41+
4042
function onReset() {
4143
responseTestService.stop();
4244
downloadTestService.stop();
4345
resetTableData();
4446
resetTableHeader();
45-
initTableData(getIpList());
47+
const newIpList = getIpList();
48+
initTableData(newIpList);
49+
nextTestRunningStatus();
4650
}
51+
52+
useEffect(() => {
53+
// in the future may need to add a status check
54+
startResponseSpeedTest(
55+
getSelectedIpList(),
56+
Number(testIpCoCurrentCount),
57+
testUrl
58+
);
59+
startDownloadSpeedTest(
60+
getSelectedIpList(),
61+
Number(testIpCoCurrentCount),
62+
testUrl
63+
);
64+
}, [testRunningStatus]);
65+
4766
function onSort(
4867
colId: MyTableHeaderColumn["id"],
4968
sortType: MyTableHeaderColumn["sort"]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useState } from "react";
2+
export enum TestRunningStatus {
3+
Uninitialized = "Uninitialized",
4+
Running = "Running",
5+
}
6+
const nextTestRunningStatusMap = {
7+
[TestRunningStatus.Uninitialized]: TestRunningStatus.Running as const,
8+
[TestRunningStatus.Running]: TestRunningStatus.Uninitialized as const,
9+
};
10+
export function useTestRunningStatus() {
11+
const [testRunningStatus, setTestRunningStatus] =
12+
useState<`${TestRunningStatus}`>(TestRunningStatus.Uninitialized);
13+
14+
function nextTestRunningStatus() {
15+
setTestRunningStatus((prev) => {
16+
return nextTestRunningStatusMap[prev];
17+
});
18+
}
19+
20+
return {
21+
testRunningStatus,
22+
nextTestRunningStatus,
23+
};
24+
}

0 commit comments

Comments
 (0)