-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧 Tests/docs on jats-to-myst transforms
- Loading branch information
Showing
4 changed files
with
307 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
packages/jats-to-myst/src/transforms/admonitions.spec.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,104 @@ | ||
import { VFile } from 'vfile'; | ||
import { describe, expect, test } from 'vitest'; | ||
import { admonitionTransform } from './admonitions'; | ||
|
||
describe('admonitionTransform', () => { | ||
test('caption title is moved to admonition title', () => { | ||
const vfile = new VFile(); | ||
const tree = { | ||
type: 'root', | ||
children: [ | ||
{ | ||
type: 'boxed-text', | ||
children: [ | ||
{ | ||
type: 'caption', | ||
children: [ | ||
{ | ||
type: 'title', | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My Title', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'text', | ||
value: 'My content', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
const result = { | ||
type: 'root', | ||
children: [ | ||
{ | ||
type: 'boxed-text', | ||
children: [ | ||
{ | ||
type: 'admonitionTitle', | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My Title', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'text', | ||
value: 'My content', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
admonitionTransform(tree, vfile); | ||
expect(tree).toEqual(result); | ||
}); | ||
test('caption with no title is lost', () => { | ||
const vfile = new VFile(); | ||
const tree = { | ||
type: 'root', | ||
children: [ | ||
{ | ||
type: 'boxed-text', | ||
children: [ | ||
{ | ||
type: 'caption', | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My Title', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'text', | ||
value: 'My content', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
const result = { | ||
type: 'root', | ||
children: [ | ||
{ | ||
type: 'boxed-text', | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My content', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
admonitionTransform(tree, vfile); | ||
expect(tree).toEqual(result); | ||
}); | ||
}); |
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
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,188 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import { sectionTransform } from './sections'; | ||
|
||
describe('sectionTransform', () => { | ||
test('section title becomes heading with depth', () => { | ||
const tree = { | ||
type: 'root', | ||
children: [ | ||
{ | ||
type: 'sec', | ||
children: [ | ||
{ | ||
type: 'title', | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My Title', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'text', | ||
value: 'My content', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
const result = { | ||
type: 'root', | ||
children: [ | ||
{ | ||
type: 'block', | ||
children: [ | ||
{ | ||
type: 'heading', | ||
depth: 1, | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My Title', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'text', | ||
value: 'My content', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
sectionTransform(tree); | ||
expect(tree).toEqual(result); | ||
}); | ||
test('section without title remains', () => { | ||
const tree = { | ||
type: 'root', | ||
children: [ | ||
{ | ||
type: 'sec', | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My content', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
const result = { | ||
type: 'root', | ||
children: [ | ||
{ | ||
type: 'block', | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My content', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
sectionTransform(tree); | ||
expect(tree).toEqual(result); | ||
}); | ||
test('nested sections flatten', () => { | ||
const tree = { | ||
type: 'root', | ||
children: [ | ||
{ | ||
type: 'sec', | ||
children: [ | ||
{ | ||
type: 'title', | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My Title', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'text', | ||
value: 'My content', | ||
}, | ||
{ | ||
type: 'sec', | ||
children: [ | ||
{ | ||
type: 'title', | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My Subitle', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'sec', | ||
children: [ | ||
{ | ||
type: 'title', | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'Another title', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
const result = { | ||
type: 'root', | ||
children: [ | ||
{ | ||
type: 'block', | ||
children: [ | ||
{ | ||
type: 'heading', | ||
depth: 1, | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My Title', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'text', | ||
value: 'My content', | ||
}, | ||
|
||
{ | ||
type: 'heading', | ||
depth: 2, | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'My Subitle', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'heading', | ||
depth: 3, | ||
children: [ | ||
{ | ||
type: 'text', | ||
value: 'Another title', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
sectionTransform(tree); | ||
expect(tree).toEqual(result); | ||
}); | ||
}); |
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