mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
test: add file list render test cases
This commit is contained in:
parent
453661af6e
commit
de5b67bb2f
4 changed files with 55 additions and 4 deletions
|
|
@ -4,6 +4,6 @@ describe(`in GitHub homepage`, () => {
|
|||
beforeAll(() => page.goto('https://github.com'))
|
||||
|
||||
it('should not render Gitako', async () => {
|
||||
expectToNotFind('.gitako-side-bar .gitako-position-wrapper')
|
||||
await expectToNotFind('.gitako-side-bar .gitako-position-wrapper')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,9 +1,27 @@
|
|||
import { expectToFind } from '../utils'
|
||||
import { expectToFind, expectToNotFind, scroll } from '../utils'
|
||||
|
||||
describe(`in Gitako project page`, () => {
|
||||
beforeAll(() => page.goto('https://github.com/EnixCoda/Gitako'))
|
||||
|
||||
it('should render Gitako', async () => {
|
||||
expectToFind('.gitako-side-bar .gitako-position-wrapper')
|
||||
await expectToFind('.gitako-side-bar .gitako-position-wrapper')
|
||||
})
|
||||
|
||||
it('should render file list', async () => {
|
||||
await expectToFind('.gitako-side-bar .files .node-item')
|
||||
})
|
||||
|
||||
it('should render while scroll', async () => {
|
||||
const filesEle = await page.waitForSelector('.gitako-side-bar .files')
|
||||
// node of tsconfig.json should NOT be rendered before scroll down
|
||||
await expectToNotFind('.gitako-side-bar .files a[title="tsconfig.json"]')
|
||||
const box = await filesEle.boundingBox()
|
||||
if (box) {
|
||||
await page.mouse.move(box.x + 40, box.y + 40)
|
||||
await scroll({ totalDistance: 100, duration: 5000 })
|
||||
|
||||
// node of tsconfig.json should be rendered now
|
||||
await expectToFind('.gitako-side-bar .files a[title="tsconfig.json"]')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
|||
13
__tests__/cases/pull-request-page.gitako.ts
Normal file
13
__tests__/cases/pull-request-page.gitako.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { expectToFind } from '../utils'
|
||||
|
||||
describe(`in Gitako project page`, () => {
|
||||
beforeAll(() => page.goto('https://github.com/EnixCoda/Gitako/pull/71'))
|
||||
|
||||
it('should render Gitako', async () => {
|
||||
await expectToFind('.gitako-side-bar .gitako-position-wrapper')
|
||||
})
|
||||
|
||||
it('should render file list', async () => {
|
||||
await expectToFind('.gitako-side-bar .files .node-item')
|
||||
})
|
||||
})
|
||||
|
|
@ -1,7 +1,27 @@
|
|||
export async function expectToFind(selector: string) {
|
||||
await expect(await page.waitForSelector(selector)).not.toBeNull()
|
||||
await expect(page.waitForSelector(selector)).resolves.not.toBeNull()
|
||||
}
|
||||
|
||||
export async function expectToNotFind(selector: string) {
|
||||
await expect(page.waitForSelector(selector, { timeout: 1000 })).rejects.toThrow()
|
||||
}
|
||||
|
||||
export function sleep(timeout: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, timeout))
|
||||
}
|
||||
|
||||
export async function scroll({
|
||||
totalDistance,
|
||||
step = 1,
|
||||
duration = 500,
|
||||
}: {
|
||||
totalDistance: number
|
||||
step?: number
|
||||
duration?: number
|
||||
}) {
|
||||
let distance = 0
|
||||
while ((distance += step) < totalDistance) {
|
||||
await (page.mouse as any).wheel({ deltaY: step })
|
||||
await sleep((duration * step) / totalDistance)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue