mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-10 01:09:43 +02:00
fix(preview): address review of the XLSX preview
- Normalize the value shapes ExcelJS loads before formatting: Date cells are formatted from their serial (UTC), so they no longer render as a local-time string a day early at negative UTC offsets; rich text joins its runs, hyperlinks show their text, error values show the error, and formula and shared-formula results (including error results) recurse. Excel serials are rounded to whole milliseconds so 00:05 no longer shows as 00:04. - sendTile() skips hidden rows and columns, and at the 2500-cell cap returns a truncated tile with a warning instead of failing the whole preview. - ExcelJS now parses a STORE-only archive rebuilt from exactly the entries admitXlsx() inflated and counted, never the fetched bytes. Admission walks local headers while JSZip reads the central directory, so overlapping entries could show the two readers different sheets. A duplicate local entry name is refused. The theme fallback reads the admitted entry too. - Row and column headings take their size from the same axis math as cells. - Document the admission, worker-only loading and SPREADSHEET_ASSET_VERSION rules in architecture-invariants, and list .xlsx in the attachments panel help and the `codeman attach` error text (built from the accepted list).
This commit is contained in:
@@ -225,6 +225,63 @@ describe('spreadsheet preview renderer', () => {
|
||||
expect(document.body.textContent).not.toContain('old cell');
|
||||
});
|
||||
|
||||
it('sizes row and column headings from the same axis math as the cells', async () => {
|
||||
const fetchMock = vi.fn(async () => ({ ok: true, arrayBuffer: async () => new ArrayBuffer(8) }));
|
||||
const renderer = loadRenderer(fetchMock);
|
||||
renderer.open({ container: document.querySelector('#preview'), url: '/book.xlsx', size: 8 });
|
||||
const worker = WorkerMock.instances[0];
|
||||
worker.emit({ type: 'ready' });
|
||||
await vi.waitFor(() => expect(worker.postMessage).toHaveBeenCalled());
|
||||
// Column B 18 wide and row 2 30pt tall, as the worker reports the fixture in
|
||||
// spreadsheet-preview-worker.test.ts; row 3 and column C hidden.
|
||||
worker.emit({
|
||||
type: 'metadata',
|
||||
styles: [],
|
||||
sheets: [
|
||||
{
|
||||
id: '1',
|
||||
name: 'Summary',
|
||||
rows: 4,
|
||||
cols: 4,
|
||||
defaultRowHeight: 20,
|
||||
defaultColumnWidth: 64,
|
||||
rowOverrides: [
|
||||
[2, 40],
|
||||
[3, 0],
|
||||
],
|
||||
columnOverrides: [
|
||||
[2, 126],
|
||||
[3, 0],
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
const request = worker.postMessage.mock.calls.at(-1)?.[0];
|
||||
worker.emit({
|
||||
type: 'tile',
|
||||
requestId: request.requestId,
|
||||
sheetId: '1',
|
||||
cells: [{ row: 2, col: 2, text: 'B2', styleId: 0 }],
|
||||
warnings: [],
|
||||
});
|
||||
const cell = document.querySelector('.spreadsheet-cell') as HTMLElement;
|
||||
const heading = (selector: string, text: string) =>
|
||||
[...document.querySelectorAll(selector)].find((element) => element.textContent === text) as
|
||||
| HTMLElement
|
||||
| undefined;
|
||||
const columnB = heading('.spreadsheet-column-heading', 'B');
|
||||
const row2 = heading('.spreadsheet-row-heading', '2');
|
||||
expect(columnB?.style.width).toBe(cell.style.width);
|
||||
expect(columnB?.style.left).toBe(cell.style.left);
|
||||
expect(row2?.style.height).toBe(cell.style.height);
|
||||
expect(row2?.style.top).toBe(cell.style.top);
|
||||
expect(heading('.spreadsheet-column-heading', 'A')?.style.width).toBe('64px');
|
||||
expect(heading('.spreadsheet-row-heading', '1')?.style.height).toBe('20px');
|
||||
// A hidden row or column has no size, so it gets no heading at all.
|
||||
expect(heading('.spreadsheet-column-heading', 'C')).toBeUndefined();
|
||||
expect(heading('.spreadsheet-row-heading', '3')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('emits colour and background together or not at all', async () => {
|
||||
const fetchMock = vi.fn(async () => ({ ok: true, arrayBuffer: async () => new ArrayBuffer(8) }));
|
||||
const renderer = loadRenderer(fetchMock);
|
||||
|
||||
Reference in New Issue
Block a user