11import { type Browser } from "puppeteer"
2- import { launchBrowser , openAppPage , sleep } from "../common/base"
2+ import { launchBrowser , newPageAndWaitCsInjected , openAppPage , sleep } from "../common/base"
33import { createLimitRule , fillTimeLimit } from "./common"
44
55let browser : Browser , extensionId : string
@@ -19,16 +19,13 @@ describe('Daily time limit', () => {
1919
2020 test ( 'basic' , async ( ) => {
2121 const limitPage = await openAppPage ( browser , extensionId , '/behavior/limit' )
22- const demoRule : timer . limit . Rule = { name : 'TEST DAILY LIMIT' , cond : [ 'https://github .com' ] , time : 5 }
22+ const demoRule : timer . limit . Rule = { name : 'TEST DAILY LIMIT' , cond : [ 'https://www.baidu .com' ] , time : 5 }
2323
2424 // 1. Insert limit rule
2525 await createLimitRule ( demoRule , limitPage )
2626
2727 // 2. Open test page
28- const testPage = await browser . newPage ( )
29- // Not wait goto finished
30- testPage . goto ( 'https://github.com/sheepzh/timer' )
31- await testPage . waitForSelector ( 'body' )
28+ const testPage = await newPageAndWaitCsInjected ( browser , extensionId , 'https://www.baidu.com' )
3229 await sleep ( 4 )
3330
3431 // Assert not limited
@@ -40,7 +37,7 @@ describe('Daily time limit', () => {
4037 const timeStr = timeTag . textContent
4138 return parseInt ( timeStr . replace ( 's' , '' ) . trim ( ) )
4239 } )
43- expect ( wastedTime >= 4 && wastedTime <= 5 ) . toBe ( true )
40+ expect ( wastedTime >= 4 ) . toBe ( true )
4441
4542 // 3. Switch to test page again
4643 await testPage . bringToFront ( )
@@ -52,11 +49,11 @@ describe('Daily time limit', () => {
5249 const descEl = shadow . shadowRoot . querySelector ( '#app .el-descriptions:not([style*="display: none"])' )
5350 const trs = descEl . querySelectorAll ( 'tr' )
5451 const name = trs [ 0 ] . querySelector ( 'td:nth-child(2)' ) . textContent
55- const time = trs [ 2 ] . querySelector ( 'td:nth-child(2) .el-tag--danger' ) . textContent
56- return { name, time }
52+ const timeStr = trs [ 2 ] . querySelector ( 'td:nth-child(2) .el-tag--danger' ) . textContent
53+ return { name, time : parseInt ( timeStr . replace ( 's' , '' ) . trim ( ) ) }
5754 } )
5855 expect ( name ) . toEqual ( demoRule . name )
59- expect ( time . replace ( 's' , '' ) . trim ( ) ) . toEqual ( '5' )
56+ expect ( time >= 5 ) . toBeTruthy ( )
6057
6158 // 5. Check limit page
6259 await limitPage . bringToFront ( )
0 commit comments