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
02509ff9
Commit
02509ff9
authored
Feb 09, 2022
by
Mark Florian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove setImmediate usage in specs
Part of
https://gitlab.com/gitlab-org/gitlab/-/issues/344247
.
parent
26138b35
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
137 deletions
+94
-137
spec/frontend/mocks_spec.js
spec/frontend/mocks_spec.js
+4
-7
spec/frontend/notebook/cells/code_spec.js
spec/frontend/notebook/cells/code_spec.js
+4
-8
spec/frontend/notebook/cells/output/index_spec.js
spec/frontend/notebook/cells/output/index_spec.js
+13
-23
spec/frontend/notebook/cells/prompt_spec.js
spec/frontend/notebook/cells/prompt_spec.js
+5
-9
spec/frontend/notebook/index_spec.js
spec/frontend/notebook/index_spec.js
+7
-13
spec/frontend/notes/deprecated_notes_spec.js
spec/frontend/notes/deprecated_notes_spec.js
+37
-44
spec/frontend/pager_spec.js
spec/frontend/pager_spec.js
+24
-33
No files found.
spec/frontend/mocks_spec.js
View file @
02509ff9
...
...
@@ -8,13 +8,10 @@ describe('Mock auto-injection', () => {
failMock
=
jest
.
spyOn
(
global
,
'
fail
'
).
mockImplementation
();
});
it
(
'
~/lib/utils/axios_utils
'
,
()
=>
{
return
Promise
.
all
([
expect
(
axios
.
get
(
'
http://gitlab.com
'
)).
rejects
.
toThrow
(
'
Unexpected unmocked request
'
),
setImmediate
(()
=>
{
expect
(
failMock
).
toHaveBeenCalledTimes
(
1
);
}),
]);
it
(
'
~/lib/utils/axios_utils
'
,
async
()
=>
{
await
expect
(
axios
.
get
(
'
http://gitlab.com
'
)).
rejects
.
toThrow
(
'
Unexpected unmocked request
'
);
expect
(
failMock
).
toHaveBeenCalledTimes
(
1
);
});
it
(
'
jQuery.ajax()
'
,
()
=>
{
...
...
spec/frontend/notebook/cells/code_spec.js
View file @
02509ff9
...
...
@@ -25,12 +25,10 @@ describe('Code component', () => {
};
describe
(
'
without output
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
vm
=
setupComponent
(
json
.
cells
[
0
]);
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
does not render output prompt
'
,
()
=>
{
...
...
@@ -39,12 +37,10 @@ describe('Code component', () => {
});
describe
(
'
with output
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
vm
=
setupComponent
(
json
.
cells
[
2
]);
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
does not render output prompt
'
,
()
=>
{
...
...
spec/frontend/notebook/cells/output/index_spec.js
View file @
02509ff9
import
Vue
from
'
vue
'
;
import
Vue
,
{
nextTick
}
from
'
vue
'
;
import
json
from
'
test_fixtures/blob/notebook/basic.json
'
;
import
CodeComponent
from
'
~/notebook/cells/output/index.vue
'
;
...
...
@@ -18,13 +18,11 @@ describe('Output component', () => {
};
describe
(
'
text output
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
const
textType
=
json
.
cells
[
2
];
createComponent
(
textType
.
outputs
[
0
]);
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
renders as plain text
'
,
()
=>
{
...
...
@@ -37,13 +35,11 @@ describe('Output component', () => {
});
describe
(
'
image output
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
const
imageType
=
json
.
cells
[
3
];
createComponent
(
imageType
.
outputs
[
0
]);
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
renders as an image
'
,
()
=>
{
...
...
@@ -86,13 +82,11 @@ describe('Output component', () => {
});
describe
(
'
svg output
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
const
svgType
=
json
.
cells
[
5
];
createComponent
(
svgType
.
outputs
[
0
]);
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
renders as an svg
'
,
()
=>
{
...
...
@@ -101,13 +95,11 @@ describe('Output component', () => {
});
describe
(
'
default to plain text
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
const
unknownType
=
json
.
cells
[
6
];
createComponent
(
unknownType
.
outputs
[
0
]);
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
renders as plain text
'
,
()
=>
{
...
...
@@ -119,16 +111,14 @@ describe('Output component', () => {
expect
(
vm
.
$el
.
querySelector
(
'
.prompt span
'
)).
not
.
toBeNull
();
});
it
(
"
renders as plain text when doesn't recognise other types
"
,
(
done
)
=>
{
it
(
"
renders as plain text when doesn't recognise other types
"
,
async
(
)
=>
{
const
unknownType
=
json
.
cells
[
7
];
createComponent
(
unknownType
.
outputs
[
0
]);
setImmediate
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
pre
'
)).
not
.
toBeNull
();
expect
(
vm
.
$el
.
textContent
.
trim
()).
toContain
(
'
testing
'
);
await
nextTick
();
done
();
}
);
expect
(
vm
.
$el
.
querySelector
(
'
pre
'
)).
not
.
toBeNull
();
expect
(
vm
.
$el
.
textContent
.
trim
()).
toContain
(
'
testing
'
);
});
});
});
spec/frontend/notebook/cells/prompt_spec.js
View file @
02509ff9
import
Vue
from
'
vue
'
;
import
Vue
,
{
nextTick
}
from
'
vue
'
;
import
PromptComponent
from
'
~/notebook/cells/prompt.vue
'
;
const
Component
=
Vue
.
extend
(
PromptComponent
);
...
...
@@ -7,7 +7,7 @@ describe('Prompt component', () => {
let
vm
;
describe
(
'
input
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
vm
=
new
Component
({
propsData
:
{
type
:
'
In
'
,
...
...
@@ -16,9 +16,7 @@ describe('Prompt component', () => {
});
vm
.
$mount
();
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
renders in label
'
,
()
=>
{
...
...
@@ -31,7 +29,7 @@ describe('Prompt component', () => {
});
describe
(
'
output
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
vm
=
new
Component
({
propsData
:
{
type
:
'
Out
'
,
...
...
@@ -40,9 +38,7 @@ describe('Prompt component', () => {
});
vm
.
$mount
();
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
renders in label
'
,
()
=>
{
...
...
spec/frontend/notebook/index_spec.js
View file @
02509ff9
import
{
mount
}
from
'
@vue/test-utils
'
;
import
Vue
from
'
vue
'
;
import
Vue
,
{
nextTick
}
from
'
vue
'
;
import
json
from
'
test_fixtures/blob/notebook/basic.json
'
;
import
jsonWithWorksheet
from
'
test_fixtures/blob/notebook/worksheets.json
'
;
import
Notebook
from
'
~/notebook/index.vue
'
;
...
...
@@ -17,12 +17,10 @@ describe('Notebook component', () => {
}
describe
(
'
without JSON
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
vm
=
buildComponent
({});
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
does not render
'
,
()
=>
{
...
...
@@ -31,12 +29,10 @@ describe('Notebook component', () => {
});
describe
(
'
with JSON
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
vm
=
buildComponent
(
json
);
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
renders cells
'
,
()
=>
{
...
...
@@ -57,12 +53,10 @@ describe('Notebook component', () => {
});
describe
(
'
with worksheets
'
,
()
=>
{
beforeEach
((
done
)
=>
{
beforeEach
(()
=>
{
vm
=
buildComponent
(
jsonWithWorksheet
);
setImmediate
(()
=>
{
done
();
});
return
nextTick
();
});
it
(
'
renders cells
'
,
()
=>
{
...
...
spec/frontend/notes/deprecated_notes_spec.js
View file @
02509ff9
...
...
@@ -5,6 +5,7 @@ import $ from 'jquery';
import
'
~/behaviors/markdown/render_gfm
'
;
import
{
createSpyObj
}
from
'
helpers/jest_helpers
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
{
setTestTimeoutOnce
}
from
'
helpers/timeout
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
*
as
urlUtility
from
'
~/lib/utils/url_utility
'
;
...
...
@@ -549,15 +550,14 @@ describe.skip('Old Notes (~/deprecated_notes.js)', () => {
expect
(
$notesContainer
.
find
(
'
.note.being-posted
'
).
length
).
toBeGreaterThan
(
0
);
});
it
(
'
should remove placeholder note when new comment is done posting
'
,
(
done
)
=>
{
it
(
'
should remove placeholder note when new comment is done posting
'
,
async
(
)
=>
{
mockNotesPost
();
$
(
'
.js-comment-button
'
).
click
();
setImmediate
(()
=>
{
expect
(
$notesContainer
.
find
(
'
.note.being-posted
'
).
length
).
toEqual
(
0
);
done
();
});
await
waitForPromises
();
expect
(
$notesContainer
.
find
(
'
.note.being-posted
'
).
length
).
toEqual
(
0
);
});
describe
(
'
postComment
'
,
()
=>
{
...
...
@@ -584,40 +584,37 @@ describe.skip('Old Notes (~/deprecated_notes.js)', () => {
});
});
it
(
'
should show actual note element when new comment is done posting
'
,
(
done
)
=>
{
it
(
'
should show actual note element when new comment is done posting
'
,
async
(
)
=>
{
mockNotesPost
();
$
(
'
.js-comment-button
'
).
click
();
setImmediate
(()
=>
{
expect
(
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
).
length
).
toBeGreaterThan
(
0
);
done
();
});
await
waitForPromises
();
expect
(
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
).
length
).
toBeGreaterThan
(
0
);
});
it
(
'
should reset Form when new comment is done posting
'
,
(
done
)
=>
{
it
(
'
should reset Form when new comment is done posting
'
,
async
(
)
=>
{
mockNotesPost
();
$
(
'
.js-comment-button
'
).
click
();
setImmediate
(()
=>
{
expect
(
$form
.
find
(
'
textarea.js-note-text
'
).
val
()).
toEqual
(
''
);
done
();
});
await
waitForPromises
();
expect
(
$form
.
find
(
'
textarea.js-note-text
'
).
val
()).
toEqual
(
''
);
});
it
(
'
should show flash error message when new comment failed to be posted
'
,
(
done
)
=>
{
it
(
'
should show flash error message when new comment failed to be posted
'
,
async
(
)
=>
{
mockNotesPostError
();
jest
.
spyOn
(
notes
,
'
addFlash
'
);
$
(
'
.js-comment-button
'
).
click
();
setImmediate
(()
=>
{
expect
(
notes
.
addFlash
).
toHaveBeenCalled
();
// JSDom doesn't support the :visible selector yet
expect
(
notes
.
flashContainer
.
style
.
display
).
not
.
toBe
(
'
none
'
);
done
();
});
await
waitForPromises
();
expect
(
notes
.
addFlash
).
toHaveBeenCalled
();
// JSDom doesn't support the :visible selector yet
expect
(
notes
.
flashContainer
.
style
.
display
).
not
.
toBe
(
'
none
'
);
});
});
...
...
@@ -657,16 +654,15 @@ describe.skip('Old Notes (~/deprecated_notes.js)', () => {
$form
.
find
(
'
textarea.js-note-text
'
).
val
(
sampleComment
);
});
it
(
'
should remove quick action placeholder when comment with quick actions is done posting
'
,
(
done
)
=>
{
it
(
'
should remove quick action placeholder when comment with quick actions is done posting
'
,
async
(
)
=>
{
jest
.
spyOn
(
gl
.
awardsHandler
,
'
addAwardToEmojiBar
'
);
$
(
'
.js-comment-button
'
).
click
();
expect
(
$notesContainer
.
find
(
'
.note.being-posted
'
).
length
).
toEqual
(
1
);
// Placeholder shown
setImmediate
(()
=>
{
expect
(
$notesContainer
.
find
(
'
.note.being-posted
'
).
length
).
toEqual
(
0
);
// Placeholder removed
done
();
});
await
waitForPromises
();
expect
(
$notesContainer
.
find
(
'
.note.being-posted
'
).
length
).
toEqual
(
0
);
// Placeholder removed
});
});
...
...
@@ -692,16 +688,15 @@ describe.skip('Old Notes (~/deprecated_notes.js)', () => {
$form
.
find
(
'
textarea.js-note-text
'
).
val
(
sampleComment
);
});
it
(
'
should show message placeholder including lines starting with slash
'
,
(
done
)
=>
{
it
(
'
should show message placeholder including lines starting with slash
'
,
async
(
)
=>
{
$
(
'
.js-comment-button
'
).
click
();
expect
(
$notesContainer
.
find
(
'
.note.being-posted
'
).
length
).
toEqual
(
1
);
// Placeholder shown
expect
(
$notesContainer
.
find
(
'
.note-body p
'
).
text
()).
toEqual
(
sampleComment
);
// No quick action processing
setImmediate
(()
=>
{
expect
(
$notesContainer
.
find
(
'
.note.being-posted
'
).
length
).
toEqual
(
0
);
// Placeholder removed
done
();
});
await
waitForPromises
();
expect
(
$notesContainer
.
find
(
'
.note.being-posted
'
).
length
).
toEqual
(
0
);
// Placeholder removed
});
});
...
...
@@ -730,23 +725,21 @@ describe.skip('Old Notes (~/deprecated_notes.js)', () => {
$form
.
find
(
'
textarea.js-note-text
'
).
html
(
sampleComment
);
});
it
(
'
should not render a script tag
'
,
(
done
)
=>
{
it
(
'
should not render a script tag
'
,
async
(
)
=>
{
$
(
'
.js-comment-button
'
).
click
();
setImmediate
(()
=>
{
const
$noteEl
=
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
);
$noteEl
.
find
(
'
.js-note-edit
'
).
click
();
$noteEl
.
find
(
'
textarea.js-note-text
'
).
html
(
updatedComment
);
$noteEl
.
find
(
'
.js-comment-save-button
'
).
click
();
await
waitForPromises
();
const
$updatedNoteEl
=
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
)
.
find
(
'
.js-task-list-container
'
);
const
$noteEl
=
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
);
$noteEl
.
find
(
'
.js-note-edit
'
).
click
();
$noteEl
.
find
(
'
textarea.js-note-text
'
).
html
(
updatedComment
);
$noteEl
.
find
(
'
.js-comment-save-button
'
).
click
();
expect
(
$updatedNoteEl
.
find
(
'
.note-text
'
).
text
().
trim
()).
toEqual
(
''
);
const
$updatedNoteEl
=
$notesContainer
.
find
(
`#note_
${
note
.
id
}
`
)
.
find
(
'
.js-task-list-container
'
);
done
();
});
expect
(
$updatedNoteEl
.
find
(
'
.note-text
'
).
text
().
trim
()).
toEqual
(
''
);
});
});
...
...
spec/frontend/pager_spec.js
View file @
02509ff9
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
$
from
'
jquery
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
removeParams
}
from
'
~/lib/utils/url_utility
'
;
import
Pager
from
'
~/pager
'
;
...
...
@@ -64,67 +65,59 @@ describe('pager', () => {
Pager
.
init
();
});
it
(
'
shows loader while loading next page
'
,
(
done
)
=>
{
it
(
'
shows loader while loading next page
'
,
async
(
)
=>
{
mockSuccess
();
jest
.
spyOn
(
Pager
.
loading
,
'
show
'
).
mockImplementation
(()
=>
{});
Pager
.
getOld
();
setImmediate
(()
=>
{
expect
(
Pager
.
loading
.
show
).
toHaveBeenCalled
();
await
waitForPromises
();
done
();
});
expect
(
Pager
.
loading
.
show
).
toHaveBeenCalled
();
});
it
(
'
hides loader on success
'
,
(
done
)
=>
{
it
(
'
hides loader on success
'
,
async
(
)
=>
{
mockSuccess
();
jest
.
spyOn
(
Pager
.
loading
,
'
hide
'
).
mockImplementation
(()
=>
{});
Pager
.
getOld
();
setImmediate
(()
=>
{
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
await
waitForPromises
();
done
();
});
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
});
it
(
'
hides loader on error
'
,
(
done
)
=>
{
it
(
'
hides loader on error
'
,
async
(
)
=>
{
mockError
();
jest
.
spyOn
(
Pager
.
loading
,
'
hide
'
).
mockImplementation
(()
=>
{});
Pager
.
getOld
();
setImmediate
(()
=>
{
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
await
waitForPromises
();
done
();
});
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
});
it
(
'
sends request to url with offset and limit params
'
,
(
done
)
=>
{
it
(
'
sends request to url with offset and limit params
'
,
async
(
)
=>
{
Pager
.
offset
=
100
;
Pager
.
limit
=
20
;
Pager
.
getOld
();
setImmediate
(()
=>
{
const
[
url
,
params
]
=
axios
.
get
.
mock
.
calls
[
0
];
await
waitForPromises
();
expect
(
params
).
toEqual
({
params
:
{
limit
:
20
,
offset
:
100
,
},
});
const
[
url
,
params
]
=
axios
.
get
.
mock
.
calls
[
0
];
expect
(
url
).
toBe
(
'
/some_list
'
);
done
();
expect
(
params
).
toEqual
({
params
:
{
limit
:
20
,
offset
:
100
,
},
});
expect
(
url
).
toBe
(
'
/some_list
'
);
});
it
(
'
disables if return count is less than limit
'
,
(
done
)
=>
{
it
(
'
disables if return count is less than limit
'
,
async
(
)
=>
{
Pager
.
offset
=
0
;
Pager
.
limit
=
20
;
...
...
@@ -132,12 +125,10 @@ describe('pager', () => {
jest
.
spyOn
(
Pager
.
loading
,
'
hide
'
).
mockImplementation
(()
=>
{});
Pager
.
getOld
();
setImmediate
(()
=>
{
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
expect
(
Pager
.
disable
).
toBe
(
true
);
await
waitForPromises
();
done
();
}
);
expect
(
Pager
.
loading
.
hide
).
toHaveBeenCalled
();
expect
(
Pager
.
disable
).
toBe
(
true
);
});
describe
(
'
has data-href attribute from list element
'
,
()
=>
{
...
...
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