Spaces:
Sleeping
Sleeping
File size: 4,412 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 | import { describe, expect, it } from 'vitest';
import { extractDocumentTables, findHeadings, getTableById } from './structureHelpers.js';
const mockDocument = {
body: {
content: [
{
startIndex: 1,
endIndex: 25,
paragraph: {
paragraphStyle: { namedStyleType: 'HEADING_2' },
elements: [{ textRun: { content: '今回のスプリントのタスク\n' } }],
},
},
{
startIndex: 25,
endIndex: 120,
table: {
tableRows: [
{
tableCells: [
{
startIndex: 30,
endIndex: 40,
content: [
{
paragraph: {
elements: [{ textRun: { content: 'No.\n' } }],
},
},
],
},
{
startIndex: 40,
endIndex: 60,
content: [
{
paragraph: {
elements: [{ textRun: { content: '課題名\n' } }],
},
},
],
},
],
},
{
tableCells: [
{
startIndex: 60,
endIndex: 78,
content: [
{
paragraph: {
elements: [{ textRun: { content: '1\n' } }],
},
},
],
},
{
startIndex: 78,
endIndex: 118,
content: [
{
paragraph: {
elements: [{ textRun: { content: 'SHIN-2870 調査\n' } }],
},
},
],
},
],
},
],
},
},
{
startIndex: 120,
endIndex: 145,
paragraph: {
paragraphStyle: { namedStyleType: 'HEADING_2' },
elements: [{ textRun: { content: '5. TDAからTAPへの確認事項\n' } }],
},
},
],
},
} as any;
describe('structureHelpers', () => {
it('extracts tables with dimensions and cell text', () => {
const tables = extractDocumentTables(mockDocument);
expect(tables).toHaveLength(1);
expect(tables[0]).toMatchObject({
tableId: 'table:body:0',
rowCount: 2,
columnCount: 2,
startIndex: 25,
endIndex: 120,
});
expect(tables[0].cells).toEqual([
{
rowIndex: 0,
columnIndex: 0,
startIndex: 30,
endIndex: 40,
contentStartIndex: null,
contentEndIndex: null,
text: 'No.',
},
{
rowIndex: 0,
columnIndex: 1,
startIndex: 40,
endIndex: 60,
contentStartIndex: null,
contentEndIndex: null,
text: '課題名',
},
{
rowIndex: 1,
columnIndex: 0,
startIndex: 60,
endIndex: 78,
contentStartIndex: null,
contentEndIndex: null,
text: '1',
},
{
rowIndex: 1,
columnIndex: 1,
startIndex: 78,
endIndex: 118,
contentStartIndex: null,
contentEndIndex: null,
text: 'SHIN-2870 調査',
},
]);
});
it('finds a table by its MCP table ID', () => {
const table = getTableById(mockDocument, 'table:body:0');
expect(table?.tableId).toBe('table:body:0');
expect(getTableById(mockDocument, 'table:body:999')).toBeNull();
});
it('finds heading sections and the next table following the heading', () => {
const sections = findHeadings(mockDocument, [
'今回のスプリントのタスク',
'5. TDAからTAPへの確認事項',
]);
expect(sections).toEqual([
{
headingText: '今回のスプリントのタスク',
headingLevel: 'HEADING_2',
startIndex: 1,
endIndex: 25,
tableIdFollowing: 'table:body:0',
},
{
headingText: '5. TDAからTAPへの確認事項',
headingLevel: 'HEADING_2',
startIndex: 120,
endIndex: 145,
tableIdFollowing: undefined,
},
]);
});
});
|