1+ import { describe , expect , it , beforeEach , afterEach } from '@rstest/core' ;
2+ import { FLOW_HTTP_TIMEOUT_KEY , resolveHttpTimeout } from "@/http" ;
3+
4+ describe ( 'resolveHttpTimeout' , ( ) => {
5+
6+ beforeEach ( ( ) => {
7+ localStorage . removeItem ( FLOW_HTTP_TIMEOUT_KEY ) ;
8+ } ) ;
9+
10+ afterEach ( ( ) => {
11+ localStorage . removeItem ( FLOW_HTTP_TIMEOUT_KEY ) ;
12+ } ) ;
13+
14+ it ( '未配置 localStorage 时返回默认值 10000' , ( ) => {
15+ const timeout = resolveHttpTimeout ( ) ;
16+ expect ( timeout ) . toEqual ( 10000 ) ;
17+ } ) ;
18+
19+ it ( '已配置合法正整数时返回对应超时时间' , ( ) => {
20+ localStorage . setItem ( FLOW_HTTP_TIMEOUT_KEY , '30000' ) ;
21+ const timeout = resolveHttpTimeout ( ) ;
22+ expect ( timeout ) . toEqual ( 30000 ) ;
23+ } ) ;
24+
25+ it ( '已配置 "0" 时视为非法,回退默认值' , ( ) => {
26+ localStorage . setItem ( FLOW_HTTP_TIMEOUT_KEY , '0' ) ;
27+ const timeout = resolveHttpTimeout ( ) ;
28+ expect ( timeout ) . toEqual ( 10000 ) ;
29+ } ) ;
30+
31+ it ( '已配置负整数时视为非法,回退默认值' , ( ) => {
32+ localStorage . setItem ( FLOW_HTTP_TIMEOUT_KEY , '-5000' ) ;
33+ const timeout = resolveHttpTimeout ( ) ;
34+ expect ( timeout ) . toEqual ( 10000 ) ;
35+ } ) ;
36+
37+ it ( '已配置非数字时视为非法,回退默认值' , ( ) => {
38+ localStorage . setItem ( FLOW_HTTP_TIMEOUT_KEY , 'abc' ) ;
39+ const timeout = resolveHttpTimeout ( ) ;
40+ expect ( timeout ) . toEqual ( 10000 ) ;
41+ } ) ;
42+
43+ it ( '已配置小数时按原值返回' , ( ) => {
44+ localStorage . setItem ( FLOW_HTTP_TIMEOUT_KEY , '2500.5' ) ;
45+ const timeout = resolveHttpTimeout ( ) ;
46+ expect ( timeout ) . toEqual ( 2500.5 ) ;
47+ } ) ;
48+ } ) ;
0 commit comments