Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/lib/utils/dom_utils_spec.js')
-rw-r--r--spec/frontend/lib/utils/dom_utils_spec.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/dom_utils_spec.js b/spec/frontend/lib/utils/dom_utils_spec.js
index d918016a5f4..f5c2a797df5 100644
--- a/spec/frontend/lib/utils/dom_utils_spec.js
+++ b/spec/frontend/lib/utils/dom_utils_spec.js
@@ -3,6 +3,8 @@ import {
canScrollUp,
canScrollDown,
parseBooleanDataAttributes,
+ isElementVisible,
+ isElementHidden,
} from '~/lib/utils/dom_utils';
const TEST_MARGIN = 5;
@@ -160,4 +162,35 @@ describe('DOM Utils', () => {
});
});
});
+
+ describe.each`
+ offsetWidth | offsetHeight | clientRectsLength | visible
+ ${0} | ${0} | ${0} | ${false}
+ ${1} | ${0} | ${0} | ${true}
+ ${0} | ${1} | ${0} | ${true}
+ ${0} | ${0} | ${1} | ${true}
+ `(
+ 'isElementVisible and isElementHidden',
+ ({ offsetWidth, offsetHeight, clientRectsLength, visible }) => {
+ const element = {
+ offsetWidth,
+ offsetHeight,
+ getClientRects: () => new Array(clientRectsLength),
+ };
+
+ const paramDescription = `offsetWidth=${offsetWidth}, offsetHeight=${offsetHeight}, and getClientRects().length=${clientRectsLength}`;
+
+ describe('isElementVisible', () => {
+ it(`returns ${visible} when ${paramDescription}`, () => {
+ expect(isElementVisible(element)).toBe(visible);
+ });
+ });
+
+ describe('isElementHidden', () => {
+ it(`returns ${!visible} when ${paramDescription}`, () => {
+ expect(isElementHidden(element)).toBe(!visible);
+ });
+ });
+ },
+ );
});