Add the possibility to change offenders' layout
This commit is contained in:
@@ -72,7 +72,8 @@ describe('index.js', function() {
|
||||
"abnormal": false,
|
||||
"score": 100,
|
||||
"abnormalityScore": 0,
|
||||
"offenders": ["body > h1[1]"]
|
||||
"offenders": "<div class=\"domTree\"><div><span>body</span><div><span>h1[1]</span></div></div></div>",
|
||||
"offendersCount": 1
|
||||
});
|
||||
|
||||
// Test javascriptExecutionTree
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
var should = require('chai').should();
|
||||
var offendersHelpers = require('../../lib/offendersHelpers');
|
||||
|
||||
describe('offendersHelpers', function() {
|
||||
|
||||
describe('domPathToArray', function() {
|
||||
|
||||
it('should transform a path to an array', function() {
|
||||
var result = offendersHelpers.domPathToArray('body > section#page > div.alternate-color > ul.retroGuide > li[0] > div.retro-chaine.france2');
|
||||
result.should.deep.equal(['body', 'section#page', 'div.alternate-color', 'ul.retroGuide', 'li[0]', 'div.retro-chaine.france2']);
|
||||
});
|
||||
|
||||
it('should work even if a space is missing', function() {
|
||||
var result = offendersHelpers.domPathToArray('body > section#page> div.alternate-color > ul.retroGuide >li[0] > div.retro-chaine.france2');
|
||||
result.should.deep.equal(['body', 'section#page', 'div.alternate-color', 'ul.retroGuide', 'li[0]', 'div.retro-chaine.france2']);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('listOfDomArraysToTree', function() {
|
||||
|
||||
it('should transform a list of arrays into a tree', function() {
|
||||
var result = offendersHelpers.listOfDomArraysToTree([
|
||||
['body', 'section#page', 'div.alternate-color', 'ul.retroGuide', 'li[0]', 'div.retro-chaine.france2'],
|
||||
['body', 'section#page', 'div.alternate-color', 'ul.retroGuide', 'li[0]', 'div.retro-chaine.france2'],
|
||||
['body', 'section#page', 'div.alternate-color', 'ul.retroGuide', 'li[1]', 'div.retro-chaine.france2']
|
||||
]);
|
||||
result.should.deep.equal({
|
||||
'body': {
|
||||
'section#page': {
|
||||
'div.alternate-color': {
|
||||
'ul.retroGuide': {
|
||||
'li[0]': {
|
||||
'div.retro-chaine.france2': 2
|
||||
},
|
||||
'li[1]': {
|
||||
'div.retro-chaine.france2': 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('domTreeToHTML', function() {
|
||||
|
||||
it('should transform a dom tree into HTML with the awaited format', function() {
|
||||
var result = offendersHelpers.domTreeToHTML({
|
||||
'body': {
|
||||
'ul.retroGuide': {
|
||||
'li[0]': {
|
||||
'div.retro-chaine.france2': 2
|
||||
},
|
||||
'li[1]': {
|
||||
'div.retro-chaine.france2': 1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
result.should.equal('<div class="domTree"><div><span>body</span><div><span>ul.retroGuide</span><div><span>li[0]</span><div><span>div.retro-chaine.france2 <span>(x2)</span></span></div></div><div><span>li[1]</span><div><span>div.retro-chaine.france2</span></div></div></div></div></div>');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('listOfDomPathsToHTML', function() {
|
||||
|
||||
it('should transform a list of path strings into HTML', function() {
|
||||
var result = offendersHelpers.listOfDomPathsToHTML([
|
||||
'body > ul.retroGuide > li[0] > div.retro-chaine.france2',
|
||||
'body > ul.retroGuide > li[1] > div.retro-chaine.france2',
|
||||
'body > ul.retroGuide > li[0] > div.retro-chaine.france2',
|
||||
]);
|
||||
|
||||
result.should.equal('<div class="domTree"><div><span>body</span><div><span>ul.retroGuide</span><div><span>li[0]</span><div><span>div.retro-chaine.france2 <span>(x2)</span></span></div></div><div><span>li[1]</span><div><span>div.retro-chaine.france2</span></div></div></div></div></div>');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -9,7 +9,7 @@ describe('rulesChecker', function() {
|
||||
|
||||
it('should produce a nice rules object', function() {
|
||||
var data = require('../fixtures/rulesCheckerInput.json');
|
||||
var policies = require('../fixtures/rulesCheckerPolicies.json');
|
||||
var policies = require('../fixtures/rulesCheckerPolicies');
|
||||
var expected = require('../fixtures/rulesCheckerOutput.json');
|
||||
|
||||
var results = rulesChecker.check(data, policies);
|
||||
|
||||
+4
-2
@@ -25,7 +25,8 @@
|
||||
"takeOffendersFrom": "metric3"
|
||||
},
|
||||
"value": 222,
|
||||
"offenders": ["offender1", "offender2"],
|
||||
"offenders": "offender1 - offender2",
|
||||
"offendersCount": 2,
|
||||
"bad": false,
|
||||
"abnormal": false,
|
||||
"score": 100,
|
||||
@@ -41,7 +42,8 @@
|
||||
"isAbnormalThreshold": 5000
|
||||
},
|
||||
"value": 6666,
|
||||
"offenders": ["offender1", "offender2"],
|
||||
"offenders": "offender1/offender2",
|
||||
"offendersCount": 2,
|
||||
"bad": true,
|
||||
"abnormal": true,
|
||||
"score": 0,
|
||||
|
||||
+13
-4
@@ -1,4 +1,5 @@
|
||||
{
|
||||
var policies = {
|
||||
|
||||
"metric1": {
|
||||
"tool": "tool1",
|
||||
"label": "The metric 1",
|
||||
@@ -14,7 +15,10 @@
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000,
|
||||
"takeOffendersFrom": "metric3"
|
||||
"takeOffendersFrom": "metric3",
|
||||
"offendersTransformFn": function(offenders) {
|
||||
return offenders.join(' - ');
|
||||
}
|
||||
},
|
||||
"metric3": {
|
||||
"tool": "tool1",
|
||||
@@ -22,7 +26,10 @@
|
||||
"message": "A great message",
|
||||
"isOkThreshold": 1000,
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
"isAbnormalThreshold": 5000,
|
||||
"offendersTransformFn": function(offenders) {
|
||||
return offenders.join('/');
|
||||
}
|
||||
},
|
||||
"metric4": {
|
||||
"tool": "tool1",
|
||||
@@ -81,4 +88,6 @@
|
||||
"isBadThreshold": 3000,
|
||||
"isAbnormalThreshold": 5000
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = policies;
|
||||
Reference in New Issue
Block a user