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
d1923580
Commit
d1923580
authored
Mar 10, 2020
by
Donald Cook
Committed by
Martin Wortschack
Mar 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor notes actions from Karma to Jest
parent
8633453d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
55 deletions
+50
-55
spec/frontend/notes/helpers.js
spec/frontend/notes/helpers.js
+12
-0
spec/frontend/notes/stores/actions_spec.js
spec/frontend/notes/stores/actions_spec.js
+37
-43
spec/javascripts/notes/helpers.js
spec/javascripts/notes/helpers.js
+1
-12
No files found.
spec/frontend/notes/helpers.js
0 → 100644
View file @
d1923580
// eslint-disable-next-line import/prefer-default-export
export
const
resetStore
=
store
=>
{
store
.
replaceState
({
notes
:
[],
targetNoteHash
:
null
,
lastFetchedAt
:
null
,
notesData
:
{},
userData
:
{},
noteableData
:
{},
});
};
spec/
javascripts
/notes/stores/actions_spec.js
→
spec/
frontend
/notes/stores/actions_spec.js
View file @
d1923580
import
$
from
'
jquery
'
;
import
{
TEST_HOST
}
from
'
spec/test_constants
'
;
import
AxiosMockAdapter
from
'
axios-mock-adapter
'
;
import
Api
from
'
~/api
'
;
import
actionsModule
,
*
as
actions
from
'
~/notes/stores/actions
'
;
import
Flash
from
'
~/flash
'
;
import
*
as
actions
from
'
~/notes/stores/actions
'
;
import
*
as
mutationTypes
from
'
~/notes/stores/mutation_types
'
;
import
*
as
notesConstants
from
'
~/notes/constants
'
;
import
createStore
from
'
~/notes/stores
'
;
...
...
@@ -19,21 +19,20 @@ import {
import
axios
from
'
~/lib/utils/axios_utils
'
;
const
TEST_ERROR_MESSAGE
=
'
Test error message
'
;
jest
.
mock
(
'
~/flash
'
);
describe
(
'
Actions Notes Store
'
,
()
=>
{
let
commit
;
let
dispatch
;
let
state
;
let
store
;
let
flashSpy
;
let
axiosMock
;
beforeEach
(()
=>
{
store
=
createStore
();
commit
=
j
asmine
.
createSpy
(
'
commit
'
);
dispatch
=
j
asmine
.
createSpy
(
'
dispatch
'
);
commit
=
j
est
.
fn
(
);
dispatch
=
j
est
.
fn
(
);
state
=
{};
flashSpy
=
spyOnDependency
(
actionsModule
,
'
Flash
'
);
axiosMock
=
new
AxiosMockAdapter
(
axios
);
});
...
...
@@ -244,10 +243,10 @@ describe('Actions Notes Store', () => {
});
describe
(
'
poll
'
,
()
=>
{
beforeEach
(
done
=>
{
jasmine
.
clock
().
install
();
jest
.
useFakeTimers
();
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
();
beforeEach
(
done
=>
{
jest
.
spyOn
(
axios
,
'
get
'
);
store
.
dispatch
(
'
setNotesData
'
,
notesDataMock
)
...
...
@@ -255,10 +254,6 @@ describe('Actions Notes Store', () => {
.
catch
(
done
.
fail
);
});
afterEach
(()
=>
{
jasmine
.
clock
().
uninstall
();
});
it
(
'
calls service with last fetched state
'
,
done
=>
{
axiosMock
.
onAny
()
...
...
@@ -271,7 +266,7 @@ describe('Actions Notes Store', () => {
expect
(
axios
.
get
).
toHaveBeenCalled
();
expect
(
store
.
state
.
lastFetchedAt
).
toBe
(
'
123456
'
);
j
asmine
.
clock
().
tick
(
1500
);
j
est
.
advanceTimersByTime
(
1500
);
})
.
then
(
()
=>
...
...
@@ -280,8 +275,8 @@ describe('Actions Notes Store', () => {
}),
)
.
then
(()
=>
{
expect
(
axios
.
get
.
calls
.
count
()
).
toBe
(
2
);
expect
(
axios
.
get
.
calls
.
mostRecent
().
args
[
1
].
headers
).
toEqual
({
expect
(
axios
.
get
.
mock
.
calls
.
length
).
toBe
(
2
);
expect
(
axios
.
get
.
mock
.
calls
[
axios
.
get
.
mock
.
calls
.
length
-
1
]
[
1
].
headers
).
toEqual
({
'
X-Last-Fetched-At
'
:
'
123456
'
,
});
})
...
...
@@ -310,13 +305,13 @@ describe('Actions Notes Store', () => {
beforeEach
(()
=>
{
axiosMock
.
onDelete
(
endpoint
).
replyOnce
(
200
,
{});
$
(
'
body
'
).
attr
(
'
data-page
'
,
''
);
document
.
body
.
setAttribute
(
'
data-page
'
,
''
);
});
afterEach
(()
=>
{
axiosMock
.
restore
();
$
(
'
body
'
).
attr
(
'
data-page
'
,
''
);
document
.
body
.
setAttribute
(
'
data-page
'
,
''
);
});
it
(
'
commits DELETE_NOTE and dispatches updateMergeRequestWidget
'
,
done
=>
{
...
...
@@ -347,7 +342,7 @@ describe('Actions Notes Store', () => {
it
(
'
dispatches removeDiscussionsFromDiff on merge request page
'
,
done
=>
{
const
note
=
{
path
:
endpoint
,
id
:
1
};
$
(
'
body
'
).
attr
(
'
data-page
'
,
'
projects:merge_requests:show
'
);
document
.
body
.
setAttribute
(
'
data-page
'
,
'
projects:merge_requests:show
'
);
testAction
(
actions
.
removeNote
,
...
...
@@ -381,13 +376,13 @@ describe('Actions Notes Store', () => {
beforeEach
(()
=>
{
axiosMock
.
onDelete
(
endpoint
).
replyOnce
(
200
,
{});
$
(
'
body
'
).
attr
(
'
data-page
'
,
''
);
document
.
body
.
setAttribute
(
'
data-page
'
,
''
);
});
afterEach
(()
=>
{
axiosMock
.
restore
();
$
(
'
body
'
).
attr
(
'
data-page
'
,
''
);
document
.
body
.
setAttribute
(
'
data-page
'
,
''
);
});
it
(
'
dispatches removeNote
'
,
done
=>
{
...
...
@@ -534,7 +529,7 @@ describe('Actions Notes Store', () => {
describe
(
'
updateMergeRequestWidget
'
,
()
=>
{
it
(
'
calls mrWidget checkStatus
'
,
()
=>
{
spyOn
(
mrWidgetEventHub
,
'
$emit
'
);
jest
.
spyOn
(
mrWidgetEventHub
,
'
$emit
'
).
mockImplementation
(()
=>
{}
);
actions
.
updateMergeRequestWidget
();
...
...
@@ -589,7 +584,7 @@ describe('Actions Notes Store', () => {
actions
.
updateOrCreateNotes
({
commit
,
state
,
getters
,
dispatch
},
[
note
]);
expect
(
commit
.
calls
.
allArgs
()
).
toEqual
([[
mutationTypes
.
UPDATE_NOTE
,
note
]]);
expect
(
commit
.
mock
.
calls
).
toEqual
([[
mutationTypes
.
UPDATE_NOTE
,
note
]]);
});
it
(
'
Creates a new note if none exisits
'
,
()
=>
{
...
...
@@ -597,7 +592,7 @@ describe('Actions Notes Store', () => {
const
getters
=
{
notesById
:
{}
};
actions
.
updateOrCreateNotes
({
commit
,
state
,
getters
,
dispatch
},
[
note
]);
expect
(
commit
.
calls
.
allArgs
()
).
toEqual
([[
mutationTypes
.
ADD_NEW_NOTE
,
note
]]);
expect
(
commit
.
mock
.
calls
).
toEqual
([[
mutationTypes
.
ADD_NEW_NOTE
,
note
]]);
});
describe
(
'
Discussion notes
'
,
()
=>
{
...
...
@@ -619,7 +614,7 @@ describe('Actions Notes Store', () => {
actions
.
updateOrCreateNotes
({
commit
,
state
,
getters
,
dispatch
},
[
discussionNote
]);
expect
(
commit
.
calls
.
allArgs
()
).
toEqual
([
expect
(
commit
.
mock
.
calls
).
toEqual
([
[
mutationTypes
.
ADD_NEW_REPLY_TO_DISCUSSION
,
discussionNote
],
]);
});
...
...
@@ -630,7 +625,7 @@ describe('Actions Notes Store', () => {
actions
.
updateOrCreateNotes
({
commit
,
state
,
getters
,
dispatch
},
[
diffNote
]);
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([
expect
(
dispatch
.
mock
.
calls
).
toEqual
([
[
'
fetchDiscussions
'
,
{
path
:
state
.
notesData
.
discussionsPath
}],
]);
});
...
...
@@ -645,7 +640,7 @@ describe('Actions Notes Store', () => {
actions
.
updateOrCreateNotes
({
commit
,
state
,
getters
,
dispatch
},
[
discussionNote
]);
expect
(
commit
.
calls
.
allArgs
()
).
toEqual
([[
mutationTypes
.
ADD_NEW_NOTE
,
discussionNote
]]);
expect
(
commit
.
mock
.
calls
).
toEqual
([[
mutationTypes
.
ADD_NEW_NOTE
,
discussionNote
]]);
});
});
});
...
...
@@ -770,7 +765,7 @@ describe('Actions Notes Store', () => {
.
then
(()
=>
done
.
fail
(
'
Expected error to be thrown!
'
))
.
catch
(
err
=>
{
expect
(
err
).
toBe
(
error
);
expect
(
flashSpy
).
not
.
toHaveBeenCalled
();
expect
(
Flash
).
not
.
toHaveBeenCalled
();
})
.
then
(
done
)
.
catch
(
done
.
fail
);
...
...
@@ -792,7 +787,7 @@ describe('Actions Notes Store', () => {
)
.
then
(
resp
=>
{
expect
(
resp
.
hasFlash
).
toBe
(
true
);
expect
(
flashSpy
).
toHaveBeenCalledWith
(
expect
(
Flash
).
toHaveBeenCalledWith
(
'
Your comment could not be submitted because something went wrong
'
,
'
alert
'
,
flashContainer
,
...
...
@@ -818,7 +813,7 @@ describe('Actions Notes Store', () => {
)
.
then
(
data
=>
{
expect
(
data
).
toBe
(
res
);
expect
(
flashSpy
).
not
.
toHaveBeenCalled
();
expect
(
Flash
).
not
.
toHaveBeenCalled
();
})
.
then
(
done
)
.
catch
(
done
.
fail
);
...
...
@@ -833,9 +828,8 @@ describe('Actions Notes Store', () => {
let
flashContainer
;
beforeEach
(()
=>
{
spyOn
(
Api
,
'
applySuggestion
'
);
dispatch
.
and
.
returnValue
(
Promise
.
resolve
());
Api
.
applySuggestion
.
and
.
returnValue
(
Promise
.
resolve
());
jest
.
spyOn
(
Api
,
'
applySuggestion
'
).
mockReturnValue
(
Promise
.
resolve
());
dispatch
.
mockReturnValue
(
Promise
.
resolve
());
flashContainer
=
{};
});
...
...
@@ -852,32 +846,32 @@ describe('Actions Notes Store', () => {
it
(
'
when service success, commits and resolves discussion
'
,
done
=>
{
testSubmitSuggestion
(
done
,
()
=>
{
expect
(
commit
.
calls
.
allArgs
()
).
toEqual
([
expect
(
commit
.
mock
.
calls
).
toEqual
([
[
mutationTypes
.
APPLY_SUGGESTION
,
{
discussionId
,
noteId
,
suggestionId
}],
]);
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([[
'
resolveDiscussion
'
,
{
discussionId
}]]);
expect
(
flashSpy
).
not
.
toHaveBeenCalled
();
expect
(
dispatch
.
mock
.
calls
).
toEqual
([[
'
resolveDiscussion
'
,
{
discussionId
}]]);
expect
(
Flash
).
not
.
toHaveBeenCalled
();
});
});
it
(
'
when service fails, flashes error message
'
,
done
=>
{
const
response
=
{
response
:
{
data
:
{
message
:
TEST_ERROR_MESSAGE
}
}
};
Api
.
applySuggestion
.
and
.
r
eturnValue
(
Promise
.
reject
(
response
));
Api
.
applySuggestion
.
mockR
eturnValue
(
Promise
.
reject
(
response
));
testSubmitSuggestion
(
done
,
()
=>
{
expect
(
commit
).
not
.
toHaveBeenCalled
();
expect
(
dispatch
).
not
.
toHaveBeenCalled
();
expect
(
flashSpy
).
toHaveBeenCalledWith
(
`
${
TEST_ERROR_MESSAGE
}
.`
,
'
alert
'
,
flashContainer
);
expect
(
Flash
).
toHaveBeenCalledWith
(
`
${
TEST_ERROR_MESSAGE
}
.`
,
'
alert
'
,
flashContainer
);
});
});
it
(
'
when resolve discussion fails, fail gracefully
'
,
done
=>
{
dispatch
.
and
.
r
eturnValue
(
Promise
.
reject
());
dispatch
.
mockR
eturnValue
(
Promise
.
reject
());
testSubmitSuggestion
(
done
,
()
=>
{
expect
(
flashSpy
).
not
.
toHaveBeenCalled
();
expect
(
Flash
).
not
.
toHaveBeenCalled
();
});
});
});
...
...
@@ -887,13 +881,13 @@ describe('Actions Notes Store', () => {
const
filter
=
0
;
beforeEach
(()
=>
{
dispatch
.
and
.
r
eturnValue
(
new
Promise
(()
=>
{}));
dispatch
.
mockR
eturnValue
(
new
Promise
(()
=>
{}));
});
it
(
'
fetches discussions with filter and persistFilter false
'
,
()
=>
{
actions
.
filterDiscussion
({
dispatch
},
{
path
,
filter
,
persistFilter
:
false
});
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([
expect
(
dispatch
.
mock
.
calls
).
toEqual
([
[
'
setLoadingState
'
,
true
],
[
'
fetchDiscussions
'
,
{
path
,
filter
,
persistFilter
:
false
}],
]);
...
...
@@ -902,7 +896,7 @@ describe('Actions Notes Store', () => {
it
(
'
fetches discussions with filter and persistFilter true
'
,
()
=>
{
actions
.
filterDiscussion
({
dispatch
},
{
path
,
filter
,
persistFilter
:
true
});
expect
(
dispatch
.
calls
.
allArgs
()
).
toEqual
([
expect
(
dispatch
.
mock
.
calls
).
toEqual
([
[
'
setLoadingState
'
,
true
],
[
'
fetchDiscussions
'
,
{
path
,
filter
,
persistFilter
:
true
}],
]);
...
...
spec/javascripts/notes/helpers.js
View file @
d1923580
// eslint-disable-next-line import/prefer-default-export
export
const
resetStore
=
store
=>
{
store
.
replaceState
({
notes
:
[],
targetNoteHash
:
null
,
lastFetchedAt
:
null
,
notesData
:
{},
userData
:
{},
noteableData
:
{},
});
};
export
*
from
'
../../frontend/notes/helpers.js
'
;
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