Files
basic-erp/apps/web/src/app/features/masters/master-extensions.spec.ts
T

43 lines
2.5 KiB
TypeScript
Raw Normal View History

import { describe, expect, it } from 'vitest';
import { MASTER_EXTENSIONS, BASE_MASTER_SCREENS, MASTER_SCREENS } from './master-screens';
import { type MasterExtensions, applyMasterExtensions } from './master-extensions';
import { masterKeysOf } from './master-model';
const by = (screens: readonly { path: string }[], path: string) => screens.find((s) => s.path === path)! as (typeof BASE_MASTER_SCREENS)[number];
const EXT: MasterExtensions = {
'/socios/clientes': {
header: { right: [{ type: 'text', key: 'U_Ref', label: 'Ref.' }] },
tabs: { general: { right: [{ type: 'text', key: 'U_Zona', label: 'Zona' }] }, pago: { left: [{ type: 'number', key: 'U_Cupo', label: 'Cupo' }] } },
newTabs: [{ id: 'extra', label: 'Extra', left: [{ type: 'checkbox', key: 'U_Vip', label: 'VIP' }], right: [] }],
listColumns: [{ key: 'U_Zona', title: 'Zona', searchable: true }],
},
};
describe('extensiones por cliente de los maestros', () => {
it('en main no agregan nada', () => {
expect(MASTER_EXTENSIONS).toEqual({});
expect(MASTER_SCREENS).toEqual(BASE_MASTER_SCREENS);
});
it('agregan campos al final de la cabecera y de las pestañas, una pestaña nueva y columnas de lista', () => {
const s = by(applyMasterExtensions(BASE_MASTER_SCREENS, EXT), '/socios/clientes');
expect(s.layout.header.right.at(-1)).toMatchObject({ key: 'U_Ref' });
expect(s.layout.tabs.find((t) => t.id === 'general')!.right.at(-1)).toMatchObject({ key: 'U_Zona' });
expect(s.layout.tabs.find((t) => t.id === 'pago')!.left.at(-1)).toMatchObject({ key: 'U_Cupo' });
expect(s.layout.tabs.at(-1)).toMatchObject({ id: 'extra' });
expect(s.columns.at(-1)).toMatchObject({ key: 'U_Zona' });
expect(masterKeysOf(s.layout)).toEqual(expect.arrayContaining(['U_Ref', 'U_Zona', 'U_Cupo', 'U_Vip']));
});
it('solo cambia la pantalla extendida', () => {
const out = applyMasterExtensions(BASE_MASTER_SCREENS, EXT);
expect(by(out, '/socios/proveedores')).toEqual(by(BASE_MASTER_SCREENS, '/socios/proveedores'));
expect(masterKeysOf(by(BASE_MASTER_SCREENS, '/socios/clientes').layout)).not.toContain('U_Zona');
});
it('una ruta o una pestaña que no existen son un error', () => {
expect(() => applyMasterExtensions(BASE_MASTER_SCREENS, { '/socios/clientez': { listColumns: [] } })).toThrow(/no existe la pantalla/);
expect(() => applyMasterExtensions(BASE_MASTER_SCREENS, { '/socios/clientes': { tabs: { nada: { left: [] } } } })).toThrow(/no tiene la pestaña/);
});
});