debian-mirror-gitlab/spec/frontend/blob/file_template_selector_spec.js

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

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-04-29 21:17:54 +05:30
import FileTemplateSelector from '~/blob/file_template_selector';
2022-07-16 23:28:13 +05:30
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
2021-04-29 21:17:54 +05:30
describe('FileTemplateSelector', () => {
let subject;
2022-07-16 23:28:13 +05:30
const dropdown = '.dropdown';
const wrapper = '.wrapper';
2021-04-29 21:17:54 +05:30
const createSubject = () => {
subject = new FileTemplateSelector({});
subject.config = {
dropdown,
wrapper,
};
subject.initDropdown = jest.fn();
};
afterEach(() => {
subject = null;
2022-07-16 23:28:13 +05:30
resetHTMLFixture();
2021-04-29 21:17:54 +05:30
});
describe('show method', () => {
beforeEach(() => {
2022-07-16 23:28:13 +05:30
setHTMLFixture(`
<div class="wrapper hidden">
<div class="dropdown"></div>
</div>
`);
2021-04-29 21:17:54 +05:30
createSubject();
});
it('calls init on first call', () => {
jest.spyOn(subject, 'init');
subject.show();
expect(subject.init).toHaveBeenCalledTimes(1);
});
it('does not call init on subsequent calls', () => {
jest.spyOn(subject, 'init');
subject.show();
expect(subject.init).toHaveBeenCalledTimes(1);
});
2022-07-16 23:28:13 +05:30
it('removes hidden class from wrapper', () => {
subject.init();
expect(subject.wrapper.classList.contains('hidden')).toBe(true);
2021-04-29 21:17:54 +05:30
subject.show();
2022-07-16 23:28:13 +05:30
expect(subject.wrapper.classList.contains('hidden')).toBe(false);
2021-04-29 21:17:54 +05:30
});
it('sets the focus on the dropdown', async () => {
subject.show();
2022-07-16 23:28:13 +05:30
jest.spyOn(subject.dropdown, 'focus');
2021-04-29 21:17:54 +05:30
jest.runAllTimers();
2022-07-16 23:28:13 +05:30
expect(subject.dropdown.focus).toHaveBeenCalled();
2021-04-29 21:17:54 +05:30
});
});
});