mediawiki-extensions-Discus.../tests/qunit/controller.test.js
Ed Sanders d40e427b5b Remove extra linebreaks from wikitext
Extra lines currently render empty list items which are invisible.
Remove these as the user probably didn't intend from them to appear
in the wikiext.

Bug: T249867
Change-Id: I75c1192a94b918783d362d38cd91a508bb169d56
2020-04-14 20:29:38 +00:00

112 lines
2.2 KiB
JavaScript

var
utils = require( './testUtils.js' ),
controller = require( 'ext.discussionTools.init' ).controller;
QUnit.module( 'mw.dt.controller', utils.newEnvironment() );
QUnit.test( 'autoSignWikitext', function ( assert ) {
var cases;
cases = [
{
msg: 'Simple message',
wikitext: 'Foo bar',
expected: 'Foo bar ~~~~'
},
{
msg: 'Whitespace',
wikitext: ' \t Foo bar \t ',
expected: 'Foo bar ~~~~'
},
{
msg: 'Already signed',
wikitext: 'Foo bar ~~~~',
expected: 'Foo bar ~~~~'
},
{
msg: 'Already signed multi-line',
wikitext: 'Foo\n\nbar\n\n~~~~',
expected: 'Foo\n\nbar\n\n~~~~'
},
{
msg: 'Already signed with hyphens',
wikitext: 'Foo bar --~~~~',
expected: 'Foo bar --~~~~'
},
{
msg: 'Already signed without space',
wikitext: 'Foo bar~~~~',
// Unless we special case certain characters, such as "-" this
// has to behave the same as "Already signed with hyphens"
expected: 'Foo bar~~~~'
},
{
msg: 'Signed with 5 tildes',
wikitext: 'Foo bar ~~~~~',
expected: 'Foo bar ~~~~'
},
{
msg: 'Signed with 3 tildes',
wikitext: 'Foo bar ~~~',
expected: 'Foo bar ~~~~'
},
{
msg: 'Signed with 3 tildes and prefix',
wikitext: 'Foo bar --~~~',
expected: 'Foo bar --~~~~'
}
];
cases.forEach( function ( caseItem ) {
assert.strictEqual(
controller.autoSignWikitext( caseItem.wikitext ),
caseItem.expected,
caseItem.msg
);
} );
} );
QUnit.test( 'sanitizeWikitextLinebreaks', function ( assert ) {
var cases;
cases = [
{
msg: 'Two linebreaks',
wikitext: 'Foo\n\nbar\n\nbaz',
expected: 'Foo\nbar\nbaz'
},
{
wikitext: 'Foo\n\nbar\n\nbaz',
expected: 'Foo\nbar\nbaz'
},
{
msg: 'Three linebreaks',
wikitext: 'Foo\n\nbar\n\nbaz',
expected: 'Foo\nbar\nbaz'
},
{
msg: 'R+N linebreaks',
wikitext: 'Foo\r\nbar\r\nbaz',
expected: 'Foo\nbar\nbaz'
},
{
msg: 'Two R+N linebreaks',
wikitext: 'Foo\r\n\r\nbar\r\n\r\nbaz',
expected: 'Foo\nbar\nbaz'
},
{
msg: 'R linebreaks',
wikitext: 'Foo\rbar\rbaz',
expected: 'Foo\nbar\nbaz'
}
];
cases.forEach( function ( caseItem ) {
assert.strictEqual(
controller.sanitizeWikitextLinebreaks( caseItem.wikitext ),
caseItem.expected,
caseItem.msg
);
} );
} );