-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: converting text alignment caused columns to disappear
- Loading branch information
Colin-Alexa Robinson
committed
Feb 28, 2024
1 parent
ab0136f
commit 172df38
Showing
7 changed files
with
751 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/@atjson/renderer-commonmark/test/__snapshots__/table.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`tables with column headings center alignment 1`] = ` | ||
"| column 1 | column 2 | | ||
|:--------:| -------- | | ||
| data 1.1 | data 1.2 | | ||
" | ||
`; | ||
|
||
exports[`tables with column headings mixed alignment 1`] = ` | ||
"| column 1 | column 2 | | ||
|:-------- | --------:| | ||
| data 1.1 | data 1.2 | | ||
" | ||
`; | ||
|
||
exports[`tables with column headings no alignment 1`] = ` | ||
"| column 1 | column 2 | | ||
| -------- | -------- | | ||
| data 1.1 | data 1.2 | | ||
" | ||
`; | ||
|
||
exports[`tables with column headings omitting columns 1`] = ` | ||
"| column 2 | | ||
| -------- | | ||
| data 1.2 | | ||
" | ||
`; | ||
|
||
exports[`tables with column headings reordering columns 1`] = ` | ||
"| column 2 | column 1 | | ||
| -------- | -------- | | ||
| data 1.2 | data 1.1 | | ||
" | ||
`; |
9 changes: 0 additions & 9 deletions
9
packages/@atjson/renderer-commonmark/test/__snapshots__/tables.test.ts.snap
This file was deleted.
Oops, something went wrong.
179 changes: 179 additions & 0 deletions
179
packages/@atjson/renderer-commonmark/test/table.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import { Block, deserialize } from "@atjson/document"; | ||
import OffsetSource, { Table } from "@atjson/offset-annotations"; | ||
import CommonmarkRenderer from "../src"; | ||
|
||
function testTable(tableAttributes: Block<Table>["attributes"]) { | ||
return deserialize( | ||
{ | ||
text: "column 1 column 2 data 1.1 data 1.2", | ||
blocks: [ | ||
{ | ||
type: "table", | ||
id: "tableId", | ||
attributes: tableAttributes, | ||
parents: [], | ||
}, | ||
{ | ||
type: "data-set", | ||
id: "dataSetId", | ||
attributes: { | ||
columns: [ | ||
{ | ||
name: "column 1", | ||
slice: "column1Id", | ||
type: "peritext", | ||
}, | ||
{ | ||
name: "column 2", | ||
slice: "column2Id", | ||
type: "peritext", | ||
}, | ||
], | ||
rows: [ | ||
{ | ||
"column 1": { | ||
slice: "cell1_1Id", | ||
jsonValue: "data 1.1", | ||
}, | ||
"column 2": { | ||
slice: "cell1_2Id", | ||
jsonValue: "data 1.2", | ||
}, | ||
}, | ||
], | ||
}, | ||
parents: ["table"], | ||
}, | ||
], | ||
marks: [ | ||
{ | ||
attributes: { | ||
refs: ["dataSetId"], | ||
}, | ||
id: "column1Id", | ||
range: "(2..10]", | ||
type: "slice", | ||
}, | ||
{ | ||
attributes: { | ||
refs: ["dataSetId"], | ||
}, | ||
id: "column2Id", | ||
range: "(11..19]", | ||
type: "slice", | ||
}, | ||
{ | ||
attributes: { | ||
refs: ["dataSetId"], | ||
}, | ||
id: "cell1_1Id", | ||
range: "(20..28]", | ||
type: "slice", | ||
}, | ||
{ | ||
attributes: { | ||
refs: ["dataSetId"], | ||
}, | ||
id: "cell1_2Id", | ||
range: "(29..37]", | ||
type: "slice", | ||
}, | ||
], | ||
}, | ||
OffsetSource | ||
); | ||
} | ||
|
||
describe("tables", () => { | ||
describe("with column headings", () => { | ||
test("no alignment", () => { | ||
let document = testTable({ | ||
columns: [ | ||
{ | ||
name: "column 1", | ||
}, | ||
{ | ||
name: "column 2", | ||
}, | ||
], | ||
dataSet: "dataSetId", | ||
showColumnHeaders: true, | ||
}); | ||
|
||
const markdown = CommonmarkRenderer.render(document); | ||
expect(markdown).toMatchSnapshot(); | ||
}); | ||
|
||
test("mixed alignment", () => { | ||
let document = testTable({ | ||
columns: [ | ||
{ | ||
name: "column 1", | ||
textAlign: "left", | ||
}, | ||
{ | ||
name: "column 2", | ||
textAlign: "right", | ||
}, | ||
], | ||
dataSet: "dataSetId", | ||
showColumnHeaders: true, | ||
}); | ||
|
||
const markdown = CommonmarkRenderer.render(document); | ||
expect(markdown).toMatchSnapshot(); | ||
}); | ||
|
||
test("center alignment", () => { | ||
let document = testTable({ | ||
columns: [ | ||
{ | ||
name: "column 1", | ||
textAlign: "center", | ||
}, | ||
{ | ||
name: "column 2", | ||
}, | ||
], | ||
dataSet: "dataSetId", | ||
showColumnHeaders: true, | ||
}); | ||
|
||
const markdown = CommonmarkRenderer.render(document); | ||
expect(markdown).toMatchSnapshot(); | ||
}); | ||
|
||
test("reordering columns", () => { | ||
let document = testTable({ | ||
columns: [ | ||
{ | ||
name: "column 2", | ||
}, | ||
{ | ||
name: "column 1", | ||
}, | ||
], | ||
dataSet: "dataSetId", | ||
showColumnHeaders: true, | ||
}); | ||
|
||
const markdown = CommonmarkRenderer.render(document); | ||
expect(markdown).toMatchSnapshot(); | ||
}); | ||
|
||
test("omitting columns", () => { | ||
let document = testTable({ | ||
columns: [ | ||
{ | ||
name: "column 2", | ||
}, | ||
], | ||
dataSet: "dataSetId", | ||
showColumnHeaders: true, | ||
}); | ||
|
||
const markdown = CommonmarkRenderer.render(document); | ||
expect(markdown).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
103 changes: 0 additions & 103 deletions
103
packages/@atjson/renderer-commonmark/test/tables.test.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.