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
b0ca5b36
Commit
b0ca5b36
authored
Aug 25, 2021
by
Vitaly Slobodin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate browser_spec to Jest
Closes
https://gitlab.com/gitlab-org/gitlab/-/issues/287678
parent
fd187fee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
9 deletions
+34
-9
spec/frontend_integration/lib/utils/browser_spec.js
spec/frontend_integration/lib/utils/browser_spec.js
+34
-9
No files found.
spec/
javascripts
/lib/utils/browser_spec.js
→
spec/
frontend_integration
/lib/utils/browser_spec.js
View file @
b0ca5b36
/**
* This file should only contain browser specific specs.
* If you need to add or update a spec, please see spec/frontend/lib/utils/*.js
* https://gitlab.com/gitlab-org/gitlab/issues/194242#note_292137135
* https://gitlab.com/groups/gitlab-org/-/epics/895#what-if-theres-a-karma-spec-which-is-simply-unmovable-to-jest-ie-it-is-dependent-on-a-running-browser-environment
*/
import
{
GlBreakpointInstance
as
breakpointInstance
}
from
'
@gitlab/ui/dist/utils
'
;
import
*
as
commonUtils
from
'
~/lib/utils/common_utils
'
;
describe
(
'
common_utils browser specific specs
'
,
()
=>
{
const
mockOffsetHeight
=
(
elem
,
offsetHeight
)
=>
{
Object
.
defineProperty
(
elem
,
'
offsetHeight
'
,
{
value
:
offsetHeight
});
};
const
mockBoundingClientRect
=
(
elem
,
rect
)
=>
{
jest
.
spyOn
(
elem
,
'
getBoundingClientRect
'
).
mockReturnValue
(
rect
);
};
describe
(
'
contentTop
'
,
()
=>
{
it
(
'
does not add height for fileTitle or compareVersionsHeader if screen is too small
'
,
()
=>
{
spyOn
(
breakpointInstance
,
'
isDesktop
'
).
and
.
r
eturnValue
(
false
);
jest
.
spyOn
(
breakpointInstance
,
'
isDesktop
'
).
mockR
eturnValue
(
false
);
setFixtures
(
`
<div class="diff-file file-title-flex-parent">
...
...
@@ -26,7 +27,7 @@ describe('common_utils browser specific specs', () => {
});
it
(
'
adds height for fileTitle and compareVersionsHeader screen is large enough
'
,
()
=>
{
spyOn
(
breakpointInstance
,
'
isDesktop
'
).
and
.
r
eturnValue
(
true
);
jest
.
spyOn
(
breakpointInstance
,
'
isDesktop
'
).
mockR
eturnValue
(
true
);
setFixtures
(
`
<div class="diff-file file-title-flex-parent">
...
...
@@ -37,6 +38,8 @@ describe('common_utils browser specific specs', () => {
</div>
`
);
mockOffsetHeight
(
document
.
querySelector
(
'
.diff-file
'
),
100
);
mockOffsetHeight
(
document
.
querySelector
(
'
.mr-version-controls
'
),
18
);
expect
(
commonUtils
.
contentTop
()).
toBe
(
18
);
});
});
...
...
@@ -54,6 +57,17 @@ describe('common_utils browser specific specs', () => {
it
(
'
returns true when provided `el` is in viewport
'
,
()
=>
{
el
.
setAttribute
(
'
style
'
,
`position: absolute; right:
${
window
.
innerWidth
+
0.2
}
;`
);
mockBoundingClientRect
(
el
,
{
x
:
8
,
y
:
8
,
width
:
0
,
height
:
0
,
top
:
8
,
right
:
8
,
bottom
:
8
,
left
:
8
,
});
document
.
body
.
appendChild
(
el
);
expect
(
commonUtils
.
isInViewport
(
el
)).
toBe
(
true
);
...
...
@@ -61,6 +75,17 @@ describe('common_utils browser specific specs', () => {
it
(
'
returns false when provided `el` is not in viewport
'
,
()
=>
{
el
.
setAttribute
(
'
style
'
,
'
position: absolute; top: -1000px; left: -1000px;
'
);
mockBoundingClientRect
(
el
,
{
x
:
-
1000
,
y
:
-
1000
,
width
:
0
,
height
:
0
,
top
:
-
1000
,
right
:
-
1000
,
bottom
:
-
1000
,
left
:
-
1000
,
});
document
.
body
.
appendChild
(
el
);
expect
(
commonUtils
.
isInViewport
(
el
)).
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