|
| 1 | +import { validateMarkdown } from "../src/utils/validateMarkdown"; |
| 2 | + |
| 3 | +describe("validate markdown", () => { |
| 4 | + it("should return false if missing a summary title (#)", () => { |
| 5 | + const md = ` |
| 6 | +Description. |
| 7 | +
|
| 8 | +## L1 Put Level's title here |
| 9 | +
|
| 10 | +> Level's summary: a short description of the level's content in one line. |
| 11 | +
|
| 12 | +Some text that describes the level`; |
| 13 | + expect(validateMarkdown(md)).toBe(false); |
| 14 | + }); |
| 15 | + |
| 16 | + it("should return false if contains multiple `#` headers", () => { |
| 17 | + const md1 = `# A Title |
| 18 | +Description. |
| 19 | +
|
| 20 | +# Another Title |
| 21 | +
|
| 22 | +## L1 Put Level's title here |
| 23 | +
|
| 24 | +> Level's summary: a short description of the level's content in one line. |
| 25 | +
|
| 26 | +Some text that describes the level`; |
| 27 | + |
| 28 | + const md2 = `# A Title |
| 29 | +Description. |
| 30 | +
|
| 31 | +
|
| 32 | +## L1 Put Level's title here |
| 33 | +
|
| 34 | +> Level's summary: a short description of the level's content in one line. |
| 35 | +
|
| 36 | +Some text that describes the level |
| 37 | +
|
| 38 | +# Another title |
| 39 | +`; |
| 40 | + |
| 41 | + expect(validateMarkdown(md1)).toBe(false); |
| 42 | + expect(validateMarkdown(md2)).toBe(false); |
| 43 | + }); |
| 44 | + |
| 45 | + it("should return false if missing a summary description", () => { |
| 46 | + const md = `# A Title |
| 47 | +
|
| 48 | +## L1 Put Level's title here |
| 49 | +
|
| 50 | +> Level's summary: a short description of the level's content in one line. |
| 51 | +
|
| 52 | +Some text that describes the level |
| 53 | +`; |
| 54 | + expect(validateMarkdown(md)).toBe(false); |
| 55 | + }); |
| 56 | + |
| 57 | + it("should return false if `##` doesn't preface a level", () => { |
| 58 | + const md = `# A Title |
| 59 | +
|
| 60 | +A description |
| 61 | +
|
| 62 | +## Put Level's title here |
| 63 | +
|
| 64 | +> Level's summary: a short description of the level's content in one line. |
| 65 | +
|
| 66 | +Some text that describes the level |
| 67 | +`; |
| 68 | + expect(validateMarkdown(md)).toBe(false); |
| 69 | + }); |
| 70 | + |
| 71 | + it("should return false if `###` doesn't preface a step", () => { |
| 72 | + const md = `# A Title |
| 73 | +
|
| 74 | +A description |
| 75 | +
|
| 76 | +## Put Level's title here |
| 77 | +
|
| 78 | +> Level's summary: a short description of the level's content in one line. |
| 79 | +
|
| 80 | +Some text that describes the level |
| 81 | +
|
| 82 | +### A Step |
| 83 | +
|
| 84 | +First step |
| 85 | +`; |
| 86 | + }); |
| 87 | + |
| 88 | + it("should return true for valid markdown", () => { |
| 89 | + const md = `# Title |
| 90 | +
|
| 91 | +Description. |
| 92 | +
|
| 93 | +## L1 Put Level's title here |
| 94 | +
|
| 95 | +> Level's summary: a short description of the level's content in one line. |
| 96 | +
|
| 97 | +Some text that describes the level |
| 98 | +
|
| 99 | +### L1S1 |
| 100 | +
|
| 101 | +First Step`; |
| 102 | + expect(validateMarkdown(md)).toBe(true); |
| 103 | + }); |
| 104 | + |
| 105 | + it("should ignore markdown content in codeblocks", () => { |
| 106 | + const md = `# Title |
| 107 | +
|
| 108 | +Description. |
| 109 | +
|
| 110 | +\`\`\`md |
| 111 | +# A codeblock |
| 112 | +
|
| 113 | +Should not be a problem |
| 114 | +\`\`\` |
| 115 | +
|
| 116 | +
|
| 117 | +## L1 Put Level's title here |
| 118 | +
|
| 119 | +> Level's summary: a short description of the level's content in one line. |
| 120 | +
|
| 121 | +Some text that describes the level |
| 122 | +
|
| 123 | +\`\`\` |
| 124 | +## Another Level in markdown |
| 125 | +
|
| 126 | +Should not be an issue |
| 127 | +\`\`\` |
| 128 | +
|
| 129 | +### L1S1 |
| 130 | +
|
| 131 | +First Step`; |
| 132 | + expect(validateMarkdown(md)).toBe(true); |
| 133 | + }); |
| 134 | +}); |
0 commit comments