Skip to content

🎧 Your Personal Streaming Service

fix(ui): honor EnableCoverAnimation for theme cover animations (#6234)

Matt Van Horna62d1629f0ff
diff --git a/ui/src/album/AlbumDetails.jsx b/ui/src/album/AlbumDetails.jsx
index 7fbc479db..8d636a047 100644
--- a/ui/src/album/AlbumDetails.jsx
+++ b/ui/src/album/AlbumDetails.jsx
@@ -16,6 +16,7 @@ import {
useRecordContext,
useTranslate,
} from 'react-admin'
+import clsx from 'clsx'
import Lightbox from 'react-image-lightbox'
import config from '../config'
import 'react-image-lightbox/style.css'
@@ -79,6 +80,9 @@ const useStyles = makeStyles(
alignItems: 'center',
justifyContent: 'center',
},
+ noCoverAnimation: {
+ '&, &::before, &::after': { animation: 'none' },
+ },
cover: {
objectFit: 'contain',
cursor: 'pointer',
@@ -250,7 +254,12 @@ const AlbumDetails = (props) => {
return (
<Card className={classes.root}>
<div className={classes.cardContents}>
- <div className={classes.coverParent}>
+ <div
+ className={clsx(
+ classes.coverParent,
+ !config.enableCoverAnimation && classes.noCoverAnimation,
+ )}
+ >
<Artwork
record={record}
fit="contain"
diff --git a/ui/src/album/AlbumDetails.test.jsx b/ui/src/album/AlbumDetails.test.jsx
index 484045444..afc4bf0a0 100644
--- a/ui/src/album/AlbumDetails.test.jsx
+++ b/ui/src/album/AlbumDetails.test.jsx
@@ -3,7 +3,29 @@ import { describe, test, expect, beforeEach, afterEach } from 'vitest'
import { render } from '@testing-library/react'
import { RecordContextProvider } from 'react-admin'
import { useMediaQuery } from '@material-ui/core'
-import { Details } from './AlbumDetails'
+import { createTheme, ThemeProvider } from '@material-ui/core/styles'
+import config from '../config'
+import AlbumDetails, { Details } from './AlbumDetails'
+
+vi.mock('../subsonic', () => ({
+ default: {
+ getAlbumInfo: () =>
+ Promise.resolve({
+ json: { 'subsonic-response': { status: 'ok', albumInfo: {} } },
+ }),
+ getCoverArtUrl: () => '',
+ },
+}))
+
+vi.mock('react-admin', async () => {
+ const actual = await vi.importActual('react-admin')
+ return {
+ ...actual,
+ useDataProvider: () => ({ getOne: vi.fn() }),
+ useNotify: () => vi.fn(),
+ useRefresh: () => vi.fn(),
+ }
+})
// Mock useMediaQuery
vi.mock('@material-ui/core', async () => {
@@ -343,3 +365,49 @@ describe('Details component', () => {
})
})
})
+
+describe('AlbumDetails cover animation', () => {
+ const albumRecord = {
+ id: '123',
+ name: 'Test Album',
+ songCount: 12,
+ duration: 3600,
+ size: 102400,
+ }
+ const originalEnableCoverAnimation = config.enableCoverAnimation
+
+ beforeEach(() => {
+ vi.mocked(useMediaQuery).mockReturnValue(false)
+ })
+
+ afterEach(() => {
+ config.enableCoverAnimation = originalEnableCoverAnimation
+ })
+
+ const renderAlbum = () =>
+ render(
+ <ThemeProvider theme={createTheme()}>
+ <RecordContextProvider value={albumRecord}>
+ <AlbumDetails />
+ </RecordContextProvider>
+ </ThemeProvider>,
+ )
+
+ test('applies noCoverAnimation when enableCoverAnimation is false', () => {
+ config.enableCoverAnimation = false
+ const { container } = renderAlbum()
+ const cover = container.querySelector('[class*="coverParent"]')
+
+ expect(cover).not.toBeNull()
+ expect(cover.className).toMatch(/noCoverAnimation/)
+ })
+
+ test('omits noCoverAnimation when enableCoverAnimation is true', () => {
+ config.enableCoverAnimation = true
+ const { container } = renderAlbum()
+ const cover = container.querySelector('[class*="coverParent"]')
+
+ expect(cover).not.toBeNull()
+ expect(cover.className).not.toMatch(/noCoverAnimation/)
+ })
+})