|
| 1 | +describe('SvgSupport', () => { |
| 2 | + beforeEach(async () => { |
| 3 | + await page.goto('http://localhost:6969/svg-support') |
| 4 | + await page.waitForSelector('[data-hydrated]') |
| 5 | + }) |
| 6 | + |
| 7 | + test('svg can render text', async () => { |
| 8 | + // Verifica se o SVG possui 4 elementos <text> dentro dele |
| 9 | + const svg = await page.$('svg'); |
| 10 | + const texts = await svg.$$('text'); |
| 11 | + expect(texts.length).toBe(4); |
| 12 | + }) |
| 13 | + |
| 14 | + test('svg can add new paths while rerendering', async () => { |
| 15 | + // Verifica se o ícone Hamburger está presente inicialmente (3 paths) |
| 16 | + const hamburgerPaths = await page.$$('svg[width="30"] path') |
| 17 | + expect(hamburgerPaths.length).toBe(3) // Hamburger has 3 paths |
| 18 | + }) |
| 19 | + |
| 20 | + test('svg can render in short circuit statements', async () => { |
| 21 | + // Verifica se o ícone de Hamburger está sendo exibido (3 paths) |
| 22 | + const hamburgerPaths = await page.$$('svg[width="30"] path') |
| 23 | + expect(hamburgerPaths.length).toBe(3) |
| 24 | + }) |
| 25 | + |
| 26 | + test('svg can render in ternary statements', async () => { |
| 27 | + let bigHamburger = await page.$('svg[width="69"]') |
| 28 | + expect(bigHamburger).toBeFalsy() |
| 29 | + |
| 30 | + // Clica no segundo botão (show) |
| 31 | + const buttons = await page.$$('button') |
| 32 | + await buttons[1].click() |
| 33 | + |
| 34 | + // Aguarda o Hamburger grande aparecer |
| 35 | + await page.waitForSelector('svg[width="69"]') |
| 36 | + |
| 37 | + // Verifica se o Hamburger foi renderizado no ternário |
| 38 | + bigHamburger = await page.$('svg[width="69"]') |
| 39 | + expect(bigHamburger).toBeTruthy() |
| 40 | + |
| 41 | + }) |
| 42 | + |
| 43 | + test('icon toggle functionality works correctly', async () => { |
| 44 | + // Primeiro verifica o estado inicial (deve ser Hamburger, 3 paths) |
| 45 | + let iconPaths = await page.$$('svg[width="30"] path') |
| 46 | + expect(iconPaths.length).toBe(3) // Hamburger tem 3 paths |
| 47 | + |
| 48 | + // Clica no primeiro botão (toggle) |
| 49 | + const buttons = await page.$$('button') |
| 50 | + await buttons[0].click() |
| 51 | + |
| 52 | + // Aguarda o ícone trocar (Close tem 2 paths) |
| 53 | + await page.waitForFunction(() => { |
| 54 | + const svg = document.querySelector('svg[width="30"]'); |
| 55 | + return svg && svg.querySelectorAll('path').length === 2; |
| 56 | + }); |
| 57 | + |
| 58 | + iconPaths = await page.$$('svg[width="30"] path') |
| 59 | + expect(iconPaths.length).toBe(2) // Close tem 2 paths |
| 60 | + |
| 61 | + // Clica novamente para voltar ao Hamburger |
| 62 | + await buttons[0].click() |
| 63 | + |
| 64 | + // Aguarda o ícone trocar de volta (Hamburger tem 3 paths) |
| 65 | + await page.waitForFunction(() => { |
| 66 | + const svg = document.querySelector('svg[width="30"]'); |
| 67 | + return svg && svg.querySelectorAll('path').length === 3; |
| 68 | + }); |
| 69 | + |
| 70 | + iconPaths = await page.$$('svg[width="30"] path') |
| 71 | + expect(iconPaths.length).toBe(3) // Hamburger tem 3 paths |
| 72 | + }) |
| 73 | + |
| 74 | + test('icon visibility toggle works correctly', async () => { |
| 75 | + |
| 76 | + // Verifica que o ícone grande não está visível inicialmente |
| 77 | + let bigHamburger = await page.$('svg[width="69"]') |
| 78 | + expect(bigHamburger).toBeFalsy() |
| 79 | + |
| 80 | + // Clica no segundo botão (show) |
| 81 | + const buttons = await page.$$('button') |
| 82 | + await buttons[1].click() |
| 83 | + |
| 84 | + // Aguarda o Hamburger grande aparecer |
| 85 | + await page.waitForSelector('svg[width="69"]') |
| 86 | + |
| 87 | + // Verifica se o Hamburger grande apareceu |
| 88 | + bigHamburger = await page.$('svg[width="69"]') |
| 89 | + expect(bigHamburger).toBeTruthy() |
| 90 | + |
| 91 | + // Clica novamente no segundo botão (show) para esconder |
| 92 | + await buttons[1].click() |
| 93 | + |
| 94 | + // Aguarda o Hamburger grande desaparecer do DOM |
| 95 | + await page.waitForSelector('svg[width="69"]', { hidden: true }) |
| 96 | + |
| 97 | + // Verifica se o Hamburger grande desapareceu |
| 98 | + bigHamburger = await page.$('svg[width="69"]') |
| 99 | + expect(bigHamburger).toBeFalsy() |
| 100 | + }) |
| 101 | + |
| 102 | + test('svg attributes are correctly applied', async () => { |
| 103 | + // Verifica se os atributos SVG estão sendo aplicados corretamente |
| 104 | + const svgElement = await page.$('svg[viewBox="0 0 240 80"]') |
| 105 | + expect(svgElement).toBeTruthy() |
| 106 | + |
| 107 | + const xmlns = await page.$eval('svg[viewBox="0 0 240 80"]', el => el.getAttribute('xmlns')) |
| 108 | + expect(xmlns).toBe('http://www.w3.org/2000/svg') |
| 109 | + }) |
| 110 | +}) |
0 commit comments