mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-08 17:26:41 +08:00
fix(classification): avoid duplicate uncategorized label
This commit is contained in:
@@ -189,6 +189,18 @@ describe('ClassificationCategoryEditor', () => {
|
||||
await waitFor(() => expect(events.updateFallbacks).toHaveBeenCalledWith({ 音乐: 'music.lossless' }))
|
||||
})
|
||||
|
||||
it('默认分类选项不会重复显示路径中的分类名称', async () => {
|
||||
const user = userEvent.setup()
|
||||
await renderEditor({
|
||||
categories: [createCategory('tv.uncategorized', '电视剧', '未分类', ['未分类', '通用'])],
|
||||
})
|
||||
|
||||
await user.click(screen.getByRole('combobox', { name: '电视剧默认分类' }))
|
||||
|
||||
expect(await screen.findByRole('option', { name: '未分类 · 通用' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('option', { name: '未分类 · 未分类 / 通用' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('路径超过最大深度时保留草稿并拒绝发出分类更新', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { events } = await renderEditor({ maxDepth: 2 })
|
||||
|
||||
@@ -27,6 +27,16 @@ describe('formatClassificationCategoryOptionTitle', () => {
|
||||
).toBe('华语电影 · 电影')
|
||||
})
|
||||
|
||||
it('removes a repeated category name from any path segment', () => {
|
||||
expect(
|
||||
formatClassificationCategoryOptionTitle({
|
||||
id: 'tv.uncategorized',
|
||||
name: '未分类',
|
||||
path: ['未分类', '通用'],
|
||||
}),
|
||||
).toBe('未分类 · 通用')
|
||||
})
|
||||
|
||||
it('can preserve a caller-specific path separator and stable ID', () => {
|
||||
expect(
|
||||
formatClassificationCategoryOptionTitle(
|
||||
|
||||
@@ -14,13 +14,12 @@ interface ClassificationCategoryOptionTitleOptions {
|
||||
pathSeparator?: string
|
||||
}
|
||||
|
||||
/** 生成分类选择器标题,避免分类名与路径末级名称重复显示。 */
|
||||
/** 生成分类选择器标题,避免分类名与路径中的同名段重复显示。 */
|
||||
export function formatClassificationCategoryOptionTitle(
|
||||
category: Pick<ClassificationCategory, 'name' | 'path' | 'id'>,
|
||||
options: ClassificationCategoryOptionTitleOptions = {},
|
||||
): string {
|
||||
const pathSegments = [...category.path]
|
||||
while (pathSegments[pathSegments.length - 1] === category.name) pathSegments.pop()
|
||||
const pathSegments = category.path.filter(segment => segment !== category.name)
|
||||
const path = pathSegments.join(options.pathSeparator ?? ' / ')
|
||||
const displayPath = path || (category.path.length ? '' : (options.emptyPathLabel ?? ''))
|
||||
const parts = [category.name, displayPath]
|
||||
|
||||
Reference in New Issue
Block a user