Skip to content

Commit 4afd117

Browse files
committed
add optional level description tests
Signed-off-by: shmck <[email protected]>
1 parent e5ab4fc commit 4afd117

File tree

3 files changed

+100
-27
lines changed

3 files changed

+100
-27
lines changed

tests/markdown.test.ts

+13
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ Some text that describes the level
9999
100100
### 1.1
101101
102+
First Step`;
103+
expect(validateMarkdown(md)).toBe(true);
104+
});
105+
106+
it("should allow for empty level content", () => {
107+
const md = `# Title
108+
109+
Description.
110+
111+
## 1. Put Level's title here
112+
113+
### 1.1
114+
102115
First Step`;
103116
expect(validateMarkdown(md)).toBe(true);
104117
});

tests/parse.test.ts

+37
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,43 @@ But not including this line.
232232
expect(result.levels[0]).toEqual(expected.levels[0]);
233233
});
234234

235+
it("should allow for empty level content", () => {
236+
const md = `# Title
237+
238+
Description.
239+
240+
## 1. Put Level's title here
241+
242+
### 1.1
243+
244+
A step
245+
`;
246+
247+
const skeleton = { levels: [{ id: "1" }] };
248+
const result = parse({
249+
text: md,
250+
skeleton,
251+
commits: {},
252+
});
253+
const expected = {
254+
levels: [
255+
{
256+
id: "1",
257+
title: "Put Level's title here",
258+
summary: "",
259+
content: "",
260+
steps: [
261+
{
262+
id: "1.1",
263+
content: "A step",
264+
},
265+
],
266+
},
267+
],
268+
};
269+
expect(result.levels[0]).toEqual(expected.levels[0]);
270+
});
271+
235272
it("should match line breaks with double line breaks for proper spacing", () => {
236273
const md = `# Title
237274

tests/tutorial.test.ts

+50-27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,48 @@ import * as T from "../typings/tutorial";
22
import tutorialSchema from "../src/schema/tutorial";
33
import { validateSchema } from "../src/utils/validateSchema";
44

5+
const validJson: Partial<T.Tutorial> = {
6+
version: "0.1.0",
7+
summary: { title: "Title", description: "Description" },
8+
config: {
9+
testRunner: {
10+
command: "aCommand",
11+
args: {
12+
filter: "filter",
13+
tap: "tap",
14+
},
15+
directory: "coderoad",
16+
setup: {
17+
commits: ["abcdef1"],
18+
commands: ["npm install"],
19+
},
20+
},
21+
repo: {
22+
uri: "https://github.com/some-repo.git",
23+
branch: "someBranch",
24+
},
25+
dependencies: [{ name: "name", version: ">=1" }],
26+
appVersions: {
27+
vscode: ">=0.7.0",
28+
},
29+
},
30+
levels: [
31+
{
32+
id: "1",
33+
title: "Level 1",
34+
summary: "The first level",
35+
content: "The first level",
36+
steps: [
37+
{
38+
id: "1.1",
39+
content: "The first step",
40+
setup: { commits: [] },
41+
},
42+
],
43+
},
44+
],
45+
};
46+
547
const validateTutorial = (json: any) => validateSchema(tutorialSchema, json);
648

749
describe("validate tutorial", () => {
@@ -12,37 +54,18 @@ describe("validate tutorial", () => {
1254
expect(valid).toBe(false);
1355
});
1456
it("should return true for a valid tutorial", () => {
15-
const json: Partial<T.Tutorial> = {
16-
version: "0.1.0",
17-
summary: { title: "Title", description: "Description" },
18-
config: {
19-
testRunner: {
20-
command: "aCommand",
21-
args: {
22-
filter: "filter",
23-
tap: "tap",
24-
},
25-
directory: "coderoad",
26-
setup: {
27-
commits: ["abcdef1"],
28-
commands: ["npm install"],
29-
},
30-
},
31-
repo: {
32-
uri: "https://github.com/some-repo.git",
33-
branch: "someBranch",
34-
},
35-
dependencies: [{ name: "name", version: ">=1" }],
36-
appVersions: {
37-
vscode: ">=0.7.0",
38-
},
39-
},
57+
const valid = validateTutorial({ ...validJson });
58+
expect(valid).toBe(true);
59+
});
60+
it("should return true for a tutorial with no level content", () => {
61+
const json = {
62+
...validJson,
4063
levels: [
4164
{
4265
id: "1",
4366
title: "Level 1",
44-
summary: "The first level",
45-
content: "The first level",
67+
summary: "",
68+
content: "",
4669
steps: [],
4770
},
4871
],

0 commit comments

Comments
 (0)