fix: close final viewer integration gaps (#5)

This commit is contained in:
2026-07-29 10:14:09 +09:00
parent cadbd5fb60
commit 8ae7c45e9a
9 changed files with 196 additions and 28 deletions
+11 -13
View File
@@ -1,28 +1,26 @@
import { readFile } from 'node:fs/promises';
import { describe, expect, it } from 'vitest';
import { isCad2DFile, parseCad } from '@hmwebviewer/viewer2d';
import { describe, expect, it, vi } from 'vitest';
import { isCad2DFile, loadCad } from '@hmwebviewer/viewer2d';
describe('viewer2d package interface', () => {
it('parses the sample DXF through the public package interface', async () => {
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 result = await parseCad({
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),
});
const entities = result.entities as Array<{ layer?: string; type?: string }>;
expect(isCad2DFile('drawing.DWG')).toBe(true);
expect(isCad2DFile('drawing.dxf')).toBe(true);
expect(isCad2DFile('drawing.pdf')).toBe(false);
expect(entities.map(({ type, layer }) => [type, layer])).toEqual([
['LINE', 'OUTLINE'],
['LINE', 'OUTLINE'],
['LINE', 'OUTLINE'],
['LINE', 'OUTLINE'],
['CIRCLE', '0'],
['TEXT', '0'],
]);
expect(summary).toEqual({ entityCount: 6 });
expect(viewer.load).toHaveBeenCalledOnce();
expect(viewer.resize).toHaveBeenCalledOnce();
});
});