diff options
author | Ryan Berliner <22206986+RyanBerliner@users.noreply.github.com> | 2021-05-20 16:50:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-20 16:50:53 +0300 |
commit | 4ac711b5b4c0f733870cd8dd1f18b73f964275fc (patch) | |
tree | c91ecac7b95b6e8fd8f82ca58d66ada9dd3be809 /js/tests/unit/util | |
parent | 79c3bf47bc125fd64cf8cac6cd34b03270d34e2d (diff) |
Refactor `isVisible` helper, fixing false positives from deep nesting or alternate means (#33960)
Diffstat (limited to 'js/tests/unit/util')
-rw-r--r-- | js/tests/unit/util/index.spec.js | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/js/tests/unit/util/index.spec.js b/js/tests/unit/util/index.spec.js index ca6430bee5..774945d1f9 100644 --- a/js/tests/unit/util/index.spec.js +++ b/js/tests/unit/util/index.spec.js @@ -326,10 +326,14 @@ describe('Util', () => { expect(Util.isVisible(div)).toEqual(false) }) - it('should return false if the parent element is not visible', () => { + it('should return false if an ancestor element is display none', () => { fixtureEl.innerHTML = [ '<div style="display: none;">', - ' <div class="content"></div>', + ' <div>', + ' <div>', + ' <div class="content"></div>', + ' </div>', + ' </div>', '</div>' ].join('') @@ -338,6 +342,38 @@ describe('Util', () => { expect(Util.isVisible(div)).toEqual(false) }) + it('should return false if an ancestor element is visibility hidden', () => { + fixtureEl.innerHTML = [ + '<div style="visibility: hidden;">', + ' <div>', + ' <div>', + ' <div class="content"></div>', + ' </div>', + ' </div>', + '</div>' + ].join('') + + const div = fixtureEl.querySelector('.content') + + expect(Util.isVisible(div)).toEqual(false) + }) + + it('should return true if an ancestor element is visibility hidden, but reverted', () => { + fixtureEl.innerHTML = [ + '<div style="visibility: hidden;">', + ' <div style="visibility: visible;">', + ' <div>', + ' <div class="content"></div>', + ' </div>', + ' </div>', + '</div>' + ].join('') + + const div = fixtureEl.querySelector('.content') + + expect(Util.isVisible(div)).toEqual(true) + }) + it('should return true if the element is visible', () => { fixtureEl.innerHTML = [ '<div>', @@ -349,6 +385,18 @@ describe('Util', () => { expect(Util.isVisible(div)).toEqual(true) }) + + it('should return false if the element is hidden, but not via display or visibility', () => { + fixtureEl.innerHTML = [ + '<details>', + ' <div id="element"></div>', + '</details>' + ].join('') + + const div = fixtureEl.querySelector('#element') + + expect(Util.isVisible(div)).toEqual(false) + }) }) describe('isDisabled', () => { |