Spaces:
Sleeping
Sleeping
File size: 5,446 Bytes
7dc28be | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | import { describe, expect, it } from 'vitest';
import { extractTableSnapshot, findTableNearestStartIndex } from './structureHelpers.js';
import { readFileSync } from 'node:fs';
const mockDocument = {
body: {
content: [
{
startIndex: 10,
endIndex: 100,
table: {
rows: 2,
columns: 2,
tableStyle: {
tableColumnProperties: [
{ widthType: 'FIXED_WIDTH', width: { magnitude: 60, unit: 'PT' } },
{ widthType: 'FIXED_WIDTH', width: { magnitude: 180, unit: 'PT' } },
],
},
tableRows: [
{
tableRowStyle: {
minRowHeight: { magnitude: 24, unit: 'PT' },
tableHeader: true,
},
tableCells: [
{
startIndex: 15,
endIndex: 25,
tableCellStyle: {
backgroundColor: { color: { rgbColor: { red: 0.85, green: 0.9, blue: 0.95 } } },
contentAlignment: 'MIDDLE',
paddingTop: { magnitude: 6, unit: 'PT' },
},
content: [
{
paragraph: {
elements: [
{
startIndex: 16,
endIndex: 19,
textRun: {
content: 'No.\n',
textStyle: { bold: true },
},
},
],
},
},
],
},
{
startIndex: 25,
endIndex: 45,
content: [
{
paragraph: {
elements: [
{
startIndex: 26,
endIndex: 30,
textRun: {
content: '課題名\n',
textStyle: { bold: true },
},
},
],
},
},
],
},
],
},
{
tableCells: [
{
startIndex: 45,
endIndex: 55,
content: [
{
paragraph: {
elements: [{ startIndex: 46, endIndex: 47, textRun: { content: '1\n' } }],
},
},
],
},
{
startIndex: 55,
endIndex: 95,
content: [
{
paragraph: {
elements: [
{
startIndex: 56,
endIndex: 69,
textRun: { content: 'SHIN-2870 調査\n' },
},
],
},
},
],
},
],
},
],
},
},
{
startIndex: 120,
endIndex: 180,
table: {
rows: 1,
columns: 1,
tableRows: [
{
tableCells: [
{
startIndex: 125,
endIndex: 135,
content: [
{
paragraph: {
elements: [{ startIndex: 126, endIndex: 130, textRun: { content: 'X\n' } }],
},
},
],
},
],
},
],
},
},
],
},
} as any;
describe('table snapshot helpers', () => {
it('extracts a reusable table snapshot with styles', () => {
const snapshot = extractTableSnapshot(mockDocument, 'table:body:0');
expect(snapshot).toMatchObject({
tableId: 'table:body:0',
rowCount: 2,
columnCount: 2,
pinnedHeaderRowsCount: 1,
data: [
['No.', '課題名'],
['1', 'SHIN-2870 調査'],
],
columnStyles: [
{ columnIndex: 0, widthPt: 60, widthType: 'FIXED_WIDTH' },
{ columnIndex: 1, widthPt: 180, widthType: 'FIXED_WIDTH' },
],
});
expect(snapshot?.rowStyles[0]).toMatchObject({
rowIndex: 0,
minRowHeightPt: 24,
tableHeader: true,
});
expect(snapshot?.cellStyles[0]).toMatchObject({
rowIndex: 0,
columnIndex: 0,
contentAlignment: 'MIDDLE',
paddingTopPt: 6,
hasBoldText: true,
});
});
it('finds the table nearest to an insertion index', () => {
const table = findTableNearestStartIndex(mockDocument, 100);
expect(table?.tableId).toBe('table:body:1');
});
it('requests tab table text and contentAlignment with the same structure as body tables', () => {
const source = readFileSync(new URL('./cloneTable.ts', import.meta.url), 'utf8');
expect(source).toContain(
'contentAlignment,paddingTop,paddingBottom,paddingLeft,paddingRight,rowSpan,columnSpan),content(paragraph('
);
});
});
|