import { describe, it, expect, beforeEach, vi } from 'vitest'
import { initEventMap } from '../../assets/modules/event-map.js'

describe('initEventMap', () => {
    beforeEach(() => {
        document.body.innerHTML = ''
        document.head.innerHTML = ''
    })

    it('does nothing without map element', () => {
        expect(() => initEventMap()).not.toThrow()
    })

    it('does nothing without data-address', () => {
        document.body.innerHTML = '<div id="event-map"></div>'
        expect(() => initEventMap()).not.toThrow()
    })

    it('loads leaflet css and js when map element exists', () => {
        document.body.innerHTML = '<div id="event-map" data-address="12 rue test, 75001 Paris"></div>'

        initEventMap()

        const link = document.querySelector('link[rel="stylesheet"]')
        expect(link).not.toBeNull()
        expect(link.href).toContain('leaflet')

        const script = document.querySelector('script')
        expect(script).not.toBeNull()
        expect(script.src).toContain('leaflet')
    })
})
