import { render, screen } from '@testing-library/react'
import { beforeEach, expect, test, vi } from 'vitest'
import { initI18n } from '@/i18n'
import Spectrogram from './Spectrogram'
beforeEach(async () => {
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
await initI18n()
})
test('it is a picture with a name, and a canvas where the browser can draw', () => {
render()
const picture = screen.getByRole('img', { name: 'Spectrogram of what is playing' })
expect(picture.querySelector('canvas')).not.toBeNull()
})
test('where the browser has no Web Audio it draws nothing and breaks nothing', () => {
vi.stubGlobal('AudioContext', undefined)
expect(() => render()).not.toThrow()
})
test('it takes the colour of this server, or of a friend', () => {
const { rerender } = render()
expect(screen.getByRole('img').className).toContain('text-primary')
rerender()
expect(screen.getByRole('img').className).toContain('text-friend')
})