tree.spec.ts 3.4 KB

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