avatarReference.spec.ts 2.5 KB

1234567891011121314151617181920212223242526272829
  1. import {expect,test} from '@playwright/test'
  2. // Standalone reference comparison; the regular app suite uses its own fixture.
  3. test('matches all OpenMausBot canonical resting frames',async({page,context},testInfo)=>{
  4. const reference=await context.newPage()
  5. await reference.goto('http://127.0.0.1:18806')
  6. await page.goto('http://127.0.0.1:18807')
  7. await expect(reference.locator('[data-testid="shape-circle"] svg path[fill="#ffffff"]').first()).toHaveAttribute('d',/.+/)
  8. await expect(page.locator('[data-part=eye0]').first()).toHaveAttribute('d',/.+/)
  9. const ids=await page.locator('[data-testid]').evaluateAll(nodes=>nodes.map(n=>n.getAttribute('data-testid')!))
  10. expect(ids).toHaveLength(28)
  11. for(const id of ids){
  12. const expected=await reference.getByTestId(id).locator('svg').evaluate(svg=>{
  13. const eyes=[...svg.querySelectorAll('path[fill="#ffffff"]')].slice(0,2)
  14. const mouth=svg.querySelector('path[stroke="#ffffff"]')!
  15. const body=svg.querySelector('[fill^="url("]')!
  16. const attrs=(el:Element)=>Object.fromEntries([...el.attributes].filter(a=>!['fill','data-part'].includes(a.name)).map(a=>[a.name,a.value]))
  17. return {viewBox:svg.getAttribute('viewBox'),eyes:eyes.map(e=>({d:e.getAttribute('d'),transform:e.getAttribute('transform')})),mouth:{d:mouth.getAttribute('d'),transform:mouth.getAttribute('transform')},anchor:eyes[0]!.parentElement!.getAttribute('transform'),body:{tag:body.tagName,attrs:attrs(body)},color:svg.querySelector('stop')!.getAttribute('stop-color')!.toLowerCase()}
  18. })
  19. const actual=await page.getByTestId(id).locator('svg').evaluate(svg=>{
  20. const eyes=[svg.querySelector('[data-part=eye0]')!,svg.querySelector('[data-part=eye1]')!],mouth=svg.querySelector('[data-part=mouth]')!,body=svg.querySelector('[data-part=outline]')!.firstElementChild!
  21. const attrs=(el:Element)=>Object.fromEntries([...el.attributes].filter(a=>!['fill','data-part'].includes(a.name)).map(a=>[a.name,a.value]))
  22. return {viewBox:svg.getAttribute('viewBox'),eyes:eyes.map(e=>({d:e.getAttribute('d'),transform:e.getAttribute('transform')})),mouth:{d:mouth.getAttribute('d'),transform:mouth.getAttribute('transform')},anchor:eyes[0]!.parentElement!.getAttribute('transform'),body:{tag:body.tagName,attrs:attrs(body)},color:body.getAttribute('fill')!.toLowerCase()}
  23. })
  24. expect(actual,id).toEqual(expected)
  25. }
  26. await reference.screenshot({path:testInfo.outputPath('openmaus-reference.png'),fullPage:true})
  27. await page.screenshot({path:testInfo.outputPath('yaoyao-v2.png'),fullPage:true})
  28. await reference.close()
  29. })