Skip to content

Commit 4a0cfee

Browse files
authored
Merge pull request #194 from ghiscoding/chore/full-coverage
chore: increase test coverage
2 parents 1c99f99 + fcae07a commit 4a0cfee

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

packages/excel-builder-vanilla/src/Excel/Worksheet.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ export class Worksheet {
355355
cell = cellCache.formula.cloneNode(true);
356356
cell.firstChild.firstChild.nodeValue = cellValue as string;
357357
break;
358-
case 'text':
359-
/*falls through*/
358+
/*falls through, text type */
360359
default: {
361360
let id: number | undefined;
362361
if (typeof this.sharedStrings?.strings[cellValue as string] !== 'undefined') {
@@ -697,7 +696,6 @@ export class Worksheet {
697696
case 'number':
698697
cellXml = `<c${rAttr}><v>${cellValue}</v></c>`;
699698
break;
700-
case 'text':
701699
default: {
702700
let id: number | undefined;
703701
if (typeof this.sharedStrings?.strings[cellValue as string] !== 'undefined') {

packages/excel-builder-vanilla/src/Excel/__tests__/Worksheet.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,18 @@ describe('Excel/Worksheet', () => {
351351
expect(xml).toContain('<row');
352352
});
353353

354+
test('serializeRows with sharedStrings with value and metadata', () => {
355+
const ws = new Worksheet({ name: 'Test' });
356+
ws.sharedStrings = { strings: {}, addString: () => 0 } as any;
357+
const xml = ws.serializeRows([
358+
[
359+
{ value: 'A', metadata: { type: 'string' } },
360+
{ value: 1, metadata: { type: 'number' } },
361+
],
362+
]);
363+
expect(xml).toContain('<row');
364+
});
365+
354366
it('should use sharedStrings.strings if defined, else call addString', () => {
355367
const ws = new Worksheet({ name: 'Test' });
356368
const addStringSpy = vi.fn(() => 42);

packages/excel-builder-vanilla/src/__tests__/excel-builder.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,11 @@ describe('Excel-Builder-Vanilla', () => {
807807
const albumTable = new Table();
808808
const originalData = [
809809
['Artist', 'Album', 'Price'],
810-
['Buckethead', 'Albino Slug', 8.99],
810+
[
811+
{ value: 'Buckethead', metadata: { type: 'string' } },
812+
{ value: 'Albino Slug', metadata: { type: 'string' } },
813+
{ value: 8.99, metadata: { type: 'number' } },
814+
],
811815
['Buckethead', 'Electric Tears', 13.99],
812816
['Buckethead', 'Colma', 11.34],
813817
['Crystal Method', 'Vegas', 10.54],
@@ -892,7 +896,11 @@ describe('Excel-Builder-Vanilla', () => {
892896
columns: [],
893897
data: [
894898
['Artist', 'Album', 'Price'],
895-
['Buckethead', 'Albino Slug', 8.99],
899+
[
900+
{ value: 'Buckethead', metadata: { type: 'string' } },
901+
{ value: 'Albino Slug', metadata: { type: 'string' } },
902+
{ value: 8.99, metadata: { type: 'number' } },
903+
],
896904
['Buckethead', 'Electric Tears', 13.99],
897905
['Buckethead', 'Colma', 11.34],
898906
['Crystal Method', 'Vegas', 10.54],

0 commit comments

Comments
 (0)