mediawiki-extensions-Discus.../tests/qunit/controller.test.js
Ed Sanders f04abd02d4 Improve autosign handling of 3/5 tilde sigs and add tests
3 or 5 tilde signatures will be assumed to be erroneous and fixed
to 4 tilde signatures. This will be visible in the preview so shouldn't
come as a suprise to users.

Bug: T245628
Change-Id: I741f0761a6fb10c99cf3239ac5c6c7e1a2b872c7
2020-04-14 20:29:31 +00:00

68 lines
1.4 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
);
} );
} );