Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8518a249
Commit
8518a249
authored
Feb 01, 2021
by
Denys Mishunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests coverage for Diff Editor
parent
b278d8cb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
61 deletions
+129
-61
spec/frontend/editor/editor_lite_spec.js
spec/frontend/editor/editor_lite_spec.js
+129
-61
No files found.
spec/frontend/editor/editor_lite_spec.js
View file @
8518a249
...
...
@@ -13,6 +13,8 @@ import {
describe
(
'
Base editor
'
,
()
=>
{
let
editorEl
;
let
editor
;
let
defaultArguments
;
const
blobOriginalContent
=
'
Foo Foo
'
;
const
blobContent
=
'
Foo Bar
'
;
const
blobPath
=
'
test.md
'
;
const
blobGlobalId
=
'
snippet_777
'
;
...
...
@@ -21,6 +23,7 @@ describe('Base editor', () => {
beforeEach
(()
=>
{
setFixtures
(
'
<div id="editor" data-editor-loading></div>
'
);
editorEl
=
document
.
getElementById
(
'
editor
'
);
defaultArguments
=
{
el
:
editorEl
,
blobPath
,
blobContent
,
blobGlobalId
};
editor
=
new
EditorLite
();
});
...
...
@@ -42,7 +45,7 @@ describe('Base editor', () => {
expect
(
editorEl
.
dataset
.
editorLoading
).
toBeUndefined
();
});
describe
(
'
instance of the Editor
'
,
()
=>
{
describe
(
'
instance of the Editor
Lite
'
,
()
=>
{
let
modelSpy
;
let
instanceSpy
;
let
use
;
...
...
@@ -57,6 +60,10 @@ describe('Base editor', () => {
dispose
=
jest
.
fn
();
use
=
jest
.
fn
();
modelsStorage
=
new
Map
();
});
describe
(
'
instance of the Code Editor
'
,
()
=>
{
beforeEach
(()
=>
{
modelSpy
=
jest
.
spyOn
(
monacoEditor
,
'
createModel
'
).
mockImplementation
(()
=>
fakeModel
);
instanceSpy
=
jest
.
spyOn
(
monacoEditor
,
'
create
'
).
mockImplementation
(()
=>
({
setModel
,
...
...
@@ -81,19 +88,28 @@ describe('Base editor', () => {
});
it
(
'
creates model to be supplied to Monaco editor
'
,
()
=>
{
editor
.
createInstance
({
el
:
editorEl
,
blobPath
,
blobContent
,
blobGlobalId
:
''
}
);
editor
.
createInstance
(
defaultArguments
);
expect
(
modelSpy
).
toHaveBeenCalledWith
(
blobContent
,
undefined
,
createUri
(
blobPath
));
expect
(
modelSpy
).
toHaveBeenCalledWith
(
blobContent
,
undefined
,
createUri
(
blobGlobalId
,
blobPath
),
);
expect
(
setModel
).
toHaveBeenCalledWith
(
fakeModel
);
});
it
(
'
does not create a model automatically if model is passed as `null`
'
,
()
=>
{
editor
.
createInstance
({
...
defaultArguments
,
model
:
null
});
expect
(
modelSpy
).
not
.
toHaveBeenCalled
();
expect
(
setModel
).
not
.
toHaveBeenCalled
();
});
it
(
'
does not create a new model if a model for the path already exists
'
,
()
=>
{
modelSpy
=
jest
.
spyOn
(
monacoEditor
,
'
createModel
'
)
.
mockImplementation
((
content
,
lang
,
uri
)
=>
modelsStorage
.
set
(
uri
.
path
,
content
));
const
instanceOptions
=
{
el
:
editorEl
,
blobPath
,
blobContent
,
blobGlobalId
:
''
};
const
a
=
editor
.
createInstance
(
instanceOptions
);
const
b
=
editor
.
createInstance
(
instanceOptions
);
const
a
=
editor
.
createInstance
(
defaultArguments
);
const
b
=
editor
.
createInstance
(
defaultArguments
);
expect
(
a
===
b
).
toBe
(
false
);
expect
(
modelSpy
).
toHaveBeenCalledTimes
(
1
);
...
...
@@ -107,7 +123,7 @@ describe('Base editor', () => {
});
it
(
'
with blobGlobalId, creates model with id in uri
'
,
()
=>
{
editor
.
createInstance
({
el
:
editorEl
,
blobPath
,
blobContent
,
blobGlobalId
}
);
editor
.
createInstance
(
defaultArguments
);
expect
(
modelSpy
).
toHaveBeenCalledWith
(
blobContent
,
...
...
@@ -124,11 +140,14 @@ describe('Base editor', () => {
el
:
editorEl
,
...
instanceOptions
,
});
expect
(
instanceSpy
).
toHaveBeenCalledWith
(
editorEl
,
expect
.
objectContaining
(
instanceOptions
));
expect
(
instanceSpy
).
toHaveBeenCalledWith
(
editorEl
,
expect
.
objectContaining
(
instanceOptions
),
);
});
it
(
'
disposes instance when the editor is disposed
'
,
()
=>
{
editor
.
createInstance
({
el
:
editorEl
,
blobPath
,
blobContent
,
blobGlobalId
}
);
editor
.
createInstance
(
defaultArguments
);
expect
(
dispose
).
not
.
toHaveBeenCalled
();
...
...
@@ -138,6 +157,55 @@ describe('Base editor', () => {
});
});
describe
(
'
instance of the Diff Editor
'
,
()
=>
{
beforeEach
(()
=>
{
modelSpy
=
jest
.
spyOn
(
monacoEditor
,
'
createModel
'
).
mockImplementation
(()
=>
fakeModel
);
instanceSpy
=
jest
.
spyOn
(
monacoEditor
,
'
createDiffEditor
'
).
mockImplementation
(()
=>
({
setModel
,
getModel
,
dispose
,
use
,
onDidDispose
:
jest
.
fn
(),
}));
jest
.
spyOn
(
monacoEditor
,
'
getModel
'
).
mockImplementation
((
uri
)
=>
{
return
modelsStorage
.
get
(
uri
.
path
);
});
});
it
(
'
Diff Editor goes through the normal path of Code Editor just with the flag ON
'
,
()
=>
{
const
spy
=
jest
.
spyOn
(
editor
,
'
createInstance
'
).
mockImplementation
(()
=>
{});
editor
.
createDiffInstance
();
expect
(
spy
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
diff
:
true
,
}),
);
});
it
(
'
initializes the instance on a supplied DOM node
'
,
()
=>
{
const
wrongInstanceSpy
=
jest
.
spyOn
(
monacoEditor
,
'
create
'
).
mockImplementation
(()
=>
({}));
editor
.
createDiffInstance
({
...
defaultArguments
,
blobOriginalContent
});
expect
(
editor
.
editorEl
).
not
.
toBe
(
null
);
expect
(
wrongInstanceSpy
).
not
.
toHaveBeenCalled
();
expect
(
instanceSpy
).
toHaveBeenCalledWith
(
editorEl
,
expect
.
anything
());
});
it
(
'
creates correct model for the Diff Editor
'
,
()
=>
{
editor
.
createDiffInstance
({
...
defaultArguments
,
blobOriginalContent
});
const
uri
=
createUri
(
blobGlobalId
,
blobPath
);
expect
(
modelSpy
).
toHaveBeenCalledTimes
(
2
);
expect
(
modelSpy
.
mock
.
calls
[
0
]).
toEqual
([
blobContent
,
undefined
,
uri
]);
expect
(
modelSpy
.
mock
.
calls
[
1
]).
toEqual
([
blobOriginalContent
,
undefined
,
uri
]);
expect
(
setModel
).
toHaveBeenCalledWith
({
original
:
expect
.
anything
(),
modified
:
fakeModel
,
});
});
});
});
describe
(
'
multiple instances
'
,
()
=>
{
let
instanceSpy
;
let
inst1Args
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment