grid.spec.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { setupPuppeteer, getExampleUrl, E2E_TIMEOUT } from './e2eUtils'
  2. interface TableData {
  3. name: string
  4. power: number
  5. }
  6. describe('e2e: grid', () => {
  7. const { page, click, text, count, typeValue, clearValue } = setupPuppeteer()
  8. const columns = ['name', 'power'] as const
  9. async function assertTable(data: TableData[]) {
  10. expect(await count('td')).toBe(data.length * columns.length)
  11. for (let i = 0; i < data.length; i++) {
  12. for (let j = 0; j < columns.length; j++) {
  13. expect(
  14. await text(`tr:nth-child(${i + 1}) td:nth-child(${j + 1})`)
  15. ).toContain(`${data[i][columns[j]]}`)
  16. }
  17. }
  18. }
  19. async function testGrid(apiType: 'classic' | 'composition') {
  20. await page().goto(getExampleUrl('grid', apiType))
  21. await page().waitForSelector('table')
  22. expect(await count('th')).toBe(2)
  23. expect(await count('th.active')).toBe(0)
  24. expect(await text('th:nth-child(1)')).toContain('Name')
  25. expect(await text('th:nth-child(2)')).toContain('Power')
  26. await assertTable([
  27. { name: 'Chuck Norris', power: Infinity },
  28. { name: 'Bruce Lee', power: 9000 },
  29. { name: 'Jackie Chan', power: 7000 },
  30. { name: 'Jet Li', power: 8000 }
  31. ])
  32. await click('th:nth-child(1)')
  33. expect(await count('th.active:nth-child(1)')).toBe(1)
  34. expect(await count('th.active:nth-child(2)')).toBe(0)
  35. expect(await count('th:nth-child(1) .arrow.dsc')).toBe(1)
  36. expect(await count('th:nth-child(2) .arrow.dsc')).toBe(0)
  37. await assertTable([
  38. { name: 'Jet Li', power: 8000 },
  39. { name: 'Jackie Chan', power: 7000 },
  40. { name: 'Chuck Norris', power: Infinity },
  41. { name: 'Bruce Lee', power: 9000 }
  42. ])
  43. await click('th:nth-child(2)')
  44. expect(await count('th.active:nth-child(1)')).toBe(0)
  45. expect(await count('th.active:nth-child(2)')).toBe(1)
  46. expect(await count('th:nth-child(1) .arrow.dsc')).toBe(1)
  47. expect(await count('th:nth-child(2) .arrow.dsc')).toBe(1)
  48. await assertTable([
  49. { name: 'Chuck Norris', power: Infinity },
  50. { name: 'Bruce Lee', power: 9000 },
  51. { name: 'Jet Li', power: 8000 },
  52. { name: 'Jackie Chan', power: 7000 }
  53. ])
  54. await click('th:nth-child(2)')
  55. expect(await count('th.active:nth-child(1)')).toBe(0)
  56. expect(await count('th.active:nth-child(2)')).toBe(1)
  57. expect(await count('th:nth-child(1) .arrow.dsc')).toBe(1)
  58. expect(await count('th:nth-child(2) .arrow.asc')).toBe(1)
  59. await assertTable([
  60. { name: 'Jackie Chan', power: 7000 },
  61. { name: 'Jet Li', power: 8000 },
  62. { name: 'Bruce Lee', power: 9000 },
  63. { name: 'Chuck Norris', power: Infinity }
  64. ])
  65. await click('th:nth-child(1)')
  66. expect(await count('th.active:nth-child(1)')).toBe(1)
  67. expect(await count('th.active:nth-child(2)')).toBe(0)
  68. expect(await count('th:nth-child(1) .arrow.asc')).toBe(1)
  69. expect(await count('th:nth-child(2) .arrow.asc')).toBe(1)
  70. await assertTable([
  71. { name: 'Bruce Lee', power: 9000 },
  72. { name: 'Chuck Norris', power: Infinity },
  73. { name: 'Jackie Chan', power: 7000 },
  74. { name: 'Jet Li', power: 8000 }
  75. ])
  76. await typeValue('input[name="query"]', 'j')
  77. await assertTable([
  78. { name: 'Jackie Chan', power: 7000 },
  79. { name: 'Jet Li', power: 8000 }
  80. ])
  81. await typeValue('input[name="query"]', 'infinity')
  82. await assertTable([{ name: 'Chuck Norris', power: Infinity }])
  83. await clearValue('input[name="query"]')
  84. expect(await count('p')).toBe(0)
  85. await typeValue('input[name="query"]', 'stringthatdoesnotexistanywhere')
  86. expect(await count('p')).toBe(1)
  87. }
  88. test(
  89. 'classic',
  90. async () => {
  91. await testGrid('classic')
  92. },
  93. E2E_TIMEOUT
  94. )
  95. test(
  96. 'composition',
  97. async () => {
  98. await testGrid('composition')
  99. },
  100. E2E_TIMEOUT
  101. )
  102. })