import { removeAtag, getAndRemoveConfig, getAndRemoveDocsifyIgnoreConfig, } from '../../src/core/render/utils.js'; import { tree } from '../../src/core/render/tpl.js'; import { slugify } from '../../src/core/render/slugify.js'; // Suite // ----------------------------------------------------------------------------- describe('core/render/utils', () => { // removeAtag() // --------------------------------------------------------------------------- describe('removeAtag()', () => { test('removeAtag from a link', () => { const result = removeAtag('content'); expect(result).toBe('content'); }); }); // getAndRemoveDocsifyIgnoreConfig() // --------------------------------------------------------------------------- describe('getAndRemoveDocsifyIgnoreConfig()', () => { test('getAndRemoveDocsifyIgnoreConfig from ', () => { const { content, ignoreAllSubs, ignoreSubHeading } = getAndRemoveDocsifyIgnoreConfig( 'My Ignore Title', ); expect(content).toBe('My Ignore Title'); expect(ignoreSubHeading).toBeTruthy(); expect(ignoreAllSubs === undefined).toBeTruthy(); }); test('getAndRemoveDocsifyIgnoreConfig from ', () => { const { content, ignoreAllSubs, ignoreSubHeading } = getAndRemoveDocsifyIgnoreConfig( 'My Ignore Title', ); expect(content).toBe('My Ignore Title'); expect(ignoreAllSubs).toBeTruthy(); expect(ignoreSubHeading === undefined).toBeTruthy(); }); test('getAndRemoveDocsifyIgnoreConfig from {docsify-ignore}', () => { const { content, ignoreAllSubs, ignoreSubHeading } = getAndRemoveDocsifyIgnoreConfig('My Ignore Title{docsify-ignore}'); expect(content).toBe('My Ignore Title'); expect(ignoreSubHeading).toBeTruthy(); expect(ignoreAllSubs === undefined).toBeTruthy(); }); test('getAndRemoveDocsifyIgnoreConfig from {docsify-ignore-all}', () => { const { content, ignoreAllSubs, ignoreSubHeading } = getAndRemoveDocsifyIgnoreConfig('My Ignore Title{docsify-ignore-all}'); expect(content).toBe('My Ignore Title'); expect(ignoreAllSubs).toBeTruthy(); expect(ignoreSubHeading === undefined).toBeTruthy(); }); }); // getAndRemoveConfig() // --------------------------------------------------------------------------- describe('getAndRemoveConfig()', () => { test('parse simple config', () => { const result = getAndRemoveConfig( "[filename](_media/example.md ':include')", ); expect(result).toMatchObject({ config: {}, str: "[filename](_media/example.md ':include')", }); }); test('parse config with arguments', () => { const result = getAndRemoveConfig( "[filename](_media/example.md ':include :foo=bar :baz test')", ); expect(result).toMatchObject({ config: { foo: 'bar', baz: true, }, str: "[filename](_media/example.md ':include test')", }); }); test('parse config with double quotes', () => { const result = getAndRemoveConfig( '[filename](_media/example.md ":include")', ); expect(result).toMatchObject({ config: {}, str: '[filename](_media/example.md ":include")', }); }); }); }); describe('core/render/tpl', () => { test('remove html tag in tree', () => { const result = tree([ { level: 2, slug: '#/cover?id=basic-usage', title: 'Basic usage', }, { level: 2, slug: '#/cover?id=custom-background', title: 'Custom background', }, { level: 2, slug: '#/cover?id=test', title: 'icoTest', }, ]); expect(result).toBe( /* html */ '', ); }); }); describe('core/render/slugify', () => { test('slugify()', () => { const result = slugify( 'Bla bla bla ', ); const result2 = slugify( 'Another broken example', ); expect(result).toBe('bla-bla-bla-'); expect(result2).toBe('another-broken-example'); }); });