| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- class SpreadsheetMarkdownIntegrationTests extends BaseTest {
- parser;
-
- setUp() {
- this.parser = new Markdown([ ...Markdown.allReaders, new MDSpreadsheetReader() ]);
- }
-
- md(markdown) {
- return normalizeWhitespace(this.parser.toHTML(markdown));
- }
-
- test_integration() {
- const markdown = '| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | =A*B |';
- const expected = '<table><thead>' +
- '<tr><th>A</th><th>B</th><th>C</th></tr>' +
- '</thead><tbody><tr>' +
- '<td class="spreadsheet-type-number" data-numeric-value="3" data-string-value="3">3</td>' +
- '<td class="spreadsheet-type-number" data-numeric-value="4" data-string-value="4">4</td>' +
- '<td class="calculated spreadsheet-type-number" data-numeric-value="12" data-string-value="12">12</td>' +
- '</tr></tbody></table>';
- const actual = this.md(markdown);
- this.assertEqual(expected, actual);
- }
-
- test_bailOut() {
- // If no formulas found table isn't modified
- const markdown = '| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | A*B |';
- const expected = '<table><thead>' +
- '<tr><th>A</th><th>B</th><th>C</th></tr>' +
- '</thead><tbody><tr>' +
- '<td>3</td>' +
- '<td>4</td>' +
- '<td>A*B</td>' +
- '</tr></tbody></table>';
- const actual = this.md(markdown);
- this.assertEqual(expected, actual);
- }
-
- test_observedError1() {
- // Saw "Uncaught Error: columnIndex must be number, got string" from this
- const markdown = '| Unit Price | Qty | Subtotal |\n| ---: | ---: | ---: |\n| $1.23 | 2 | =A*B FILL |\n| $4.99 | 6 | |\n| Total | | =SUM(C:C) |';
- const expected = '<table><thead><tr>' +
- '<th style="text-align: right;">Unit Price</th>' +
- '<th style="text-align: right;">Qty</th>' +
- '<th>Subtotal</th>' +
- '</tr></thead><tbody><tr>' +
- '<td class="spreadsheet-type-currency" style="text-align: right;" data-numeric-value="1.23" data-string-value="1.23">$1.23</td>' +
- '<td class="spreadsheet-type-number" style="text-align: right;" data-numeric-value="2" data-string-value="2">2</td>' +
- '<td class="calculated spreadsheet-type-currency" data-numeric-value="2.46" data-string-value="2.46">$2.46</td>' +
- '</tr><tr>' +
- '<td class="spreadsheet-type-currency" style="text-align: right;" data-numeric-value="4.99" data-string-value="4.99">$4.99</td>' +
- '<td class="spreadsheet-type-number" style="text-align: right;" data-numeric-value="6" data-string-value="6">6</td>' +
- '<td class="calculated spreadsheet-type-currency" data-numeric-value="29.94" data-string-value="29.94">$29.94</td>' +
- '</tr><tr>' +
- '<td class="spreadsheet-type-string" style="text-align: right;" data-string-value="Total">Total</td>' +
- '<td class="spreadsheet-type-blank" style="text-align: right;" data-numeric-value="0" data-string-value=""></td>' +
- '<td class="calculated spreadsheet-type-currency" data-numeric-value="32.4" data-string-value="32.4">$32.40</td>' +
- '</tr></tbody></table>';
- const actual = this.md(markdown);
- this.assertEqual(expected, actual);
- }
-
- test_styledValue() {
- const markdown = "| A | B | C |\n| --- | --- | --- |\n| **3** | _4_ | =A*B |";
- const expected = '<table><thead>' +
- '<tr><th>A</th><th>B</th><th>C</th></tr>' +
- '</thead><tbody><tr>' +
- '<td class="spreadsheet-type-number" data-numeric-value="3" data-string-value="3"><strong>3</strong></td>' +
- '<td class="spreadsheet-type-number" data-numeric-value="4" data-string-value="4"><em>4</em></td>' +
- '<td class="calculated spreadsheet-type-number" data-numeric-value="12" data-string-value="12">12</td>' +
- '</tr></tbody></table>';
- const actual = this.md(markdown);
- this.assertEqual(expected, actual);
- }
-
- test_styledFormula() {
- const markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | **=A*B** |";
- const expected = '<table><thead>' +
- '<tr><th>A</th><th>B</th><th>C</th></tr>' +
- '</thead><tbody><tr>' +
- '<td class="spreadsheet-type-number" data-numeric-value="3" data-string-value="3">3</td>' +
- '<td class="spreadsheet-type-number" data-numeric-value="4" data-string-value="4">4</td>' +
- '<td class="calculated spreadsheet-type-number" data-numeric-value="12" data-string-value="12"><strong>12</strong></td>' +
- '</tr></tbody></table>';
- const actual = this.md(markdown);
- this.assertEqual(expected, actual);
- }
-
- test_styledFormula_multiple() {
- const markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | ~~**=A*B**~~ |";
- const expected = '<table><thead>' +
- '<tr><th>A</th><th>B</th><th>C</th></tr>' +
- '</thead><tbody><tr>' +
- '<td class="spreadsheet-type-number" data-numeric-value="3" data-string-value="3">3</td>' +
- '<td class="spreadsheet-type-number" data-numeric-value="4" data-string-value="4">4</td>' +
- '<td class="calculated spreadsheet-type-number" data-numeric-value="12" data-string-value="12"><s><strong>12</strong></s></td>' +
- '</tr></tbody></table>';
- const actual = this.md(markdown);
- this.assertEqual(expected, actual);
- }
-
- test_preservedOperators() {
- // Regular markdown will want to convert *B* into emphasized B
- const markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | =A*B*4 |";
- const expected = '<table><thead>' +
- '<tr><th>A</th><th>B</th><th>C</th></tr>' +
- '</thead><tbody><tr>' +
- '<td class="spreadsheet-type-number" data-numeric-value="3" data-string-value="3">3</td>' +
- '<td class="spreadsheet-type-number" data-numeric-value="4" data-string-value="4">4</td>' +
- '<td class="calculated spreadsheet-type-number" data-numeric-value="48" data-string-value="48">48</td>' +
- '</tr></tbody></table>';
- const actual = this.md(markdown);
- this.assertEqual(expected, actual);
- }
- }
|