mirror of
https://github.com/navidrome/navidrome.git
synced 2025-08-10 00:52:20 +00:00
Some checks failed
Pipeline: Test, Lint, Build / Get version info (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test JS code (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint i18n files (push) Has been cancelled
Pipeline: Test, Lint, Build / Check Docker configuration (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v5) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v6) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v7) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Push Docker manifest (push) Has been cancelled
Pipeline: Test, Lint, Build / Build Windows installers (push) Has been cancelled
Pipeline: Test, Lint, Build / Package/Release (push) Has been cancelled
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Has been cancelled
Signed-off-by: Deluan <deluan@navidrome.org>
87 lines
2.2 KiB
JavaScript
87 lines
2.2 KiB
JavaScript
import React from 'react'
|
|
import { render } from '@testing-library/react'
|
|
import { PathField } from './PathField'
|
|
import { usePermissions, useRecordContext } from 'react-admin'
|
|
import config from '../config'
|
|
|
|
// Mock react-admin hooks
|
|
vi.mock('react-admin', () => ({
|
|
usePermissions: vi.fn(),
|
|
useRecordContext: vi.fn(),
|
|
}))
|
|
|
|
// Mock config
|
|
vi.mock('../config', () => ({
|
|
default: {
|
|
separator: '/',
|
|
},
|
|
}))
|
|
|
|
describe('PathField', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('renders path without libraryPath for non-admin users', () => {
|
|
// Setup
|
|
usePermissions.mockReturnValue({ permissions: 'user' })
|
|
useRecordContext.mockReturnValue({
|
|
path: 'music/song.mp3',
|
|
libraryPath: '/data/media',
|
|
})
|
|
|
|
// Act
|
|
const { container } = render(<PathField />)
|
|
|
|
// Assert
|
|
expect(container.textContent).toBe('music/song.mp3')
|
|
expect(container.textContent).not.toContain('/data/media')
|
|
})
|
|
|
|
it('renders combined path for admin users when libraryPath does not end with separator', () => {
|
|
// Setup
|
|
usePermissions.mockReturnValue({ permissions: 'admin' })
|
|
useRecordContext.mockReturnValue({
|
|
path: 'music/song.mp3',
|
|
libraryPath: '/data/media',
|
|
})
|
|
|
|
// Act
|
|
const { container } = render(<PathField />)
|
|
|
|
// Assert
|
|
expect(container.textContent).toBe('/data/media/music/song.mp3')
|
|
})
|
|
|
|
it('renders combined path for admin users when libraryPath ends with separator', () => {
|
|
// Setup
|
|
usePermissions.mockReturnValue({ permissions: 'admin' })
|
|
useRecordContext.mockReturnValue({
|
|
path: 'music/song.mp3',
|
|
libraryPath: '/data/media/',
|
|
})
|
|
|
|
// Act
|
|
const { container } = render(<PathField />)
|
|
|
|
// Assert
|
|
expect(container.textContent).toBe('/data/media/music/song.mp3')
|
|
})
|
|
|
|
it('works with a different separator from config', () => {
|
|
// Setup
|
|
config.separator = '\\'
|
|
usePermissions.mockReturnValue({ permissions: 'admin' })
|
|
useRecordContext.mockReturnValue({
|
|
path: 'music\\song.mp3',
|
|
libraryPath: 'C:\\data',
|
|
})
|
|
|
|
// Act
|
|
const { container } = render(<PathField />)
|
|
|
|
// Assert
|
|
expect(container.textContent).toBe('C:\\data\\music\\song.mp3')
|
|
})
|
|
})
|