Skip to content

Commit 3c12487

Browse files
committed
test(CLI) Some tests for CLI arguments
Signed-off-by: Jerome Simeon <[email protected]>
1 parent 5d398fb commit 3c12487

File tree

2 files changed

+146
-1
lines changed

2 files changed

+146
-1
lines changed

packages/markdown-cli/test/cli.js

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ describe('#validateParseArgs', () => {
5555
process.chdir(path.resolve(__dirname, 'data/'));
5656
const args = Commands.validateParseArgs({
5757
_: ['parse'],
58-
template: './',
5958
sample: 'sample.md'
6059
});
6160
args.sample.should.match(/sample.md$/);
@@ -69,6 +68,72 @@ describe('#validateParseArgs', () => {
6968
});
7069
});
7170

71+
describe('#validateDraftArgs', () => {
72+
it('no args specified', () => {
73+
process.chdir(path.resolve(__dirname, 'data/'));
74+
const args = Commands.validateDraftArgs({
75+
_: ['draft'],
76+
});
77+
args.data.should.match(/data.json$/);
78+
});
79+
it('no args specified (verbose)', () => {
80+
process.chdir(path.resolve(__dirname, 'data/'));
81+
const args = Commands.validateDraftArgs({
82+
_: ['draft'],
83+
verbose: true
84+
});
85+
args.data.should.match(/data.json$/);
86+
});
87+
it('all args specified', () => {
88+
process.chdir(path.resolve(__dirname, 'data/'));
89+
const args = Commands.validateDraftArgs({
90+
_: ['draft'],
91+
data: 'data.json'
92+
});
93+
args.data.should.match(/data.json$/);
94+
});
95+
it('bad data.json', () => {
96+
process.chdir(path.resolve(__dirname, 'data/'));
97+
(() => Commands.validateDraftArgs({
98+
_: ['draft'],
99+
data: 'data_en.md'
100+
})).should.throw('A data.json file is required. Try the --data flag or create a data.json.');
101+
});
102+
});
103+
104+
describe('#validateNormalizeArgs', () => {
105+
it('no args specified', () => {
106+
process.chdir(path.resolve(__dirname, 'data/'));
107+
const args = Commands.validateNormalizeArgs({
108+
_: ['normalize'],
109+
});
110+
args.sample.should.match(/sample.md$/);
111+
});
112+
it('no args specified (verbose)', () => {
113+
process.chdir(path.resolve(__dirname, 'data/'));
114+
const args = Commands.validateNormalizeArgs({
115+
_: ['normalize'],
116+
verbose: true
117+
});
118+
args.sample.should.match(/sample.md$/);
119+
});
120+
it('all args specified', () => {
121+
process.chdir(path.resolve(__dirname, 'data/'));
122+
const args = Commands.validateNormalizeArgs({
123+
_: ['normalize'],
124+
sample: 'sample.md'
125+
});
126+
args.sample.should.match(/sample.md$/);
127+
});
128+
it('bad sample.md', () => {
129+
process.chdir(path.resolve(__dirname, 'data/'));
130+
(() => Commands.validateNormalizeArgs({
131+
_: ['normalize'],
132+
sample: 'sample_en.md'
133+
})).should.throw('A sample.md file is required. Try the --sample flag or create a sample.md.');
134+
});
135+
});
136+
72137
describe('markdown-cli', () => {
73138
const sample = path.resolve(__dirname, 'data', 'acceptance.md');
74139
const sampleExpected = path.resolve(__dirname, 'data', 'acceptance.json');
@@ -156,6 +221,15 @@ describe('markdown-cli', () => {
156221
const result = await Commands.draft(sampleExpectedSlate, null, options);
157222
result.should.eql(sampleExpectedText);
158223
});
224+
225+
it('should generate a markdown file from Slate (verbose)', async () => {
226+
const options = {};
227+
options.cicero = false;
228+
options.slate = true;
229+
options.verbose = true;
230+
const result = await Commands.draft(sampleExpectedSlate, null, options);
231+
result.should.eql(sampleExpectedText);
232+
});
159233
});
160234

