Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5967930
formatter.test.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
formatter.test.js
View Options
import
*
as
formatter
from
'../../src/formatter'
;
QUnit
.
module
(
'ext.popups.formatter'
,
{
beforeEach
()
{
mw
.
util
=
{
escapeRegExp
:
this
.
sandbox
.
spy
(
(
str
)
=>
{
return
str
.
replace
(
/([\\{}()|.?*+\-^$[\]])/g
,
'\\$1'
);
}
)
};
},
afterEach
()
{
mw
.
util
=
null
;
}
}
);
QUnit
.
test
(
'Title is bold'
,
(
assert
)
=>
{
const
cases
=
[
[
'Isaac Newton was born in'
,
'Isaac Newton'
,
'<b>Isaac Newton</b> was born in'
,
'Title as first word'
],
[
'The C* language not to be confused with C# or C'
,
'C*'
,
'The <b>C*</b> language not to be confused with C# or C'
,
'Title containing *'
],
[
'I like trains'
,
'Train'
,
'I like <b>train</b>s'
,
'Make the simple plural bold'
],
[
'Foo\'s pub is a pub in Bar'
,
'Foo\'s pub'
,
'<b>Foo\'s pub</b> is a pub in Bar'
,
'Correct escaping'
],
[
'"Heroes" is a David Bowie album'
,
'"Heroes"'
,
'<b>"Heroes"</b> is a David Bowie album'
,
'Quotes in title'
],
[
'*Testing if Things are correctly identified'
,
'Things'
,
'*Testing if <b>Things</b> are correctly identified'
,
'Article that begins with asterisk'
],
[
'Testing if repeated words are not matched when repeated'
,
'Repeated'
,
'Testing if <b>repeated</b> words are not matched when repeated'
,
'Repeated title'
]
];
function
runTest
(
extract
,
title
,
expected
,
msg
)
{
const
$div
=
$
(
'<div>'
).
append
(
formatter
.
formatPlainTextExtract
(
extract
,
title
)
);
assert
.
strictEqual
(
$div
.
html
(),
expected
,
msg
);
}
cases
.
forEach
(
(
case_
)
=>
{
runTest
(
case_
[
0
],
case_
[
1
],
case_
[
2
],
case_
[
3
]
);
}
);
}
);
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Oct 3, 12:43 (2 d, 23 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
3d/ba/99238206e95b6e166f627c083f5a
Default Alt Text
formatter.test.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment