tree.spec.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import path from 'node:path'
  2. import { E2E_TIMEOUT, setupPuppeteer } from './e2eUtils'
  3. describe('e2e: tree', () => {
  4. const { page, click, count, text, children, isVisible } = setupPuppeteer()
  5. async function testTree(apiType: 'classic' | 'composition') {
  6. const baseUrl = `file://${path.resolve(
  7. __dirname,
  8. `../../examples/${apiType}/tree.html`,
  9. )}`
  10. await page().goto(baseUrl)
  11. expect(await count('.item')).toBe(12)
  12. expect(await count('.add')).toBe(4)
  13. expect(await count('.item > ul')).toBe(4)
  14. expect(await isVisible('#demo li ul')).toBe(false)
  15. expect(await text('#demo li div span')).toBe('[+]')
  16. // expand root
  17. await click('.bold')
  18. expect(await isVisible('#demo ul')).toBe(true)
  19. expect((await children('#demo li ul')).length).toBe(4)
  20. expect(await text('#demo li div span')).toContain('[-]')
  21. expect(await text('#demo > .item > ul > .item:nth-child(1)')).toContain(
  22. 'hello',
  23. )
  24. expect(await text('#demo > .item > ul > .item:nth-child(2)')).toContain(
  25. 'wat',
  26. )
  27. expect(await text('#demo > .item > ul > .item:nth-child(3)')).toContain(
  28. 'child folder',
  29. )
  30. expect(await text('#demo > .item > ul > .item:nth-child(3)')).toContain(
  31. '[+]',
  32. )
  33. // add items to root
  34. await click('#demo > .item > ul > .add')
  35. expect((await children('#demo li ul')).length).toBe(5)
  36. expect(await text('#demo > .item > ul > .item:nth-child(1)')).toContain(
  37. 'hello',
  38. )
  39. expect(await text('#demo > .item > ul > .item:nth-child(2)')).toContain(
  40. 'wat',
  41. )
  42. expect(await text('#demo > .item > ul > .item:nth-child(3)')).toContain(
  43. 'child folder',
  44. )
  45. expect(await text('#demo > .item > ul > .item:nth-child(3)')).toContain(
  46. '[+]',
  47. )
  48. expect(await text('#demo > .item > ul > .item:nth-child(4)')).toContain(
  49. 'new stuff',
  50. )
  51. // add another item
  52. await click('#demo > .item > ul > .add')
  53. expect((await children('#demo li ul')).length).toBe(6)
  54. expect(await text('#demo > .item > ul > .item:nth-child(1)')).toContain(
  55. 'hello',
  56. )
  57. expect(await text('#demo > .item > ul > .item:nth-child(2)')).toContain(
  58. 'wat',
  59. )
  60. expect(await text('#demo > .item > ul > .item:nth-child(3)')).toContain(
  61. 'child folder',
  62. )
  63. expect(await text('#demo > .item > ul > .item:nth-child(3)')).toContain(
  64. '[+]',
  65. )
  66. expect(await text('#demo > .item > ul > .item:nth-child(4)')).toContain(
  67. 'new stuff',
  68. )
  69. expect(await text('#demo > .item > ul > .item:nth-child(5)')).toContain(
  70. 'new stuff',
  71. )
  72. await click('#demo ul .bold')
  73. expect(await isVisible('#demo ul ul')).toBe(true)
  74. expect(await text('#demo ul > .item:nth-child(3)')).toContain('[-]')
  75. expect((await children('#demo ul ul')).length).toBe(5)
  76. await click('.bold')
  77. expect(await isVisible('#demo ul')).toBe(false)
  78. expect(await text('#demo li div span')).toContain('[+]')
  79. await click('.bold')
  80. expect(await isVisible('#demo ul')).toBe(true)
  81. expect(await text('#demo li div span')).toContain('[-]')
  82. await click('#demo ul > .item div', { count: 2 })
  83. expect(await count('.item')).toBe(15)
  84. expect(await count('.item > ul')).toBe(5)
  85. expect(await text('#demo ul > .item:nth-child(1)')).toContain('[-]')
  86. expect((await children('#demo ul > .item:nth-child(1) > ul')).length).toBe(
  87. 2,
  88. )
  89. }
  90. test(
  91. 'classic',
  92. async () => {
  93. await testTree('classic')
  94. },
  95. E2E_TIMEOUT,
  96. )
  97. test(
  98. 'composition',
  99. async () => {
  100. await testTree('composition')
  101. },
  102. E2E_TIMEOUT,
  103. )
  104. })