dokkie
Version:
Create good looking documentation from your Readme
113 lines • 5.26 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const page_1 = require("./page");
const mock_1 = require("../test/mock");
const path_1 = require("path");
const { readdir, readFile } = require("fs").promises;
const mockOutput = "temp/pages";
const altSettings = Object.assign(Object.assign({}, mock_1.baseSettings), { output: mockOutput, layout: "website", navigation: [], files: [
{
name: "readme",
path: "/Users/silvandiepen/Repos/_projects/dokkie/pages/usage/readme.md",
ext: ".md",
date: "2020-05-28T09:58:59.948Z",
data: "# Test1\n",
meta: {},
html: '<h1 id="test1">Test1</h1>\n',
title: "Test1",
route: path_1.join(mockOutput, "test1/index.html"),
destpath: path_1.join(__dirname, "../../", mockOutput, "test1"),
filename: "index.html",
},
{
name: "readme",
path: "/Users/silvandiepen/Repos/_projects/dokkie/pages/usage/readme.md",
ext: ".md",
date: "2020-05-28T09:58:59.948Z",
data: "# Test2\n",
meta: { remove: true },
html: '<h1 id="test2">Test2</h1>\n',
title: "Test2",
route: path_1.join(mockOutput, "test2/index.html"),
destpath: path_1.join(__dirname, "../../", mockOutput, "test2"),
filename: "index.html",
},
] });
describe("Page", () => {
it("Should filter hidden pages", () => __awaiter(void 0, void 0, void 0, function* () {
try {
const result = yield page_1.filterHiddenPages(altSettings);
expect(result.files.length).toBe(1);
}
catch (err) {
throw Error(err);
}
}));
it("Create Pages", () => __awaiter(void 0, void 0, void 0, function* () {
try {
yield page_1.getLayout(altSettings).then(page_1.createPages);
const testDir = yield readdir(path_1.join(__dirname, "../../", altSettings.output));
expect(testDir[1]).toBe("test2");
}
catch (err) {
throw Error(err);
}
}));
it("Create Pages - with Filter", () => __awaiter(void 0, void 0, void 0, function* () {
try {
yield page_1.filterHiddenPages(altSettings).then(page_1.getLayout).then(page_1.createPages);
const testDir = yield readdir(path_1.join(__dirname, "../../", altSettings.output));
expect(testDir[0]).toBe("test1");
}
catch (err) {
throw Error(err);
}
}));
it("Page has contents", () => __awaiter(void 0, void 0, void 0, function* () {
try {
const data = yield page_1.filterHiddenPages(altSettings).then(page_1.getLayout);
yield page_1.createPages(data);
const testFile = yield readFile(path_1.join(__dirname, "../../", altSettings.output, "/test1/index.html")).then((r) => r.toString());
expect(testFile.includes("test1")).toBeTruthy();
}
catch (err) {
throw Error(err);
}
}));
it("Page has title based on Content title", () => __awaiter(void 0, void 0, void 0, function* () {
try {
const data = yield page_1.filterHiddenPages(altSettings).then(page_1.getLayout);
yield page_1.createPages(data);
const testFile = yield readFile(path_1.join(__dirname, "../../", altSettings.output, "/test1/index.html")).then((r) => r.toString());
document.body.innerHTML = testFile;
const headerTitle = document.body.querySelector("header h1 a");
expect(headerTitle.innerHTML).toEqual("Test1");
}
catch (err) {
throw Error(err);
}
}));
it("Page has title based on Page title", () => __awaiter(void 0, void 0, void 0, function* () {
try {
const data = yield page_1.filterHiddenPages(Object.assign(Object.assign({}, altSettings), { projectTitle: "AnotherTest" })).then(page_1.getLayout);
yield page_1.createPages(data);
const testFile = yield readFile(path_1.join(__dirname, "../../", altSettings.output, "/test1/index.html")).then((r) => r.toString());
document.body.innerHTML = testFile;
const headerTitle = document.body.querySelector("header h1 a");
expect(headerTitle.innerHTML).toEqual("AnotherTest");
}
catch (err) {
throw Error(err);
}
}));
});
//# sourceMappingURL=page.spec.js.map