import * as React from 'react'
import { cleanup, render, screen } from '@testing-library/react'
import { QualityInfo } from './QualityInfo'
describe('', () => {
afterEach(cleanup)
it('only render suffix for lossless formats', () => {
const info = { suffix: 'FLAC', bitRate: 1008 }
render()
expect(screen.getByText('FLAC')).toBeInTheDocument()
})
it('only render suffix and bitrate for lossy formats', () => {
const info = {
suffix: 'MP3',
bitRate: 320,
rgAlbumGain: -5,
rgAlbumPeak: 1,
rgTrackGain: 2.3,
rgTrackPeak: 0.5,
}
render()
expect(screen.getByText('MP3 320')).toBeInTheDocument()
})
it('renders placeholder if suffix is missing', () => {
const info = {}
render()
expect(screen.getByText('N/A')).toBeInTheDocument()
})
it('does not break if record is null', () => {
render()
expect(screen.getByText('N/A')).toBeInTheDocument()
})
it('renders album gain info, no peak limit', () => {
render(
,
)
expect(screen.getByText('N/A (-5.00 dB)')).toBeInTheDocument()
})
it('renders track gain info, no peak limit capping, preAmp', () => {
render(
,
)
expect(screen.getByText('N/A (1.30 dB)')).toBeInTheDocument()
})
it('renders gain info limited by peak', () => {
render(
,
)
expect(screen.getByText('FLAC (0.00 dB)')).toBeInTheDocument()
})
it('shows transcode arrow when transcodeStream is provided', () => {
const info = { suffix: 'FLAC', bitRate: 1008 }
const transcodeStream = { codec: 'opus', audioBitrate: 128000 }
render()
expect(screen.getByText('FLAC → OPUS 128')).toBeInTheDocument()
})
it('shows transcode with lossy source including bitrate', () => {
const info = { suffix: 'FLAC', bitRate: 1008 }
const transcodeStream = { codec: 'mp3', audioBitrate: 320000 }
render()
expect(screen.getByText('FLAC → MP3 320')).toBeInTheDocument()
})
it('does not show arrow when isDirectPlay is true', () => {
const info = { suffix: 'MP3', bitRate: 320 }
render()
expect(screen.getByText('MP3 320')).toBeInTheDocument()
})
it('behaves normally when no transcode props are passed', () => {
const info = { suffix: 'MP3', bitRate: 320 }
render()
expect(screen.getByText('MP3 320')).toBeInTheDocument()
})
})