Files
e-ticket/tests/js/tabs.test.js
Serreau Jovann 922e8c5e02 Add JS tests, refactor SitemapController, extract JS modules
- Extract mobile-menu.js and tabs.js from app.js
- Add Vitest tests with happy-dom and v8 coverage (100% on modules)
- Add JS test step to CI frontend and SonarQube workflows
- SonarQube: add JS lcov coverage report path
- SitemapController: extract URLSET_TEMPLATE constant, deduplicate methods

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 00:19:34 +01:00

55 lines
1.8 KiB
JavaScript

import { describe, it, expect, beforeEach } from 'vitest'
import { initTabs } from '../../assets/modules/tabs.js'
describe('initTabs', () => {
beforeEach(() => {
document.body.innerHTML = `
<button data-tab="tab-a" style="background-color:#111827;color:white;">Tab A</button>
<button data-tab="tab-b" style="background-color:white;color:#111827;">Tab B</button>
<div id="tab-a" style="display:block;">Content A</div>
<div id="tab-b" style="display:none;">Content B</div>
`
})
it('switches active tab on click', () => {
initTabs()
const btnB = document.querySelector('[data-tab="tab-b"]')
btnB.click()
expect(document.getElementById('tab-a').style.display).toBe('none')
expect(document.getElementById('tab-b').style.display).toBe('block')
})
it('updates button styles on click', () => {
initTabs()
const btnA = document.querySelector('[data-tab="tab-a"]')
const btnB = document.querySelector('[data-tab="tab-b"]')
btnB.click()
expect(btnB.style.backgroundColor).toBe('#111827')
expect(btnB.style.color).toBe('white')
expect(btnA.style.backgroundColor).toBe('white')
expect(btnA.style.color).toBe('#111827')
})
it('switches back to first tab', () => {
initTabs()
const btnA = document.querySelector('[data-tab="tab-a"]')
const btnB = document.querySelector('[data-tab="tab-b"]')
btnB.click()
btnA.click()
expect(document.getElementById('tab-a').style.display).toBe('block')
expect(document.getElementById('tab-b').style.display).toBe('none')
})
it('does nothing without tab elements', () => {
document.body.innerHTML = ''
expect(() => initTabs()).not.toThrow()
})
})