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
cc96bc92
Commit
cc96bc92
authored
Jun 15, 2020
by
Coung Ngo
Committed by
Phil Hughes
Jun 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update issue_show app_spec.js to use vue-test-utils
Updated it as it did not use vue-test-utils
parent
95c3aee2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
145 additions
and
135 deletions
+145
-135
spec/frontend/issue_show/components/app_spec.js
spec/frontend/issue_show/components/app_spec.js
+145
-135
No files found.
spec/frontend/issue_show/components/app_spec.js
View file @
cc96bc92
import
Vue
from
'
vue
'
;
import
{
mount
}
from
'
@vue/test-utils
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
visitUrl
}
from
'
~/lib/utils/url_utility
'
;
import
{
visitUrl
}
from
'
~/lib/utils/url_utility
'
;
import
'
~/behaviors/markdown/render_gfm
'
;
import
'
~/behaviors/markdown/render_gfm
'
;
import
i
ssuableApp
from
'
~/issue_show/components/app.vue
'
;
import
I
ssuableApp
from
'
~/issue_show/components/app.vue
'
;
import
eventHub
from
'
~/issue_show/event_hub
'
;
import
eventHub
from
'
~/issue_show/event_hub
'
;
import
{
initialRequest
,
secondRequest
}
from
'
../mock_data
'
;
import
{
initialRequest
,
secondRequest
}
from
'
../mock_data
'
;
...
@@ -23,7 +23,7 @@ const publishedIncidentUrl = 'https://status.com/';
...
@@ -23,7 +23,7 @@ const publishedIncidentUrl = 'https://status.com/';
describe
(
'
Issuable output
'
,
()
=>
{
describe
(
'
Issuable output
'
,
()
=>
{
let
mock
;
let
mock
;
let
realtimeRequestCount
=
0
;
let
realtimeRequestCount
=
0
;
let
vm
;
let
wrapper
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
setFixtures
(
`
setFixtures
(
`
...
@@ -42,8 +42,6 @@ describe('Issuable output', () => {
...
@@ -42,8 +42,6 @@ describe('Issuable output', () => {
</div>
</div>
`
);
`
);
const
IssuableDescriptionComponent
=
Vue
.
extend
(
issuableApp
);
mock
=
new
MockAdapter
(
axios
);
mock
=
new
MockAdapter
(
axios
);
mock
mock
.
onGet
(
'
/gitlab-org/gitlab-shell/-/issues/9/realtime_changes/realtime_changes
'
)
.
onGet
(
'
/gitlab-org/gitlab-shell/-/issues/9/realtime_changes/realtime_changes
'
)
...
@@ -53,7 +51,7 @@ describe('Issuable output', () => {
...
@@ -53,7 +51,7 @@ describe('Issuable output', () => {
return
res
;
return
res
;
});
});
vm
=
new
IssuableDescriptionComponent
(
{
wrapper
=
mount
(
IssuableApp
,
{
propsData
:
{
propsData
:
{
canUpdate
:
true
,
canUpdate
:
true
,
canDestroy
:
true
,
canDestroy
:
true
,
...
@@ -73,15 +71,16 @@ describe('Issuable output', () => {
...
@@ -73,15 +71,16 @@ describe('Issuable output', () => {
zoomMeetingUrl
,
zoomMeetingUrl
,
publishedIncidentUrl
,
publishedIncidentUrl
,
},
},
})
.
$mount
()
;
});
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
mock
.
restore
();
mock
.
restore
();
realtimeRequestCount
=
0
;
realtimeRequestCount
=
0
;
vm
.
poll
.
stop
();
wrapper
.
vm
.
poll
.
stop
();
vm
.
$destroy
();
wrapper
.
destroy
();
wrapper
=
null
;
});
});
it
(
'
should render a title/description/edited and update title/description/edited on update
'
,
()
=>
{
it
(
'
should render a title/description/edited and update title/description/edited on update
'
,
()
=>
{
...
@@ -89,101 +88,100 @@ describe('Issuable output', () => {
...
@@ -89,101 +88,100 @@ describe('Issuable output', () => {
return
axios
return
axios
.
waitForAll
()
.
waitForAll
()
.
then
(()
=>
{
.
then
(()
=>
{
editedText
=
vm
.
$el
.
querySelector
(
'
.edited-text
'
);
editedText
=
wrapper
.
find
(
'
.edited-text
'
);
})
})
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
document
.
querySelector
(
'
title
'
).
innerText
).
toContain
(
'
this is a title (#1)
'
);
expect
(
document
.
querySelector
(
'
title
'
).
innerText
).
toContain
(
'
this is a title (#1)
'
);
expect
(
vm
.
$el
.
querySelector
(
'
.title
'
).
innerHTML
).
toContain
(
'
<p>this is a title</p>
'
);
expect
(
wrapper
.
find
(
'
.title
'
).
text
()).
toContain
(
'
this is a title
'
);
expect
(
vm
.
$el
.
querySelector
(
'
.md
'
).
innerHTML
).
toContain
(
'
<p>this is a description!</p>
'
);
expect
(
wrapper
.
find
(
'
.md
'
).
text
()).
toContain
(
'
this is a description!
'
);
expect
(
vm
.
$el
.
querySelector
(
'
.js-task-list-field
'
)
.
value
).
toContain
(
expect
(
wrapper
.
find
(
'
.js-task-list-field
'
).
element
.
value
).
toContain
(
'
this is a description
'
,
'
this is a description
'
,
);
);
expect
(
formatText
(
editedText
.
innerText
)).
toMatch
(
/Edited
[\s\S]
+
?
by Some User/
);
expect
(
formatText
(
editedText
.
text
()
)).
toMatch
(
/Edited
[\s\S]
+
?
by Some User/
);
expect
(
editedText
.
querySelector
(
'
.author-link
'
).
href
).
toMatch
(
/
\/
some_user$/
);
expect
(
editedText
.
find
(
'
.author-link
'
).
attributes
(
'
href
'
)
).
toMatch
(
/
\/
some_user$/
);
expect
(
editedText
.
querySelector
(
'
time
'
)).
toBeTruthy
();
expect
(
editedText
.
find
(
'
time
'
).
text
(
)).
toBeTruthy
();
expect
(
vm
.
state
.
lock_version
).
toEqual
(
1
);
expect
(
wrapper
.
vm
.
state
.
lock_version
).
toEqual
(
1
);
})
})
.
then
(()
=>
{
.
then
(()
=>
{
vm
.
poll
.
makeRequest
();
wrapper
.
vm
.
poll
.
makeRequest
();
return
axios
.
waitForAll
();
return
axios
.
waitForAll
();
})
})
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
document
.
querySelector
(
'
title
'
).
innerText
).
toContain
(
'
2 (#1)
'
);
expect
(
document
.
querySelector
(
'
title
'
).
innerText
).
toContain
(
'
2 (#1)
'
);
expect
(
vm
.
$el
.
querySelector
(
'
.title
'
).
innerHTML
).
toContain
(
'
<p>2</p>
'
);
expect
(
wrapper
.
find
(
'
.title
'
).
text
()).
toContain
(
'
2
'
);
expect
(
vm
.
$el
.
querySelector
(
'
.md
'
).
innerHTML
).
toContain
(
'
<p>42</p>
'
);
expect
(
wrapper
.
find
(
'
.md
'
).
text
()).
toContain
(
'
42
'
);
expect
(
vm
.
$el
.
querySelector
(
'
.js-task-list-field
'
)
.
value
).
toContain
(
'
42
'
);
expect
(
wrapper
.
find
(
'
.js-task-list-field
'
).
element
.
value
).
toContain
(
'
42
'
);
expect
(
vm
.
$el
.
querySelector
(
'
.edited-text
'
)).
toBeTruthy
();
expect
(
wrapper
.
find
(
'
.edited-text
'
).
text
(
)).
toBeTruthy
();
expect
(
formatText
(
vm
.
$el
.
querySelector
(
'
.edited-text
'
).
innerText
)).
toMatch
(
expect
(
formatText
(
wrapper
.
find
(
'
.edited-text
'
).
text
()
)).
toMatch
(
/Edited
[\s\S]
+
?
by Other User/
,
/Edited
[\s\S]
+
?
by Other User/
,
);
);
expect
(
editedText
.
querySelector
(
'
.author-link
'
).
href
).
toMatch
(
/
\/
other_user$/
);
expect
(
editedText
.
find
(
'
.author-link
'
).
attributes
(
'
href
'
)
).
toMatch
(
/
\/
other_user$/
);
expect
(
editedText
.
querySelector
(
'
time
'
)).
toBeTruthy
();
expect
(
editedText
.
find
(
'
time
'
).
text
(
)).
toBeTruthy
();
expect
(
vm
.
state
.
lock_version
).
toEqual
(
2
);
expect
(
wrapper
.
vm
.
state
.
lock_version
).
toEqual
(
2
);
});
});
});
});
it
(
'
shows actions if permissions are correct
'
,
()
=>
{
it
(
'
shows actions if permissions are correct
'
,
()
=>
{
vm
.
showForm
=
true
;
wrapper
.
vm
.
showForm
=
true
;
return
vm
.
$nextTick
().
then
(()
=>
{
return
wrapper
.
vm
.
$nextTick
().
then
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.btn
'
)).
not
.
toBeNull
(
);
expect
(
wrapper
.
contains
(
'
.markdown-selector
'
)).
toBe
(
true
);
});
});
});
});
it
(
'
does not show actions if permissions are incorrect
'
,
()
=>
{
it
(
'
does not show actions if permissions are incorrect
'
,
()
=>
{
vm
.
showForm
=
true
;
wrapper
.
vm
.
showForm
=
true
;
vm
.
canUpdate
=
false
;
wrapper
.
setProps
({
canUpdate
:
false
})
;
return
vm
.
$nextTick
().
then
(()
=>
{
return
wrapper
.
vm
.
$nextTick
().
then
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.markdown-selector
'
)).
toBeNull
(
);
expect
(
wrapper
.
contains
(
'
.markdown-selector
'
)).
toBe
(
false
);
});
});
});
});
it
(
'
does not update formState if form is already open
'
,
()
=>
{
it
(
'
does not update formState if form is already open
'
,
()
=>
{
vm
.
updateAndShowForm
();
wrapper
.
vm
.
updateAndShowForm
();
vm
.
state
.
titleText
=
'
testing 123
'
;
wrapper
.
vm
.
state
.
titleText
=
'
testing 123
'
;
vm
.
updateAndShowForm
();
wrapper
.
vm
.
updateAndShowForm
();
return
vm
.
$nextTick
().
then
(()
=>
{
return
wrapper
.
vm
.
$nextTick
().
then
(()
=>
{
expect
(
vm
.
store
.
formState
.
title
).
not
.
toBe
(
'
testing 123
'
);
expect
(
wrapper
.
vm
.
store
.
formState
.
title
).
not
.
toBe
(
'
testing 123
'
);
});
});
});
});
it
(
'
opens reCAPTCHA modal if update rejected as spam
'
,
()
=>
{
it
(
'
opens reCAPTCHA modal if update rejected as spam
'
,
()
=>
{
let
modal
;
let
modal
;
jest
.
spyOn
(
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
data
:
{
data
:
{
recaptcha_html
:
'
<div class="g-recaptcha">recaptcha_html</div>
'
,
recaptcha_html
:
'
<div class="g-recaptcha">recaptcha_html</div>
'
,
},
},
});
});
vm
.
canUpdate
=
true
;
wrapper
.
vm
.
canUpdate
=
true
;
vm
.
showForm
=
true
;
wrapper
.
vm
.
showForm
=
true
;
return
vm
return
wrapper
.
vm
.
$nextTick
()
.
$nextTick
()
.
then
(()
=>
{
.
then
(()
=>
{
vm
.
$refs
.
recaptchaModal
.
scriptSrc
=
'
//scriptsrc
'
;
wrapper
.
vm
.
$refs
.
recaptchaModal
.
scriptSrc
=
'
//scriptsrc
'
;
return
vm
.
updateIssuable
();
return
wrapper
.
vm
.
updateIssuable
();
})
})
.
then
(()
=>
{
.
then
(()
=>
{
modal
=
vm
.
$el
.
querySelector
(
'
.js-recaptcha-modal
'
);
modal
=
wrapper
.
find
(
'
.js-recaptcha-modal
'
);
expect
(
modal
.
isVisible
()).
toBe
(
true
);
expect
(
modal
.
style
.
display
).
not
.
toEqual
(
'
none
'
);
expect
(
modal
.
find
(
'
.g-recaptcha
'
).
text
()).
toEqual
(
'
recaptcha_html
'
);
expect
(
modal
.
querySelector
(
'
.g-recaptcha
'
).
textContent
).
toEqual
(
'
recaptcha_html
'
);
expect
(
document
.
body
.
querySelector
(
'
.js-recaptcha-script
'
).
src
).
toMatch
(
'
//scriptsrc
'
);
expect
(
document
.
body
.
querySelector
(
'
.js-recaptcha-script
'
).
src
).
toMatch
(
'
//scriptsrc
'
);
})
})
.
then
(()
=>
{
.
then
(()
=>
{
modal
.
querySelector
(
'
.close
'
).
click
(
);
modal
.
find
(
'
.close
'
).
trigger
(
'
click
'
);
return
vm
.
$nextTick
();
return
wrapper
.
vm
.
$nextTick
();
})
})
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
modal
.
style
.
display
).
toEqual
(
'
none
'
);
expect
(
modal
.
isVisible
()).
toBe
(
false
);
expect
(
document
.
body
.
querySelector
(
'
.js-recaptcha-script
'
)).
toBeNull
();
expect
(
document
.
body
.
querySelector
(
'
.js-recaptcha-script
'
)).
toBeNull
();
});
});
});
});
...
@@ -194,102 +192,105 @@ describe('Issuable output', () => {
...
@@ -194,102 +192,105 @@ describe('Issuable output', () => {
${
'
zoomMeetingUrl
'
}
|
${
zoomMeetingUrl
}
${
'
zoomMeetingUrl
'
}
|
${
zoomMeetingUrl
}
${
'
publishedIncidentUrl
'
}
|
${
publishedIncidentUrl
}
${
'
publishedIncidentUrl
'
}
|
${
publishedIncidentUrl
}
`
(
'
sets the $prop correctly on underlying pinned links
'
,
({
prop
,
value
})
=>
{
`
(
'
sets the $prop correctly on underlying pinned links
'
,
({
prop
,
value
})
=>
{
expect
(
vm
[
prop
]).
toEqual
(
value
);
expect
(
wrapper
.
vm
[
prop
]).
toEqual
(
value
);
expect
(
vm
.
$el
.
querySelector
(
`[data-testid="
${
prop
}
"]`
).
href
).
toBe
(
value
);
expect
(
wrapper
.
find
(
`[data-testid="
${
prop
}
"]`
).
attributes
(
'
href
'
)
).
toBe
(
value
);
});
});
});
});
describe
(
'
updateIssuable
'
,
()
=>
{
describe
(
'
updateIssuable
'
,
()
=>
{
it
(
'
fetches new data after update
'
,
()
=>
{
it
(
'
fetches new data after update
'
,
()
=>
{
const
updateStoreSpy
=
jest
.
spyOn
(
vm
,
'
updateStoreState
'
);
const
updateStoreSpy
=
jest
.
spyOn
(
wrapper
.
vm
,
'
updateStoreState
'
);
const
getDataSpy
=
jest
.
spyOn
(
vm
.
service
,
'
getData
'
);
const
getDataSpy
=
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
getData
'
);
jest
.
spyOn
(
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
data
:
{
web_url
:
window
.
location
.
pathname
},
data
:
{
web_url
:
window
.
location
.
pathname
},
});
});
return
vm
.
updateIssuable
().
then
(()
=>
{
return
wrapper
.
vm
.
updateIssuable
().
then
(()
=>
{
expect
(
updateStoreSpy
).
toHaveBeenCalled
();
expect
(
updateStoreSpy
).
toHaveBeenCalled
();
expect
(
getDataSpy
).
toHaveBeenCalled
();
expect
(
getDataSpy
).
toHaveBeenCalled
();
});
});
});
});
it
(
'
correctly updates issuable data
'
,
()
=>
{
it
(
'
correctly updates issuable data
'
,
()
=>
{
const
spy
=
jest
.
spyOn
(
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
const
spy
=
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
data
:
{
web_url
:
window
.
location
.
pathname
},
data
:
{
web_url
:
window
.
location
.
pathname
},
});
});
return
vm
.
updateIssuable
().
then
(()
=>
{
return
wrapper
.
vm
.
updateIssuable
().
then
(()
=>
{
expect
(
spy
).
toHaveBeenCalledWith
(
vm
.
formState
);
expect
(
spy
).
toHaveBeenCalledWith
(
wrapper
.
vm
.
formState
);
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
close.form
'
);
expect
(
eventHub
.
$emit
).
toHaveBeenCalledWith
(
'
close.form
'
);
});
});
});
});
it
(
'
does not redirect if issue has not moved
'
,
()
=>
{
it
(
'
does not redirect if issue has not moved
'
,
()
=>
{
jest
.
spyOn
(
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
data
:
{
data
:
{
web_url
:
window
.
location
.
pathname
,
web_url
:
window
.
location
.
pathname
,
confidential
:
vm
.
isConfidential
,
confidential
:
wrapper
.
vm
.
isConfidential
,
},
},
});
});
return
vm
.
updateIssuable
().
then
(()
=>
{
return
wrapper
.
vm
.
updateIssuable
().
then
(()
=>
{
expect
(
visitUrl
).
not
.
toHaveBeenCalled
();
expect
(
visitUrl
).
not
.
toHaveBeenCalled
();
});
});
});
});
it
(
'
does not redirect if issue has not moved and user has switched tabs
'
,
()
=>
{
it
(
'
does not redirect if issue has not moved and user has switched tabs
'
,
()
=>
{
jest
.
spyOn
(
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
data
:
{
data
:
{
web_url
:
''
,
web_url
:
''
,
confidential
:
vm
.
isConfidential
,
confidential
:
wrapper
.
vm
.
isConfidential
,
},
},
});
});
return
vm
.
updateIssuable
().
then
(()
=>
{
return
wrapper
.
vm
.
updateIssuable
().
then
(()
=>
{
expect
(
visitUrl
).
not
.
toHaveBeenCalled
();
expect
(
visitUrl
).
not
.
toHaveBeenCalled
();
});
});
});
});
it
(
'
redirects if returned web_url has changed
'
,
()
=>
{
it
(
'
redirects if returned web_url has changed
'
,
()
=>
{
jest
.
spyOn
(
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
updateIssuable
'
).
mockResolvedValue
({
data
:
{
data
:
{
web_url
:
'
/testing-issue-move
'
,
web_url
:
'
/testing-issue-move
'
,
confidential
:
vm
.
isConfidential
,
confidential
:
wrapper
.
vm
.
isConfidential
,
},
},
});
});
vm
.
updateIssuable
();
wrapper
.
vm
.
updateIssuable
();
return
vm
.
updateIssuable
().
then
(()
=>
{
return
wrapper
.
vm
.
updateIssuable
().
then
(()
=>
{
expect
(
visitUrl
).
toHaveBeenCalledWith
(
'
/testing-issue-move
'
);
expect
(
visitUrl
).
toHaveBeenCalledWith
(
'
/testing-issue-move
'
);
});
});
});
});
describe
(
'
shows dialog when issue has unsaved changed
'
,
()
=>
{
describe
(
'
shows dialog when issue has unsaved changed
'
,
()
=>
{
it
(
'
confirms on title change
'
,
()
=>
{
it
(
'
confirms on title change
'
,
()
=>
{
vm
.
showForm
=
true
;
wrapper
.
vm
.
showForm
=
true
;
vm
.
state
.
titleText
=
'
title has changed
'
;
wrapper
.
vm
.
state
.
titleText
=
'
title has changed
'
;
const
e
=
{
returnValue
:
null
};
const
e
=
{
returnValue
:
null
};
vm
.
handleBeforeUnloadEvent
(
e
);
wrapper
.
vm
.
handleBeforeUnloadEvent
(
e
);
return
vm
.
$nextTick
().
then
(()
=>
{
return
wrapper
.
vm
.
$nextTick
().
then
(()
=>
{
expect
(
e
.
returnValue
).
not
.
toBeNull
();
expect
(
e
.
returnValue
).
not
.
toBeNull
();
});
});
});
});
it
(
'
confirms on description change
'
,
()
=>
{
it
(
'
confirms on description change
'
,
()
=>
{
vm
.
showForm
=
true
;
wrapper
.
vm
.
showForm
=
true
;
vm
.
state
.
descriptionText
=
'
description has changed
'
;
wrapper
.
vm
.
state
.
descriptionText
=
'
description has changed
'
;
const
e
=
{
returnValue
:
null
};
const
e
=
{
returnValue
:
null
};
vm
.
handleBeforeUnloadEvent
(
e
);
wrapper
.
vm
.
handleBeforeUnloadEvent
(
e
);
return
vm
.
$nextTick
().
then
(()
=>
{
return
wrapper
.
vm
.
$nextTick
().
then
(()
=>
{
expect
(
e
.
returnValue
).
not
.
toBeNull
();
expect
(
e
.
returnValue
).
not
.
toBeNull
();
});
});
});
});
it
(
'
does nothing when nothing has changed
'
,
()
=>
{
it
(
'
does nothing when nothing has changed
'
,
()
=>
{
const
e
=
{
returnValue
:
null
};
const
e
=
{
returnValue
:
null
};
vm
.
handleBeforeUnloadEvent
(
e
);
wrapper
.
vm
.
handleBeforeUnloadEvent
(
e
);
return
vm
.
$nextTick
().
then
(()
=>
{
return
wrapper
.
vm
.
$nextTick
().
then
(()
=>
{
expect
(
e
.
returnValue
).
toBeNull
();
expect
(
e
.
returnValue
).
toBeNull
();
});
});
});
});
...
@@ -297,8 +298,9 @@ describe('Issuable output', () => {
...
@@ -297,8 +298,9 @@ describe('Issuable output', () => {
describe
(
'
error when updating
'
,
()
=>
{
describe
(
'
error when updating
'
,
()
=>
{
it
(
'
closes form on error
'
,
()
=>
{
it
(
'
closes form on error
'
,
()
=>
{
jest
.
spyOn
(
vm
.
service
,
'
updateIssuable
'
).
mockRejectedValue
();
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
updateIssuable
'
).
mockRejectedValue
();
return
vm
.
updateIssuable
().
then
(()
=>
{
return
wrapper
.
vm
.
updateIssuable
().
then
(()
=>
{
expect
(
eventHub
.
$emit
).
not
.
toHaveBeenCalledWith
(
'
close.form
'
);
expect
(
eventHub
.
$emit
).
not
.
toHaveBeenCalledWith
(
'
close.form
'
);
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
innerText
.
trim
()).
toBe
(
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
innerText
.
trim
()).
toBe
(
`Error updating issue`
,
`Error updating issue`
,
...
@@ -307,12 +309,12 @@ describe('Issuable output', () => {
...
@@ -307,12 +309,12 @@ describe('Issuable output', () => {
});
});
it
(
'
returns the correct error message for issuableType
'
,
()
=>
{
it
(
'
returns the correct error message for issuableType
'
,
()
=>
{
jest
.
spyOn
(
vm
.
service
,
'
updateIssuable
'
).
mockRejectedValue
();
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
updateIssuable
'
).
mockRejectedValue
();
vm
.
issuableType
=
'
merge request
'
;
wrapper
.
setProps
({
issuableType
:
'
merge request
'
})
;
return
vm
return
wrapper
.
vm
.
$nextTick
()
.
$nextTick
()
.
then
(
vm
.
updateIssuable
)
.
then
(
wrapper
.
vm
.
updateIssuable
)
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
eventHub
.
$emit
).
not
.
toHaveBeenCalledWith
(
'
close.form
'
);
expect
(
eventHub
.
$emit
).
not
.
toHaveBeenCalledWith
(
'
close.form
'
);
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
innerText
.
trim
()).
toBe
(
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
innerText
.
trim
()).
toBe
(
...
@@ -324,12 +326,12 @@ describe('Issuable output', () => {
...
@@ -324,12 +326,12 @@ describe('Issuable output', () => {
it
(
'
shows error message from backend if exists
'
,
()
=>
{
it
(
'
shows error message from backend if exists
'
,
()
=>
{
const
msg
=
'
Custom error message from backend
'
;
const
msg
=
'
Custom error message from backend
'
;
jest
jest
.
spyOn
(
vm
.
service
,
'
updateIssuable
'
)
.
spyOn
(
wrapper
.
vm
.
service
,
'
updateIssuable
'
)
.
mockRejectedValue
({
response
:
{
data
:
{
errors
:
[
msg
]
}
}
});
.
mockRejectedValue
({
response
:
{
data
:
{
errors
:
[
msg
]
}
}
});
return
vm
.
updateIssuable
().
then
(()
=>
{
return
wrapper
.
vm
.
updateIssuable
().
then
(()
=>
{
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
innerText
.
trim
()).
toBe
(
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
innerText
.
trim
()).
toBe
(
`
${
vm
.
defaultErrorMessage
}
.
${
msg
}
`
,
`
${
wrapper
.
vm
.
defaultErrorMessage
}
.
${
msg
}
`
,
);
);
});
});
});
});
...
@@ -338,34 +340,34 @@ describe('Issuable output', () => {
...
@@ -338,34 +340,34 @@ describe('Issuable output', () => {
describe
(
'
deleteIssuable
'
,
()
=>
{
describe
(
'
deleteIssuable
'
,
()
=>
{
it
(
'
changes URL when deleted
'
,
()
=>
{
it
(
'
changes URL when deleted
'
,
()
=>
{
jest
.
spyOn
(
vm
.
service
,
'
deleteIssuable
'
).
mockResolvedValue
({
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
deleteIssuable
'
).
mockResolvedValue
({
data
:
{
data
:
{
web_url
:
'
/test
'
,
web_url
:
'
/test
'
,
},
},
});
});
return
vm
.
deleteIssuable
().
then
(()
=>
{
return
wrapper
.
vm
.
deleteIssuable
().
then
(()
=>
{
expect
(
visitUrl
).
toHaveBeenCalledWith
(
'
/test
'
);
expect
(
visitUrl
).
toHaveBeenCalledWith
(
'
/test
'
);
});
});
});
});
it
(
'
stops polling when deleting
'
,
()
=>
{
it
(
'
stops polling when deleting
'
,
()
=>
{
const
spy
=
jest
.
spyOn
(
vm
.
poll
,
'
stop
'
);
const
spy
=
jest
.
spyOn
(
wrapper
.
vm
.
poll
,
'
stop
'
);
jest
.
spyOn
(
vm
.
service
,
'
deleteIssuable
'
).
mockResolvedValue
({
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
deleteIssuable
'
).
mockResolvedValue
({
data
:
{
data
:
{
web_url
:
'
/test
'
,
web_url
:
'
/test
'
,
},
},
});
});
return
vm
.
deleteIssuable
().
then
(()
=>
{
return
wrapper
.
vm
.
deleteIssuable
().
then
(()
=>
{
expect
(
spy
).
toHaveBeenCalledWith
();
expect
(
spy
).
toHaveBeenCalledWith
();
});
});
});
});
it
(
'
closes form on error
'
,
()
=>
{
it
(
'
closes form on error
'
,
()
=>
{
jest
.
spyOn
(
vm
.
service
,
'
deleteIssuable
'
).
mockRejectedValue
();
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
deleteIssuable
'
).
mockRejectedValue
();
return
vm
.
deleteIssuable
().
then
(()
=>
{
return
wrapper
.
vm
.
deleteIssuable
().
then
(()
=>
{
expect
(
eventHub
.
$emit
).
not
.
toHaveBeenCalledWith
(
'
close.form
'
);
expect
(
eventHub
.
$emit
).
not
.
toHaveBeenCalledWith
(
'
close.form
'
);
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
innerText
.
trim
()).
toBe
(
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
innerText
.
trim
()).
toBe
(
'
Error deleting issue
'
,
'
Error deleting issue
'
,
...
@@ -376,23 +378,25 @@ describe('Issuable output', () => {
...
@@ -376,23 +378,25 @@ describe('Issuable output', () => {
describe
(
'
updateAndShowForm
'
,
()
=>
{
describe
(
'
updateAndShowForm
'
,
()
=>
{
it
(
'
shows locked warning if form is open & data is different
'
,
()
=>
{
it
(
'
shows locked warning if form is open & data is different
'
,
()
=>
{
return
vm
return
wrapper
.
vm
.
$nextTick
()
.
$nextTick
()
.
then
(()
=>
{
.
then
(()
=>
{
vm
.
updateAndShowForm
();
wrapper
.
vm
.
updateAndShowForm
();
vm
.
poll
.
makeRequest
();
wrapper
.
vm
.
poll
.
makeRequest
();
return
new
Promise
(
resolve
=>
{
return
new
Promise
(
resolve
=>
{
vm
.
$watch
(
'
formState.lockedWarningVisible
'
,
value
=>
{
wrapper
.
vm
.
$watch
(
'
formState.lockedWarningVisible
'
,
value
=>
{
if
(
value
)
resolve
();
if
(
value
)
{
resolve
();
}
});
});
});
});
})
})
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
vm
.
formState
.
lockedWarningVisible
).
toEqual
(
true
);
expect
(
wrapper
.
vm
.
formState
.
lockedWarningVisible
).
toEqual
(
true
);
expect
(
vm
.
formState
.
lock_version
).
toEqual
(
1
);
expect
(
wrapper
.
vm
.
formState
.
lock_version
).
toEqual
(
1
);
expect
(
vm
.
$el
.
querySelector
(
'
.alert
'
)).
not
.
toBeNull
(
);
expect
(
wrapper
.
contains
(
'
.alert
'
)).
toBe
(
true
);
});
});
});
});
});
});
...
@@ -401,14 +405,14 @@ describe('Issuable output', () => {
...
@@ -401,14 +405,14 @@ describe('Issuable output', () => {
let
formSpy
;
let
formSpy
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
formSpy
=
jest
.
spyOn
(
vm
,
'
updateAndShowForm
'
);
formSpy
=
jest
.
spyOn
(
wrapper
.
vm
,
'
updateAndShowForm
'
);
});
});
it
(
'
shows the form if template names request is successful
'
,
()
=>
{
it
(
'
shows the form if template names request is successful
'
,
()
=>
{
const
mockData
=
[{
name
:
'
Bug
'
}];
const
mockData
=
[{
name
:
'
Bug
'
}];
mock
.
onGet
(
'
/issuable-templates-path
'
).
reply
(()
=>
Promise
.
resolve
([
200
,
mockData
]));
mock
.
onGet
(
'
/issuable-templates-path
'
).
reply
(()
=>
Promise
.
resolve
([
200
,
mockData
]));
return
vm
.
requestTemplatesAndShowForm
().
then
(()
=>
{
return
wrapper
.
vm
.
requestTemplatesAndShowForm
().
then
(()
=>
{
expect
(
formSpy
).
toHaveBeenCalledWith
(
mockData
);
expect
(
formSpy
).
toHaveBeenCalledWith
(
mockData
);
});
});
});
});
...
@@ -418,7 +422,7 @@ describe('Issuable output', () => {
...
@@ -418,7 +422,7 @@ describe('Issuable output', () => {
.
onGet
(
'
/issuable-templates-path
'
)
.
onGet
(
'
/issuable-templates-path
'
)
.
reply
(()
=>
Promise
.
reject
(
new
Error
(
'
something went wrong
'
)));
.
reply
(()
=>
Promise
.
reject
(
new
Error
(
'
something went wrong
'
)));
return
vm
.
requestTemplatesAndShowForm
().
then
(()
=>
{
return
wrapper
.
vm
.
requestTemplatesAndShowForm
().
then
(()
=>
{
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
textContent
).
toContain
(
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
textContent
).
toContain
(
'
Error updating issue
'
,
'
Error updating issue
'
,
);
);
...
@@ -430,35 +434,39 @@ describe('Issuable output', () => {
...
@@ -430,35 +434,39 @@ describe('Issuable output', () => {
describe
(
'
show inline edit button
'
,
()
=>
{
describe
(
'
show inline edit button
'
,
()
=>
{
it
(
'
should not render by default
'
,
()
=>
{
it
(
'
should not render by default
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.title-container .note-action-button
'
)).
toBeDefined
(
);
expect
(
wrapper
.
contains
(
'
.btn-edit
'
)).
toBe
(
true
);
});
});
it
(
'
should render if showInlineEditButton
'
,
()
=>
{
it
(
'
should render if showInlineEditButton
'
,
()
=>
{
vm
.
showInlineEditButton
=
true
;
wrapper
.
setProps
({
showInlineEditButton
:
true
})
;
expect
(
vm
.
$el
.
querySelector
(
'
.title-container .note-action-button
'
)).
toBeDefined
();
return
wrapper
.
vm
.
$nextTick
(()
=>
{
expect
(
wrapper
.
contains
(
'
.btn-edit
'
)).
toBe
(
true
);
});
});
});
});
});
describe
(
'
updateStoreState
'
,
()
=>
{
describe
(
'
updateStoreState
'
,
()
=>
{
it
(
'
should make a request and update the state of the store
'
,
()
=>
{
it
(
'
should make a request and update the state of the store
'
,
()
=>
{
const
data
=
{
foo
:
1
};
const
data
=
{
foo
:
1
};
const
getDataSpy
=
jest
.
spyOn
(
vm
.
service
,
'
getData
'
).
mockResolvedValue
({
data
});
const
getDataSpy
=
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
getData
'
).
mockResolvedValue
({
data
});
const
updateStateSpy
=
jest
.
spyOn
(
vm
.
store
,
'
updateState
'
).
mockImplementation
(
jest
.
fn
);
const
updateStateSpy
=
jest
.
spyOn
(
wrapper
.
vm
.
store
,
'
updateState
'
)
.
mockImplementation
(
jest
.
fn
);
return
vm
.
updateStoreState
().
then
(()
=>
{
return
wrapper
.
vm
.
updateStoreState
().
then
(()
=>
{
expect
(
getDataSpy
).
toHaveBeenCalled
();
expect
(
getDataSpy
).
toHaveBeenCalled
();
expect
(
updateStateSpy
).
toHaveBeenCalledWith
(
data
);
expect
(
updateStateSpy
).
toHaveBeenCalledWith
(
data
);
});
});
});
});
it
(
'
should show error message if store update fails
'
,
()
=>
{
it
(
'
should show error message if store update fails
'
,
()
=>
{
jest
.
spyOn
(
vm
.
service
,
'
getData
'
).
mockRejectedValue
();
jest
.
spyOn
(
wrapper
.
vm
.
service
,
'
getData
'
).
mockRejectedValue
();
vm
.
issuableType
=
'
merge request
'
;
wrapper
.
setProps
({
issuableType
:
'
merge request
'
})
;
return
vm
.
updateStoreState
().
then
(()
=>
{
return
wrapper
.
vm
.
updateStoreState
().
then
(()
=>
{
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
innerText
.
trim
()).
toBe
(
expect
(
document
.
querySelector
(
'
.flash-container .flash-text
'
).
innerText
.
trim
()).
toBe
(
`Error updating
${
vm
.
issuableType
}
`
,
`Error updating
${
wrapper
.
vm
.
issuableType
}
`
,
);
);
});
});
});
});
...
@@ -466,48 +474,50 @@ describe('Issuable output', () => {
...
@@ -466,48 +474,50 @@ describe('Issuable output', () => {
describe
(
'
issueChanged
'
,
()
=>
{
describe
(
'
issueChanged
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
vm
.
store
.
formState
.
title
=
''
;
wrapper
.
vm
.
store
.
formState
.
title
=
''
;
vm
.
store
.
formState
.
description
=
''
;
wrapper
.
vm
.
store
.
formState
.
description
=
''
;
vm
.
initialDescriptionText
=
''
;
wrapper
.
setProps
({
vm
.
initialTitleText
=
''
;
initialDescriptionText
:
''
,
initialTitleText
:
''
,
});
});
});
it
(
'
returns true when title is changed
'
,
()
=>
{
it
(
'
returns true when title is changed
'
,
()
=>
{
vm
.
store
.
formState
.
title
=
'
RandomText
'
;
wrapper
.
vm
.
store
.
formState
.
title
=
'
RandomText
'
;
expect
(
vm
.
issueChanged
).
toBe
(
true
);
expect
(
wrapper
.
vm
.
issueChanged
).
toBe
(
true
);
});
});
it
(
'
returns false when title is empty null
'
,
()
=>
{
it
(
'
returns false when title is empty null
'
,
()
=>
{
vm
.
store
.
formState
.
title
=
null
;
wrapper
.
vm
.
store
.
formState
.
title
=
null
;
expect
(
vm
.
issueChanged
).
toBe
(
false
);
expect
(
wrapper
.
vm
.
issueChanged
).
toBe
(
false
);
});
});
it
(
'
returns false when `initialTitleText` is null and `formState.title` is empty string
'
,
()
=>
{
it
(
'
returns false when `initialTitleText` is null and `formState.title` is empty string
'
,
()
=>
{
vm
.
store
.
formState
.
title
=
''
;
wrapper
.
vm
.
store
.
formState
.
title
=
''
;
vm
.
initialTitleText
=
null
;
wrapper
.
setProps
({
initialTitleText
:
null
})
;
expect
(
vm
.
issueChanged
).
toBe
(
false
);
expect
(
wrapper
.
vm
.
issueChanged
).
toBe
(
false
);
});
});
it
(
'
returns true when description is changed
'
,
()
=>
{
it
(
'
returns true when description is changed
'
,
()
=>
{
vm
.
store
.
formState
.
description
=
'
RandomText
'
;
wrapper
.
vm
.
store
.
formState
.
description
=
'
RandomText
'
;
expect
(
vm
.
issueChanged
).
toBe
(
true
);
expect
(
wrapper
.
vm
.
issueChanged
).
toBe
(
true
);
});
});
it
(
'
returns false when description is empty null
'
,
()
=>
{
it
(
'
returns false when description is empty null
'
,
()
=>
{
vm
.
store
.
formState
.
title
=
null
;
wrapper
.
vm
.
store
.
formState
.
description
=
null
;
expect
(
vm
.
issueChanged
).
toBe
(
false
);
expect
(
wrapper
.
vm
.
issueChanged
).
toBe
(
false
);
});
});
it
(
'
returns false when `initialDescriptionText` is null and `formState.description` is empty string
'
,
()
=>
{
it
(
'
returns false when `initialDescriptionText` is null and `formState.description` is empty string
'
,
()
=>
{
vm
.
store
.
formState
.
description
=
''
;
wrapper
.
vm
.
store
.
formState
.
description
=
''
;
vm
.
initialDescriptionText
=
null
;
wrapper
.
setProps
({
initialDescriptionText
:
null
})
;
expect
(
vm
.
issueChanged
).
toBe
(
false
);
expect
(
wrapper
.
vm
.
issueChanged
).
toBe
(
false
);
});
});
});
});
});
});
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