2021-04-06 11:09:23 -04:00
|
|
|
import FileTemplateSelector from '~/blob/file_template_selector';
|
2022-05-17 14:09:20 -04:00
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2021-04-06 11:09:23 -04:00
|
|
|
|
|
|
|
describe('FileTemplateSelector', () => {
|
|
|
|
let subject;
|
2022-05-17 14:09:20 -04:00
|
|
|
|
|
|
|
const dropdown = '.dropdown';
|
|
|
|
const wrapper = '.wrapper';
|
2021-04-06 11:09:23 -04:00
|
|
|
|
|
|
|
const createSubject = () => {
|
|
|
|
subject = new FileTemplateSelector({});
|
|
|
|
subject.config = {
|
|
|
|
dropdown,
|
|
|
|
wrapper,
|
|
|
|
};
|
|
|
|
subject.initDropdown = jest.fn();
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
subject = null;
|
2022-05-17 14:09:20 -04:00
|
|
|
resetHTMLFixture();
|
2021-04-06 11:09:23 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('show method', () => {
|
|
|
|
beforeEach(() => {
|
2022-05-17 14:09:20 -04:00
|
|
|
setHTMLFixture(`
|
|
|
|
<div class="wrapper hidden">
|
|
|
|
<div class="dropdown"></div>
|
|
|
|
</div>
|
|
|
|
`);
|
2021-04-06 11:09:23 -04:00
|
|
|
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-05-17 14:09:20 -04:00
|
|
|
it('removes hidden class from wrapper', () => {
|
|
|
|
subject.init();
|
|
|
|
expect(subject.wrapper.classList.contains('hidden')).toBe(true);
|
2021-04-06 11:09:23 -04:00
|
|
|
|
|
|
|
subject.show();
|
2022-05-17 14:09:20 -04:00
|
|
|
expect(subject.wrapper.classList.contains('hidden')).toBe(false);
|
2021-04-06 11:09:23 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the focus on the dropdown', async () => {
|
|
|
|
subject.show();
|
2022-05-17 14:09:20 -04:00
|
|
|
jest.spyOn(subject.dropdown, 'focus');
|
2021-04-06 11:09:23 -04:00
|
|
|
jest.runAllTimers();
|
|
|
|
|
2022-05-17 14:09:20 -04:00
|
|
|
expect(subject.dropdown.focus).toHaveBeenCalled();
|
2021-04-06 11:09:23 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|