mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: update marked test cases
This commit is contained in:
@ -3,4 +3,7 @@
|
||||
module.exports = {
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
moduleNameMapper: {
|
||||
"lodash-es": "lodash",
|
||||
},
|
||||
};
|
||||
|
@ -40,6 +40,7 @@
|
||||
"eslint-plugin-react": "^7.27.1",
|
||||
"jest": "^29.1.2",
|
||||
"less": "^4.1.1",
|
||||
"lodash": "^4.17.21",
|
||||
"postcss": "^8.4.5",
|
||||
"prettier": "2.5.1",
|
||||
"tailwindcss": "^3.0.18",
|
||||
|
@ -1,6 +1,5 @@
|
||||
import dayjs from "dayjs";
|
||||
import relativeTime from "dayjs/plugin/relativeTime";
|
||||
import { indexOf } from "lodash-es";
|
||||
import { memo, useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
@ -132,7 +131,7 @@ const Memo: React.FC<Props> = (props: Props) => {
|
||||
const todoElementList = [...(memoContainerRef.current?.querySelectorAll(`span.todo-block[data-value=${status}]`) ?? [])];
|
||||
for (const element of todoElementList) {
|
||||
if (element === targetEl) {
|
||||
const index = indexOf(todoElementList, element);
|
||||
const index = todoElementList.indexOf(element);
|
||||
const tempList = memo.content.split(status === "DONE" ? /- \[x\] / : /- \[ \] /);
|
||||
let finalContent = "";
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { isEmpty } from "lodash-es";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { userService } from "../../services";
|
||||
@ -47,7 +46,7 @@ const PreferencesSection = () => {
|
||||
};
|
||||
|
||||
const handleCreateUserBtnClick = async () => {
|
||||
if (isEmpty(state.createUserEmail) || isEmpty(state.createUserPassword)) {
|
||||
if (state.createUserEmail === "" || state.createUserPassword === "") {
|
||||
toastHelper.error(t("message.fill-form"));
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { assign, isNull, isUndefined } from "lodash-es";
|
||||
|
||||
export const isNullorUndefined = (value: any) => {
|
||||
return isNull(value) || isUndefined(value);
|
||||
return value === null || value === undefined;
|
||||
};
|
||||
|
||||
export function getNowTimeStamp(): number {
|
||||
@ -96,7 +94,7 @@ export const getElementBounding = (element: HTMLElement, relativeEl?: HTMLElemen
|
||||
};
|
||||
|
||||
if ((relativeEl.tagName !== "BODY" && relativeElPosition === "relative") || relativeElPosition === "sticky") {
|
||||
return assign(bounding, {
|
||||
return Object.assign(bounding, {
|
||||
top: elementRect.top - relativeElRect.top,
|
||||
left: elementRect.left - relativeElRect.left,
|
||||
});
|
||||
@ -117,13 +115,13 @@ export const getElementBounding = (element: HTMLElement, relativeEl?: HTMLElemen
|
||||
};
|
||||
|
||||
if (isElementFixed(element)) {
|
||||
return assign(bounding, {
|
||||
return Object.assign(bounding, {
|
||||
top: elementRect.top,
|
||||
left: elementRect.left,
|
||||
});
|
||||
}
|
||||
|
||||
return assign(bounding, {
|
||||
return Object.assign(bounding, {
|
||||
top: elementRect.top + scrollTop,
|
||||
left: elementRect.left + scrollLeft,
|
||||
});
|
||||
|
@ -27,6 +27,10 @@ export const marked = (markdownStr: string, blockParsers = blockElementParserLis
|
||||
let matchedIndex = -1;
|
||||
|
||||
for (const parser of inlineElementParserList) {
|
||||
if (parser.name === "plain text" && matchedInlineParser !== undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const startIndex = markdownStr.search(parser.regex);
|
||||
const matchedLength = match(markdownStr, parser.regex);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { describe, expect, test } from "@jest/globals";
|
||||
import { unescape } from "lodash-es";
|
||||
import { marked } from ".";
|
||||
|
||||
describe("test marked parser", () => {
|
||||
@ -27,7 +28,7 @@ console.log("hello world!")
|
||||
];
|
||||
|
||||
for (const t of tests) {
|
||||
expect(marked(t.markdown)).toBe(t.want);
|
||||
expect(unescape(marked(t.markdown))).toBe(t.want);
|
||||
}
|
||||
});
|
||||
test("parse todo list block", () => {
|
||||
@ -43,7 +44,7 @@ console.log("hello world!")
|
||||
];
|
||||
|
||||
for (const t of tests) {
|
||||
expect(marked(t.markdown)).toBe(t.want);
|
||||
expect(unescape(marked(t.markdown))).toBe(t.want);
|
||||
}
|
||||
});
|
||||
test("parse list block", () => {
|
||||
@ -59,7 +60,7 @@ console.log("hello world!")
|
||||
];
|
||||
|
||||
for (const t of tests) {
|
||||
expect(marked(t.markdown)).toBe(t.want);
|
||||
expect(unescape(marked(t.markdown))).toBe(t.want);
|
||||
}
|
||||
});
|
||||
test("parse inline element", () => {
|
||||
@ -71,7 +72,7 @@ console.log("hello world!")
|
||||
];
|
||||
|
||||
for (const t of tests) {
|
||||
expect(marked(t.markdown)).toBe(t.want);
|
||||
expect(unescape(marked(t.markdown))).toBe(t.want);
|
||||
}
|
||||
});
|
||||
test("parse plain link", () => {
|
||||
@ -83,7 +84,7 @@ console.log("hello world!")
|
||||
];
|
||||
|
||||
for (const t of tests) {
|
||||
expect(marked(t.markdown)).toBe(t.want);
|
||||
expect(unescape(marked(t.markdown))).toBe(t.want);
|
||||
}
|
||||
});
|
||||
test("parse inline code", () => {
|
||||
@ -95,7 +96,7 @@ console.log("hello world!")
|
||||
];
|
||||
|
||||
for (const t of tests) {
|
||||
expect(marked(t.markdown)).toBe(t.want);
|
||||
expect(unescape(marked(t.markdown))).toBe(t.want);
|
||||
}
|
||||
});
|
||||
test("parse bold and em text", () => {
|
||||
@ -119,7 +120,7 @@ console.log("hello world!")
|
||||
];
|
||||
|
||||
for (const t of tests) {
|
||||
expect(marked(t.markdown)).toBe(t.want);
|
||||
expect(unescape(marked(t.markdown))).toBe(t.want);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { isUndefined } from "lodash-es";
|
||||
import { locationService } from ".";
|
||||
import * as api from "../helpers/api";
|
||||
import store from "../store";
|
||||
@ -58,7 +57,7 @@ const userService = {
|
||||
},
|
||||
|
||||
isVisitorMode: () => {
|
||||
return !isUndefined(userService.getUserIdFromPath());
|
||||
return !(userService.getUserIdFromPath() === undefined);
|
||||
},
|
||||
|
||||
getUserIdFromPath: () => {
|
||||
|
@ -2927,6 +2927,11 @@ lodash.merge@^4.6.2:
|
||||
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
|
||||
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
|
||||
|
||||
lodash@^4.17.21:
|
||||
version "4.17.21"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
|
||||
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
||||
|
||||
loose-envify@^1.1.0, loose-envify@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
|
||||
|
Reference in New Issue
Block a user