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
$
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
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
getSelector
,
dismiss
,
inserted
}
from
'
~/feature_highlight/feature_highlight_helper
'
;
import
{
getSelector
,
dismiss
,
inserted
}
from
'
~/feature_highlight/feature_highlight_helper
'
;
import
{
togglePopover
}
from
'
~/shared/popover
'
;
import
{
togglePopover
}
from
'
~/shared/popover
'
;
...
@@ -17,34 +15,23 @@ describe('feature highlight helper', () => {
...
@@ -17,34 +15,23 @@ describe('feature highlight helper', () => {
});
});
describe
(
'
dismiss
'
,
()
=>
{
describe
(
'
dismiss
'
,
()
=>
{
let
mock
;
const
context
=
{
const
context
=
{
hide
:
()
=>
{},
hide
:
()
=>
{},
attr
:
()
=>
'
/-/callouts/dismiss
'
,
attr
:
()
=>
'
/-/callouts/dismiss
'
,
};
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
jest
.
spyOn
(
axios
,
'
post
'
).
mockResolvedValue
();
jest
.
spyOn
(
togglePopover
,
'
call
'
).
mockImplementation
(()
=>
{});
spyOn
(
togglePopover
,
'
call
'
).
and
.
callFake
(()
=>
{});
jest
.
spyOn
(
context
,
'
hide
'
).
mockImplementation
(()
=>
{});
spyOn
(
context
,
'
hide
'
).
and
.
callFake
(()
=>
{});
dismiss
.
call
(
context
);
dismiss
.
call
(
context
);
});
});
afterEach
(()
=>
{
it
(
'
calls persistent dismissal endpoint
'
,
()
=>
{
mock
.
restore
();
expect
(
axios
.
post
).
toHaveBeenCalledWith
(
});
'
/-/callouts/dismiss
'
,
expect
.
objectContaining
({
feature_name
:
undefined
}),
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 hide popover
'
,
()
=>
{
it
(
'
calls hide popover
'
,
()
=>
{
...
@@ -65,7 +52,7 @@ describe('feature highlight helper', () => {
...
@@ -65,7 +52,7 @@ describe('feature highlight helper', () => {
},
},
};
};
spyOn
(
$
.
fn
,
'
on
'
).
and
.
callFake
(
event
=>
{
jest
.
spyOn
(
$
.
fn
,
'
on
'
).
mockImplementation
(
event
=>
{
expect
(
event
).
toEqual
(
'
click
'
);
expect
(
event
).
toEqual
(
'
click
'
);
done
();
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';
...
@@ -3,34 +3,20 @@ import domContentLoaded from '~/feature_highlight/feature_highlight_options';
describe
(
'
feature highlight options
'
,
()
=>
{
describe
(
'
feature highlight options
'
,
()
=>
{
describe
(
'
domContentLoaded
'
,
()
=>
{
describe
(
'
domContentLoaded
'
,
()
=>
{
it
(
'
should not call highlightFeatures when breakpoint is xs
'
,
()
=>
{
it
.
each
`
jest
.
spyOn
(
bp
,
'
getBreakpointSize
'
).
mockReturnValue
(
'
xs
'
);
breakPoint | shouldCall
${
'
xs
'
}
|
${
false
}
expect
(
domContentLoaded
()).
toBe
(
false
);
${
'
sm
'
}
|
${
false
}
});
${
'
md
'
}
|
${
false
}
${
'
lg
'
}
|
${
false
}
it
(
'
should not call highlightFeatures when breakpoint is sm
'
,
()
=>
{
${
'
xl
'
}
|
${
true
}
jest
.
spyOn
(
bp
,
'
getBreakpointSize
'
).
mockReturnValue
(
'
sm
'
);
`
(
'
when breakpoint is $breakPoint should call highlightFeatures is $shouldCall
'
,
expect
(
domContentLoaded
()).
toBe
(
false
);
({
breakPoint
,
shouldCall
})
=>
{
});
jest
.
spyOn
(
bp
,
'
getBreakpointSize
'
).
mockReturnValue
(
breakPoint
);
it
(
'
should not call highlightFeatures when breakpoint is md
'
,
()
=>
{
expect
(
domContentLoaded
()).
toBe
(
shouldCall
);
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
);
});
});
});
});
});
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';
...
@@ -4,6 +4,8 @@ import * as featureHighlight from '~/feature_highlight/feature_highlight';
import
*
as
popover
from
'
~/shared/popover
'
;
import
*
as
popover
from
'
~/shared/popover
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
jest
.
mock
(
'
~/shared/popover
'
);
describe
(
'
feature highlight
'
,
()
=>
{
describe
(
'
feature highlight
'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
setFixtures
(
`
setFixtures
(
`
...
@@ -28,7 +30,7 @@ describe('feature highlight', () => {
...
@@ -28,7 +30,7 @@ describe('feature highlight', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
mock
=
new
MockAdapter
(
axios
);
mock
.
onGet
(
'
/test
'
).
reply
(
200
);
mock
.
onGet
(
'
/test
'
).
reply
(
200
);
spyOn
(
window
,
'
addEventListener
'
);
jest
.
spyOn
(
window
,
'
addEventListener
'
).
mockImplementation
(()
=>
{}
);
featureHighlight
.
setupFeatureHighlightPopover
(
'
test
'
,
0
);
featureHighlight
.
setupFeatureHighlightPopover
(
'
test
'
,
0
);
});
});
...
@@ -44,27 +46,21 @@ describe('feature highlight', () => {
...
@@ -44,27 +46,21 @@ describe('feature highlight', () => {
});
});
it
(
'
setup mouseenter
'
,
()
=>
{
it
(
'
setup mouseenter
'
,
()
=>
{
const
toggleSpy
=
spyOn
(
popover
.
togglePopover
,
'
call
'
);
$
(
selector
).
trigger
(
'
mouseenter
'
);
$
(
selector
).
trigger
(
'
mouseenter
'
);
expect
(
toggleSpy
).
toHaveBeenCalledWith
(
jasmine
.
any
(
Object
),
true
);
expect
(
popover
.
mouseenter
).
toHaveBeenCalledWith
(
expect
.
any
(
Object
)
);
});
});
it
(
'
setup debounced mouseleave
'
,
done
=>
{
it
(
'
setup debounced mouseleave
'
,
()
=>
{
const
toggleSpy
=
spyOn
(
popover
.
togglePopover
,
'
call
'
);
$
(
selector
).
trigger
(
'
mouseleave
'
);
$
(
selector
).
trigger
(
'
mouseleave
'
);
// Even though we've set the debounce to 0ms, setTimeout is needed for the debounce
expect
(
popover
.
debouncedMouseleave
).
toHaveBeenCalled
();
setTimeout
(()
=>
{
expect
(
toggleSpy
).
toHaveBeenCalledWith
(
jasmine
.
any
(
Object
),
false
);
done
();
},
0
);
});
});
it
(
'
setup show.bs.popover
'
,
()
=>
{
it
(
'
setup show.bs.popover
'
,
()
=>
{
$
(
selector
).
trigger
(
'
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
,
once
:
true
,
});
});
});
});
...
@@ -72,23 +68,6 @@ describe('feature highlight', () => {
...
@@ -72,23 +68,6 @@ describe('feature highlight', () => {
it
(
'
removes disabled attribute
'
,
()
=>
{
it
(
'
removes disabled attribute
'
,
()
=>
{
expect
(
$
(
'
.js-feature-highlight
'
).
is
(
'
:disabled
'
)).
toEqual
(
false
);
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
'
,
()
=>
{
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