-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathvisit-limit.test.ts
More file actions
47 lines (38 loc) · 1.63 KB
/
visit-limit.test.ts
File metadata and controls
47 lines (38 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { launchBrowser, LaunchContext, MOCK_URL, sleep } from '../common/base'
import { createLimitRule } from './common'
describe('Time limit per visit', () => {
let context: LaunchContext
beforeEach(async () => context = await launchBrowser())
afterEach(() => context.close())
test("More 5 minutes", async () => {
const limitPage = await context.openAppPage('/behavior/limit')
const demoRule: timer.limit.Rule = {
id: 1, name: 'TEST DAILY LIMIT',
cond: [MOCK_URL],
visitTime: 1,
enabled: true, allowDelay: true, locked: false,
}
// 1. Insert limit rule
await createLimitRule(demoRule, limitPage)
// 2. Open test page
const testPage = await context.newPageAndWaitCsInjected(MOCK_URL)
await sleep(2)
// 3. Modal exist and then click more 5 minutes
const clicked = await testPage.evaluate(() => {
const shadow = document.querySelector('extension-time-tracker-overlay')
if (!shadow) return false
const button = shadow.shadowRoot?.querySelector<HTMLButtonElement>('.el-button--primary')
button?.click()
return !!button
})
expect(clicked).toBeTruthy()
// 4. Modal disappear
await sleep(.5)
const modalExist = await testPage.evaluate(() => {
const shadow = document.querySelector('extension-time-tracker-overlay')
if (!shadow) return false
return !!shadow.shadowRoot!.querySelector('body:not([style*="display: none"])')
})
expect(modalExist).toBeFalsy()
}, 10000)
})