Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4104208
identifyLeadParagraph.test.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
identifyLeadParagraph.test.js
View Options
/* global $ */
const
jQuery
=
require
(
'../utils/jQuery'
),
dom
=
require
(
'../utils/dom'
),
sinon
=
require
(
'sinon'
);
let
sandbox
,
identifyLeadParagraph
;
QUnit
.
module
(
'MobileFrontend mobile.editor.overlay/identifyLeadParagraph'
,
{
beforeEach
:
function
()
{
sandbox
=
sinon
.
sandbox
.
create
();
dom
.
setUp
(
sandbox
,
global
);
jQuery
.
setUp
(
sandbox
,
global
);
identifyLeadParagraph
=
require
(
'../../../src/mobile.editor.overlay/identifyLeadParagraph'
);
},
afterEach
:
function
()
{
jQuery
.
tearDown
();
sandbox
.
restore
();
}
}
);
// Keep in sync with MoveLeadParagraphTransformTest::provideTransform()
function
provideCases
()
{
const
infobox
=
'<table class="infobox">1</table>'
,
coordinates
=
'<span id="coordinates"><span>0;0</span></span>'
,
anotherInfobox
=
'<table class="infobox">2</table>'
,
stackInfobox
=
`<div class="mw-stack">
${
infobox
}
</div>`
,
emptyStack
=
'<div class="mw-stack">Empty</div>'
,
multiStackInfobox
=
`<div class="mw-stack">
${
infobox
}${
anotherInfobox
}
</div>`
,
paragraph
=
'<p><b>First paragraph</b> <span> with info that links to a '
+
'\n <a href="">Page</a></span> and some more content</p>'
,
emptyP
=
'<p></p>'
,
// The paragraphWithWhitespacesOnly has not only whitespaces (space,new line,tab)
// , but also contains a span with whitespaces
paragraphWithWhitespacesOnly
=
'<p class="someParagraphClass"> \t'
+
'\n<span> \t\r\n</span></p>'
,
collapsibleInfobox
=
'<table class="collapsible"><table class="infobox"></table></table>'
,
collapsibleNotInfobox
=
'<table class="collapsible">'
+
'<table class="mf-test-infobox"></table></table>'
;
return
[
[
`
${
collapsibleNotInfobox
}
<p>one</p>`
,
'p'
,
'Collapsible mf-infoboxes are not moved.'
],
[
`
${
collapsibleInfobox
}
<p>one</p>`
,
'p'
,
'Collapsible infoboxes are moved.'
],
[
'<div><table class="mf-infobox"></table></div><p>one</p>'
,
'p'
],
[
`
${
infobox
}${
paragraph
}
`
,
'p'
],
[
`
${
emptyP
}${
emptyP
}${
infobox
}${
paragraph
}
`
,
'p:last-of-type'
,
'Empty paragraphs are ignored'
],
[
`
${
paragraphWithWhitespacesOnly
}${
infobox
}${
paragraph
}
`
,
'p:last-of-type'
,
'T199282: lead paragraph should move when there is empty paragraph before infobox'
],
[
`
${
infobox
}${
paragraphWithWhitespacesOnly
}
`
,
null
,
'T199282: the empty paragraph should not be treated as lead paragraph'
],
[
`
${
paragraph
}${
emptyP
}${
infobox
}${
paragraph
}
`
,
'p:first-of-type'
,
'T188825: Infobox has to be first non-empty element'
],
[
`
${
stackInfobox
}${
paragraph
}
`
,
'p'
,
'T170006: If the infobox is wrapped in a known container it can be moved'
],
[
`
${
emptyStack
}${
paragraph
}
`
,
'p'
,
'T170006: However if no infobox inside don\'t move.'
],
[
`
${
infobox
}${
emptyStack
}${
paragraph
}
`
,
'p'
,
'T170006: When a stack and an infobox, ignore mw-stack'
],
[
`
${
multiStackInfobox
}${
paragraph
}
`
,
'p'
,
'T170006: Multiple infoboxes will also be moved'
],
[
`
${
infobox
}
<p>
${
coordinates
}
</p><p>First paragraph</p>`
,
'p:last-of-type'
,
'Paragraph with just coordinates in it is ignored'
],
[
`
${
infobox
}
<p>First paragraph with
${
coordinates
}
</p><p>Second paragraph</p>`
,
'p:first-of-type'
,
'Paragraph with coordinates in it is still the first paragraph'
],
[
`
${
infobox
}
<p><span>foo</span>
${
coordinates
}
</p><p>Second paragraph</p>`
,
'p:first-of-type'
,
'Paragraph with non-empty nested child and coordinates in it is still the first paragraph'
],
[
`
${
infobox
}
<p>Lead <span>
${
coordinates
}
</span> para</p><p>Not lead</p>`
,
'p:first-of-type'
,
'Paragraph with nested coordinates is still the first paragraph'
]
];
}
QUnit
.
test
(
'identifyLeadParagraph'
,
function
(
assert
)
{
const
cases
=
provideCases
();
for
(
let
i
=
0
;
i
<
cases
.
length
;
i
++
)
{
const
[
html
,
expectedSel
,
message
]
=
cases
[
i
];
const
$dom
=
$
(
'<section>'
).
html
(
html
);
const
expectedNode
=
expectedSel
?
$dom
.
find
(
expectedSel
)[
0
]
:
null
;
assert
.
strictEqual
(
expectedNode
,
identifyLeadParagraph
(
$dom
),
message
);
}
}
);
File Metadata
Details
Attached
Mime Type
text/html
Expires
Tue, Aug 18, 18:22 (3 w, 1 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
41/f4/735056d67d860b104e3b1419c29d
Default Alt Text
identifyLeadParagraph.test.js (4 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment