1
0

todomvc.spec.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { setupPuppeteer, E2E_TIMEOUT } from 'test/helpers'
  2. describe('e2e/todomvc', () => {
  3. const {
  4. page,
  5. isVisible,
  6. isChecked,
  7. isFocused,
  8. text,
  9. value,
  10. count,
  11. hasClass,
  12. hover,
  13. click,
  14. keyUp,
  15. setValue,
  16. enterValue,
  17. clearValue
  18. } = setupPuppeteer()
  19. async function testTodoMVC (url) {
  20. await page().goto(url)
  21. expect(await isVisible('.main')).toBe(false)
  22. expect(await isVisible('.footer')).toBe(false)
  23. expect(await count('.filters .selected')).toBe(1)
  24. await enterValue('.new-todo', 'test')
  25. expect(await count('.todo')).toBe(1)
  26. expect(await isVisible('.todo .edit')).toBe(false)
  27. expect(await text('.todo label')).toContain('test')
  28. expect(await text('.todo-count strong')).toContain('1')
  29. expect(await isChecked('.todo .toggle')).toBe(false)
  30. expect(await isVisible('.main')).toBe(true)
  31. expect(await isVisible('.footer')).toBe(true)
  32. expect(await isVisible('.clear-completed')).toBe(false)
  33. expect(await value('.new-todo')).toBe('')
  34. await enterValue('.new-todo', 'test2')
  35. expect(await count('.todo')).toBe(2)
  36. expect(await text('.todo:nth-child(2) label')).toContain('test2')
  37. expect(await text('.todo-count strong')).toContain('2')
  38. // toggle
  39. await click('.todo .toggle')
  40. expect(await count('.todo.completed')).toBe(1)
  41. expect(await hasClass('.todo:nth-child(1)', 'completed')).toBe(true)
  42. expect(await text('.todo-count strong')).toContain('1')
  43. expect(await isVisible('.clear-completed')).toBe(true)
  44. await enterValue('.new-todo', 'test3')
  45. expect(await count('.todo')).toBe(3)
  46. expect(await text('.todo:nth-child(3) label')).toContain('test3')
  47. expect(await text('.todo-count strong')).toContain('2')
  48. await enterValue('.new-todo', 'test4')
  49. await enterValue('.new-todo', 'test5')
  50. expect(await count('.todo')).toBe(5)
  51. expect(await text('.todo-count strong')).toContain('4')
  52. // toggle more
  53. await click('.todo:nth-child(4) .toggle')
  54. await click('.todo:nth-child(5) .toggle')
  55. expect(await count('.todo.completed')).toBe(3)
  56. expect(await text('.todo-count strong')).toContain('2')
  57. // remove
  58. await hover('.todo:nth-child(1)')
  59. await click('.todo:nth-child(1) .destroy')
  60. expect(await count('.todo')).toBe(4)
  61. expect(await count('.todo.completed')).toBe(2)
  62. expect(await text('.todo-count strong')).toContain('2')
  63. await hover('.todo:nth-child(2)')
  64. await click('.todo:nth-child(2) .destroy')
  65. expect(await count('.todo')).toBe(3)
  66. expect(await count('.todo.completed')).toBe(2)
  67. expect(await text('.todo-count strong')).toContain('1')
  68. // remove all
  69. await click('.clear-completed')
  70. expect(await count('.todo')).toBe(1)
  71. expect(await text('.todo label')).toContain('test2')
  72. expect(await count('.todo.completed')).toBe(0)
  73. expect(await text('.todo-count strong')).toBe('1')
  74. expect(await isVisible('.clear-completed')).toBe(false)
  75. // prepare to test filters
  76. await enterValue('.new-todo', 'test')
  77. await enterValue('.new-todo', 'test')
  78. await click('.todo:nth-child(2) .toggle')
  79. await click('.todo:nth-child(3) .toggle')
  80. // active filter
  81. await click('.filters li:nth-child(2) a')
  82. expect(await count('.todo')).toBe(1)
  83. expect(await count('.todo.completed')).toBe(0)
  84. // add item with filter active
  85. await enterValue('.new-todo', 'test')
  86. expect(await count('.todo', 2)).toBe(2)
  87. // complted filter
  88. await click('.filters li:nth-child(3) a')
  89. expect(await count('.todo')).toBe(2)
  90. expect(await count('.todo.completed')).toBe(2)
  91. // toggling with filter active
  92. await click('.todo .toggle')
  93. expect(await count('.todo')).toBe(1)
  94. await click('.filters li:nth-child(2) a')
  95. expect(await count('.todo')).toBe(3)
  96. await click('.todo .toggle')
  97. expect(await count('.todo')).toBe(2)
  98. // editing triggered by blur
  99. await click('.filters li:nth-child(1) a')
  100. await click('.todo:nth-child(1) label', { clickCount: 2 })
  101. expect(await count('.todo.editing')).toBe(1)
  102. expect(await isFocused('.todo:nth-child(1) .edit')).toBe(true)
  103. await clearValue('.todo:nth-child(1) .edit')
  104. await setValue('.todo:nth-child(1) .edit', 'edited!')
  105. await click('footer') // blur
  106. expect(await count('.todo.editing')).toBe(0)
  107. expect(await text('.todo:nth-child(1) label')).toBe('edited!')
  108. // editing triggered by enter
  109. await click('.todo label', { clickCount: 2 })
  110. await clearValue('.todo:nth-child(1) .edit')
  111. await enterValue('.todo:nth-child(1) .edit', 'edited again!')
  112. expect(await count('.todo.editing')).toBe(0)
  113. expect(await text('.todo:nth-child(1) label')).toBe('edited again!')
  114. // cancel
  115. await click('.todo label', { clickCount: 2 })
  116. await clearValue('.todo:nth-child(1) .edit')
  117. await setValue('.todo:nth-child(1) .edit', 'edited!')
  118. await keyUp('Escape')
  119. expect(await count('.todo.editing')).toBe(0)
  120. expect(await text('.todo:nth-child(1) label')).toBe('edited again!')
  121. // empty value should remove
  122. await click('.todo label', { clickCount: 2 })
  123. await clearValue('.todo:nth-child(1) .edit')
  124. await enterValue('.todo:nth-child(1) .edit', ' ')
  125. expect(await count('.todo')).toBe(3)
  126. // toggle all
  127. await click('label[for="toggle-all"]')
  128. expect(await count('.todo.completed')).toBe(3)
  129. await click('label[for="toggle-all"]')
  130. expect(await count('.todo:not(.completed)')).toBe(3)
  131. }
  132. test('classic', async () => {
  133. await testTodoMVC('http://localhost:8080/classic/todomvc/')
  134. }, E2E_TIMEOUT)
  135. test('composition', async () => {
  136. await testTodoMVC('http://localhost:8080/composition/todomvc/')
  137. }, E2E_TIMEOUT)
  138. })