Skip to content
This repository has been archived by the owner on Jan 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #67 from xgaia/js_test
Browse files Browse the repository at this point in the history
Positionable Tests
  • Loading branch information
Olivier Filangi committed Aug 2, 2016
2 parents 4c36581 + 4a200fa commit a159bab
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 4 deletions.
4 changes: 1 addition & 3 deletions askomics/static/js/link/AskomicsPositionableLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ class AskomicsPositionableLink extends AskomicsLink {

buildFiltersSPARQL(filters) {
let equalsign = '';
let ua = userAbstraction;

if (!this.strict) {
equalsign = '=';
}

let node = this.target ;
let secondNode = this.source ;
let info = ua.getPositionableEntities();


if (this.same_ref) {
Expand Down Expand Up @@ -94,7 +92,7 @@ class AskomicsPositionableLink extends AskomicsLink {
break;

default:
throw new Error("buildPositionableConstraintsGraph: unkown type :"+JSON.stringify(type));
throw new Error("buildPositionableConstraintsGraph: unkown type: "+this.type);
}
}

Expand Down
2 changes: 2 additions & 0 deletions askomics/test/client/index_tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<!-- askomicsTestFiles:js -->
<script src="js/istanbul/test/AskomicsLinkTest.js"></script>
<script src="js/istanbul/test/AskomicsNodeTest.js"></script>
<script src="js/istanbul/test/AskomicsPositionableLinkTest.js"></script>
<script src="js/istanbul/test/AskomicsPositionableNodeTest.js"></script>
<script src="js/istanbul/test/GraphBuilderTest.js"></script>
<script src="js/istanbul/test/GraphLinkTest.js"></script>
<script src="js/istanbul/test/GraphNodeTest.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion askomics/test/client/js/AskomicsLinkTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ describe('AskomicsLink', function(){
chai.assert.deepEqual(variates, []);
});
});
});
});
95 changes: 95 additions & 0 deletions askomics/test/client/js/AskomicsPositionableLinkTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*jshint esversion: 6 */

describe('AskomicsPositionableLink', function(){
let node1 = new GraphNode({ uri:"http://wwww.system/test1",label:'',_id: 15, _SPARQLid: "HelloWorldNode1", _suggested: false }, 12.5,16.3);
let node2 = new GraphNode({ uri:"http://wwww.system/test2",_id: 16, _SPARQLid: "HelloWorlNode2", _suggested: true }, 14.1,26.3);
let link = new AskomicsPositionableLink({ uri:'http://wwww.system/link1'},node1,node2);
describe('#Constructeur empty', function(){
it('* test constructor *', function(){
chai.assert.deepEqual(link.type, 'included');
chai.assert.deepEqual(link.label, 'included in');
chai.assert.deepEqual(link.same_tax, true);
chai.assert.deepEqual(link.same_ref, true);
chai.assert.deepEqual(link.strict, true);
});
});

describe('#SetJSON', function() {
it('* test setjson() *', function() {
let link2 = new AskomicsPositionableLink({ uri:'http://wwww.system/link1'},node1,node2);
let JSON_link = {
"_id": 11,
"_SPARQLid": "positionable1",
"_suggested": false,
"_uri": "positionable",
"_label": "excluded of",
"_linkindex": 1,
"_source": {},
"_target": {},
"_transitive": true,
"_negative": false,
"type": "excluded",
"same_tax": false,
"same_ref": true,
"strict": false
}

chai.expect(function () { link2.setjson(JSON_link); }).to.throw('Devel error: setjson : obj._source have no id property : {"_id":11,"_SPARQLid":"positionable1","_suggested":false,"_uri":"positionable","_label":"excluded of","_linkindex":1,"_source":{},"_target":{},"_transitive":true,"_negative":false,"type":"excluded","same_tax":false,"same_ref":true,"strict":false}');
//FIXME: setJSON without throwing an error
//link.setjson(JSON_link);
//chai.assert.deepEqual(link, JSON_link);
});
});


describe('#BuiltConstraintSPARQL', function() {
it('* test the constraints *', function() {
let expectedResult = [
[
"?URI :position_taxon ?taxon_",
"?URI :position_ref ?ref_",
"?URI :position_taxon ?taxon_",
"?URI :position_ref ?ref_",
"?URI :position_start ?start_",
"?URI :position_end ?end_",
"?URI :position_start ?start_",
"?URI :position_end ?end_",
"FILTER(?ref_ = ?ref_)",
"FILTER(?taxon_ = ?taxon_)",
"FILTER((?start_ > ?start_ ) && (?end_ < ?end_))"
],
""
];
chai.assert.deepEqual(link.buildConstraintsSPARQL(), expectedResult);
});
});


describe('#BuiltFiltersSPARQL', function() {
it('* test the filters *', function() {
let expectedResult = [
"FILTER(?ref_ = ?ref_)",
"FILTER(?taxon_ = ?taxon_)",
"FILTER((?start_ > ?start_ ) && (?end_ < ?end_))"
];
let filters = [];
link.buildFiltersSPARQL(filters);
chai.assert.deepEqual(filters, expectedResult);
});

it('* test the error *', function() {
let link2 = link;
let filters = [];
link2.type = 'bla';
chai.expect(function () { link2.buildFiltersSPARQL(filters); }).to.throw("buildPositionableConstraintsGraph: unkown type: bla");

});
});

describe('#Positionable link Display methods', function(){
it('* String output *', function(){
chai.assert.typeOf(link.getFillColor(),'string');
});
});

});
41 changes: 41 additions & 0 deletions askomics/test/client/js/AskomicsPositionableNodeTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*jshint esversion: 6 */

//define a positionable node
let PositionableNodeJSON = {
"_id": 0,
"_SPARQLid": "helloWorld",
"_suggested": false,
"_uri": "http://test.askomics#helloWorld",
"_label": "helloWorld",
"_actif": true,
"_weight": 1,
"_x": 0.0,
"_y": 0.0,
"_nlink": {},
"_attributes": {},
"_categories": {},
"_filters": {},
"_values": {},
"_isregexp": {},
"_inverseMatch": {}
}


describe('AskomicsPositionableNode', function(){
describe('#Constructor/JSON', function(){
it('* test all methods *', function(){
let positionableNode = new AskomicsPositionableNode({uri:"http://wwww.system/test1"},0.0,0.0);
positionableNode.setjson(PositionableNodeJSON);
chai.assert.deepEqual(positionableNode, PositionableNodeJSON);
});
});

describe('#Attribute Graph Display methods', function(){
it('* String output *', function(){
let nodeEmpty = new AskomicsPositionableNode({ label:"helloWorld", uri:"/huoulu/lolo/dddddd#", _id: 15, _SPARQLid: "HelloWorld16", _suggested: true }, 12.5,16.3);
chai.assert.typeOf(nodeEmpty.getTextFillColor(),'string');
chai.assert.typeOf(nodeEmpty.getTextStrokeColor(),'string');
chai.assert.typeOf(nodeEmpty.getNodeFillColor(),'string');
});
});
});

0 comments on commit a159bab

Please sign in to comment.