Skip to content

Instantly share code, notes, and snippets.

@kyldvs
Created December 4, 2018 00:58
Show Gist options
  • Save kyldvs/22f5d85e287cd006dcdd89f64c1c4b39 to your computer and use it in GitHub Desktop.
Save kyldvs/22f5d85e287cd006dcdd89f64c1c4b39 to your computer and use it in GitHub Desktop.
test("Basic Table", ({expect}) => {
let actual =
<Format>
<Table
borderStyle=SimpleLines
columns=[
<ColumnConfig width=8 />,
<ColumnConfig width=16 />,
<ColumnConfig width=8 />,
]>
<Row> "a1" "b1" "c1" </Row>
<Row> "a2" "b2 is a cell that needs to wrap" "c2" </Row>
<Row> "a3" "b3" "c3" "d3" </Row>
<Row> "a4" "b4" </Row>
<Row> "a5" "b5" "c5" </Row>
</Table>
</Format>;
let expected =
""
++ "------------------------------------------\n"
++ "| a1 | b1 | c1 |\n"
++ "------------------------------------------\n"
++ "| a2 | b2 is a cell | c2 |\n"
++ "| | that needs to | |\n"
++ "| | wrap | |\n"
++ "------------------------------------------\n"
++ "| a3 | b3 | c3 |\n"
++ "------------------------------------------\n"
++ "| a4 | b4 | |\n"
++ "------------------------------------------\n"
++ "| a5 | b5 | c5 |\n"
++ "------------------------------------------";
expect.string(actual).toEqual(expected);
});
test("Box Light Table", ({expect}) => {
let actual =
<Format>
<Table
borderStyle=BoxLight
columns=[
<ColumnConfig width=8 />,
<ColumnConfig width=16 />,
<ColumnConfig width=8 />,
]>
<Row> "a1" "b1" "c1" </Row>
<Row> "a2" "b2 is a cell that needs to wrap" "c2" </Row>
<Row> "a3" "b3" "c3" "d3" </Row>
<Row> "a4" "b4" </Row>
<Row> "a5" "b5" "c5" </Row>
</Table>
</Format>;
let expected =
""
++ "┌──────────┬──────────────────┬──────────┐\n"
++ "│ a1 │ b1 │ c1 │\n"
++ "├──────────┼──────────────────┼──────────┤\n"
++ "│ a2 │ b2 is a cell │ c2 │\n"
++ "│ │ that needs to │ │\n"
++ "│ │ wrap │ │\n"
++ "├──────────┼──────────────────┼──────────┤\n"
++ "│ a3 │ b3 │ c3 │\n"
++ "├──────────┼──────────────────┼──────────┤\n"
++ "│ a4 │ b4 │ │\n"
++ "├──────────┼──────────────────┼──────────┤\n"
++ "│ a5 │ b5 │ c5 │\n"
++ "└──────────┴──────────────────┴──────────┘";
expect.string(actual).toEqual(expected);
});
test("Basic Table with no borders", ({expect}) => {
let actual =
<Format>
<Table
border=None
columns=[
<ColumnConfig width=8 />,
<ColumnConfig width=16 />,
<ColumnConfig width=8 />,
]>
<Row> "a1" "b1" "c1" </Row>
<Row> "a2" "b2 is a cell that needs to wrap" "c2" </Row>
<Row> "a3" "b3" "c3" "d3" </Row>
<Row> "a4" "b4" </Row>
<Row> "a5" "b5" "c5" </Row>
</Table>
</Format>;
let expected =
""
++ " \n"
++ " a1 b1 c1 \n"
++ " \n"
++ " a2 b2 is a cell c2 \n"
++ " that needs to \n"
++ " wrap \n"
++ " \n"
++ " a3 b3 c3 \n"
++ " \n"
++ " a4 b4 \n"
++ " \n"
++ " a5 b5 c5 \n"
++ " ";
expect.string(actual).toEqual(expected);
});
test("Table with inner borders", ({expect}) => {
let actual =
<Format>
<Table
border=Inner
borderStyle=BoxLight
columns=[
<ColumnConfig width=8 />,
<ColumnConfig width=16 />,
<ColumnConfig width=8 />,
]>
<Row> "a1" "b1" "c1" </Row>
<Row> "a2" "b2 is a cell that needs to wrap" "c2" </Row>
<Row> "a3" "b3" "c3" "d3" </Row>
<Row> "a4" "b4" </Row>
<Row> "a5" "b5" "c5" </Row>
</Table>
</Format>;
let expected =
""
++ " \n"
++ " a1 │ b1 │ c1 \n"
++ " ─────────┼──────────────────┼───────── \n"
++ " a2 │ b2 is a cell │ c2 \n"
++ " │ that needs to │ \n"
++ " │ wrap │ \n"
++ " ─────────┼──────────────────┼───────── \n"
++ " a3 │ b3 │ c3 \n"
++ " ─────────┼──────────────────┼───────── \n"
++ " a4 │ b4 │ \n"
++ " ─────────┼──────────────────┼───────── \n"
++ " a5 │ b5 │ c5 \n"
++ " ";
expect.string(actual).toEqual(expected);
});
test("Table with outer borders", ({expect}) => {
let actual =
<Format>
<Table
border=Outer
borderStyle=BoxLight
columns=[
<ColumnConfig width=8 />,
<ColumnConfig width=16 />,
<ColumnConfig width=8 />,
]>
<Row> "a1" "b1" "c1" </Row>
<Row> "a2" "b2 is a cell that needs to wrap" "c2" </Row>
<Row> "a3" "b3" "c3" "d3" </Row>
<Row> "a4" "b4" </Row>
<Row> "a5" "b5" "c5" </Row>
</Table>
</Format>;
let expected =
""
++ "┌────────────────────────────────────────┐\n"
++ "│ a1 b1 c1 │\n"
++ "│ │\n"
++ "│ a2 b2 is a cell c2 │\n"
++ "│ that needs to │\n"
++ "│ wrap │\n"
++ "│ │\n"
++ "│ a3 b3 c3 │\n"
++ "│ │\n"
++ "│ a4 b4 │\n"
++ "│ │\n"
++ "│ a5 b5 c5 │\n"
++ "└────────────────────────────────────────┘";
expect.string(actual).toEqual(expected);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment