123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- const globalAny: any = global;
- globalAny.VDITOR_VERSION = "version";
- import {Options} from "../../src/ts/util/Options";
- describe("Options", () => {
- const cache = {
- enable: true,
- id: "vditorTest",
- };
- test("Options toolbar", () => {
- const options = new Options({
- cache,
- toolbar: ["br", "fullscreen", {
- hotkey: "⌘-a",
- name: "preview",
- }],
- });
- expect(options.merge()).toMatchObject({
- cache,
- toolbar: [{
- name: "br",
- }, {
- hotkey: "⌘-'",
- name: "fullscreen",
- tipPosition: "nw",
- }, {
- hotkey: "⌘-a",
- name: "preview",
- tipPosition: "nw",
- }],
- });
- });
- test("Options upload", () => {
- const options = new Options({
- cache,
- upload: {
- accept: ".jpg",
- },
- });
- expect(options.merge()).toMatchObject({
- cache,
- upload: {
- accept: ".jpg",
- filename: expect.anything(),
- linkToImgUrl: "",
- max: 10 * 1024 * 1024,
- url: "",
- },
- });
- });
- test("Options classes", () => {
- const options = new Options({
- cache,
- classes: {
- preview: "content-reset",
- },
- });
- expect(options.merge()).toMatchObject({
- cache,
- classes: {
- preview: "content-reset",
- },
- });
- });
- test("Options preview", () => {
- const options = new Options({
- cache,
- preview: {
- mode: "both",
- url: "https://ld246.com/md",
- },
- });
- expect(options.merge()).toMatchObject({
- cache,
- preview: {
- delay: 1000,
- mode: "both",
- url: "https://ld246.com/md",
- },
- });
- });
- test("Options preview hljs", () => {
- const options = new Options({
- cache,
- preview: {
- hljs: {
- style: "github",
- },
- mode: "both",
- },
- });
- expect(options.merge().preview).toEqual({
- delay: 1000,
- hljs: {
- enable: true,
- lineNumber: false,
- style: "github",
- },
- markdown: {
- autoSpace: false,
- chinesePunct: false,
- codeBlockPreview: true,
- fixTermTypo: false,
- footnotes: true,
- linkBase: "",
- listStyle: false,
- sanitize: true,
- setext: false,
- toc: false,
- },
- math: {
- engine: "KaTeX",
- inlineDigit: false,
- macros: {},
- },
- maxWidth: 800,
- mode: "both",
- theme: "light",
- themes: {dark: "", light: "", wechat: ""},
- });
- });
- test("Options hint", () => {
- const options = new Options({
- cache,
- hint: {
- emoji: {
- "+1": "👍",
- },
- emojiTail: "前往设置",
- },
- });
- expect(options.merge()).toMatchObject({
- cache,
- hint: {
- delay: 200,
- emoji: {
- "+1": "👍",
- },
- emojiPath: "https://cdn.jsdelivr.net/npm/vditor@version/dist/images/emoji",
- emojiTail: "前往设置",
- },
- });
- });
- test("Options resize", () => {
- const options = new Options({
- cache,
- resize: {
- enable: true,
- },
- });
- expect(options.merge()).toMatchObject({
- cache,
- resize: {
- enable: true,
- position: "bottom",
- },
- });
- });
- });
|