2
0

todomvc.spec.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import path from 'node:path'
  2. import {
  3. E2E_TIMEOUT,
  4. setupPuppeteer,
  5. } from '../../../packages/vue/__tests__/e2e/e2eUtils'
  6. import connect from 'connect'
  7. import sirv from 'sirv'
  8. describe('e2e: todomvc', () => {
  9. const {
  10. page,
  11. click,
  12. isVisible,
  13. count,
  14. text,
  15. value,
  16. isChecked,
  17. isFocused,
  18. classList,
  19. enterValue,
  20. clearValue,
  21. timeout,
  22. } = setupPuppeteer()
  23. let server: any
  24. const port = '8194'
  25. beforeAll(() => {
  26. server = connect()
  27. .use(sirv(path.resolve(import.meta.dirname, '../dist')))
  28. .listen(port)
  29. process.on('SIGTERM', () => server && server.close())
  30. })
  31. afterAll(() => {
  32. server.close()
  33. })
  34. async function removeItemAt(n: number) {
  35. const item = (await page().$('.todo:nth-child(' + n + ')'))!
  36. const itemBBox = (await item.boundingBox())!
  37. await page().mouse.move(itemBBox.x + 10, itemBBox.y + 10)
  38. await click('.todo:nth-child(' + n + ') .destroy')
  39. }
  40. test(
  41. 'vapor',
  42. async () => {
  43. const baseUrl = `http://localhost:${port}/todomvc/`
  44. await page().goto(baseUrl)
  45. expect(await isVisible('.main')).toBe(false)
  46. expect(await isVisible('.footer')).toBe(false)
  47. expect(await count('.filters .selected')).toBe(1)
  48. expect(await text('.filters .selected')).toBe('All')
  49. expect(await count('.todo')).toBe(0)
  50. await enterValue('.new-todo', 'test')
  51. expect(await count('.todo')).toBe(1)
  52. expect(await isVisible('.todo .edit')).toBe(false)
  53. expect(await text('.todo label')).toBe('test')
  54. expect(await text('.todo-count strong')).toBe('1')
  55. expect(await isChecked('.todo .toggle')).toBe(false)
  56. expect(await isVisible('.main')).toBe(true)
  57. expect(await isVisible('.footer')).toBe(true)
  58. expect(await isVisible('.clear-completed')).toBe(false)
  59. expect(await value('.new-todo')).toBe('')
  60. await enterValue('.new-todo', 'test2')
  61. expect(await count('.todo')).toBe(2)
  62. expect(await text('.todo:nth-child(2) label')).toBe('test2')
  63. expect(await text('.todo-count strong')).toBe('2')
  64. // toggle
  65. await click('.todo .toggle')
  66. expect(await count('.todo.completed')).toBe(1)
  67. expect(await classList('.todo:nth-child(1)')).toContain('completed')
  68. expect(await text('.todo-count strong')).toBe('1')
  69. expect(await isVisible('.clear-completed')).toBe(true)
  70. await enterValue('.new-todo', 'test3')
  71. expect(await count('.todo')).toBe(3)
  72. expect(await text('.todo:nth-child(3) label')).toBe('test3')
  73. expect(await text('.todo-count strong')).toBe('2')
  74. await enterValue('.new-todo', 'test4')
  75. await enterValue('.new-todo', 'test5')
  76. expect(await count('.todo')).toBe(5)
  77. expect(await text('.todo-count strong')).toBe('4')
  78. // toggle more
  79. await click('.todo:nth-child(4) .toggle')
  80. await click('.todo:nth-child(5) .toggle')
  81. expect(await count('.todo.completed')).toBe(3)
  82. expect(await text('.todo-count strong')).toBe('2')
  83. // remove
  84. await removeItemAt(1)
  85. expect(await count('.todo')).toBe(4)
  86. expect(await count('.todo.completed')).toBe(2)
  87. expect(await text('.todo-count strong')).toBe('2')
  88. await removeItemAt(2)
  89. expect(await count('.todo')).toBe(3)
  90. expect(await count('.todo.completed')).toBe(2)
  91. expect(await text('.todo-count strong')).toBe('1')
  92. // remove all
  93. await click('.clear-completed')
  94. expect(await count('.todo')).toBe(1)
  95. expect(await text('.todo label')).toBe('test2')
  96. expect(await count('.todo.completed')).toBe(0)
  97. expect(await text('.todo-count strong')).toBe('1')
  98. expect(await isVisible('.clear-completed')).toBe(false)
  99. // prepare to test filters
  100. await enterValue('.new-todo', 'test')
  101. await enterValue('.new-todo', 'test')
  102. await click('.todo:nth-child(2) .toggle')
  103. await click('.todo:nth-child(3) .toggle')
  104. // active filter
  105. await click('.filters li:nth-child(2) a')
  106. await timeout(1)
  107. expect(await count('.todo')).toBe(1)
  108. expect(await count('.todo.completed')).toBe(0)
  109. // add item with filter active
  110. await enterValue('.new-todo', 'test')
  111. expect(await count('.todo')).toBe(2)
  112. // completed filter
  113. await click('.filters li:nth-child(3) a')
  114. await timeout(1)
  115. expect(await count('.todo')).toBe(2)
  116. expect(await count('.todo.completed')).toBe(2)
  117. // filter on page load
  118. await page().goto(`${baseUrl}#active`)
  119. expect(await count('.todo')).toBe(2)
  120. expect(await count('.todo.completed')).toBe(0)
  121. expect(await text('.todo-count strong')).toBe('2')
  122. // completed on page load
  123. await page().goto(`${baseUrl}#completed`)
  124. expect(await count('.todo')).toBe(2)
  125. expect(await count('.todo.completed')).toBe(2)
  126. expect(await text('.todo-count strong')).toBe('2')
  127. // toggling with filter active
  128. await click('.todo .toggle')
  129. expect(await count('.todo')).toBe(1)
  130. await click('.filters li:nth-child(2) a')
  131. await timeout(1)
  132. expect(await count('.todo')).toBe(3)
  133. await click('.todo .toggle')
  134. expect(await count('.todo')).toBe(2)
  135. // editing triggered by blur
  136. await click('.filters li:nth-child(1) a')
  137. await timeout(1)
  138. await click('.todo:nth-child(1) label', { clickCount: 2 })
  139. expect(await count('.todo.editing')).toBe(1)
  140. expect(await isFocused('.todo:nth-child(1) .edit')).toBe(true)
  141. await clearValue('.todo:nth-child(1) .edit')
  142. await page().type('.todo:nth-child(1) .edit', 'edited!')
  143. await click('.new-todo') // blur
  144. expect(await count('.todo.editing')).toBe(0)
  145. expect(await text('.todo:nth-child(1) label')).toBe('edited!')
  146. // editing triggered by enter
  147. await click('.todo label', { clickCount: 2 })
  148. await enterValue('.todo:nth-child(1) .edit', 'edited again!')
  149. expect(await count('.todo.editing')).toBe(0)
  150. expect(await text('.todo:nth-child(1) label')).toBe('edited again!')
  151. // cancel
  152. await click('.todo label', { clickCount: 2 })
  153. await clearValue('.todo:nth-child(1) .edit')
  154. await page().type('.todo:nth-child(1) .edit', 'edited!')
  155. await page().keyboard.press('Escape')
  156. expect(await count('.todo.editing')).toBe(0)
  157. expect(await text('.todo:nth-child(1) label')).toBe('edited again!')
  158. // empty value should remove
  159. await click('.todo label', { clickCount: 2 })
  160. await enterValue('.todo:nth-child(1) .edit', ' ')
  161. expect(await count('.todo')).toBe(3)
  162. // toggle all
  163. await click('.toggle-all+label')
  164. expect(await count('.todo.completed')).toBe(3)
  165. await click('.toggle-all+label')
  166. expect(await count('.todo:not(.completed)')).toBe(3)
  167. },
  168. E2E_TIMEOUT,
  169. )
  170. })