fix(preview): satisfy strict spreadsheet lint

This commit is contained in:
yudshj committed 2026-09-21 15:35:57 +08:00
1 parent ad9f77db04
commit 61a0acc4da
4 files changed
+20 -17

No files matched your search

@@ -7,7 +7,8 @@ import { formatCell, initialSelection, type ExcelLimits, type ExcelPreview } fro
set_cptable(codepages)
// SheetJS publishes SSF as `any`; this is the one formatter capability used by the adapter.
const isDateFormat: (format: string) => boolean = SSF.is_date
const spreadsheetFormatter = SSF as { is_date(format: string): boolean }
const isDateFormat = (format: string) => spreadsheetFormatter.is_date(format)
/**
* Decode a binary XLS workbook without accepting renamed text or HTML files.
@@ -26,17 +26,17 @@ describe('Excel conversion', () => {
expect(first.frozen).toEqual({ type: 'rangeBoth', range: { row_focus: 1, column_focus: 0 } })
expect(first.luckysheet_select_save).toEqual([{ row: [0, 0], column: [0, 3], row_focus: 0, column_focus: 0 }])
const second = sheets[1]!
const secondCell = (r: number, c: number) => second.celldata!.find(value => value.r === r && value.c === c)!.v!
expect(second.luckysheet_select_save).toEqual([{ row: [0, 0], column: [0, 0], row_focus: 0, column_focus: 0 }])
expect(second.celldata).toEqual(expect.arrayContaining([
expect.objectContaining({ r: 0, c: 0, v: expect.objectContaining({ f: '=_xlfn.XLOOKUP(1,{1},{42})', v: 42, m: '42' }) }),
expect.objectContaining({ r: 1, c: 0, v: expect.objectContaining({ f: '=SUM(1,2)', m: '' }) }),
expect.objectContaining({ r: 0, c: 1, v: expect.objectContaining({ m: '2026-09-16' }) }),
expect.objectContaining({ r: 0, c: 2, v: expect.objectContaining({ v: '富文本 示例', ct: { t: 'inlineStr', s: expect.any(Array) } }) }),
expect.objectContaining({ r: 0, c: 3, v: expect.objectContaining({ v: 'Link text' }) }),
expect.objectContaining({ r: 2, c: 0, v: expect.objectContaining({ f: '=SUM(1,2)', v: 3 }) }),
expect.objectContaining({ r: 3, c: 0, v: expect.objectContaining({ v: true }) }),
expect.objectContaining({ r: 4, c: 0, v: expect.objectContaining({ v: '#DIV/0!' }) }),
]))
expect(secondCell(0, 0)).toMatchObject({ f: '=_xlfn.XLOOKUP(1,{1},{42})', v: 42, m: '42' })
expect(secondCell(1, 0)).toMatchObject({ f: '=SUM(1,2)', m: '' })
expect(secondCell(0, 1)).toMatchObject({ m: '2026-09-16' })
expect(secondCell(0, 2)).toMatchObject({ v: '富文本 示例', ct: { t: 'inlineStr' } })
expect(secondCell(0, 2).ct?.s).toBeInstanceOf(Array)
expect(secondCell(0, 3)).toMatchObject({ v: 'Link text' })
expect(secondCell(2, 0)).toMatchObject({ f: '=SUM(1,2)', v: 3 })
expect(secondCell(3, 0)).toMatchObject({ v: true })
expect(secondCell(4, 0)).toMatchObject({ v: '#DIV/0!' })
expect(second.config).toMatchObject({ rowhidden: { 6: 0 }, colhidden: { 4: 0 }, rowlen: { 6: 40 * 96 / 72 } })
expect(sheets[2]).toMatchObject({ hide: 1, status: 0 })
expect(missingResults).toBe(1)
@@ -54,12 +54,11 @@ it('maps optional row metadata, empty formula caches, errors, and Date values',
sheet['B5'] = { t: 'd', v: new Date('2024-03-01T00:00:00Z'), z: 'yyyy-mm-dd' }
sheet['C5'] = { t: 'e', v: 7, w: '#DIV/0!' }
const { sheets, missingResults } = mapXlsWorkbook(workbook, limits)
const cell = (r: number, c: number) => sheets[0]!.celldata!.find(value => value.r === r && value.c === c)!.v!
expect(sheets[0]!.config).toMatchObject({ rowlen: { 0: 40, 1: 18 }, rowhidden: { 2: 0 }, columnlen: { 0: 130 }, colhidden: { 1: 0 } })
expect(sheets[0]!.celldata).toEqual(expect.arrayContaining([
{ r: 3, c: 1, v: expect.objectContaining({ f: '=1+2', m: '' }) },
{ r: 4, c: 1, v: expect.objectContaining({ m: '2024-03-01' }) },
{ r: 4, c: 2, v: expect.objectContaining({ v: '#DIV/0!' }) },
]))
expect(cell(3, 1)).toMatchObject({ f: '=1+2', m: '' })
expect(cell(4, 1)).toMatchObject({ m: '2024-03-01' })
expect(cell(4, 2)).toMatchObject({ v: '#DIV/0!' })
expect(missingResults).toBe(1)
})
@@ -29,8 +29,11 @@ it('registers complete binary reads and removes the slot and locale on disposal'
expect(binaryDocumentPath(registry.getSnapshot(), path)).toBe(/\.(xlsx|xls)$/iu.test(path))
}
expect(registerLocale).toHaveBeenCalledWith('sidebarExcel', { zh, en })
expect(register).toHaveBeenCalledWith(expect.objectContaining({ locale: 'sidebarExcel', inject: expect.any(Function) }), LazyExcelBody)
expect(register).toHaveBeenCalledOnce()
expect(register.mock.calls[0]![1]).toBe(LazyExcelBody)
const options = register.mock.calls[0]![0] as { inject: () => unknown }
expect(options).toMatchObject({ locale: 'sidebarExcel' })
expect(options.inject).toBeTypeOf('function')
expect(options.inject()).toEqual({ limits })
} finally { await fiber.dispose() }
expect(registry.getSnapshot()).toEqual([])