import { readFile } from 'node:fs/promises'; import { describe, expect, it, vi } from 'vitest'; import { isCad2DFile, loadCad } from '@hmwebviewer/viewer2d'; describe('viewer2d package interface', () => { it('parses and loads the sample DXF without exposing the parser result', async () => { const file = await readFile( new URL('../apps/viewer-2d-sample/public/samples/simple.dxf', import.meta.url), ); const viewer = { load: vi.fn(), resize: vi.fn(), }; const summary = await loadCad(viewer, { name: 'simple.dxf', data: file.buffer.slice(file.byteOffset, file.byteOffset + file.byteLength), }); expect(isCad2DFile('drawing.DWG')).toBe(true); expect(isCad2DFile('drawing.dxf')).toBe(true); expect(isCad2DFile('drawing.pdf')).toBe(false); expect(summary).toEqual({ entityCount: 6 }); expect(viewer.load).toHaveBeenCalledOnce(); expect(viewer.resize).toHaveBeenCalledOnce(); }); });