// @vitest-environment happy-dom
import { describe, it, expect } from 'vitest'

import ActiveDownloadsPanel from '../../src/components/subscriptions/ActiveDownloadsPanel.vue'
import { useDownloadsStore } from '../../src/stores/downloads.js'
import { freshPinia, mountComponent } from '../support/mountComponent.js'

describe('ActiveDownloadsPanel', () => {
  it('lists a running download with its artist', () => {
    const pinia = freshPinia()
    useDownloadsStore().activeEvents = [{
      id: 1, status: 'running',
      started_at: new Date(Date.now() - 65000).toISOString(),
      platform: 'patreon', artist_name: 'Alice',
    }]
    const w = mountComponent(ActiveDownloadsPanel, { pinia })
    const t = w.text()
    expect(t).toContain('Alice')
    expect(t).toContain('downloading')
    w.unmount() // clear the 1s elapsed-timer interval
  })

  it('renders nothing when there is no active work', () => {
    const pinia = freshPinia()
    useDownloadsStore().activeEvents = []
    const w = mountComponent(ActiveDownloadsPanel, { pinia })
    expect(w.text()).toBe('')
    w.unmount()
  })
})
