| 1 |
( function () { |
| 2 |
const iconElement = document.createElement( 'div' ), |
| 3 |
pageIssuesParser = require( 'skins.minerva.scripts/page-issues/parser.js' ), |
| 4 |
extractMessage = pageIssuesParser.extract; |
| 5 |
|
| 6 |
iconElement.classList.add( 'minerva-icon--issue-generic-defaultColor', 'minerva-ambox-icon' ); |
| 7 |
QUnit.module( 'Minerva pageIssuesParser' ); |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
function newBox( className ) { |
| 14 |
const box = document.createElement( 'div' ); |
| 15 |
box.className = className; |
| 16 |
return box; |
| 17 |
} |
| 18 |
|
| 19 |
QUnit.test( 'extractMessage', ( assert ) => { |
| 20 |
[ |
| 21 |
[ |
| 22 |
$( '<div>' ).html( |
| 23 |
'<div class="mbox-text">Smelly</div>' |
| 24 |
).appendTo( '<div class="mw-collapsible-content" />' ), |
| 25 |
{ |
| 26 |
issue: { |
| 27 |
severity: 'DEFAULT', |
| 28 |
iconElement, |
| 29 |
grouped: true |
| 30 |
}, |
| 31 |
text: '<p>Smelly</p>' |
| 32 |
}, |
| 33 |
'When the box is a child of mw-collapsible-content it grouped' |
| 34 |
], |
| 35 |
[ |
| 36 |
$( '<div>' ).html( |
| 37 |
'<div class="mbox-text">Dirty</div>' |
| 38 |
), |
| 39 |
{ |
| 40 |
issue: { |
| 41 |
severity: 'DEFAULT', |
| 42 |
iconElement, |
| 43 |
grouped: false |
| 44 |
}, |
| 45 |
text: '<p>Dirty</p>' |
| 46 |
}, |
| 47 |
'When the box is not child of mw-collapsible-content it !grouped' |
| 48 |
] |
| 49 |
].forEach( ( test ) => { |
| 50 |
const msg = extractMessage( test[ 0 ] ); |
| 51 |
delete msg.$el; |
| 52 |
assert.deepEqual( |
| 53 |
msg, |
| 54 |
test[ 1 ], |
| 55 |
test[ 2 ] |
| 56 |
); |
| 57 |
} ); |
| 58 |
} ); |
| 59 |
|
| 60 |
QUnit.test( 'parseSeverity', ( assert ) => { |
| 61 |
const tests = [ |
| 62 |
[ '', 'DEFAULT', 'empty' ], |
| 63 |
[ 'foo', 'DEFAULT', 'unknown' ], |
| 64 |
[ 'ambox-style', 'LOW', 'style' ], |
| 65 |
[ 'ambox-content', 'MEDIUM', 'content' ], |
| 66 |
[ 'ambox-speedy', 'HIGH', 'speedy' ], |
| 67 |
[ 'ambox-delete', 'HIGH', 'delete' ], |
| 68 |
|
| 69 |
[ 'ambox-move', 'DEFAULT', 'move' ], |
| 70 |
|
| 71 |
[ 'ambox-content ambox-POV', 'MEDIUM', 'point of view' ] |
| 72 |
|
| 73 |
]; |
| 74 |
tests.forEach( ( params, i ) => { |
| 75 |
const className = params[ 0 ]; |
| 76 |
const expect = params[ 1 ]; |
| 77 |
const test = params[ 2 ]; |
| 78 |
const box = newBox( className ); |
| 79 |
assert.strictEqual( |
| 80 |
pageIssuesParser.test.parseSeverity( box ), |
| 81 |
expect, |
| 82 |
'Result should be the correct severity; case ' + i + ': ' + test + '.' |
| 83 |
); |
| 84 |
} ); |
| 85 |
} ); |
| 86 |
|
| 87 |
QUnit.test( 'parseType', ( assert ) => { |
| 88 |
const tests = [ |
| 89 |
[ '', 'DEFAULT', 'issue-generic', 'empty' ], |
| 90 |
[ 'foo', 'DEFAULT', 'issue-generic', 'unknown' ], |
| 91 |
[ 'ambox-move', 'DEFAULT', 'issue-type-move', 'move' ], |
| 92 |
[ 'ambox-POV', 'MEDIUM', 'issue-type-point-of-view', 'point of view' ], |
| 93 |
[ '', 'DEFAULT', 'issue-generic', 'Default severity' ], |
| 94 |
[ '', 'LOW', 'issue-severity-low', 'Low severity' ], |
| 95 |
[ '', 'MEDIUM', 'issue-severity-medium', 'Medium severity' ], |
| 96 |
[ '', 'HIGH', 'issue-generic', 'HIGH severity' ] |
| 97 |
]; |
| 98 |
tests.forEach( ( params, i ) => { |
| 99 |
const className = params[ 0 ]; |
| 100 |
const severity = params[ 1 ]; |
| 101 |
const expect = { |
| 102 |
name: params[ 2 ], |
| 103 |
severity: severity |
| 104 |
}; |
| 105 |
const test = params[ 3 ]; |
| 106 |
const box = newBox( className ); |
| 107 |
assert.propEqual( |
| 108 |
pageIssuesParser.test.parseType( box, severity ), |
| 109 |
expect, |
| 110 |
'Result should be the correct icon type; case ' + i + ': ' + test + '.' |
| 111 |
); |
| 112 |
} ); |
| 113 |
} ); |
| 114 |
|
| 115 |
QUnit.test( 'parseGroup', ( assert ) => { |
| 116 |
const tests = [ |
| 117 |
[ undefined, false, 'orphaned' ], |
| 118 |
[ '', false, 'ungrouped' ], |
| 119 |
[ 'mw-collapsible-content', true, 'grouped' ] |
| 120 |
]; |
| 121 |
tests.forEach( ( params, i ) => { |
| 122 |
const parentClassName = params[ 0 ]; |
| 123 |
const expect = params[ 1 ]; |
| 124 |
const test = params[ 2 ]; |
| 125 |
const box = newBox( '' ); |
| 126 |
if ( parentClassName !== undefined ) { |
| 127 |
const parent = document.createElement( 'div' ); |
| 128 |
parent.className = parentClassName; |
| 129 |
parent.appendChild( box ); |
| 130 |
} |
| 131 |
assert.strictEqual( |
| 132 |
pageIssuesParser.test.parseGroup( box ), |
| 133 |
expect, |
| 134 |
'Result should be the correct grouping; case ' + i + ': ' + test + '.' |
| 135 |
); |
| 136 |
} ); |
| 137 |
} ); |
| 138 |
|
| 139 |
QUnit.test( 'iconName', ( assert ) => { |
| 140 |
const tests = [ |
| 141 |
[ '', 'DEFAULT', 'issue-generic-defaultColor' ], |
| 142 |
[ '', 'LOW', 'issue-severity-low-lowColor' ], |
| 143 |
[ '', 'MEDIUM', 'issue-severity-medium-mediumColor' ], |
| 144 |
[ '', 'HIGH', 'issue-generic-highColor' ], |
| 145 |
[ 'ambox-move', 'DEFAULT', 'issue-type-move-defaultColor' ], |
| 146 |
[ 'ambox-POV', 'MEDIUM', 'issue-type-point-of-view-mediumColor' ], |
| 147 |
|
| 148 |
|
| 149 |
[ 'ambox-style ambox-POV', 'LOW', 'issue-type-point-of-view-mediumColor' ], |
| 150 |
[ 'ambox-content ambox-move', 'MEDIUM', 'issue-type-move-defaultColor' ] |
| 151 |
]; |
| 152 |
tests.forEach( ( params, i ) => { |
| 153 |
const className = params[ 0 ]; |
| 154 |
const severity = params[ 1 ]; |
| 155 |
const expect = params[ 2 ]; |
| 156 |
const box = newBox( className ); |
| 157 |
assert.strictEqual( |
| 158 |
pageIssuesParser.iconName( box, severity ), |
| 159 |
expect, |
| 160 |
'Result should be the correct ResourceLoader icon name; case ' + i + ': ' + severity + '.' |
| 161 |
); |
| 162 |
} ); |
| 163 |
} ); |
| 164 |
|
| 165 |
QUnit.test( 'maxSeverity', ( assert ) => { |
| 166 |
const tests = [ |
| 167 |
[ [], 'DEFAULT' ], |
| 168 |
[ [ 'DEFAULT' ], 'DEFAULT' ], |
| 169 |
[ [ 'DEFAULT', 'LOW' ], 'LOW' ], |
| 170 |
[ [ 'DEFAULT', 'LOW', 'MEDIUM' ], 'MEDIUM' ], |
| 171 |
[ [ 'DEFAULT', 'LOW', 'MEDIUM', 'HIGH' ], 'HIGH' ], |
| 172 |
[ [ 'HIGH', 'DEFAULT', 'LOW', 'MEDIUM' ], 'HIGH' ], |
| 173 |
[ [ 'DEFAULT', 'HIGH', 'LOW', 'MEDIUM' ], 'HIGH' ] |
| 174 |
]; |
| 175 |
tests.forEach( ( params, i ) => { |
| 176 |
const severities = params[ 0 ]; |
| 177 |
const expect = params[ 1 ]; |
| 178 |
|
| 179 |
assert.strictEqual( |
| 180 |
pageIssuesParser.maxSeverity( severities ), |
| 181 |
expect, |
| 182 |
'Result should be the highest severity in the array; case ' + i + '.' |
| 183 |
); |
| 184 |
} ); |
| 185 |
} ); |
| 186 |
|
| 187 |
}() ); |