2026-03-21 12:27:00 +01:00
|
|
|
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
Add Billet entity, BilletDesign, ticket designer, CRUD billets, commissions
- Create Billet entity: name, position, priceHT, quantity (nullable=unlimited),
isGeneratedBillet, hasDefinedExit, notBuyable, type (billet/reservation_brocante/vote),
stripeProductId, description, picture (VichUploader), category (ManyToOne CASCADE)
- Create BilletDesign entity (OneToOne Event): accentColor, invitationTitle, invitationColor
- Billet CRUD: add/edit/delete with access control, Stripe product sync on connected account
- Billet reorder: drag & drop with position field, refactored sortable.js for both categories and billets
- Ticket designer tab (custom offer only): accent color, invitation title/color, live iframe preview
- A4 ticket preview: 4 zones (HG infos+billet, HD affiche, BG association, BD sortie+invitation), fake QR code SVG
- Commission calculator JS: live breakdown of E-Ticket fee, Stripe fee (1.5%+0.25EUR), net amount
- Sales recap on categories tab: qty sold, total HT, total commissions, total net
- DisableProfilerSubscriber: disable web profiler toolbar on preview iframe
- CSP: allow self in frame-src and frame-ancestors for preview iframe
- Flysystem: dedicated billets.storage for billet images
- Upload accept restricted to png/jpeg/webp/gif (no HEIC)
- Makefile: add force_sql_dev command
- CLAUDE.md: add rule to never modify existing migrations
- Consolidate all migrations into single Version20260321111125
- Tests: BilletTest (20), BilletDesignTest (6), DisableProfilerSubscriberTest (5),
billet-designer.test.js (7), commission-calculator.test.js (7),
AccountControllerTest billet CRUD tests (11)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 12:19:46 +01:00
|
|
|
import { initBilletDesigner } from '../../assets/modules/billet-designer.js'
|
|
|
|
|
|
|
|
|
|
describe('initBilletDesigner', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does nothing without designer element', () => {
|
|
|
|
|
expect(() => initBilletDesigner()).not.toThrow()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does nothing without preview url', () => {
|
|
|
|
|
document.body.innerHTML = '<div id="billet-designer"></div>'
|
|
|
|
|
expect(() => initBilletDesigner()).not.toThrow()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('does nothing without iframe', () => {
|
|
|
|
|
document.body.innerHTML = '<div id="billet-designer" data-preview-url="/preview"></div>'
|
|
|
|
|
expect(() => initBilletDesigner()).not.toThrow()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('reloads iframe on color input change', () => {
|
|
|
|
|
document.body.innerHTML = `
|
|
|
|
|
<div id="billet-designer" data-preview-url="/preview">
|
|
|
|
|
<input type="color" name="bg_color" value="#ffffff">
|
|
|
|
|
<iframe id="billet-preview-frame" src="/preview"></iframe>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
initBilletDesigner()
|
|
|
|
|
|
|
|
|
|
const input = document.querySelector('input[name="bg_color"]')
|
|
|
|
|
input.value = '#ff0000'
|
|
|
|
|
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
|
|
|
|
|
|
|
|
const iframe = document.getElementById('billet-preview-frame')
|
|
|
|
|
expect(iframe.src).toContain('bg_color=%23ff0000')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('reloads iframe on checkbox change', () => {
|
|
|
|
|
document.body.innerHTML = `
|
|
|
|
|
<div id="billet-designer" data-preview-url="/preview">
|
|
|
|
|
<input type="checkbox" name="show_logo" checked>
|
|
|
|
|
<iframe id="billet-preview-frame" src="/preview"></iframe>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
initBilletDesigner()
|
|
|
|
|
|
|
|
|
|
const checkbox = document.querySelector('input[name="show_logo"]')
|
|
|
|
|
checkbox.checked = false
|
|
|
|
|
checkbox.dispatchEvent(new Event('change', { bubbles: true }))
|
|
|
|
|
|
|
|
|
|
const iframe = document.getElementById('billet-preview-frame')
|
|
|
|
|
expect(iframe.src).toContain('show_logo=0')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('includes all inputs in preview url', () => {
|
|
|
|
|
document.body.innerHTML = `
|
|
|
|
|
<div id="billet-designer" data-preview-url="/preview">
|
|
|
|
|
<input type="color" name="bg_color" value="#ffffff">
|
|
|
|
|
<input type="color" name="text_color" value="#111111">
|
|
|
|
|
<input type="checkbox" name="show_logo" checked>
|
|
|
|
|
<iframe id="billet-preview-frame" src="/preview"></iframe>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
initBilletDesigner()
|
|
|
|
|
|
|
|
|
|
const input = document.querySelector('input[name="bg_color"]')
|
|
|
|
|
input.dispatchEvent(new Event('input', { bubbles: true }))
|
|
|
|
|
|
|
|
|
|
const iframe = document.getElementById('billet-preview-frame')
|
|
|
|
|
expect(iframe.src).toContain('bg_color=%23ffffff')
|
|
|
|
|
expect(iframe.src).toContain('text_color=%23111111')
|
|
|
|
|
expect(iframe.src).toContain('show_logo=1')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('reloads on reload button click', () => {
|
|
|
|
|
document.body.innerHTML = `
|
|
|
|
|
<div id="billet-designer" data-preview-url="/preview">
|
|
|
|
|
<input type="color" name="bg_color" value="#aabbcc">
|
|
|
|
|
<iframe id="billet-preview-frame" src="/preview"></iframe>
|
|
|
|
|
<button id="billet-reload-preview"></button>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
initBilletDesigner()
|
|
|
|
|
|
|
|
|
|
document.getElementById('billet-reload-preview').click()
|
|
|
|
|
|
|
|
|
|
const iframe = document.getElementById('billet-preview-frame')
|
|
|
|
|
expect(iframe.src).toContain('bg_color=%23aabbcc')
|
|
|
|
|
})
|
2026-03-21 12:27:00 +01:00
|
|
|
|
|
|
|
|
it('saves design on save button click', () => {
|
|
|
|
|
const fetchMock = vi.fn().mockResolvedValue({ ok: true })
|
|
|
|
|
globalThis.fetch = fetchMock
|
|
|
|
|
|
|
|
|
|
document.body.innerHTML = `
|
|
|
|
|
<div id="billet-designer" data-preview-url="/preview" data-save-url="/save">
|
|
|
|
|
<input type="color" name="accent_color" value="#4f46e5">
|
|
|
|
|
<input type="text" name="invitation_title" value="VIP">
|
|
|
|
|
<iframe id="billet-preview-frame" src="/preview"></iframe>
|
|
|
|
|
<button id="billet-save-design"></button>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
initBilletDesigner()
|
|
|
|
|
document.getElementById('billet-save-design').click()
|
|
|
|
|
|
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith('/save', expect.objectContaining({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
}))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('save does nothing without save url', () => {
|
|
|
|
|
const fetchMock = vi.fn()
|
|
|
|
|
globalThis.fetch = fetchMock
|
|
|
|
|
|
|
|
|
|
document.body.innerHTML = `
|
|
|
|
|
<div id="billet-designer" data-preview-url="/preview">
|
|
|
|
|
<input type="color" name="accent_color" value="#4f46e5">
|
|
|
|
|
<iframe id="billet-preview-frame" src="/preview"></iframe>
|
|
|
|
|
<button id="billet-save-design"></button>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
initBilletDesigner()
|
|
|
|
|
document.getElementById('billet-save-design').click()
|
|
|
|
|
|
|
|
|
|
expect(fetchMock).not.toHaveBeenCalled()
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-21 12:28:30 +01:00
|
|
|
it('save includes non-checkbox input values in form data', () => {
|
|
|
|
|
const fetchMock = vi.fn().mockResolvedValue({ ok: true })
|
|
|
|
|
globalThis.fetch = fetchMock
|
|
|
|
|
|
|
|
|
|
document.body.innerHTML = `
|
|
|
|
|
<div id="billet-designer" data-preview-url="/preview" data-save-url="/save">
|
|
|
|
|
<input type="text" name="invitation_title" value="VIP Pass">
|
|
|
|
|
<iframe id="billet-preview-frame" src="/preview"></iframe>
|
|
|
|
|
<button id="billet-save-design"></button>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
initBilletDesigner()
|
|
|
|
|
document.getElementById('billet-save-design').click()
|
|
|
|
|
|
|
|
|
|
const formData = fetchMock.mock.calls[0][1].body
|
|
|
|
|
expect(formData.get('invitation_title')).toBe('VIP Pass')
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-21 12:27:00 +01:00
|
|
|
it('save includes checkbox values in form data', () => {
|
|
|
|
|
const fetchMock = vi.fn().mockResolvedValue({ ok: true })
|
|
|
|
|
globalThis.fetch = fetchMock
|
|
|
|
|
|
|
|
|
|
document.body.innerHTML = `
|
|
|
|
|
<div id="billet-designer" data-preview-url="/preview" data-save-url="/save">
|
|
|
|
|
<input type="checkbox" name="show_logo" checked>
|
|
|
|
|
<input type="color" name="accent_color" value="#000000">
|
|
|
|
|
<iframe id="billet-preview-frame" src="/preview"></iframe>
|
|
|
|
|
<button id="billet-save-design"></button>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
initBilletDesigner()
|
|
|
|
|
document.getElementById('billet-save-design').click()
|
|
|
|
|
|
|
|
|
|
expect(fetchMock).toHaveBeenCalled()
|
|
|
|
|
const formData = fetchMock.mock.calls[0][1].body
|
|
|
|
|
expect(formData.get('show_logo')).toBe('1')
|
|
|
|
|
expect(formData.get('accent_color')).toBe('#000000')
|
|
|
|
|
})
|
Add Billet entity, BilletDesign, ticket designer, CRUD billets, commissions
- Create Billet entity: name, position, priceHT, quantity (nullable=unlimited),
isGeneratedBillet, hasDefinedExit, notBuyable, type (billet/reservation_brocante/vote),
stripeProductId, description, picture (VichUploader), category (ManyToOne CASCADE)
- Create BilletDesign entity (OneToOne Event): accentColor, invitationTitle, invitationColor
- Billet CRUD: add/edit/delete with access control, Stripe product sync on connected account
- Billet reorder: drag & drop with position field, refactored sortable.js for both categories and billets
- Ticket designer tab (custom offer only): accent color, invitation title/color, live iframe preview
- A4 ticket preview: 4 zones (HG infos+billet, HD affiche, BG association, BD sortie+invitation), fake QR code SVG
- Commission calculator JS: live breakdown of E-Ticket fee, Stripe fee (1.5%+0.25EUR), net amount
- Sales recap on categories tab: qty sold, total HT, total commissions, total net
- DisableProfilerSubscriber: disable web profiler toolbar on preview iframe
- CSP: allow self in frame-src and frame-ancestors for preview iframe
- Flysystem: dedicated billets.storage for billet images
- Upload accept restricted to png/jpeg/webp/gif (no HEIC)
- Makefile: add force_sql_dev command
- CLAUDE.md: add rule to never modify existing migrations
- Consolidate all migrations into single Version20260321111125
- Tests: BilletTest (20), BilletDesignTest (6), DisableProfilerSubscriberTest (5),
billet-designer.test.js (7), commission-calculator.test.js (7),
AccountControllerTest billet CRUD tests (11)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 12:19:46 +01:00
|
|
|
})
|