Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nozer committed Jun 10, 2018
1 parent 8123ae9 commit 7eaa138
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quill-delta-to-html",
"version": "0.8.3",
"version": "0.8.4",
"description": "Converts Quill's delta ops to HTML",
"main": "./dist/commonjs/main.js",
"types":"./dist/commonjs/main.d.ts",
Expand Down
41 changes: 21 additions & 20 deletions test/DeltaInsertOp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import * as assert from "assert";

import {InsertData, InsertDataQuill} from './../src/InsertData';
import {DeltaInsertOp} from './../src/DeltaInsertOp';
import {DataType, AlignType, ListType} from './../src/value-types';

describe('DeltaInsertOp', function() {

describe('constructor()', function() {
it('should instantiate', function() {
var embed = new InsertDataQuill("image", "https://");
var embed = new InsertDataQuill(DataType.Image, "https://");
var t = new DeltaInsertOp(embed);
assert.equal(t instanceof DeltaInsertOp, true);
assert.equal(t.insert instanceof InsertDataQuill, true);
Expand All @@ -18,7 +19,7 @@ describe('DeltaInsertOp', function() {
t = new DeltaInsertOp("test");
assert.deepEqual(t.insert.value, 'test');

t = new DeltaInsertOp(new InsertDataQuill("formula", "x=data"));
t = new DeltaInsertOp(new InsertDataQuill(DataType.Formula, "x=data"));
assert.equal(t.insert.value, "x=data");
});
});
Expand All @@ -35,12 +36,12 @@ describe('DeltaInsertOp', function() {

describe('hasSameAdiAs()', function() {
it('should successfully if two ops have same align indent and direction', function() {
var op1 = new DeltaInsertOp("\n", {align: 'right', indent: 2});
var op2 = new DeltaInsertOp("\n", {align: 'right', indent: 2});
var op1 = new DeltaInsertOp("\n", {align: AlignType.Right, indent: 2});
var op2 = new DeltaInsertOp("\n", {align: AlignType.Right, indent: 2});

assert.ok(op1.hasSameAdiAs(op2));

var op2 = new DeltaInsertOp("\n", {align: 'right', indent: 3});
var op2 = new DeltaInsertOp("\n", {align: AlignType.Right, indent: 3});
assert.ok(!op1.hasSameAdiAs(op2));
});
});
Expand All @@ -67,7 +68,7 @@ describe('DeltaInsertOp', function() {
var op = new DeltaInsertOp("\n", {});
assert.equal(op.isJustNewline(), true);

op = new DeltaInsertOp("\n\n ", {list: "ordered"});
op = new DeltaInsertOp("\n\n ", {list: ListType.Ordered});
assert.equal(op.isJustNewline(), false);
});
});
Expand All @@ -77,74 +78,74 @@ describe('DeltaInsertOp', function() {
var op = new DeltaInsertOp("\n", {});
assert.equal(op.isList(), false);

op = new DeltaInsertOp("fds ", {list: "ordered"});
op = new DeltaInsertOp("fds ", {list: ListType.Ordered});
assert.equal(op.isList(), true);
});
});

describe('isBulletList()', function() {
it('should return true if op is a bullet list', function() {
var op = new DeltaInsertOp("\n", {list: 'bullet'});
var op = new DeltaInsertOp("\n", {list: ListType.Bullet});
assert.equal(op.isBulletList(), true);

op = new DeltaInsertOp("fds ", {list: "ordered"});
op = new DeltaInsertOp("fds ", {list: ListType.Ordered});
assert.equal(op.isBulletList(), false);
});
});

describe('isOrderedList()', function() {
it('should return true if op is an ordered list', function() {
var op = new DeltaInsertOp("\n", {list: 'bullet'});
var op = new DeltaInsertOp("\n", {list: ListType.Bullet});
assert.equal(op.isOrderedList(), false);

op = new DeltaInsertOp("fds ", {list: "ordered"});
op = new DeltaInsertOp("fds ", {list: ListType.Ordered});
assert.equal(op.isOrderedList(), true);
});
});

describe('isSameListAs()', function() {
it('should return true if op list type same as the comparison', function() {
var op = new DeltaInsertOp("\n", {list: 'bullet'});
var op2 = new DeltaInsertOp("ds", {list: 'bullet'});
var op = new DeltaInsertOp("\n", {list: ListType.Bullet});
var op2 = new DeltaInsertOp("ds", {list: ListType.Bullet});
assert.equal(op.isSameListAs(op2), true);

var op3 = new DeltaInsertOp("fds ", {list: "ordered"});
var op3 = new DeltaInsertOp("fds ", {list: ListType.Ordered});
assert.equal(op.isSameListAs(op3), false);
});
});

describe('isText()', function() {
it('should correctly identify insert type', function() {
var op = new DeltaInsertOp("\n", {list: 'bullet'});
var op = new DeltaInsertOp("\n", {list: ListType.Bullet});
assert.equal(op.isVideo(), false);
assert.equal(op.isText(), true);

op = new DeltaInsertOp(new InsertDataQuill("image", "d"), {list: "ordered"});
op = new DeltaInsertOp(new InsertDataQuill(DataType.Image, "d"), {list: ListType.Ordered});
assert.equal(op.isImage(), true);
assert.equal(op.isText(), false);
});
});

describe('isVideo()/isImage()/isFormula()', function() {
it('should correctly identify embed type', function() {
var op = new DeltaInsertOp(new InsertDataQuill("video", ""));
var op = new DeltaInsertOp(new InsertDataQuill(DataType.Video, ""));
assert.equal(op.isVideo(), true);
assert.equal(op.isFormula(), false);
assert.equal(op.isImage(), false);

op = new DeltaInsertOp(new InsertDataQuill("image", "d"));
op = new DeltaInsertOp(new InsertDataQuill(DataType.Image, "d"));
assert.equal(op.isImage(), true);
assert.equal(op.isFormula(), false);

op = new DeltaInsertOp(new InsertDataQuill("formula", "d"));
op = new DeltaInsertOp(new InsertDataQuill(DataType.Formula, "d"));
assert.equal(op.isVideo(), false);
assert.equal(op.isFormula(), true);
});
});

describe('isLink()', function() {
it('should correctly identify if op is a link', function() {
var op = new DeltaInsertOp(new InsertDataQuill("video", ""), {link: 'http://'});
var op = new DeltaInsertOp(new InsertDataQuill(DataType.Video, ""), {link: 'http://'});
assert.equal(op.isLink(), false);


Expand Down
5 changes: 3 additions & 2 deletions test/InsertData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import 'mocha';
import * as assert from "assert";

import { InsertData, InsertDataQuill, InsertDataCustom } from './../src/InsertData';
import {DataType} from './../src/value-types';

describe('InsertData', function () {
describe('InsertDataQuill', function () {
describe('constructor()', function () {
it('should instantiate', function () {
var t = new InsertDataQuill("video", "https://");
var t = new InsertDataQuill(DataType.Video, "https://");
assert.equal(t.type === "video", true);
assert.equal(t.value === "https://", true);

t = new InsertDataQuill("text", "hello");
t = new InsertDataQuill(DataType.Text, "hello");
assert.equal(t.type === "text", true);
assert.equal(t.value === "hello", true);
});
Expand Down
20 changes: 10 additions & 10 deletions test/OpToHtmlConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ describe('OpToHtmlConverter', function () {
'ql-font-roman', 'ql-size-small'];
assert.deepEqual(c.getCssClasses(), classes);

o = new DeltaInsertOp(new InsertDataQuill("image", ""), attrs);
o = new DeltaInsertOp(new InsertDataQuill(DataType.Image, ""), attrs);
c = new OpToHtmlConverter(o);
assert.deepEqual(c.getCssClasses(), classes.concat('ql-image'));

o = new DeltaInsertOp(new InsertDataQuill("video", ""), attrs);
o = new DeltaInsertOp(new InsertDataQuill(DataType.Video, ""), attrs);
c = new OpToHtmlConverter(o);
assert.deepEqual(c.getCssClasses(), classes.concat('ql-video'));

o = new DeltaInsertOp(new InsertDataQuill("formula", ""), attrs);
o = new DeltaInsertOp(new InsertDataQuill(DataType.Formula, ""), attrs);
c = new OpToHtmlConverter(o);
assert.deepEqual(c.getCssClasses(), classes.concat('ql-formula'));

Expand Down Expand Up @@ -137,28 +137,28 @@ describe('OpToHtmlConverter', function () {
var c = new OpToHtmlConverter(o);
assert.deepEqual(c.getTagAttributes(), []);

var o = new DeltaInsertOp(new InsertDataQuill("image", "-"), { color: 'red' });
var o = new DeltaInsertOp(new InsertDataQuill(DataType.Image, "-"), { color: 'red' });
var c = new OpToHtmlConverter(o);
assert.deepEqual(c.getTagAttributes(), [
{ key: 'class', value: "ql-image" },
{ key: 'src', value: "-" }
]);

var o = new DeltaInsertOp(new InsertDataQuill("image", "-"), { width: '200' });
var o = new DeltaInsertOp(new InsertDataQuill(DataType.Image, "-"), { width: '200' });
var c = new OpToHtmlConverter(o);
assert.deepEqual(c.getTagAttributes(), [
{ key: 'class', value: "ql-image" },
{ key: 'width', value: "200"},
{ key: 'src', value: "-" }
]);

var o = new DeltaInsertOp(new InsertDataQuill('formula', "-"), { color: 'red' });
var o = new DeltaInsertOp(new InsertDataQuill(DataType.Formula, "-"), { color: 'red' });
var c = new OpToHtmlConverter(o);
assert.deepEqual(c.getTagAttributes(), [
{ key: 'class', value: "ql-formula" }
]);

var o = new DeltaInsertOp(new InsertDataQuill('video', "-"), { color: 'red' });
var o = new DeltaInsertOp(new InsertDataQuill(DataType.Video, "-"), { color: 'red' });
var c = new OpToHtmlConverter(o);
assert.deepEqual(c.getTagAttributes(), [
{ key: 'class', value: "ql-video" },
Expand Down Expand Up @@ -195,11 +195,11 @@ describe('OpToHtmlConverter', function () {
c = new OpToHtmlConverter(o);
assert.equal(c.getContent(), 'sss<&>,');

o = new DeltaInsertOp(new InsertDataQuill('formula', 'ff'), { bold: true });
o = new DeltaInsertOp(new InsertDataQuill(DataType.Formula, 'ff'), { bold: true });
c = new OpToHtmlConverter(o);
assert.equal(c.getContent(), 'ff');

o = new DeltaInsertOp(new InsertDataQuill('video', 'ff'), { bold: true });
o = new DeltaInsertOp(new InsertDataQuill(DataType.Video, 'ff'), { bold: true });
c = new OpToHtmlConverter(o);
assert.equal(c.getContent(), '');
});
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('OpToHtmlConverter', function () {
c1 = new OpToHtmlConverter(op);
assert.equal(c1.getHtml(), '\n');

var op = new DeltaInsertOp(new InsertDataQuill("image", "http://"));
var op = new DeltaInsertOp(new InsertDataQuill(DataType.Image, "http://"));
c1 = new OpToHtmlConverter(op);
assert.equal(c1.getHtml(), '<img class="ql-image" src="http://"/>');
});
Expand Down
5 changes: 3 additions & 2 deletions test/grouper/Grouper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import * as assert from "assert";
import { Grouper } from './../../src/grouper/Grouper';
import { DeltaInsertOp } from './../../src/DeltaInsertOp';
import { InsertData, InsertDataQuill } from './../../src/InsertData';
import { ListGroup, ListItem, VideoItem, InlineGroup, BlockGroup, TDataGroup
import { ListGroup, ListItem, VideoItem, InlineGroup, BlockGroup, TDataGroup
} from './../../src/grouper/group-types';
import {DataType} from './../../src/value-types';
describe('Grouper', function () {


describe('#pairOpsWithTheirBlock()', function () {
var ops = [
new DeltaInsertOp(new InsertDataQuill("video", "http://")),
new DeltaInsertOp(new InsertDataQuill(DataType.Video, "http://")),
new DeltaInsertOp("hello"),
new DeltaInsertOp("\n"),
new DeltaInsertOp("how are you?"),
Expand Down
23 changes: 12 additions & 11 deletions test/grouper/ListNester.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import { DeltaInsertOp } from './../../src/DeltaInsertOp';
import { InsertData } from './../../src/InsertData';
import { ListGroup, ListItem, VideoItem, InlineGroup, BlockGroup, TDataGroup
} from './../../src/grouper/group-types';
import {ListType} from './../../src/value-types';

describe('ListNester', function () {

describe('nest()', function () {
it('should not nest different types of lists', function () {
var ops = [
new DeltaInsertOp("ordered list 1 item 1"),
new DeltaInsertOp("\n", { list: 'ordered' }),
new DeltaInsertOp("\n", { list: ListType.Ordered }),
new DeltaInsertOp("bullet list 1 item 1"),
new DeltaInsertOp("\n", { list: 'bullet' }),
new DeltaInsertOp("\n", { list: ListType.Bullet }),
new DeltaInsertOp("bullet list 1 item 2"),
new DeltaInsertOp("\n", { list: 'bullet' }),
new DeltaInsertOp("\n", { list: ListType.Bullet }),
new DeltaInsertOp("haha"),
new DeltaInsertOp("\n"),
new DeltaInsertOp("\n", { list: 'bullet' }),
new DeltaInsertOp("\n", { list: ListType.Bullet }),
];

var groups = Grouper.pairOpsWithTheirBlock(ops);
Expand All @@ -41,19 +42,19 @@ describe('ListNester', function () {
it('should nest if lists are same and later ones have higher indent', function () {
var ops = [
new DeltaInsertOp("item 1"),
new DeltaInsertOp("\n", { list: 'ordered' }),
new DeltaInsertOp("\n", { list: ListType.Ordered }),
new DeltaInsertOp("item 1a"),
new DeltaInsertOp("\n", { list: 'ordered', indent: 1 }),
new DeltaInsertOp("\n", { list: ListType.Ordered, indent: 1 }),
new DeltaInsertOp("item 1a-i"),
new DeltaInsertOp("\n", { list: 'ordered', indent: 3 }),
new DeltaInsertOp("\n", { list: ListType.Ordered, indent: 3 }),
new DeltaInsertOp("item 1b"),
new DeltaInsertOp("\n", { list: 'ordered', indent: 1 }),
new DeltaInsertOp("\n", { list: ListType.Ordered, indent: 1 }),
new DeltaInsertOp("item 2", ),
new DeltaInsertOp("\n", { list: 'ordered' }),
new DeltaInsertOp("\n", { list: ListType.Ordered }),
new DeltaInsertOp("haha"),
new DeltaInsertOp("\n"),
new DeltaInsertOp("\n", { list: 'ordered', indent:5 }),
new DeltaInsertOp("\n", { list: 'bullet', indent:4 }),
new DeltaInsertOp("\n", { list: ListType.Ordered, indent:5 }),
new DeltaInsertOp("\n", { list: ListType.Bullet, indent:4 }),
]
var pairs = Grouper.pairOpsWithTheirBlock(ops);

Expand Down

0 comments on commit 7eaa138

Please sign in to comment.