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
c84d184d
Commit
c84d184d
authored
Apr 28, 2020
by
Nicolò Maria Mezzopera
Committed by
Denys Mishunov
Apr 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate feature highlight to jest
- feature_highlight_helper - feature_highlight
parent
5407ed81
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
79 deletions
+31
-79
spec/frontend/feature_highlight/feature_highlight_helper_spec.js
...ontend/feature_highlight/feature_highlight_helper_spec.js
+9
-22
spec/frontend/feature_highlight/feature_highlight_options_spec.js
...ntend/feature_highlight/feature_highlight_options_spec.js
+15
-29
spec/frontend/feature_highlight/feature_highlight_spec.js
spec/frontend/feature_highlight/feature_highlight_spec.js
+7
-28
No files found.
spec/
javascripts
/feature_highlight/feature_highlight_helper_spec.js
→
spec/
frontend
/feature_highlight/feature_highlight_helper_spec.js
View file @
c84d184d
import
$
from
'
jquery
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
getSetTimeoutPromise
from
'
spec/helpers/set_timeout_promise_helper
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
getSelector
,
dismiss
,
inserted
}
from
'
~/feature_highlight/feature_highlight_helper
'
;
import
{
togglePopover
}
from
'
~/shared/popover
'
;
...
...
@@ -17,34 +15,23 @@ describe('feature highlight helper', () => {
});
describe
(
'
dismiss
'
,
()
=>
{
let
mock
;
const
context
=
{
hide
:
()
=>
{},
attr
:
()
=>
'
/-/callouts/dismiss
'
,
};
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
spyOn
(
togglePopover
,
'
call
'
).
and
.
callFake
(()
=>
{});
spyOn
(
context
,
'
hide
'
).
and
.
callFake
(()
=>
{});
jest
.
spyOn
(
axios
,
'
post
'
).
mockResolvedValue
();
jest
.
spyOn
(
togglePopover
,
'
call
'
).
mockImplementation
(()
=>
{});
jest
.
spyOn
(
context
,
'
hide
'
).
mockImplementation
(()
=>
{});
dismiss
.
call
(
context
);
});
afterEach
(()
=>
{
mock
.
restore
();
});
it
(
'
calls persistent dismissal endpoint
'
,
done
=>
{
const
spy
=
jasmine
.
createSpy
(
'
dismiss-endpoint-hit
'
);
mock
.
onPost
(
'
/-/callouts/dismiss
'
).
reply
(
spy
);
getSetTimeoutPromise
()
.
then
(()
=>
{
expect
(
spy
).
toHaveBeenCalled
();
})
.
then
(
done
)
.
catch
(
done
.
fail
);
it
(
'
calls persistent dismissal endpoint
'
,
()
=>
{
expect
(
axios
.
post
).
toHaveBeenCalledWith
(
'
/-/callouts/dismiss
'
,
expect
.
objectContaining
({
feature_name
:
undefined
}),
);
});
it
(
'
calls hide popover
'
,
()
=>
{
...
...
@@ -65,7 +52,7 @@ describe('feature highlight helper', () => {
},
};
spyOn
(
$
.
fn
,
'
on
'
).
and
.
callFake
(
event
=>
{
jest
.
spyOn
(
$
.
fn
,
'
on
'
).
mockImplementation
(
event
=>
{
expect
(
event
).
toEqual
(
'
click
'
);
done
();
});
...
...
spec/frontend/feature_highlight/feature_highlight_options_spec.js
View file @
c84d184d
...
...
@@ -3,34 +3,20 @@ import domContentLoaded from '~/feature_highlight/feature_highlight_options';
describe
(
'
feature highlight options
'
,
()
=>
{
describe
(
'
domContentLoaded
'
,
()
=>
{
it
(
'
should not call highlightFeatures when breakpoint is xs
'
,
()
=>
{
jest
.
spyOn
(
bp
,
'
getBreakpointSize
'
).
mockReturnValue
(
'
xs
'
);
expect
(
domContentLoaded
()).
toBe
(
false
);
});
it
(
'
should not call highlightFeatures when breakpoint is sm
'
,
()
=>
{
jest
.
spyOn
(
bp
,
'
getBreakpointSize
'
).
mockReturnValue
(
'
sm
'
);
expect
(
domContentLoaded
()).
toBe
(
false
);
});
it
(
'
should not call highlightFeatures when breakpoint is md
'
,
()
=>
{
jest
.
spyOn
(
bp
,
'
getBreakpointSize
'
).
mockReturnValue
(
'
md
'
);
expect
(
domContentLoaded
()).
toBe
(
false
);
});
it
(
'
should not call highlightFeatures when breakpoint is not xl
'
,
()
=>
{
jest
.
spyOn
(
bp
,
'
getBreakpointSize
'
).
mockReturnValue
(
'
lg
'
);
expect
(
domContentLoaded
()).
toBe
(
false
);
});
it
(
'
should call highlightFeatures when breakpoint is xl
'
,
()
=>
{
jest
.
spyOn
(
bp
,
'
getBreakpointSize
'
).
mockReturnValue
(
'
xl
'
);
expect
(
domContentLoaded
()).
toBe
(
true
);
});
it
.
each
`
breakPoint | shouldCall
${
'
xs
'
}
|
${
false
}
${
'
sm
'
}
|
${
false
}
${
'
md
'
}
|
${
false
}
${
'
lg
'
}
|
${
false
}
${
'
xl
'
}
|
${
true
}
`
(
'
when breakpoint is $breakPoint should call highlightFeatures is $shouldCall
'
,
({
breakPoint
,
shouldCall
})
=>
{
jest
.
spyOn
(
bp
,
'
getBreakpointSize
'
).
mockReturnValue
(
breakPoint
);
expect
(
domContentLoaded
()).
toBe
(
shouldCall
);
},
);
});
});
spec/
javascripts
/feature_highlight/feature_highlight_spec.js
→
spec/
frontend
/feature_highlight/feature_highlight_spec.js
View file @
c84d184d
...
...
@@ -4,6 +4,8 @@ import * as featureHighlight from '~/feature_highlight/feature_highlight';
import
*
as
popover
from
'
~/shared/popover
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
jest
.
mock
(
'
~/shared/popover
'
);
describe
(
'
feature highlight
'
,
()
=>
{
beforeEach
(()
=>
{
setFixtures
(
`
...
...
@@ -28,7 +30,7 @@ describe('feature highlight', () => {
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
mock
.
onGet
(
'
/test
'
).
reply
(
200
);
spyOn
(
window
,
'
addEventListener
'
);
jest
.
spyOn
(
window
,
'
addEventListener
'
).
mockImplementation
(()
=>
{}
);
featureHighlight
.
setupFeatureHighlightPopover
(
'
test
'
,
0
);
});
...
...
@@ -44,27 +46,21 @@ describe('feature highlight', () => {
});
it
(
'
setup mouseenter
'
,
()
=>
{
const
toggleSpy
=
spyOn
(
popover
.
togglePopover
,
'
call
'
);
$
(
selector
).
trigger
(
'
mouseenter
'
);
expect
(
toggleSpy
).
toHaveBeenCalledWith
(
jasmine
.
any
(
Object
),
true
);
expect
(
popover
.
mouseenter
).
toHaveBeenCalledWith
(
expect
.
any
(
Object
)
);
});
it
(
'
setup debounced mouseleave
'
,
done
=>
{
const
toggleSpy
=
spyOn
(
popover
.
togglePopover
,
'
call
'
);
it
(
'
setup debounced mouseleave
'
,
()
=>
{
$
(
selector
).
trigger
(
'
mouseleave
'
);
// Even though we've set the debounce to 0ms, setTimeout is needed for the debounce
setTimeout
(()
=>
{
expect
(
toggleSpy
).
toHaveBeenCalledWith
(
jasmine
.
any
(
Object
),
false
);
done
();
},
0
);
expect
(
popover
.
debouncedMouseleave
).
toHaveBeenCalled
();
});
it
(
'
setup show.bs.popover
'
,
()
=>
{
$
(
selector
).
trigger
(
'
show.bs.popover
'
);
expect
(
window
.
addEventListener
).
toHaveBeenCalledWith
(
'
scroll
'
,
jasmine
.
any
(
Function
),
{
expect
(
window
.
addEventListener
).
toHaveBeenCalledWith
(
'
scroll
'
,
expect
.
any
(
Function
),
{
once
:
true
,
});
});
...
...
@@ -72,23 +68,6 @@ describe('feature highlight', () => {
it
(
'
removes disabled attribute
'
,
()
=>
{
expect
(
$
(
'
.js-feature-highlight
'
).
is
(
'
:disabled
'
)).
toEqual
(
false
);
});
it
(
'
displays popover
'
,
()
=>
{
expect
(
document
.
querySelector
(
selector
).
getAttribute
(
'
aria-describedby
'
)).
toBeFalsy
();
$
(
selector
).
trigger
(
'
mouseenter
'
);
expect
(
document
.
querySelector
(
selector
).
getAttribute
(
'
aria-describedby
'
)).
toBeTruthy
();
});
it
(
'
toggles when clicked
'
,
()
=>
{
$
(
selector
).
trigger
(
'
mouseenter
'
);
const
popoverId
=
$
(
selector
).
attr
(
'
aria-describedby
'
);
const
toggleSpy
=
spyOn
(
popover
.
togglePopover
,
'
call
'
);
$
(
`#
${
popoverId
}
.dismiss-feature-highlight`
).
click
();
expect
(
toggleSpy
).
toHaveBeenCalled
();
});
});
describe
(
'
findHighestPriorityFeature
'
,
()
=>
{
...
...
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