Skip to content

Commit

Permalink
WIP: add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeng committed Dec 26, 2017
1 parent 3c4b11d commit 8dd54eb
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 29 deletions.
1 change: 0 additions & 1 deletion demo/ajax-datasource.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

$('#chart-container').orgchart({
'data' : '/orgchart/initdata',
'depth': 2,
'nodeContent': 'title'
});

Expand Down
5 changes: 2 additions & 3 deletions demo/drag-drop.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
{ 'name': 'Hei Hei', 'title': 'senior engineer',
'children': [
{ 'name': 'Pang Pang', 'title': 'engineer' },
{ 'name': 'Xiang Xiang', 'title': 'UE engineer' }
{ 'name': 'Dan Dan', 'title': 'UE engineer' }
]
}
]
},
{ 'name': 'Hong Miao', 'title': 'department manager' },
{ 'name': 'Chun Miao', 'title': 'department manager' }
{ 'name': 'Hong Miao', 'title': 'department manager' }
]
};

Expand Down
15 changes: 7 additions & 8 deletions demo/local-datasource.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@
$(function() {

var datasource = {
'id': 'n1',
'name': 'Lao Lao',
'title': 'general manager',
'children': [
{ 'id': 'n2', 'name': 'Bo Miao', 'title': 'department manager' },
{ 'id': 'n3', 'name': 'Su Miao', 'title': 'department manager',
{ 'name': 'Bo Miao', 'title': 'department manager' },
{ 'name': 'Su Miao', 'title': 'department manager',
'children': [
{ 'id': 'n5', 'name': 'Tie Hua', 'title': 'senior engineer' },
{ 'id': 'n6', 'name': 'Hei Hei', 'title': 'senior engineer',
{ 'name': 'Tie Hua', 'title': 'senior engineer' },
{ 'name': 'Hei Hei', 'title': 'senior engineer',
'children': [
{ 'id': 'n8', 'name': 'Dan Dan', 'title': 'engineer' }
{ 'name': 'Dan Dan', 'title': 'engineer' }
]
},
{ 'id': 'n7', 'name': 'Pang Pang', 'title': 'senior engineer' }
{ 'name': 'Pang Pang', 'title': 'senior engineer' }
]
},
{ 'id': 'n4', 'name': 'Hong Miao', 'title': 'department manager' }
{ 'name': 'Hong Miao', 'title': 'department manager' }
]
}

Expand Down
4 changes: 2 additions & 2 deletions demo/vertical-depth.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
{ 'name': 'Dan Dan', 'title': 'engineer' },
{ 'name': 'Er Dan', 'title': 'engineer',
'children': [
{ 'name': 'Xuan Xuan', 'title': 'intern' },
{ 'name': 'Er Xuan', 'title': 'intern' }
{ 'name': 'San Dan', 'title': 'intern' },
{ 'name': 'Si Dan', 'title': 'intern' }
]
}
]}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"debug": "mocha ./test/**/*-tests.js --inspect-brk",
"build": "gulp build",
"start": "gulp serve",
"e2e": "testcafe chrome test/e2e/"
"e2e": "testcafe chrome test/e2e/",
"e2e:debug": "testcafe --inspect-brk chrome test/e2e"
},
"repository": {
"type": "git",
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/drag-drop/page-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Selector } from 'testcafe';

const nodes = Selector('.node');

export default class Page {
constructor () {
this.laolao = nodes.withText('Lao Lao');
this.bomiao = nodes.withText('Bo Miao');
this.sumiao = nodes.withText('Su Miao');
this.hongmiao = nodes.withText('Hong Miao');
this.lixin = nodes.withText('Li Xin');
this.tiehua = nodes.withText('Tie Hua');
this.heihei = nodes.withText('Hei Hei');
this.pangpang = nodes.withText('Pang Pang');
this.dandan = nodes.withText('Dan Dan');
}
}
74 changes: 74 additions & 0 deletions test/e2e/drag-drop/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Selector } from 'testcafe';
import Page from './page-model';

fixture `Drag & Drop`
.page `127.0.0.1:3000/drag-drop.html`;

const page = new Page();
const laolao = page.laolao;
const bomiao = page.bomiao;
const sumiao = page.sumiao;
const hongmiao = page.hongmiao;
const lixin = page.lixin;
const tiehua = page.tiehua;
const heihei = page.heihei;
const pangpang = page.pangpang;
const dandan = page.dandan;

const findNextNode = node => node.parent(3).nextSibling().find('.title').textContent;
const findOnlyChild = node => node.parent(1).sibling(':last-child').find('.title').textContent;
const getChildrenCount = node => node.parent(1).sibling(':last-child').child('td').count;
const getDescendantsCount = node => node.parent(1).sibling(':last-child').find('.node').count;

test('drag lixin onto hongmiao', async t => {
await t
.dragToElement(lixin, hongmiao)
.expect(hongmiao.parent(1).sibling().count).eql(3)
.expect(findOnlyChild(hongmiao)).eql('Li Xin')
.expect(bomiao.parent(1).sibling().count).eql(0);
});

test('drag lixin onto heihei', async t => {
await t
.dragToElement(lixin, heihei)
.expect(getChildrenCount(heihei)).eql(3)
.expect(findNextNode(dandan)).eql('Li Xin')
.expect(bomiao.parent(1).sibling().count).eql(0);
});

test('heihei onto hongmiao', async t => {
await t
.dragToElement(heihei, hongmiao)
.expect(getDescendantsCount(hongmiao)).eql(3)
.expect(findOnlyChild(hongmiao)).eql('Hei Hei')
.expect(findOnlyChild(sumiao)).eql('Tie Hua');
});

test('heihei onto bomiao', async t => {
await t
.dragToElement(heihei, bomiao)
.expect(getDescendantsCount(bomiao)).eql(4)
.expect(findNextNode(lixin)).eql('Hei Hei')
.expect(findOnlyChild(sumiao)).eql('Tie Hua');
});

test('pangpang onto heihei', async t => {
await t
.dragToElement(pangpang, heihei)
.expect(getChildrenCount(heihei)).eql(2)
.expect(findNextNode(dandan)).eql('Pang Pang');
});

test('dandan onto heihei', async t => {
await t
.dragToElement(dandan, heihei)
.expect(getChildrenCount(heihei)).eql(2)
.expect(findNextNode(pangpang)).eql('Dan Dan');
});

// test('hongmiao onto lixin', async t => {
// await t
// .dragToElement(hongmiao, lixin, { speed: 1 })
// .expect(sumiao.parent(3).nextSibling().find('.title').textContent).eql('Hong Miao')
// .expect(lixin.parent(1).sibling().count).eql(0);
// });
14 changes: 0 additions & 14 deletions test/e2e/local-datasource/page-model.js

This file was deleted.

16 changes: 16 additions & 0 deletions test/e2e/local-datasource/page-modeljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Selector } from 'testcafe';

const nodes = Selector('.node');

export default class Page {
constructor () {
this.laolao = nodes.withText('Lao Lao');
this.bomiao = nodes.withText('Bo Miao');
this.sumiao = nodes.withText('Su Miao');
this.hongmiao = nodes.withText('Hong Miao');
this.tiehua = nodes.withText('Tie Hua');
this.heihei = nodes.withText('Hei Hei');
this.pangpang = nodes.withText('Pang Pang');
this.dandan = nodes.withText('Dan Dan');
}
}
File renamed without changes.

0 comments on commit 8dd54eb

Please sign in to comment.