Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4110164
ve.dm.MWReferenceModel.test.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
ve.dm.MWReferenceModel.test.js
View Options
'use strict'
;
/*!
* @license MIT
*/
QUnit
.
module
(
've.dm.MWReferenceModel (Cite)'
,
ve
.
test
.
utils
.
newMwEnvironment
()
);
/* Tests */
QUnit
.
test
(
'find an unknown ref'
,
(
assert
)
=>
{
const
doc
=
ve
.
dm
.
citeExample
.
createExampleDocument
(
'references'
);
const
surface
=
new
ve
.
dm
.
Surface
(
doc
);
const
refNode
=
new
ve
.
dm
.
MWReferenceNode
(
{
type
:
'mwReference'
,
attributes
:
{},
originalDomElementsHash
:
Math
.
random
()
}
);
refNode
.
setDocument
(
doc
);
const
refModel
=
ve
.
dm
.
MWReferenceModel
.
static
.
newFromReferenceNode
(
refNode
);
// TODO: Callers might be surprised, the docs hint that a missing entry results in `null`.
assert
.
strictEqual
(
refModel
.
findInternalItem
(
surface
),
undefined
);
}
);
QUnit
.
test
(
'find a known ref'
,
(
assert
)
=>
{
const
doc
=
ve
.
dm
.
citeExample
.
createExampleDocument
(
'references'
);
const
surface
=
new
ve
.
dm
.
Surface
(
doc
);
// We know exactly where the third ref node is, grab it from the document.
const
refNode
=
doc
.
getDocumentNode
().
children
[
1
].
children
[
3
];
const
refModel
=
ve
.
dm
.
MWReferenceModel
.
static
.
newFromReferenceNode
(
refNode
);
const
found
=
refModel
.
findInternalItem
(
surface
);
assert
.
strictEqual
(
found
.
type
,
'internalItem'
);
}
);
QUnit
.
test
(
'insert new ref'
,
(
assert
)
=>
{
const
doc
=
new
ve
.
dm
.
Document
(
[
{
type
:
'paragraph'
,
internal
:
{
generated
:
'empty'
}
},
{
type
:
'/paragraph'
},
{
type
:
'internalList'
},
{
type
:
'/internalList'
}
]
);
const
surface
=
new
ve
.
dm
.
Surface
(
doc
);
const
internalList
=
doc
.
getInternalList
();
// Create a new, blank reference model linked to the doc.
const
refModel
=
new
ve
.
dm
.
MWReferenceModel
(
doc
);
const
oldNodeCount
=
internalList
.
getItemNodeCount
();
const
oldDocLength
=
doc
.
getLength
();
refModel
.
insertInternalItem
(
surface
);
assert
.
strictEqual
(
internalList
.
getItemNodeCount
(),
oldNodeCount
+
1
,
'internalItem added'
);
surface
.
setLinearSelection
(
new
ve
.
Range
(
1
)
);
refModel
.
insertReferenceNode
(
surface
.
getFragment
().
collapseToEnd
()
);
assert
.
strictEqual
(
doc
.
getLength
(),
oldDocLength
+
6
,
'mwReference added to document'
);
refModel
.
updateInternalItem
(
surface
);
assert
.
strictEqual
(
internalList
.
getNodeGroup
(
'mwReference/'
).
getAllReuses
(
'auto/0'
).
length
,
1
,
'keyedNodes track the ref'
);
}
);
QUnit
.
test
(
'insert ref reuse'
,
(
assert
)
=>
{
const
doc
=
ve
.
dm
.
citeExample
.
createExampleDocument
(
'references'
);
const
surface
=
new
ve
.
dm
.
Surface
(
doc
);
const
internalList
=
doc
.
getInternalList
();
// Duplicate a ref.
const
refNode
=
doc
.
getDocumentNode
().
children
[
1
].
children
[
3
];
const
refModel
=
ve
.
dm
.
MWReferenceModel
.
static
.
newFromReferenceNode
(
refNode
);
const
oldNodeCount
=
internalList
.
getItemNodeCount
();
const
oldDocLength
=
doc
.
getLength
();
assert
.
strictEqual
(
internalList
.
getNodeGroup
(
'mwReference/'
).
getAllReuses
(
'auto/0'
).
length
,
1
,
'Initial document does not reuse ref'
);
refModel
.
insertInternalItem
(
surface
);
assert
.
strictEqual
(
internalList
.
getItemNodeCount
(),
oldNodeCount
+
1
,
'internalItem added'
);
surface
.
setLinearSelection
(
new
ve
.
Range
(
1
)
);
refModel
.
insertReferenceNode
(
surface
.
getFragment
().
collapseToEnd
()
);
assert
.
strictEqual
(
doc
.
getLength
(),
oldDocLength
+
10
,
'mwReference added to document'
);
refModel
.
updateInternalItem
(
surface
);
assert
.
strictEqual
(
internalList
.
getNodeGroup
(
'mwReference/'
).
getAllReuses
(
'auto/0'
).
length
,
2
,
'keyedNodes track the ref reuse'
);
}
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 18, 21:35 (2 d, 20 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c2/23/e3981a42e7f2cab6f7b61563fcbb
Default Alt Text
ve.dm.MWReferenceModel.test.js (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment