discord-bot icon indicating copy to clipboard operation
discord-bot copied to clipboard

add tests to check for custom column delimiters

Open github-actions[bot] opened this issue 3 years ago • 0 comments

https://github.com/Heptagram-Project/discord-bot/blob/be90a670e10125f833c9a5cc459e26601fe72409/test/utils/formatText.spec.ts#L33


import { assert } from "chai";

import { formatTextToTable } from "../../src/utils/formatText";

suite("formatTextToTable", () => {
  test("is defined", () => {
    assert.isDefined(formatTextToTable, "formatTextToTable is not defined!");
    assert.isFunction(
      formatTextToTable,
      "formatTextToTable is not a function!"
    );
  });
  test("given empty array returns empty string", () =>
    assert.deepEqual(
      formatTextToTable([]),
      "",
      "function did not return empty string"
    ));
  test("given 2d empty array, returns empty string", () =>
    assert.deepEqual(
      formatTextToTable([[]]),
      "",
      "function did not return empty string"
    ));
  test("given 2d empty array, with seperate defined headers, returns headers", () =>
    assert.deepEqual(
      formatTextToTable([], {
        headers: ["one", "two"],
      }),
      "one | two\n---------",
      "did not return headers"
    ));
  // TODO: add tests to check for custom column delimiters
  test("given 2d empty array, with empty seperate defined headers, returns empty string", () =>
    assert.deepEqual(
      formatTextToTable([[]], {
        headers: [],
      }),
      "",
      "did not return empty string"
    ));
  test("given 2d array with data with long headers, display table", () =>
    assert.deepEqual(
      formatTextToTable(
        [
          ["brad", "100"],
          ["foo", "bar"],
        ],
        {
          headers: ["name", "aggeeeeeeeee"],
        }
      ),
      "name | aggeeeeeeeee\n-------------------\nbrad | 100         \nfoo  | bar         ",
      "did not return table"
    ));
});

github-actions[bot] avatar Jul 20 '22 15:07 github-actions[bot]