2019-12-18 22:19:31 +08:00
|
|
|
import path from 'path'
|
2020-06-26 02:04:23 +08:00
|
|
|
import { setupPuppeteer, E2E_TIMEOUT } from '../../__tests__/e2eUtils'
|
2019-12-18 22:19:31 +08:00
|
|
|
|
|
|
|
interface TableData {
|
|
|
|
name: string
|
|
|
|
power: number
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('e2e: grid', () => {
|
2020-06-12 22:32:27 +08:00
|
|
|
const { page, click, text, count, typeValue, clearValue } = setupPuppeteer()
|
2019-12-18 22:19:31 +08:00
|
|
|
const columns = ['name', 'power'] as const
|
|
|
|
|
|
|
|
async function assertTable(data: TableData[]) {
|
|
|
|
expect(await count('td')).toBe(data.length * columns.length)
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
for (let j = 0; j < columns.length; j++) {
|
|
|
|
expect(
|
|
|
|
await text(`tr:nth-child(${i + 1}) td:nth-child(${j + 1})`)
|
2021-09-02 04:39:46 +08:00
|
|
|
).toContain(`${data[i][columns[j]]}`)
|
2019-12-18 22:19:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function testGrid(apiType: 'classic' | 'composition') {
|
|
|
|
const baseUrl = `file://${path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../${apiType}/grid.html`
|
|
|
|
)}`
|
|
|
|
|
|
|
|
await page().goto(baseUrl)
|
2021-07-02 01:56:38 +08:00
|
|
|
await page().waitForSelector('table')
|
2019-12-18 22:19:31 +08:00
|
|
|
expect(await count('th')).toBe(2)
|
|
|
|
expect(await count('th.active')).toBe(0)
|
|
|
|
expect(await text('th:nth-child(1)')).toContain('Name')
|
|
|
|
expect(await text('th:nth-child(2)')).toContain('Power')
|
|
|
|
await assertTable([
|
|
|
|
{ name: 'Chuck Norris', power: Infinity },
|
|
|
|
{ name: 'Bruce Lee', power: 9000 },
|
|
|
|
{ name: 'Jackie Chan', power: 7000 },
|
|
|
|
{ name: 'Jet Li', power: 8000 }
|
|
|
|
])
|
|
|
|
|
|
|
|
await click('th:nth-child(1)')
|
|
|
|
expect(await count('th.active:nth-child(1)')).toBe(1)
|
|
|
|
expect(await count('th.active:nth-child(2)')).toBe(0)
|
|
|
|
expect(await count('th:nth-child(1) .arrow.dsc')).toBe(1)
|
|
|
|
expect(await count('th:nth-child(2) .arrow.dsc')).toBe(0)
|
|
|
|
await assertTable([
|
|
|
|
{ name: 'Jet Li', power: 8000 },
|
|
|
|
{ name: 'Jackie Chan', power: 7000 },
|
|
|
|
{ name: 'Chuck Norris', power: Infinity },
|
|
|
|
{ name: 'Bruce Lee', power: 9000 }
|
|
|
|
])
|
|
|
|
|
|
|
|
await click('th:nth-child(2)')
|
|
|
|
expect(await count('th.active:nth-child(1)')).toBe(0)
|
|
|
|
expect(await count('th.active:nth-child(2)')).toBe(1)
|
|
|
|
expect(await count('th:nth-child(1) .arrow.dsc')).toBe(1)
|
|
|
|
expect(await count('th:nth-child(2) .arrow.dsc')).toBe(1)
|
|
|
|
await assertTable([
|
|
|
|
{ name: 'Chuck Norris', power: Infinity },
|
|
|
|
{ name: 'Bruce Lee', power: 9000 },
|
|
|
|
{ name: 'Jet Li', power: 8000 },
|
|
|
|
{ name: 'Jackie Chan', power: 7000 }
|
|
|
|
])
|
|
|
|
|
|
|
|
await click('th:nth-child(2)')
|
|
|
|
expect(await count('th.active:nth-child(1)')).toBe(0)
|
|
|
|
expect(await count('th.active:nth-child(2)')).toBe(1)
|
|
|
|
expect(await count('th:nth-child(1) .arrow.dsc')).toBe(1)
|
|
|
|
expect(await count('th:nth-child(2) .arrow.asc')).toBe(1)
|
|
|
|
await assertTable([
|
|
|
|
{ name: 'Jackie Chan', power: 7000 },
|
|
|
|
{ name: 'Jet Li', power: 8000 },
|
|
|
|
{ name: 'Bruce Lee', power: 9000 },
|
|
|
|
{ name: 'Chuck Norris', power: Infinity }
|
|
|
|
])
|
|
|
|
|
|
|
|
await click('th:nth-child(1)')
|
|
|
|
expect(await count('th.active:nth-child(1)')).toBe(1)
|
|
|
|
expect(await count('th.active:nth-child(2)')).toBe(0)
|
|
|
|
expect(await count('th:nth-child(1) .arrow.asc')).toBe(1)
|
|
|
|
expect(await count('th:nth-child(2) .arrow.asc')).toBe(1)
|
|
|
|
await assertTable([
|
|
|
|
{ name: 'Bruce Lee', power: 9000 },
|
|
|
|
{ name: 'Chuck Norris', power: Infinity },
|
|
|
|
{ name: 'Jackie Chan', power: 7000 },
|
|
|
|
{ name: 'Jet Li', power: 8000 }
|
|
|
|
])
|
|
|
|
|
2020-06-12 22:32:27 +08:00
|
|
|
await typeValue('input[name="query"]', 'j')
|
2019-12-18 22:19:31 +08:00
|
|
|
await assertTable([
|
|
|
|
{ name: 'Jackie Chan', power: 7000 },
|
|
|
|
{ name: 'Jet Li', power: 8000 }
|
|
|
|
])
|
|
|
|
|
2020-06-12 22:32:27 +08:00
|
|
|
await typeValue('input[name="query"]', 'infinity')
|
2019-12-18 22:19:31 +08:00
|
|
|
await assertTable([{ name: 'Chuck Norris', power: Infinity }])
|
|
|
|
|
|
|
|
await clearValue('input[name="query"]')
|
|
|
|
expect(await count('p')).toBe(0)
|
2020-06-12 22:32:27 +08:00
|
|
|
await typeValue('input[name="query"]', 'stringthatdoesnotexistanywhere')
|
2019-12-18 22:19:31 +08:00
|
|
|
expect(await count('p')).toBe(1)
|
|
|
|
}
|
|
|
|
|
2020-02-06 10:10:43 +08:00
|
|
|
test(
|
|
|
|
'classic',
|
|
|
|
async () => {
|
|
|
|
await testGrid('classic')
|
|
|
|
},
|
|
|
|
E2E_TIMEOUT
|
|
|
|
)
|
2019-12-18 22:19:31 +08:00
|
|
|
|
2020-02-06 10:10:43 +08:00
|
|
|
test(
|
|
|
|
'composition',
|
|
|
|
async () => {
|
|
|
|
await testGrid('composition')
|
|
|
|
},
|
|
|
|
E2E_TIMEOUT
|
|
|
|
)
|
2019-12-18 22:19:31 +08:00
|
|
|
})
|