debian-mirror-gitlab/spec/frontend/vue_shared/directives/autofocusonshow_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-12-04 20:38:33 +05:30
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;
2020-06-23 00:09:42 +05:30
beforeEach(() => {
2019-12-04 20:38:33 +05:30
setFixtures('<div id="container" style="display: none;"><input id="inputel"/></div>');
el = document.querySelector('#inputel');
});
it('should bind IntersectionObserver on input element', () => {
2020-06-23 00:09:42 +05:30
jest.spyOn(el, 'focus').mockImplementation(() => {});
2019-12-04 20:38:33 +05:30
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: () => {},
};
2020-06-23 00:09:42 +05:30
jest.spyOn(el.visibilityObserver, 'disconnect').mockImplementation(() => {});
2019-12-04 20:38:33 +05:30
autofocusonshow.unbind(el);
expect(el.visibilityObserver).toBeDefined();
expect(el.visibilityObserver.disconnect).toHaveBeenCalled();
});
});
});