From da08b9b122e6cfd1d5e14c6374521885ddb421cb Mon Sep 17 00:00:00 2001 From: samuele-cozzi Date: Wed, 8 Mar 2023 14:51:43 +0100 Subject: [PATCH] fix: unit tests --- README.md | 2 +- tests/__mocks__/obsidian.ts | 1 + tests/filePath.test.ts | 32 ++++++++++++++++---------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 68930cc..007e3e0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Maintainability](https://api.codeclimate.com/v1/badges/78932986b29ffe273e56/maintainability)](https://codeclimate.com/github/samuele-cozzi/obsidian-marp-slides/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/78932986b29ffe273e56/test_coverage)](https://codeclimate.com/github/samuele-cozzi/obsidian-marp-slides/test_coverage) [![LICENSE](https://img.shields.io/github/license/samuele-cozzi/obsidian-marp-slides)](https://github.com/samuele-cozzi/obsidian-marp-slides/blob/main/LICENSE) -![Obsidian Downloads](https://img.shields.io/badge/dynamic/json?logo=obsidian&color=%23483699&label=downloads&query=%24%5B%22better-word-count%22%5D.downloads&url=https%3A%2F%2Fraw.githubusercontent.com%2Fobsidianmd%2Fobsidian-releases%2Fmaster%2Fcommunity-plugin-stats.json&style=for-the-badge) + Marp Slides is very simple & powerful slide deck extension for [Obsidian](href="https://obsidian.md") based on [Marp](https://marp.app/) diff --git a/tests/__mocks__/obsidian.ts b/tests/__mocks__/obsidian.ts index 1951105..7673fc3 100644 --- a/tests/__mocks__/obsidian.ts +++ b/tests/__mocks__/obsidian.ts @@ -31,6 +31,7 @@ export const normalizePath = jest.fn().mockImplementation((str: string) => { function normalize (path: string) { if (typeof path !== 'string') { + console.log(path); throw new TypeError('expected path to be a string'); } diff --git a/tests/filePath.test.ts b/tests/filePath.test.ts index 7c70990..55c37d2 100644 --- a/tests/filePath.test.ts +++ b/tests/filePath.test.ts @@ -13,8 +13,8 @@ test('file base path', () => { const filePath = new FilePath(DEFAULT_SETTINGS); const tests : pathsUtility[] = [ - { base: "aaa", relative: "bbb", expected: "aaa/bbb/"}//, - //{ base: "C:\\user\\foo\\vault", relative: "\\folder\\file", expected: "C:\\user\\foo\\vault\\folder\\file\\"}, + { base: "aaa", relative: "bbb", expected: "app://local/aaa/bbb/"}, + { base: "C:\\user\\foo\\vault", relative: "folder\\file", expected: "app://local/C:/user/foo/vault/folder/file/"}, ]; tests.forEach(element => { @@ -30,23 +30,23 @@ test('file base path', () => { }); -// test('file path', () => { +test('file path', () => { -// const filePath = new FilePath(DEFAULT_SETTINGS); -// const tests : pathsUtility[] = [ -// { base: "aaa", relative: "bbb.md", expected: "aaa/bbb.md"}, -// { base: "C:\\user\\foo\\vault", relative: "\\folder\\file.md", expected: "C:\\user\\foo\\vault\\folder\\file.md"}, -// ]; + const filePath = new FilePath(DEFAULT_SETTINGS); + const tests : pathsUtility[] = [ + { base: "aaa", relative: "bbb.md", expected: "aaa/bbb.md"}, + { base: "C:\\user\\foo\\vault", relative: "folder\\file.md", expected: "C:/user/foo/vault/folder/file.md"}, + ]; -// tests.forEach(element => { -// const file = new TFile; + tests.forEach(element => { + const file = new TFile; -// file.parent.path = element.relative; -// file.vault.adapter.write(element.base, ''); + file.path = element.relative; + file.vault.adapter.write(element.base, ''); -// const result = filePath.getCompleteFilePath(file); + const result = filePath.getCompleteFilePath(file); -// expect(result).toBe(element.expected); -// }); + expect(result).toBe(element.expected); + }); -// }); \ No newline at end of file +}); \ No newline at end of file