- Add isHidden field to Category entity with migration (DEFAULT false for existing rows) - Add isHidden checkbox to edit category template and "Masquee" badge on category list - Save isHidden in editCategory controller method - Fix Category.isActive() indentation - Create CategoryTest with full coverage (14 tests): defaults, setters, setEvent logic, isActive, isHidden - Add category CRUD tests to AccountControllerTest: add/edit/delete/reorder categories with access control - Add cookie-consent tests for dev env early return and Cloudflare tunnel script - Exclude PayoutPdfService from phpunit coverage and SonarQube analysis Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
119 lines
4.6 KiB
JavaScript
119 lines
4.6 KiB
JavaScript
import { describe, it, expect, beforeEach } from 'vitest'
|
|
import { initCookieConsent } from '../../assets/modules/cookie-consent.js'
|
|
|
|
describe('initCookieConsent', () => {
|
|
beforeEach(() => {
|
|
document.cookie = 'e_ticket_consent=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/'
|
|
document.querySelectorAll('script[data-analytics]').forEach(s => s.remove())
|
|
document.body.innerHTML = `
|
|
<div id="cookie-banner" class="hidden">
|
|
<button id="cookie-accept"></button>
|
|
<button id="cookie-refuse"></button>
|
|
</div>
|
|
`
|
|
})
|
|
|
|
it('shows banner when no consent cookie', () => {
|
|
initCookieConsent()
|
|
const banner = document.getElementById('cookie-banner')
|
|
expect(banner.classList.contains('hidden')).toBe(false)
|
|
})
|
|
|
|
it('hides banner and sets cookie on accept', () => {
|
|
initCookieConsent()
|
|
document.getElementById('cookie-accept').click()
|
|
const banner = document.getElementById('cookie-banner')
|
|
expect(banner.classList.contains('hidden')).toBe(true)
|
|
expect(document.cookie).toContain('e_ticket_consent=accepted')
|
|
})
|
|
|
|
it('hides banner and sets cookie on refuse', () => {
|
|
initCookieConsent()
|
|
document.getElementById('cookie-refuse').click()
|
|
const banner = document.getElementById('cookie-banner')
|
|
expect(banner.classList.contains('hidden')).toBe(true)
|
|
expect(document.cookie).toContain('e_ticket_consent=refused')
|
|
})
|
|
|
|
it('does not show banner if already accepted', () => {
|
|
document.cookie = 'e_ticket_consent=accepted;path=/'
|
|
initCookieConsent()
|
|
const banner = document.getElementById('cookie-banner')
|
|
expect(banner.classList.contains('hidden')).toBe(true)
|
|
})
|
|
|
|
it('does not show banner if already refused', () => {
|
|
document.cookie = 'e_ticket_consent=refused;path=/'
|
|
initCookieConsent()
|
|
const banner = document.getElementById('cookie-banner')
|
|
expect(banner.classList.contains('hidden')).toBe(true)
|
|
})
|
|
|
|
it('handles banner without buttons', () => {
|
|
document.body.innerHTML = '<div id="cookie-banner" class="hidden"></div>'
|
|
initCookieConsent()
|
|
const banner = document.getElementById('cookie-banner')
|
|
expect(banner.classList.contains('hidden')).toBe(false)
|
|
})
|
|
|
|
it('does nothing without banner element', () => {
|
|
document.body.innerHTML = ''
|
|
expect(() => initCookieConsent()).not.toThrow()
|
|
})
|
|
|
|
it('loads analytics script on accept', () => {
|
|
initCookieConsent()
|
|
document.getElementById('cookie-accept').click()
|
|
const script = document.querySelector('script[data-analytics]')
|
|
expect(script).not.toBeNull()
|
|
expect(script.src).toContain('/stats/script.js')
|
|
expect(script.dataset.websiteId).toBe('a1f85dd5-741f-4df7-840a-7ef0931ed0cc')
|
|
})
|
|
|
|
it('does not load analytics on refuse', () => {
|
|
initCookieConsent()
|
|
document.getElementById('cookie-refuse').click()
|
|
const script = document.querySelector('script[data-analytics]')
|
|
expect(script).toBeNull()
|
|
})
|
|
|
|
it('does not duplicate analytics script if already loaded', () => {
|
|
document.cookie = 'e_ticket_consent=accepted;path=/'
|
|
initCookieConsent()
|
|
initCookieConsent()
|
|
const scripts = document.querySelectorAll('script[data-analytics]')
|
|
expect(scripts.length).toBe(1)
|
|
})
|
|
|
|
it('loads analytics immediately if already accepted', () => {
|
|
document.cookie = 'e_ticket_consent=accepted;path=/'
|
|
initCookieConsent()
|
|
const script = document.querySelector('script[data-analytics]')
|
|
expect(script).not.toBeNull()
|
|
})
|
|
|
|
it('does not load analytics in dev environment', () => {
|
|
document.body.dataset.env = 'dev'
|
|
document.cookie = 'e_ticket_consent=accepted;path=/'
|
|
initCookieConsent()
|
|
const script = document.querySelector('script[data-analytics]')
|
|
expect(script).toBeNull()
|
|
})
|
|
|
|
it('loads cloudflare tunnel script on accept', () => {
|
|
initCookieConsent()
|
|
document.getElementById('cookie-accept').click()
|
|
const script = document.querySelector('script[data-cf-beacon]')
|
|
expect(script).not.toBeNull()
|
|
expect(script.src).toContain('/assets/perf.js')
|
|
})
|
|
|
|
it('does not duplicate cloudflare script', () => {
|
|
document.cookie = 'e_ticket_consent=accepted;path=/'
|
|
initCookieConsent()
|
|
initCookieConsent()
|
|
const scripts = document.querySelectorAll('script[data-cf-beacon]')
|
|
expect(scripts.length).toBe(1)
|
|
})
|
|
})
|