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
23e014a9
Commit
23e014a9
authored
May 19, 2020
by
Himanshu Kapoor
Committed by
Enrique Alcántara
May 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate javascripts/sidebar specs to Jest
Migrate specs in spec/javascripts/sidebar from Karma to Jest.
parent
454c8f25
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
193 additions
and
32 deletions
+193
-32
spec/frontend/sidebar/components/time_tracking/time_tracker_spec.js
...end/sidebar/components/time_tracking/time_tracker_spec.js
+23
-22
spec/frontend/sidebar/lock/lock_issue_sidebar_spec.js
spec/frontend/sidebar/lock/lock_issue_sidebar_spec.js
+3
-3
spec/frontend/sidebar/sidebar_move_issue_spec.js
spec/frontend/sidebar/sidebar_move_issue_spec.js
+167
-0
spec/javascripts/sidebar/mock_data.js
spec/javascripts/sidebar/mock_data.js
+0
-7
No files found.
spec/
javascripts
/sidebar/components/time_tracking/time_tracker_spec.js
→
spec/
frontend
/sidebar/components/time_tracking/time_tracker_spec.js
View file @
23e014a9
import
Vue
from
'
vue
'
;
import
mountComponent
from
'
spec/
helpers/vue_mount_component_helper
'
;
import
mountComponent
from
'
helpers/vue_mount_component_helper
'
;
import
TimeTracker
from
'
~/sidebar/components/time_tracking/time_tracker.vue
'
;
describe
(
'
Issuable Time Tracker
'
,
()
=>
{
...
...
@@ -35,7 +35,9 @@ describe('Issuable Time Tracker', () => {
...
TimeTracker
.
components
,
transition
:
{
// disable animations
template
:
'
<div><slot></slot></div>
'
,
render
(
h
)
{
return
h
(
'
div
'
,
this
.
$slots
.
default
);
},
},
},
});
...
...
@@ -100,9 +102,9 @@ describe('Issuable Time Tracker', () => {
it
(
'
should show full times when the sidebar is collapsed
'
,
done
=>
{
Vue
.
nextTick
(()
=>
{
const
timeTrackingText
=
vm
.
$el
.
querySelector
(
'
.time-tracking-collapsed-summary span
'
)
.
innerTex
t
;
.
textConten
t
;
expect
(
timeTrackingText
).
toBe
(
'
1h 23m / 1d 3h
'
);
expect
(
timeTrackingText
.
trim
()
).
toBe
(
'
1h 23m / 1d 3h
'
);
done
();
});
});
...
...
@@ -175,10 +177,10 @@ describe('Issuable Time Tracker', () => {
it
(
'
should display the human readable version of time estimated
'
,
done
=>
{
Vue
.
nextTick
(()
=>
{
const
estimateText
=
vm
.
$el
.
querySelector
(
'
.time-tracking-estimate-only-pane
'
)
.
innerTex
t
;
const
correctText
=
'
Estimated: 2h 46m
'
;
.
textConten
t
;
const
correctText
=
'
Estimated:
2h 46m
'
;
expect
(
estimateText
).
toBe
(
correctText
);
expect
(
estimateText
.
trim
()
).
toBe
(
correctText
);
done
();
});
});
...
...
@@ -196,7 +198,7 @@ describe('Issuable Time Tracker', () => {
it
(
'
should display the human readable version of time spent
'
,
done
=>
{
Vue
.
nextTick
(()
=>
{
const
spentText
=
vm
.
$el
.
querySelector
(
'
.time-tracking-spend-only-pane
'
).
innerTex
t
;
const
spentText
=
vm
.
$el
.
querySelector
(
'
.time-tracking-spend-only-pane
'
).
textConten
t
;
const
correctText
=
'
Spent: 1h 23m
'
;
expect
(
spentText
).
toBe
(
correctText
);
...
...
@@ -218,12 +220,12 @@ describe('Issuable Time Tracker', () => {
it
(
'
should only show the "No time tracking" pane when both timeEstimate and time_spent are falsey
'
,
done
=>
{
Vue
.
nextTick
(()
=>
{
const
$noTrackingPane
=
vm
.
$el
.
querySelector
(
'
.time-tracking-no-tracking-pane
'
);
const
noTrackingText
=
$noTrackingPane
.
innerTex
t
;
const
noTrackingText
=
$noTrackingPane
.
textConten
t
;
const
correctText
=
'
No estimate or time spent
'
;
expect
(
vm
.
showNoTimeTrackingState
).
toBe
(
true
);
expect
(
$noTrackingPane
).
toBeVisible
();
expect
(
noTrackingText
).
toBe
(
correctText
);
expect
(
noTrackingText
.
trim
()
).
toBe
(
correctText
);
done
();
});
});
...
...
@@ -234,12 +236,10 @@ describe('Issuable Time Tracker', () => {
const
closeHelpButton
=
()
=>
vm
.
$el
.
querySelector
(
'
.close-help-button
'
);
const
helpPane
=
()
=>
vm
.
$el
.
querySelector
(
'
.time-tracking-help-state
'
);
beforeEach
(
done
=>
{
beforeEach
(
()
=>
{
initTimeTrackingComponent
({
timeEstimate
:
0
,
timeSpent
:
0
});
Vue
.
nextTick
()
.
then
(
done
)
.
catch
(
done
.
fail
);
return
vm
.
$nextTick
();
});
it
(
'
should not show the "Help" pane by default
'
,
()
=>
{
...
...
@@ -247,16 +247,17 @@ describe('Issuable Time Tracker', () => {
expect
(
helpPane
()).
toBeNull
();
});
it
(
'
should show the "Help" pane when help button is clicked
'
,
done
=>
{
it
(
'
should show the "Help" pane when help button is clicked
'
,
()
=>
{
helpButton
().
click
();
Vue
.
nextTick
()
.
then
(()
=>
{
expect
(
vm
.
showHelpState
).
toBe
(
true
);
expect
(
helpPane
()).
toBeVisible
();
})
.
then
(
done
)
.
catch
(
done
.
fail
);
return
vm
.
$nextTick
().
then
(()
=>
{
expect
(
vm
.
showHelpState
).
toBe
(
true
);
// let animations run
jest
.
advanceTimersByTime
(
500
);
expect
(
helpPane
()).
toBeVisible
();
});
});
it
(
'
should not show the "Help" pane when help button is clicked and then closed
'
,
done
=>
{
...
...
spec/
javascripts
/sidebar/lock/lock_issue_sidebar_spec.js
→
spec/
frontend
/sidebar/lock/lock_issue_sidebar_spec.js
View file @
23e014a9
import
Vue
from
'
vue
'
;
import
{
mockTracking
,
triggerEvent
}
from
'
spec/
helpers/tracking_helper
'
;
import
{
mockTracking
,
triggerEvent
}
from
'
helpers/tracking_helper
'
;
import
lockIssueSidebar
from
'
~/sidebar/components/lock/lock_issue_sidebar.vue
'
;
describe
(
'
LockIssueSidebar
'
,
()
=>
{
...
...
@@ -61,7 +61,7 @@ describe('LockIssueSidebar', () => {
});
it
(
'
tracks an event when "Edit" is clicked
'
,
()
=>
{
const
spy
=
mockTracking
(
'
_category_
'
,
vm1
.
$el
,
spyOn
);
const
spy
=
mockTracking
(
'
_category_
'
,
vm1
.
$el
,
jest
.
spyOn
);
triggerEvent
(
'
.lock-edit
'
);
expect
(
spy
).
toHaveBeenCalledWith
(
'
_category_
'
,
'
click_edit_button
'
,
{
...
...
@@ -77,7 +77,7 @@ describe('LockIssueSidebar', () => {
expect
(
vm1
.
isLockDialogOpen
).
toBe
(
true
);
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expect
(
vm1
.
$el
.
innerHTML
.
includes
(
'
Unlock this issue?
'
)).
toBe
(
true
);
done
();
...
...
spec/
javascripts
/sidebar/sidebar_move_issue_spec.js
→
spec/
frontend
/sidebar/sidebar_move_issue_spec.js
View file @
23e014a9
...
...
@@ -7,15 +7,16 @@ import SidebarService from '~/sidebar/services/sidebar_service';
import
SidebarMoveIssue
from
'
~/sidebar/lib/sidebar_move_issue
'
;
import
Mock
from
'
./mock_data
'
;
describe
(
'
SidebarMoveIssue
'
,
function
()
{
describe
(
'
SidebarMoveIssue
'
,
()
=>
{
let
mock
;
const
test
=
{};
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
const
mockData
=
Mock
.
responseMap
.
GET
[
'
/autocomplete/projects?project_id=15
'
];
mock
.
onGet
(
'
/autocomplete/projects?project_id=15
'
).
reply
(
200
,
mockData
);
t
his
.
mediator
=
new
SidebarMediator
(
Mock
.
mediator
);
t
his
.
$content
=
$
(
`
t
est
.
mediator
=
new
SidebarMediator
(
Mock
.
mediator
);
t
est
.
$content
=
$
(
`
<div class="dropdown">
<div class="js-toggle"></div>
<div class="dropdown-menu">
...
...
@@ -24,15 +25,15 @@ describe('SidebarMoveIssue', function() {
<div class="js-confirm-button"></div>
</div>
`
);
t
his
.
$toggleButton
=
this
.
$content
.
find
(
'
.js-toggle
'
);
t
his
.
$confirmButton
=
this
.
$content
.
find
(
'
.js-confirm-button
'
);
t
est
.
$toggleButton
=
test
.
$content
.
find
(
'
.js-toggle
'
);
t
est
.
$confirmButton
=
test
.
$content
.
find
(
'
.js-confirm-button
'
);
t
his
.
sidebarMoveIssue
=
new
SidebarMoveIssue
(
t
his
.
mediator
,
t
his
.
$toggleButton
,
t
his
.
$confirmButton
,
t
est
.
sidebarMoveIssue
=
new
SidebarMoveIssue
(
t
est
.
mediator
,
t
est
.
$toggleButton
,
t
est
.
$confirmButton
,
);
t
his
.
sidebarMoveIssue
.
init
();
t
est
.
sidebarMoveIssue
.
init
();
});
afterEach
(()
=>
{
...
...
@@ -40,46 +41,46 @@ describe('SidebarMoveIssue', function() {
SidebarStore
.
singleton
=
null
;
SidebarMediator
.
singleton
=
null
;
t
his
.
sidebarMoveIssue
.
destroy
();
t
est
.
sidebarMoveIssue
.
destroy
();
mock
.
restore
();
});
describe
(
'
init
'
,
()
=>
{
it
(
'
should initialize the dropdown and listeners
'
,
()
=>
{
spyOn
(
this
.
sidebarMoveIssue
,
'
initDropdown
'
);
spyOn
(
this
.
sidebarMoveIssue
,
'
addEventListeners
'
);
jest
.
spyOn
(
test
.
sidebarMoveIssue
,
'
initDropdown
'
).
mockImplementation
(()
=>
{}
);
jest
.
spyOn
(
test
.
sidebarMoveIssue
,
'
addEventListeners
'
).
mockImplementation
(()
=>
{}
);
t
his
.
sidebarMoveIssue
.
init
();
t
est
.
sidebarMoveIssue
.
init
();
expect
(
t
his
.
sidebarMoveIssue
.
initDropdown
).
toHaveBeenCalled
();
expect
(
t
his
.
sidebarMoveIssue
.
addEventListeners
).
toHaveBeenCalled
();
expect
(
t
est
.
sidebarMoveIssue
.
initDropdown
).
toHaveBeenCalled
();
expect
(
t
est
.
sidebarMoveIssue
.
addEventListeners
).
toHaveBeenCalled
();
});
});
describe
(
'
destroy
'
,
()
=>
{
it
(
'
should remove the listeners
'
,
()
=>
{
spyOn
(
this
.
sidebarMoveIssue
,
'
removeEventListeners
'
);
jest
.
spyOn
(
test
.
sidebarMoveIssue
,
'
removeEventListeners
'
).
mockImplementation
(()
=>
{}
);
t
his
.
sidebarMoveIssue
.
destroy
();
t
est
.
sidebarMoveIssue
.
destroy
();
expect
(
t
his
.
sidebarMoveIssue
.
removeEventListeners
).
toHaveBeenCalled
();
expect
(
t
est
.
sidebarMoveIssue
.
removeEventListeners
).
toHaveBeenCalled
();
});
});
describe
(
'
initDropdown
'
,
()
=>
{
it
(
'
should initialize the gl_dropdown
'
,
()
=>
{
spyOn
(
$
.
fn
,
'
glDropdown
'
);
jest
.
spyOn
(
$
.
fn
,
'
glDropdown
'
).
mockImplementation
(()
=>
{}
);
t
his
.
sidebarMoveIssue
.
initDropdown
();
t
est
.
sidebarMoveIssue
.
initDropdown
();
expect
(
$
.
fn
.
glDropdown
).
toHaveBeenCalled
();
});
it
(
'
escapes html from project name
'
,
done
=>
{
t
his
.
$toggleButton
.
dropdown
(
'
toggle
'
);
t
est
.
$toggleButton
.
dropdown
(
'
toggle
'
);
set
Timeout
(()
=>
{
expect
(
t
his
.
$content
.
find
(
'
.js-move-issue-dropdown-item
'
)[
1
].
innerHTML
.
trim
()).
toEqual
(
set
Immediate
(()
=>
{
expect
(
t
est
.
$content
.
find
(
'
.js-move-issue-dropdown-item
'
)[
1
].
innerHTML
.
trim
()).
toEqual
(
'
<img src=x onerror=alert(document.domain)> foo / bar
'
,
);
done
();
...
...
@@ -89,78 +90,78 @@ describe('SidebarMoveIssue', function() {
describe
(
'
onConfirmClicked
'
,
()
=>
{
it
(
'
should move the issue with valid project ID
'
,
()
=>
{
spyOn
(
this
.
mediator
,
'
moveIssue
'
).
and
.
r
eturnValue
(
Promise
.
resolve
());
t
his
.
mediator
.
setMoveToProjectId
(
7
);
jest
.
spyOn
(
test
.
mediator
,
'
moveIssue
'
).
mockR
eturnValue
(
Promise
.
resolve
());
t
est
.
mediator
.
setMoveToProjectId
(
7
);
t
his
.
sidebarMoveIssue
.
onConfirmClicked
();
t
est
.
sidebarMoveIssue
.
onConfirmClicked
();
expect
(
t
his
.
mediator
.
moveIssue
).
toHaveBeenCalled
();
expect
(
t
his
.
$confirmButton
.
prop
(
'
disabled
'
)).
toBeTruthy
();
expect
(
t
his
.
$confirmButton
.
hasClass
(
'
is-loading
'
)).
toBe
(
true
);
expect
(
t
est
.
mediator
.
moveIssue
).
toHaveBeenCalled
();
expect
(
t
est
.
$confirmButton
.
prop
(
'
disabled
'
)).
toBeTruthy
();
expect
(
t
est
.
$confirmButton
.
hasClass
(
'
is-loading
'
)).
toBe
(
true
);
});
it
(
'
should remove loading state from confirm button on failure
'
,
done
=>
{
spyOn
(
window
,
'
Flash
'
);
spyOn
(
this
.
mediator
,
'
moveIssue
'
).
and
.
r
eturnValue
(
Promise
.
reject
());
t
his
.
mediator
.
setMoveToProjectId
(
7
);
jest
.
spyOn
(
window
,
'
Flash
'
).
mockImplementation
(()
=>
{}
);
jest
.
spyOn
(
test
.
mediator
,
'
moveIssue
'
).
mockR
eturnValue
(
Promise
.
reject
());
t
est
.
mediator
.
setMoveToProjectId
(
7
);
t
his
.
sidebarMoveIssue
.
onConfirmClicked
();
t
est
.
sidebarMoveIssue
.
onConfirmClicked
();
expect
(
t
his
.
mediator
.
moveIssue
).
toHaveBeenCalled
();
expect
(
t
est
.
mediator
.
moveIssue
).
toHaveBeenCalled
();
// Wait for the move issue request to fail
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expect
(
window
.
Flash
).
toHaveBeenCalled
();
expect
(
t
his
.
$confirmButton
.
prop
(
'
disabled
'
)).
toBeFalsy
();
expect
(
t
his
.
$confirmButton
.
hasClass
(
'
is-loading
'
)).
toBe
(
false
);
expect
(
t
est
.
$confirmButton
.
prop
(
'
disabled
'
)).
toBeFalsy
();
expect
(
t
est
.
$confirmButton
.
hasClass
(
'
is-loading
'
)).
toBe
(
false
);
done
();
});
});
it
(
'
should not move the issue with id=0
'
,
()
=>
{
spyOn
(
this
.
mediator
,
'
moveIssue
'
);
t
his
.
mediator
.
setMoveToProjectId
(
0
);
jest
.
spyOn
(
test
.
mediator
,
'
moveIssue
'
).
mockImplementation
(()
=>
{}
);
t
est
.
mediator
.
setMoveToProjectId
(
0
);
t
his
.
sidebarMoveIssue
.
onConfirmClicked
();
t
est
.
sidebarMoveIssue
.
onConfirmClicked
();
expect
(
t
his
.
mediator
.
moveIssue
).
not
.
toHaveBeenCalled
();
expect
(
t
est
.
mediator
.
moveIssue
).
not
.
toHaveBeenCalled
();
});
});
it
(
'
should set moveToProjectId on dropdown item "No project" click
'
,
done
=>
{
spyOn
(
this
.
mediator
,
'
setMoveToProjectId
'
);
jest
.
spyOn
(
test
.
mediator
,
'
setMoveToProjectId
'
).
mockImplementation
(()
=>
{}
);
// Open the dropdown
t
his
.
$toggleButton
.
dropdown
(
'
toggle
'
);
t
est
.
$toggleButton
.
dropdown
(
'
toggle
'
);
// Wait for the autocomplete request to finish
set
Timeout
(()
=>
{
t
his
.
$content
set
Immediate
(()
=>
{
t
est
.
$content
.
find
(
'
.js-move-issue-dropdown-item
'
)
.
eq
(
0
)
.
trigger
(
'
click
'
);
expect
(
t
his
.
mediator
.
setMoveToProjectId
).
toHaveBeenCalledWith
(
0
);
expect
(
t
his
.
$confirmButton
.
prop
(
'
disabled
'
)).
toBeTruthy
();
expect
(
t
est
.
mediator
.
setMoveToProjectId
).
toHaveBeenCalledWith
(
0
);
expect
(
t
est
.
$confirmButton
.
prop
(
'
disabled
'
)).
toBeTruthy
();
done
();
}
,
0
);
});
});
it
(
'
should set moveToProjectId on dropdown item click
'
,
done
=>
{
spyOn
(
this
.
mediator
,
'
setMoveToProjectId
'
);
jest
.
spyOn
(
test
.
mediator
,
'
setMoveToProjectId
'
).
mockImplementation
(()
=>
{}
);
// Open the dropdown
t
his
.
$toggleButton
.
dropdown
(
'
toggle
'
);
t
est
.
$toggleButton
.
dropdown
(
'
toggle
'
);
// Wait for the autocomplete request to finish
set
Timeout
(()
=>
{
t
his
.
$content
set
Immediate
(()
=>
{
t
est
.
$content
.
find
(
'
.js-move-issue-dropdown-item
'
)
.
eq
(
1
)
.
trigger
(
'
click
'
);
expect
(
t
his
.
mediator
.
setMoveToProjectId
).
toHaveBeenCalledWith
(
20
);
expect
(
t
his
.
$confirmButton
.
attr
(
'
disabled
'
)).
toBe
(
undefined
);
expect
(
t
est
.
mediator
.
setMoveToProjectId
).
toHaveBeenCalledWith
(
20
);
expect
(
t
est
.
$confirmButton
.
attr
(
'
disabled
'
)).
toBe
(
undefined
);
done
();
}
,
0
);
});
});
});
spec/javascripts/sidebar/mock_data.js
deleted
100644 → 0
View file @
454c8f25
// No new code should be added to this file. Instead, modify the
// file this one re-exports from. For more detail about why, see:
// https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/31349
import
mockData
from
'
../../frontend/sidebar/mock_data
'
;
export
default
mockData
;
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