decaf-dev_obsidian-vault-ex.../tests/unit/link-validators.test.ts
DecafDev e0f1d64e81
Update cover image system (#283)
* fix: handle loading of external image embeds or embeds without an image extension

* refactor: rename to clear smi cache setting

* fix: don't load image property when cover image source is set to off

* refactor: remove unused fix

* feat: implement new cover image system

* refactor: use correct padding for new lines in settings

* refactor: rename to clear cache data
2024-08-01 00:37:04 -06:00

110 lines
2.3 KiB
TypeScript

import {
isExternalEmbed,
isInternalEmbed,
isWikiLink,
} from "src/svelte/app/services/link-utils/link-validators";
describe("isWikiLink", () => {
it("should return false for content without a wiki link", () => {
//Arrange
const content = "This is some text";
//Act
const result = isWikiLink(content);
//Assert
expect(result).toEqual(false);
});
it("should return true for content with a wiki link", () => {
//Arrange
const content = "[[file.jpg]]";
//Act
const result = isWikiLink(content);
//Assert
expect(result).toEqual(true);
});
it("should return true for content with a wiki link with a paremeter", () => {
//Arrange
const content = "[[file.jpg|200]]";
//Act
const result = isWikiLink(content);
//Assert
expect(result).toEqual(true);
});
});
describe("isInternalEmbed", () => {
it("should return false for content without an internal embed", () => {
//Arrange
const content = "This is some text";
//Act
const result = isInternalEmbed(content);
//Assert
expect(result).toEqual(false);
});
it("should return true for content with an internal embed", () => {
//Arrange
const content = "![[file.jpg]]";
//Act
const result = isInternalEmbed(content);
//Assert
expect(result).toEqual(true);
});
it("should return true for content with an internal embed with a parameter", () => {
//Arrange
const content = "![[file.jpg|200]]";
//Act
const result = isInternalEmbed(content);
//Assert
expect(result).toEqual(true);
});
});
describe("isExternalEmbed", () => {
it("should return false for content without an external image embed", () => {
//Arrange
const content = "This is some text";
//Act
const result = isExternalEmbed(content);
//Assert
expect(result).toEqual(false);
});
it("should return true for content with an external image embed", () => {
//Arrange
const content = "![cover](https://example.com/file.jpg)";
//Act
const result = isExternalEmbed(content);
//Assert
expect(result).toEqual(true);
});
it("should return true for content with an external image embed with no alt text", () => {
//Arrange
const content = "![](https://example.com/file.jpg)";
//Act
const result = isExternalEmbed(content);
//Assert
expect(result).toEqual(true);
});
});