Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julesvirallinen committed Sep 26, 2023
1 parent e13271e commit 77c7965
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/publisher/Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PathRewriteRules } from "./DigitalGardenSiteManager";
import DigitalGardenSettings from "../models/settings";
import { Assets, GardenPageCompiler } from "../compiler/GardenPageCompiler";

interface MarkedForPublishing {
export interface MarkedForPublishing {
notes: TFile[];
images: string[];
}
Expand Down
35 changes: 20 additions & 15 deletions src/test/Publisher.test.ts → src/test/Compiler.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import { MetadataCache, TFile, Vault } from "obsidian";
import DigitalGardenSettings from "../models/settings";
import Publisher from "../publisher/Publisher";
import { GardenPageCompiler } from "../compiler/GardenPageCompiler";

jest.mock("obsidian");

describe("Publisher", () => {
describe("Compiler", () => {
describe("generateTransclusionHeader", () => {
const getTestPublisher = (settings: Partial<DigitalGardenSettings>) => {
return new Publisher(
{} as unknown as Vault,
{} as unknown as MetadataCache,
{ pathRewriteRules: "", ...settings } as DigitalGardenSettings,
const getTestCompiler = (settings: Partial<DigitalGardenSettings>) => {
return new GardenPageCompiler(
// TODO add jest-mock-creator
{} as Vault,
{
pathRewriteRules: "",
...settings,
} as DigitalGardenSettings,
{} as MetadataCache,
jest.fn(),
);
};

it("should replace {{title}} with the basename of the file", () => {
const testPublisher = getTestPublisher({});
const testCompiler = getTestCompiler({});
const EXPECTED_TITLE = "expected";

const result = testPublisher.generateTransclusionHeader(
const result = testCompiler.generateTransclusionHeader(
"# {{title}}",
{ basename: EXPECTED_TITLE } as TFile,
);
Expand All @@ -27,9 +32,9 @@ describe("Publisher", () => {
});

it("should add # to header if it is not a markdown header", () => {
const testPublisher = getTestPublisher({});
const testCompiler = getTestCompiler({});

const result = testPublisher.generateTransclusionHeader(
const result = testCompiler.generateTransclusionHeader(
"header",
{} as TFile,
);
Expand All @@ -38,9 +43,9 @@ describe("Publisher", () => {
});

it("Ensures that header has space after #", () => {
const testPublisher = getTestPublisher({});
const testCompiler = getTestCompiler({});

const result = testPublisher.generateTransclusionHeader(
const result = testCompiler.generateTransclusionHeader(
"###header",
{} as TFile,
);
Expand All @@ -49,9 +54,9 @@ describe("Publisher", () => {
});

it("Returns undefined if heading is undefined", () => {
const testPublisher = getTestPublisher({});
const testCompiler = getTestCompiler({});

const result = testPublisher.generateTransclusionHeader(
const result = testCompiler.generateTransclusionHeader(
undefined,
{} as TFile,
);
Expand Down

0 comments on commit 77c7965

Please sign in to comment.