feat(dashboard): add revision-safe interactive widget grid
This commit is contained in:
@@ -1,5 +1,34 @@
|
||||
import { defaultDashboardLayout, normalizeDashboardLayout, WIDGETS } from './dashboardLayout';
|
||||
|
||||
test('legacy preferences migrate to bounded geometry while preserving order, visibility and revision', () => {
|
||||
const input = { version: 1, revision: 7, widgets: [
|
||||
{ id: 'skills', visible: false, size: 'full' },
|
||||
{ id: 'attention', visible: true, size: 'standard' },
|
||||
{ id: 'cards', visible: true, size: 'full' },
|
||||
] };
|
||||
const original = JSON.stringify(input);
|
||||
const result = normalizeDashboardLayout(input);
|
||||
expect(result.version).toBe(2);
|
||||
expect(result.revision).toBe(7);
|
||||
expect(result.widgets.map(row => row.id).slice(0, 3)).toEqual(['skills', 'attention', 'cards']);
|
||||
expect(result.widgets[0]).toMatchObject({ visible: false, size: 'full', w: 12 });
|
||||
expect(result.widgets[1]).toMatchObject({ visible: true, size: 'standard', x: 0, y: 0, w: 6 });
|
||||
expect(result.widgets[2]).toMatchObject({ visible: true, size: 'full', x: 0, w: 12 });
|
||||
expect(result.widgets.slice(3).every(row => !row.visible)).toBe(true);
|
||||
expect(normalizeDashboardLayout(input)).toEqual(result);
|
||||
expect(JSON.stringify(input)).toBe(original);
|
||||
});
|
||||
|
||||
test('schema two preserves chosen hidden geometry without resetting the owner revision', () => {
|
||||
const result = normalizeDashboardLayout({ version: 2, revision: 12, widgets: [
|
||||
{ id: 'attention', visible: false, size: 'standard', x: 4, y: 17, w: 8, h: 10 },
|
||||
] });
|
||||
expect(result.version).toBe(2);
|
||||
expect(result.revision).toBe(12);
|
||||
expect(result.widgets[0]).toEqual({ id: 'attention', visible: false, size: 'standard', x: 4, y: 17, w: 8, h: 10 });
|
||||
expect(result.widgets.slice(1).every(row => !row.visible)).toBe(true);
|
||||
});
|
||||
|
||||
test('default catalogue preserves every section and supported widths', () => {
|
||||
const layout = defaultDashboardLayout();
|
||||
expect(layout.widgets.map(w => w.id)).toEqual(['cards', 'attention', 'funnel', 'activity', 'stageAge', 'sources', 'salary', 'companies', 'skills']);
|
||||
@@ -17,12 +46,12 @@ test('saved layouts retain known order, reject duplicates and append missing sec
|
||||
{ id: 'cards', visible: 'yes', size: 'standard' },
|
||||
] });
|
||||
expect(result.revision).toBe(7);
|
||||
expect(result.widgets[0]).toEqual({ id: 'skills', visible: false, size: 'full' });
|
||||
expect(result.widgets[1]).toEqual({ id: 'cards', visible: false, size: 'full' });
|
||||
expect(result.widgets[0]).toMatchObject({ id: 'skills', visible: false, size: 'full' });
|
||||
expect(result.widgets[1]).toMatchObject({ id: 'cards', visible: false, size: 'full' });
|
||||
expect(result.widgets.slice(2).every(w => !w.visible)).toBe(true);
|
||||
expect(result.widgets).toHaveLength(9);
|
||||
});
|
||||
|
||||
test.each([null, {}, { version: 2, revision: 8, widgets: [] }, { version: 1, revision: -1, widgets: [] }])('invalid input has safe defaults: %j', input => {
|
||||
test.each([null, {}, { version: 3, revision: 8, widgets: [] }, { version: 1, revision: -1, widgets: [] }])('invalid input has safe defaults: %j', input => {
|
||||
expect(normalizeDashboardLayout(input)).toEqual(defaultDashboardLayout());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user