svg.spec.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import path from 'path'
  2. import { setupPuppeteer } from './e2eUtils'
  3. declare const globalStats: {
  4. label: string
  5. value: number
  6. }[]
  7. declare function valueToPoint(
  8. value: number,
  9. index: number,
  10. total: number
  11. ): {
  12. x: number
  13. y: number
  14. }
  15. describe('e2e: svg', () => {
  16. const { page, click, count, setValue } = setupPuppeteer()
  17. async function assertStats(total: number) {
  18. await page().evaluate(
  19. total => {
  20. const points = globalStats
  21. .map((stat, i) => {
  22. const point = valueToPoint(stat.value, i, total)
  23. return point.x + ',' + point.y
  24. })
  25. .join(' ')
  26. return document.querySelector('polygon')!.attributes[0].value === points
  27. },
  28. [total]
  29. )
  30. }
  31. async function testSvg(apiType: 'classic' | 'composition') {
  32. const baseUrl = `file://${path.resolve(
  33. __dirname,
  34. `../${apiType}/svg.html`
  35. )}`
  36. await page().goto(baseUrl)
  37. await page().waitFor('svg')
  38. expect(await count('g')).toBe(1)
  39. expect(await count('polygon')).toBe(1)
  40. expect(await count('circle')).toBe(1)
  41. expect(await count('text')).toBe(6)
  42. expect(await count('label')).toBe(6)
  43. expect(await count('button')).toBe(7)
  44. expect(await count('input[type="range"]')).toBe(6)
  45. await assertStats(6)
  46. await click('button.remove')
  47. expect(await count('text')).toBe(5)
  48. expect(await count('label')).toBe(5)
  49. expect(await count('button')).toBe(6)
  50. expect(await count('input[type="range"]')).toBe(5)
  51. await assertStats(5)
  52. await setValue('input[name="newlabel"]', 'foo')
  53. await click('#add > button')
  54. expect(await count('text')).toBe(6)
  55. expect(await count('label')).toBe(6)
  56. expect(await count('button')).toBe(7)
  57. expect(await count('input[type="range"]')).toBe(6)
  58. await assertStats(6)
  59. }
  60. test('classic', async () => {
  61. await testSvg('classic')
  62. })
  63. test('composition', async () => {
  64. await testSvg('composition')
  65. })
  66. })