mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
more tests
This commit is contained in:
4
nextjs/src/models/local/IModuleItem.ts
Normal file
4
nextjs/src/models/local/IModuleItem.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export interface IModuleItem {
|
||||||
|
name: string;
|
||||||
|
dueAt: string;
|
||||||
|
}
|
||||||
7
nextjs/src/models/local/page/localCoursePage.ts
Normal file
7
nextjs/src/models/local/page/localCoursePage.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { IModuleItem } from "../IModuleItem";
|
||||||
|
|
||||||
|
export interface LocalCoursePage extends IModuleItem {
|
||||||
|
name: string;
|
||||||
|
text: string;
|
||||||
|
dueAt: string;
|
||||||
|
}
|
||||||
32
nextjs/src/models/local/page/pageMarkdown.ts
Normal file
32
nextjs/src/models/local/page/pageMarkdown.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { extractLabelValue } from "../assignmnet/utils/markdownUtils";
|
||||||
|
import { LocalCoursePage } from "./localCoursePage";
|
||||||
|
|
||||||
|
export const pageMarkdown = {
|
||||||
|
toMarkdown: (page: LocalCoursePage) => {
|
||||||
|
const printableDueDate = new Date(page.dueAt)
|
||||||
|
.toISOString()
|
||||||
|
.replace("\u202F", " ");
|
||||||
|
const settingsMarkdown = `Name: ${page.name}\nDueDateForOrdering: ${printableDueDate}\n---\n`;
|
||||||
|
return settingsMarkdown + page.text;
|
||||||
|
},
|
||||||
|
|
||||||
|
parseMarkdown: (pageMarkdown: string) => {
|
||||||
|
const rawSettings = pageMarkdown.split("---")[0];
|
||||||
|
const name = extractLabelValue(rawSettings, "Name");
|
||||||
|
const rawDate = extractLabelValue(rawSettings, "DueDateForOrdering");
|
||||||
|
|
||||||
|
const parsedDate = new Date(rawDate);
|
||||||
|
if (isNaN(parsedDate.getTime())) {
|
||||||
|
throw new Error(`could not parse due date: ${rawDate}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = pageMarkdown.split("---\n")[1];
|
||||||
|
|
||||||
|
const page: LocalCoursePage = {
|
||||||
|
name,
|
||||||
|
dueAt: parsedDate.toISOString(),
|
||||||
|
text,
|
||||||
|
};
|
||||||
|
return page;
|
||||||
|
},
|
||||||
|
};
|
||||||
19
nextjs/src/models/local/tests/markdown/pageMarkdown.test.ts
Normal file
19
nextjs/src/models/local/tests/markdown/pageMarkdown.test.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { describe, it, expect } from "vitest";
|
||||||
|
import { LocalCoursePage } from "../../page/localCoursePage";
|
||||||
|
import { pageMarkdown } from "../../page/pageMarkdown";
|
||||||
|
|
||||||
|
describe("PageMarkdownTests", () => {
|
||||||
|
it("can parse page", () => {
|
||||||
|
const page: LocalCoursePage = {
|
||||||
|
name: "test title",
|
||||||
|
text: "test text content",
|
||||||
|
dueAt: new Date().toISOString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const pageMarkdownString = pageMarkdown.toMarkdown(page);
|
||||||
|
|
||||||
|
const parsedPage = pageMarkdown.parseMarkdown(pageMarkdownString);
|
||||||
|
|
||||||
|
expect(parsedPage).toEqual(page);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user