diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-22 21:08:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-22 21:08:21 +0300 |
commit | 1cf95147eabbb193c1db2526e6c8888e950a3987 (patch) | |
tree | 88ae9b19860f7d0552efd048f47d494adcaa03af /spec/frontend/vue_shared/directives | |
parent | d6e421b21ed5574700c165cd3361094f4093ac72 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared/directives')
-rw-r--r-- | spec/frontend/vue_shared/directives/autofocusonshow_spec.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/directives/autofocusonshow_spec.js b/spec/frontend/vue_shared/directives/autofocusonshow_spec.js new file mode 100644 index 00000000000..90530b7d5c2 --- /dev/null +++ b/spec/frontend/vue_shared/directives/autofocusonshow_spec.js @@ -0,0 +1,46 @@ +import autofocusonshow from '~/vue_shared/directives/autofocusonshow'; + +/** + * We're testing this directive's hooks as pure functions + * since behaviour of this directive is highly-dependent + * on underlying DOM methods. + */ +describe('AutofocusOnShow directive', () => { + describe('with input invisible on component render', () => { + let el; + + beforeEach(() => { + setFixtures('<div id="container" style="display: none;"><input id="inputel"/></div>'); + el = document.querySelector('#inputel'); + + window.IntersectionObserver = class { + observe = jest.fn(); + }; + }); + + afterEach(() => { + delete window.IntersectionObserver; + }); + + it('should bind IntersectionObserver on input element', () => { + jest.spyOn(el, 'focus').mockImplementation(() => {}); + + autofocusonshow.inserted(el); + + expect(el.visibilityObserver).toBeDefined(); + expect(el.focus).not.toHaveBeenCalled(); + }); + + it('should stop IntersectionObserver on input element on unbind hook', () => { + el.visibilityObserver = { + disconnect: () => {}, + }; + jest.spyOn(el.visibilityObserver, 'disconnect').mockImplementation(() => {}); + + autofocusonshow.unbind(el); + + expect(el.visibilityObserver).toBeDefined(); + expect(el.visibilityObserver.disconnect).toHaveBeenCalled(); + }); + }); +}); |