1
1
import assert from 'assert'
2
2
import domino from 'domino'
3
- import dominoDocumentFragment from '../utilities/DominoDocumentFragment'
4
3
import pagelib from '../../build/wikimedia-page-library-transform'
5
4
6
- const documentFragmentFromHTMLString = dominoDocumentFragment . documentFragmentFromHTMLString
7
5
const configureRedLinkTemplate = pagelib . RedLinks . test . configureRedLinkTemplate
8
- const redLinkAnchorsInContent = pagelib . RedLinks . test . redLinkAnchorsInContent
6
+ const redLinkAnchorsInDocument = pagelib . RedLinks . test . redLinkAnchorsInDocument
9
7
const newRedLinkTemplate = pagelib . RedLinks . test . newRedLinkTemplate
10
8
const replaceAnchorWithSpan = pagelib . RedLinks . test . replaceAnchorWithSpan
11
9
const hideRedLinks = pagelib . RedLinks . hideRedLinks
@@ -29,18 +27,10 @@ describe('RedLinks', () => {
29
27
} )
30
28
} )
31
29
32
- describe ( 'redLinkAnchorsInContent ()' , ( ) => {
30
+ describe ( 'redLinkAnchorsInDocument ()' , ( ) => {
33
31
it ( 'should find one red link in a document' , ( ) => {
34
32
const doc = domino . createDocument ( '<a id="link1">1</a><a id="link2" class="new">2</a>' )
35
- const redLinkAnchors = redLinkAnchorsInContent ( doc )
36
- assert . ok ( redLinkAnchors . length === 1 )
37
- assert . ok ( redLinkAnchors [ 0 ] . id === 'link2' )
38
- } )
39
-
40
- it ( 'should find one red link in a document fragment' , ( ) => {
41
- const frag =
42
- documentFragmentFromHTMLString ( '<a id="link1">1</a><a id="link2" class="new">2</a>' )
43
- const redLinkAnchors = redLinkAnchorsInContent ( frag )
33
+ const redLinkAnchors = redLinkAnchorsInDocument ( doc )
44
34
assert . ok ( redLinkAnchors . length === 1 )
45
35
assert . ok ( redLinkAnchors [ 0 ] . id === 'link2' )
46
36
} )
@@ -72,25 +62,6 @@ describe('RedLinks', () => {
72
62
// Ensure the swap happened - element '#two' should now be a SPAN
73
63
assert . ok ( elementTwoTagName ( doc ) === 'SPAN' )
74
64
} )
75
-
76
- it ( 'should replace a document fragment anchor with a span' , ( ) => {
77
- // We'll swap the 'A#two' with 'SPAN#two'
78
- const frag =
79
- documentFragmentFromHTMLString ( '<a id="one">1</a><a id="two" class="new">2</a>' )
80
- const elementTwoTagName = frag => frag . querySelector ( '#two' ) . tagName // eslint-disable-line require-jsdoc, max-len
81
- // #two should initially be an 'A'
82
- assert . ok ( elementTwoTagName ( frag ) === 'A' )
83
-
84
- // Here's the replacement 'SPAN#two'
85
- const span = domino . createDocument ( ) . createElement ( 'SPAN' )
86
- span . id = 'two'
87
-
88
- // Swap!
89
- replaceAnchorWithSpan ( frag . querySelector ( '#two' ) , span )
90
-
91
- // Ensure the swap happened - element '#two' should now be a SPAN
92
- assert . ok ( elementTwoTagName ( frag ) === 'SPAN' )
93
- } )
94
65
} )
95
66
96
67
describe ( 'hideRedLinks()' , ( ) => {
@@ -103,17 +74,5 @@ describe('RedLinks', () => {
103
74
assert . ok ( item2 . tagName === 'SPAN' )
104
75
assert . ok ( item2 . innerHTML === '<b>2</b>' )
105
76
} )
106
-
107
- it ( 'should hide the expected red links in a document fragment' , ( ) => {
108
- const doc = domino . createDocument ( )
109
- const frag =
110
- documentFragmentFromHTMLString ( '<a id="item1">1</a><a id="item2" class="new"><b>2</b></a>' )
111
- hideRedLinks ( doc , frag )
112
- const item1 = frag . querySelector ( '#item1' )
113
- const item2 = frag . querySelector ( '.new' )
114
- assert . ok ( item1 . tagName === 'A' )
115
- assert . ok ( item2 . tagName === 'SPAN' )
116
- assert . ok ( item2 . innerHTML === '<b>2</b>' )
117
- } )
118
77
} )
119
78
} )
0 commit comments