mediawiki-skins-MinervaNeue/tests/qunit/skins.minerva.scripts/pageIssues.test.js
Stephen Niedzielski 3dc9cff2c2 Hygiene: separate page issue view logic
- Move page issue view components that do not modify the DOM during
  during construction to PageIssueLearnMoreLink.js and PageIssueLink.js.
  PascalCase is used optimistically for filenaming in the hopes that
  these functions can become something like a JSX component. A "new"
  function prefix is used in the meantime.

- Move page issue view logic that munges the existing DOM to
  pageIssueFormatter.js. Substitute "create" prefixes for insert so that
  clients won't forget that calling the function is a modify operation.
  Alternative naming welcome but it shouldn't be confused with more
  idealistic components that do not depend on DOM state for
  construction.

- Consolidate createPageIssueBanner() and
  createPageIssueBannerMultiple() into insertPageIssueBanner() as the
  code was quite similar and were it a true component, it would probably
  be a single component.

All new files appear under page/ to keep their distinction from the
overlay code clear.

Some view logic remains in pageIssues.js but it shall be difficult to
isolate.

Bug: T212376
Change-Id: Iccce709c34fa8de5a28a5a00098add5775e3dc9a
2019-02-13 00:42:56 +00:00

124 lines
3.3 KiB
JavaScript

( function ( M ) {
var
pageIssues = M.require( 'skins.minerva.scripts/pageIssues' ),
mobile = M.require( 'mobile.startup' ),
util = mobile.util,
insertBannersOrNotice = pageIssues.test.insertBannersOrNotice,
icon = {},
MEDIUM_ISSUE = {
issue: {
severity: 'MEDIUM',
icon: icon
},
iconString: 'i',
text: 't'
},
LOW_ISSUE = {
issue: {
severity: 'LOW',
icon: icon
},
iconString: 'i',
text: 't'
},
HIGH_ISSUE = {
issue: {
severity: 'HIGH',
icon: icon
},
iconString: 'i',
text: 't'
},
getAllIssuesSections = pageIssues.test.getAllIssuesSections,
OverlayManager = mobile.OverlayManager,
Page = mobile.Page,
overlayManager = new OverlayManager( require( 'mediawiki.router' ) ),
$mockContainer = $(
'<div id=\'bodyContent\'>' +
'<table class=\'ambox ambox-content\'>' +
'<tbody class=\'mbox-text\'>' +
'<tr><td><span class=\'mbox-text-span\'> ambox text span </span></td></tr>' +
'</tbody>' +
'</table>' +
'</div>'
),
labelText = 'label text',
inline = true,
SECTION = '0',
processedAmbox = insertBannersOrNotice(
new Page( { el: $mockContainer } ),
labelText, SECTION, inline, overlayManager
);
QUnit.module( 'Minerva cleanuptemplates' );
QUnit.test( 'insertBannersOrNotice() should add a "learn more" message', function ( assert ) {
assert.strictEqual( /⧼skin-minerva-issue-learn-more⧽/.test( processedAmbox.html() ), true );
} );
QUnit.test( 'insertBannersOrNotice() should add an icon', function ( assert ) {
assert.strictEqual( /mw-ui-icon/.test( processedAmbox.html() ), true );
} );
QUnit.test( 'clicking on the product of insertBannersOrNotice() should trigger a URL change', function ( assert ) {
processedAmbox.click();
assert.strictEqual( window.location.hash, '#/issues/' + SECTION );
} );
QUnit.test( 'getAllIssuesSections', function ( assert ) {
var multipleIssuesWithDeletion,
multipleIssues, allIssuesOldTreatment, allIssuesNewTreatment;
allIssuesOldTreatment = {
0: [
MEDIUM_ISSUE,
LOW_ISSUE,
MEDIUM_ISSUE
]
};
multipleIssues = {
0: [
util.extend( {}, MEDIUM_ISSUE, { grouped: true } ),
util.extend( {}, LOW_ISSUE, { grouped: true } ),
util.extend( {}, MEDIUM_ISSUE, { grouped: true } )
]
};
multipleIssuesWithDeletion = {
0: [
HIGH_ISSUE,
util.extend( {}, MEDIUM_ISSUE, { grouped: true } ),
util.extend( {}, LOW_ISSUE, { grouped: true } ),
util.extend( {}, MEDIUM_ISSUE, { grouped: true } )
]
};
allIssuesNewTreatment = {
0: [
HIGH_ISSUE,
LOW_ISSUE,
MEDIUM_ISSUE
],
1: [
MEDIUM_ISSUE
]
};
assert.propEqual(
getAllIssuesSections( allIssuesOldTreatment ),
[ '0', '0', '0' ],
'section numbers correctly extracted from old treatment'
);
assert.propEqual(
getAllIssuesSections( allIssuesNewTreatment ),
[ '0', '0', '0', '1' ],
'section numbers correctly extracted from new treatment'
);
assert.propEqual(
getAllIssuesSections( multipleIssues ),
[ '0' ],
'multiple issues are packed into one entry since there is one box'
);
assert.propEqual(
getAllIssuesSections( multipleIssuesWithDeletion ),
[ '0', '0' ],
'while multiple issues are grouped, non-multiple issues are still reported'
);
} );
}( mw.mobileFrontend ) );