Skip to content

Commit 0f8338b

Browse files
committed
WIP: add integration tests
1 parent 34e787a commit 0f8338b

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

test/integration/tests.js

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var chai = require("chai");
22
var sinon = require("sinon");
33
var sinonChai = require("sinon-chai");
4-
chai.should();
4+
var should = chai.should();
55
chai.use(sinonChai);
66
var jsdom = require("jsdom");
77
var { JSDOM } = jsdom;
@@ -101,17 +101,57 @@ describe('orgchart -- integration tests', function () {
101101
$container.empty();
102102
});
103103

104-
it("Adding new root node", function () {
104+
it('addParent()', function () {
105105
oc.addParent($laolao, { 'name': 'Lao Ye', 'id': 'n0' });
106106
$laolao.closest('.nodes').prevAll().should.lengthOf(3);
107107
oc.$chart.find('.node:first').should.deep.equal($('#n0'));
108108
});
109109

110-
it("when one node's parent is hidden, its sibling branches are hidden too", function () {
111-
oc.hideParent($hongmiao);
112-
$bomiao.is('.slide-right').should.be.true;
113-
$sumiao.is('.slide-right').should.be.true;
114-
$sumiao.find('.slide-right').should.lengthOf($sumiao.find('.node').length);
110+
describe('addChildren()', function () {
111+
it('Add child nodes to the leaf node', function () {
112+
oc.addChildren($bomiao, { 'children': [{'name': 'Li Xin', 'id': 'n11' }] });
113+
$bomiao.closest('tr').siblings().should.lengthOf(3);
114+
$bomiao.closest('tr').siblings('.nodes').find('.node').attr('id').should.equal('n11');
115+
});
116+
117+
it('Add child nodes to the un-leaf node', function () {
118+
oc.addChildren($sumiao, { 'children': [{'name': 'Li Xin', 'id': 'n11' }] });
119+
$sumiao.closest('tr').siblings('.nodes').children().should.lengthOf(4);
120+
$sumiao.closest('tr').siblings('.nodes').children(':last').find('.node').attr('id').should.equal('n11');
121+
});
122+
});
123+
124+
describe('addSiblings()', function () {
125+
it('Just add sibling nodes', function () {
126+
oc.addSiblings($sumiao, { 'siblings': [{'name': 'Li Xin', 'id': 'n11' }] });
127+
$laolao.closest('tr').siblings('.nodes').children().should.lengthOf(4);
128+
$laolao.closest('tr').siblings('.nodes').children(':last').find('.node').attr('id').should.equal('n11');
129+
});
130+
131+
it('Add sibling nodes as well as parent node', function () {
132+
oc.addSiblings($laolao, { 'name': 'Lao Ye', 'id': 'n0', 'children': [{'name': 'Li Xin', 'id': 'n11' }] });
133+
$laolao.closest('.nodes').prevAll().should.lengthOf(3);
134+
oc.$chart.find('.node:first').should.deep.equal($('#n0'));
135+
$laolao.closest('table').parent().siblings().should.lengthOf(1);
136+
$laolao.closest('table').parent().siblings().find('.node').attr('id').should.equal('n11');
137+
});
138+
});
139+
140+
describe('removeNodes()', function () {
141+
it('Remove leaf node', function () {
142+
oc.removeNodes($dandan);
143+
$tiehua.closest('tr').siblings().should.lengthOf(0);
144+
});
145+
it('Remove parent node', function () {
146+
oc.removeNodes($tiehua);
147+
$sumiao.closest('tr').siblings('.nodes').children().should.lengthOf(2);
148+
$('#n5').should.lengthOf(0);
149+
$('#n8').should.lengthOf(0);
150+
});
151+
it('Remove parent node', function () {
152+
oc.removeNodes($laolao);
153+
oc.$chartContainer.is(':empty').should.be.true;
154+
});
115155
});
116156

117157
});

0 commit comments

Comments
 (0)