161235
describe('#normalize', () => {
@@ -182,5 +256,14 @@ describe('markdown-cli', () => {
182256
const result = await Commands.normalize(sample, null, options);
183257
result.should.eql(sampleExpectedText);
184258
});
259+
260+
it('should Slate <> Markdown roundtrip (verbose)', async () => {
261+
const options = {};
262+
options.cicero = false;
263+
options.slate = true;
264+
options.verbose = true;
265+
const result = await Commands.normalize(sample, null, options);
266+
result.should.eql(sampleExpectedText);
267+
});
185268
});
186269
});
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"$class": "org.accordproject.commonmark.Document",
3+
"xmlns": "http://commonmark.org/xml/1.0",
4+
"nodes": [
5+
{
6+
"$class": "org.accordproject.commonmark.Heading",
7+
"level": "1",
8+
"nodes": [
9+
{
10+
"$class": "org.accordproject.commonmark.Text",
11+
"text": "Heading"
12+
}
13+
]
14+
},
15+
{
16+
"$class": "org.accordproject.commonmark.Paragraph",
17+
"nodes": [
18+
{
19+
"$class": "org.accordproject.commonmark.Text",
20+
"text": "And below is a "
21+
},
22+
{
23+
"$class": "org.accordproject.commonmark.Strong",
24+
"nodes": [
25+
{
26+
"$class": "org.accordproject.commonmark.Text",
27+
"text": "clause"
28+
}
29+
]
30+
},
31+
{
32+
"$class": "org.accordproject.commonmark.Text",
33+
"text": "."
34+
}
35+
]
36+
},
37+
{
38+
"$class": "org.accordproject.commonmark.CodeBlock",
39+
"info": "<clause src=\"ap://[email protected]#721d1aa0999a5d278653e211ae2a64b75fdd8ca6fa1f34255533c942404c5c1f\" clauseid=\"479adbb4-dc55-4d1a-ab12-b6c5e16900c0\"/>",
40+
"tag": {
41+
"$class": "org.accordproject.commonmark.TagInfo",
42+
"tagName": "clause",
43+
"attributeString": "src = \"ap://[email protected]#721d1aa0999a5d278653e211ae2a64b75fdd8ca6fa1f34255533c942404c5c1f\" clauseid = \"479adbb4-dc55-4d1a-ab12-b6c5e16900c0\" ",
44+
"attributes": [
45+
{
46+
"$class": "org.accordproject.commonmark.Attribute",
47+
"name": "src",
48+
"value": "ap://[email protected]#721d1aa0999a5d278653e211ae2a64b75fdd8ca6fa1f34255533c942404c5c1f"
49+
},
50+
{
51+
"$class": "org.accordproject.commonmark.Attribute",
52+
"name": "clauseid",
53+
"value": "479adbb4-dc55-4d1a-ab12-b6c5e16900c0"
54+
}
55+
],
56+
"content": "",
57+
"closed": true
58+
},
59+
"text": "Acceptance of Delivery. <variable id=\"shipper\" value=\"%22Party%20A%22\"/> will be deemed to have completed its delivery obligations if in <variable id=\"receiver\" value=\"%22Party%20B%22\"/>'s opinion, the <variable id=\"deliverable\" value=\"%22Widgets%22\"/> satisfies the Acceptance Criteria, and <variable id=\"receiver\" value=\"%22Party%20B%22\"/> notifies <variable id=\"shipper\" value=\"%22Party%20A%22\"/> in writing that it is accepting the <variable id=\"deliverable\" value=\"%22Widgets%22\"/>.\n\nInspection and Notice. <variable id=\"receiver\" value=\"%22Party%20B%22\"/> will have <variable id=\"businessDays\" value=\"10\"/> Business Days' to inspect and evaluate the <variable id=\"deliverable\" value=\"%22Widgets%22\"/> on the delivery date before notifying <variable id=\"shipper\" value=\"%22Party%20A%22\"/> that it is either accepting or rejecting the <variable id=\"deliverable\" value=\"%22Widgets%22\"/>.\n\nAcceptance Criteria. The \"Acceptance Criteria\" are the specifications the <variable id=\"deliverable\" value=\"%22Widgets%22\"/> must meet for the <variable id=\"shipper\" value=\"%22Party%20A%22\"/> to comply with its requirements and obligations under this agreement, detailed in <variable id=\"attachment\" value=\"%22Attachment%20X%22\"/>, attached to this agreement.\n"
60+
}
61+
]
62+
}

0 commit comments

Comments
 (0)