feat: add UI components for alert dialog, badge, checkbox, dialog, label, select, sheet, table, textarea
- Implemented AlertDialog component with overlay, content, header, footer, title, description, action, and cancel functionalities. - Created Badge component with variant support for different styles. - Developed Checkbox component with custom styling and indicator. - Added Dialog component with trigger, close, overlay, content, header, footer, title, and description. - Introduced Label component for form elements. - Built Select component with trigger, content, group, item, label, separator, and scroll buttons. - Created Sheet component with trigger, close, overlay, content, header, footer, title, and description. - Implemented Table component with header, body, footer, row, head, cell, and caption. - Added Textarea component with custom styling. - Established API service for game management with CRUD operations and metadata search functionalities. - Updated dependencies in package lock files.
This commit is contained in:
@@ -11,8 +11,7 @@ vi.mock('../../src/services/checksumService', () => ({
|
||||
|
||||
vi.mock('../../src/plugins/prisma', () => ({
|
||||
default: {
|
||||
game: { findUnique: vi.fn(), create: vi.fn() },
|
||||
romFile: { upsert: vi.fn() },
|
||||
game: { findFirst: vi.fn(), create: vi.fn(), update: vi.fn() },
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -31,7 +30,7 @@ describe('services/importService', () => {
|
||||
expect(typeof importDirectory).toBe('function');
|
||||
});
|
||||
|
||||
it('cuando hay un archivo y persist:true crea Game y hace romFile.upsert, y devuelve resumen', async () => {
|
||||
it('cuando hay un archivo y persist:true crea Game con source=rom y devuelve resumen', async () => {
|
||||
const files = [
|
||||
{
|
||||
path: '/roms/Sonic.bin',
|
||||
@@ -48,32 +47,104 @@ describe('services/importService', () => {
|
||||
(scanDirectory as unknown as Mock).mockResolvedValue(files);
|
||||
(computeHashes as unknown as Mock).mockResolvedValue(hashes);
|
||||
|
||||
(prisma.game.findUnique as unknown as Mock).mockResolvedValue(null);
|
||||
(prisma.game.findFirst as unknown as Mock).mockResolvedValue(null);
|
||||
(prisma.game.create as unknown as Mock).mockResolvedValue({
|
||||
id: 77,
|
||||
title: 'Sonic',
|
||||
slug: 'sonic',
|
||||
});
|
||||
(prisma.romFile.upsert as unknown as Mock).mockResolvedValue({ id: 1 });
|
||||
|
||||
const summary = await importDirectory({ dir: '/roms', persist: true });
|
||||
|
||||
expect((scanDirectory as unknown as Mock).mock.calls[0][0]).toBe('/roms');
|
||||
expect((computeHashes as unknown as Mock).mock.calls[0][0]).toBe('/roms/Sonic.bin');
|
||||
|
||||
expect((prisma.game.findUnique as unknown as Mock).mock.calls[0][0]).toEqual({
|
||||
where: { slug: 'sonic' },
|
||||
expect((prisma.game.findFirst as unknown as Mock).mock.calls[0][0]).toEqual({
|
||||
where: { source: 'rom', romChecksum: 'md5-abc' },
|
||||
});
|
||||
expect((prisma.game.create as unknown as Mock).mock.calls[0][0]).toEqual({
|
||||
data: { title: 'Sonic', slug: 'sonic' },
|
||||
data: {
|
||||
title: 'Sonic',
|
||||
slug: 'sonic-1234567890123',
|
||||
source: 'rom',
|
||||
romPath: '/roms/Sonic.bin',
|
||||
romFilename: 'Sonic.bin',
|
||||
romSize: 123,
|
||||
romChecksum: 'md5-abc',
|
||||
romFormat: 'bin',
|
||||
romHashes: JSON.stringify(hashes),
|
||||
addedAt: expect.any(Date),
|
||||
lastSeenAt: expect.any(Date),
|
||||
},
|
||||
});
|
||||
expect((prisma.romFile.upsert as unknown as Mock).mock.calls.length).toBe(1);
|
||||
const upsertArgs = (prisma.romFile.upsert as unknown as Mock).mock.calls[0][0];
|
||||
expect(upsertArgs.where).toEqual({ checksum: 'md5-abc' });
|
||||
expect(upsertArgs.create.gameId).toBe(77);
|
||||
expect(upsertArgs.create.filename).toBe('Sonic.bin');
|
||||
expect(upsertArgs.create.hashes).toBe(JSON.stringify(hashes));
|
||||
|
||||
expect(summary).toEqual({ processed: 1, createdCount: 1, upserted: 1 });
|
||||
expect(summary).toEqual({ processed: 1, createdCount: 1, upserted: 0 });
|
||||
});
|
||||
|
||||
it('cuando el juego ya existe (mismo checksum), actualiza lastSeenAt', async () => {
|
||||
const files = [
|
||||
{
|
||||
path: '/roms/Sonic.bin',
|
||||
filename: 'Sonic.bin',
|
||||
name: 'Sonic.bin',
|
||||
size: 123,
|
||||
format: 'bin',
|
||||
isArchive: false,
|
||||
},
|
||||
];
|
||||
|
||||
const hashes = { size: 123, md5: 'md5-abc', sha1: 'sha1-abc', crc32: 'abcd' };
|
||||
|
||||
(scanDirectory as unknown as Mock).mockResolvedValue(files);
|
||||
(computeHashes as unknown as Mock).mockResolvedValue(hashes);
|
||||
|
||||
(prisma.game.findFirst as unknown as Mock).mockResolvedValue({
|
||||
id: 77,
|
||||
title: 'Sonic',
|
||||
slug: 'sonic',
|
||||
});
|
||||
(prisma.game.update as unknown as Mock).mockResolvedValue({
|
||||
id: 77,
|
||||
title: 'Sonic',
|
||||
slug: 'sonic',
|
||||
});
|
||||
|
||||
const summary = await importDirectory({ dir: '/roms', persist: true });
|
||||
|
||||
expect((prisma.game.update as unknown as Mock).mock.calls[0][0]).toEqual({
|
||||
where: { id: 77 },
|
||||
data: {
|
||||
lastSeenAt: expect.any(Date),
|
||||
romHashes: JSON.stringify(hashes),
|
||||
},
|
||||
});
|
||||
|
||||
expect(summary).toEqual({ processed: 1, createdCount: 0, upserted: 1 });
|
||||
});
|
||||
|
||||
it('cuando persist=false no guarda nada en la base de datos', async () => {
|
||||
const files = [
|
||||
{
|
||||
path: '/roms/Sonic.bin',
|
||||
filename: 'Sonic.bin',
|
||||
name: 'Sonic.bin',
|
||||
size: 123,
|
||||
format: 'bin',
|
||||
isArchive: false,
|
||||
},
|
||||
];
|
||||
|
||||
const hashes = { size: 123, md5: 'md5-abc', sha1: 'sha1-abc', crc32: 'abcd' };
|
||||
|
||||
(scanDirectory as unknown as Mock).mockResolvedValue(files);
|
||||
(computeHashes as unknown as Mock).mockResolvedValue(hashes);
|
||||
|
||||
const summary = await importDirectory({ dir: '/roms', persist: false });
|
||||
|
||||
expect(prisma.game.findFirst).not.toHaveBeenCalled();
|
||||
expect(prisma.game.create).not.toHaveBeenCalled();
|
||||
expect(prisma.game.update).not.toHaveBeenCalled();
|
||||
|
||||
expect(summary).toEqual({ processed: 1, createdCount: 0, upserted: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user