fix custom nav dialog restore default i18n issue

This commit is contained in:
pa
2026-03-12 21:32:20 +09:00
parent 76ff4844db
commit 6c8ed126b1
3 changed files with 215 additions and 0 deletions

View File

@@ -192,6 +192,7 @@
type: 'folder',
id: entry.id,
name: entry.name,
nameKey: entry.nameKey || null,
icon: entry.icon,
items: Array.isArray(entry.items) ? [...entry.items] : []
};
@@ -667,6 +668,7 @@
const entry = localLayout.value.find((e) => e.type === 'folder' && e.id === folderEditor.editingId);
if (entry) {
entry.name = folderEditor.data.name.trim();
entry.nameKey = null;
entry.icon = folderEditor.data.icon?.trim() || DEFAULT_FOLDER_ICON;
localLayout.value = [...localLayout.value];
}
@@ -675,6 +677,7 @@
type: 'folder',
id: folderEditor.data.id,
name: folderEditor.data.name.trim(),
nameKey: null,
icon: folderEditor.data.icon?.trim() || DEFAULT_FOLDER_ICON,
items: []
});

View File

@@ -0,0 +1,76 @@
import { describe, expect, it, vi } from 'vitest';
import { mount } from '@vue/test-utils';
vi.mock('vue-i18n', () => ({ useI18n: () => ({ t: (k) => k }) }));
vi.mock('@/shared/utils/common', () => ({ openExternalLink: vi.fn() }));
vi.mock('@/components/ui/dialog', () => ({
Dialog: { template: '<div><slot /></div>' },
DialogContent: { template: '<div><slot /></div>' },
DialogFooter: { template: '<div><slot /></div>' },
DialogHeader: { template: '<div><slot /></div>' },
DialogTitle: { template: '<div><slot /></div>' }
}));
vi.mock('@/components/ui/button', () => ({
Button: {
emits: ['click'],
template: '<button data-testid="btn" @click="$emit(\'click\')"><slot /></button>'
}
}));
vi.mock('@/components/ui/hover-card', () => ({
HoverCard: { template: '<div><slot /></div>' },
HoverCardContent: { template: '<div><slot /></div>' },
HoverCardTrigger: { template: '<div><slot /></div>' }
}));
vi.mock('@/components/ui/input-group', () => ({
InputGroupButton: { template: '<button><slot /></button>' },
InputGroupField: { template: '<input />' }
}));
vi.mock('@/components/ui/separator', () => ({ Separator: { template: '<hr />' } }));
vi.mock('@/components/ui/tree', () => ({
Tree: {
props: ['items'],
template: '<div><slot :flatten-items="[]" /></div>'
}
}));
vi.mock('@dnd-kit/vue', () => ({ DragDropProvider: { template: '<div><slot /></div>' } }));
vi.mock('@dnd-kit/vue/sortable', () => ({ isSortable: () => false }));
vi.mock('lucide-vue-next', () => new Proxy({}, { get: () => ({ template: '<i />' }) }));
vi.mock('../SortableTreeNode.vue', () => ({ default: { template: '<div />' } }));
import CustomNavDialog from '../CustomNavDialog.vue';
describe('CustomNavDialog.vue', () => {
it('keeps folder nameKey when restoring defaults and saving', async () => {
const defaultLayout = [
{
type: 'folder',
id: 'default-folder-social',
nameKey: 'nav_tooltip.social',
name: 'Social',
icon: 'ri-group-line',
items: ['friend-log']
}
];
const wrapper = mount(CustomNavDialog, {
props: {
visible: true,
layout: [],
hiddenKeys: [],
defaultLayout
}
});
const buttons = wrapper.findAll('[data-testid="btn"]');
const resetButton = buttons.find((button) => button.text().includes('nav_menu.custom_nav.restore_default'));
const saveButton = buttons.find((button) => button.text().includes('common.actions.confirm'));
await resetButton.trigger('click');
await saveButton.trigger('click');
const emitted = wrapper.emitted('save');
expect(emitted).toBeTruthy();
expect(emitted[0][0]).toEqual(defaultLayout);
expect(emitted[0][0][0].nameKey).toBe('nav_tooltip.social');
});
});