mirror of
https://github.com/pooyash1998/chartspark.git
synced 2026-07-22 06:53:29 +00:00
31 lines
933 B
TypeScript
31 lines
933 B
TypeScript
import { TableParser } from '../../src/parsers/tableParser';
|
|
|
|
describe('TableParser', () => {
|
|
const parser = new TableParser();
|
|
|
|
const TABLE = '| Item | Sales |\n|------|-------|\n| Apples | 120 |\n| Bananas | 95 |';
|
|
|
|
describe('canParse', () => {
|
|
it('detects a markdown table', () => {
|
|
expect(parser.canParse(TABLE)).toBe(true);
|
|
});
|
|
it('rejects plain text', () => {
|
|
expect(parser.canParse('hello world')).toBe(false);
|
|
});
|
|
it('accepts table without separator row (Live Preview selections omit it)', () => {
|
|
expect(parser.canParse('| A | B |\n| 1 | 2 |')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('parse', () => {
|
|
it('extracts labels and numeric values', () => {
|
|
const result = parser.parse(TABLE);
|
|
expect(result.labels).toEqual(['Apples', 'Bananas']);
|
|
expect(result.values).toEqual([120, 95]);
|
|
});
|
|
|
|
it('sets totalItems', () => {
|
|
expect(parser.parse(TABLE).metadata.totalItems).toBe(2);
|
|
});
|
|
});
|
|
});
|