import 'mocha'; import * as assert from 'assert'; import { DeltaInsertOp } from './../src/DeltaInsertOp'; import { QuillDeltaToHtmlConverter } from "./../src/QuillDeltaToHtmlConverter"; import { callWhenXEqualY } from './_helper'; import { delta1 } from './data/delta1'; import { GroupType, ListType } from './../src/value-types'; import { encodeHtml } from './../src/funcs-html'; describe('QuillDeltaToHtmlConverter', function () { describe('constructor()', function () { var hugeOps = [ { insert: 'huge', attributes: { size: 'huge' } }, { insert: "\n" } ]; it('should instantiate return proper html', function () { var qdc = new QuillDeltaToHtmlConverter(delta1.ops, { classPrefix: 'noz' }); var html = qdc.convert(); assert.equal(html, delta1.html); }); it('should set default inline styles for `inlineStyles: true`', function () { var qdc = new QuillDeltaToHtmlConverter(hugeOps, { inlineStyles: true }); var html = qdc.convert(); assert.equal(html.includes('huge'), true, html); }); it('should set default inline styles when `inlineStyles` is a truthy non-object', function () { var qdc = new QuillDeltaToHtmlConverter(hugeOps, { inlineStyles: 1 } as any); var html = qdc.convert(); assert.equal(html.includes('huge'), true, html); }); it('should allow setting inline styles', function () { var qdc = new QuillDeltaToHtmlConverter(hugeOps, { inlineStyles: { size: { huge: 'font-size: 6em' } } }); var html = qdc.convert(); assert.equal(html.includes('huge'), true, html); }); }); describe("convert()", function () { var ops2 = [ { insert: "this is text" }, { insert: "\n" }, { insert: "this is code" }, { insert: "\n", attributes: { 'code-block': true } }, { insert: "this is code TOO!" }, { insert: "\n", attributes: { 'code-block': true } }, ]; it('should render html', function () { var qdc = new QuillDeltaToHtmlConverter(ops2); var html = qdc.convert(); assert.equal(html.indexOf('
this is code') > -1, true, html);
      });

      it('should render mention', function () {
         let ops = [
            {
               insert: "mention", attributes: {
                  mentions: true,
                  mention: {
                     'end-point': 'http://abc.com',
                     slug: 'a',
                     class: 'abc', target: '_blank'
                  }
               }
            }
         ]
         var qdc = new QuillDeltaToHtmlConverter(ops);
         var html = qdc.convert();
         assert.equal(html, ['

mention

' ].join("")); var qdc = new QuillDeltaToHtmlConverter([{ insert: 'mention', attributes: { mentions: true, mention: { slug: 'aa' } } }]); var html = qdc.convert(); assert.equal(html, ['

mention

' ].join("")); }); it('should render image and image links', function() { let ops = [ {insert: {image: "http://yahoo.com/abc.jpg"}}, {insert: {image: "http://yahoo.com/def.jpg"}, attributes: {link: "http://aha"}}, ]; let qdc = new QuillDeltaToHtmlConverter(ops) let html = qdc.convert(); assert.equal(html, [ '

', '', '', '', '', '

' ].join('')) }); it('should open and close list tags', function () { var ops4 = [ { insert: "mr\n" }, { insert: "hello" }, { insert: "\n", attributes: { list: 'ordered' } }, { insert: "there" }, { insert: "\n", attributes: { list: 'bullet' } }, { insert: "\n", attributes: { list: 'ordered' } }, ] var qdc = new QuillDeltaToHtmlConverter(ops4); var html = qdc.convert(); assert.equal(html.indexOf('

mr') > -1, true); assert.equal(html.indexOf('