discourse-table-builder/test/unit/lib/utilities-test.js
Keegan George 7b37c6acc1
FIX: Special character alignment issue (#10)
* DEV: Use alternate fork of `array-to-table`

* DEV: Add unit test for `arrayToTable()` method

* Move `arrayToTable` so it is available for unit tests

* DEV: Add assertion for creating a markdown table with special chars

When a table with special characters (such as `$`) is inserted in a cell to the right of a blank cell. The alignment of the table gets ruined if the table doesn't have surrounding pipes. This check ensures this alignment is correct.

Co-authored-by: Penar Musaraj <pmusaraj@gmail.com>
2022-08-11 11:33:34 -07:00

58 lines
1.4 KiB
JavaScript

import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import mdTableFixture from "../../fixtures/md-table-fixture";
import mdTableSpecialCharsFixture from "../../fixtures/md-table-special-chars-fixture";
import { arrayToTable } from "../../../discourse-table-builder/lib/utilities";
discourseModule("Unit | Utilities", function () {
test("arrayToTable", function (assert) {
const tableData = [
{
Make: "Toyota",
Model: "Supra",
Year: "1998",
},
{
Make: "Nissan",
Model: "Skyline",
Year: "1999",
},
{
Make: "Honda",
Model: "S2000",
Year: "2001",
},
];
assert.strictEqual(
arrayToTable(tableData),
mdTableFixture,
"it creates a markdown table from an array of objects (with headers as keys)"
);
const specialCharsTableData = [
{
Make: "Toyota",
Model: "Supra",
Price: "$50,000",
},
{
Make: "",
Model: "Celica",
Price: "$20,000",
},
{
Make: "Nissan",
Model: "GTR",
Price: "$80,000",
},
];
assert.strictEqual(
arrayToTable(specialCharsTableData),
mdTableSpecialCharsFixture,
"it creates a markdown table with special characters in correct alignment"
);
});
});