Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5983636
codemirror.lint.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
codemirror.lint.test.js
View Options
// eslint-disable-next-line n/no-missing-require
const
{
Text
}
=
require
(
'ext.CodeMirror.v6.lib'
);
const
CodeMirrorLint
=
require
(
'../../resources/codemirror.lint.js'
);
const
cmLint
=
new
CodeMirrorLint
();
const
{
dom
,
update
}
=
cmLint
.
panel
;
const
doc
=
Text
.
of
(
[
'foo'
,
'bar'
]
);
const
apply
=
jest
.
fn
();
const
updateSelection
=
(
anchor
,
head
)
=>
{
update
(
{
state
:
{
doc
,
selection
:
{
main
:
{
anchor
,
head
}
}
},
transactions
:
[],
selectionSet
:
true
}
);
};
describe
(
'CodeMirrorLint'
,
()
=>
{
beforeEach
(
()
=>
{
cmLint
.
diagnostics
=
[
{
from
:
0
,
to
:
1
,
severity
:
'error'
,
message
:
'Error message'
,
actions
:
[
{
name
:
'Fix'
,
apply
},
{
name
:
'Suggestion'
,
apply
}
]
},
{
from
:
0
,
to
:
1
,
severity
:
'warning'
,
message
:
'Warning message'
},
{
from
:
0
,
to
:
1
,
severity
:
'info'
,
message
:
'Info message'
}
];
}
);
it
(
'should contain 3 parts'
,
()
=>
{
expect
(
dom
.
childElementCount
).
toEqual
(
3
);
expect
(
dom
.
firstChild
.
className
).
toEqual
(
'cm-mw-panel--status-worker'
);
expect
(
dom
.
firstChild
.
childElementCount
).
toEqual
(
3
);
expect
(
dom
.
firstChild
.
firstChild
.
className
).
toEqual
(
'cm-mw-panel--status-error'
);
expect
(
dom
.
firstChild
.
firstChild
.
lastChild
.
textContent
).
toEqual
(
'0'
);
expect
(
dom
.
firstChild
.
children
[
1
].
className
).
toEqual
(
'cm-mw-panel--status-warning'
);
expect
(
dom
.
firstChild
.
children
[
1
].
lastChild
.
textContent
).
toEqual
(
'0'
);
expect
(
dom
.
firstChild
.
lastChild
.
className
).
toEqual
(
'cm-mw-panel--status-info'
);
expect
(
dom
.
firstChild
.
lastChild
.
lastChild
.
textContent
).
toEqual
(
'0'
);
expect
(
dom
.
children
[
1
].
className
).
toEqual
(
'cm-mw-panel--status-message'
);
expect
(
dom
.
lastChild
.
className
).
toEqual
(
'cm-mw-panel--status-line'
);
}
);
it
(
'should update the diagnostics count'
,
()
=>
{
const
errorText
=
dom
.
querySelector
(
'.cm-mw-panel--status-error'
).
lastChild
;
const
warningText
=
dom
.
querySelector
(
'.cm-mw-panel--status-warning'
).
lastChild
;
const
infoText
=
dom
.
querySelector
(
'.cm-mw-panel--status-info'
).
lastChild
;
cmLint
.
updateDiagnosticsCount
(
'error'
,
errorText
);
cmLint
.
updateDiagnosticsCount
(
'warning'
,
warningText
);
cmLint
.
updateDiagnosticsCount
(
'info'
,
infoText
);
expect
(
errorText
.
textContent
).
toEqual
(
'1'
);
expect
(
warningText
.
textContent
).
toEqual
(
'1'
);
expect
(
infoText
.
textContent
).
toEqual
(
'1'
);
}
);
it
(
'should update the diagnostic message'
,
()
=>
{
const
message
=
dom
.
querySelector
(
'.cm-mw-panel--status-message'
);
cmLint
.
updateDiagnosticMessage
(
0
,
message
);
expect
(
message
.
textContent
).
toEqual
(
'Error messageFixSuggestion'
);
cmLint
.
updateDiagnosticMessage
(
2
,
message
);
expect
(
message
.
textContent
).
toEqual
(
''
);
cmLint
.
updateDiagnosticMessage
(
1
,
message
);
expect
(
message
.
textContent
).
toEqual
(
'Error messageFixSuggestion'
);
for
(
const
button
of
message
.
querySelectorAll
(
'button'
)
)
{
button
.
click
();
}
expect
(
apply
).
toHaveBeenCalledTimes
(
2
);
}
);
it
(
'should update the position/selection'
,
()
=>
{
const
line
=
dom
.
lastChild
;
updateSelection
(
1
,
1
);
expect
(
line
.
textContent
).
toEqual
(
'1:1'
);
updateSelection
(
1
,
6
);
expect
(
line
.
textContent
).
toEqual
(
'2:2|(1:1)'
);
updateSelection
(
5
,
2
);
expect
(
line
.
textContent
).
toEqual
(
'1:2|(1:0)'
);
}
);
}
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Oct 3, 22:57 (1 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
ce/7b/5755763573b600870298a1db9f2f
Default Alt Text
codemirror.lint.test.js (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment