debian-mirror-gitlab/spec/frontend/namespace_select_spec.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import NamespaceSelect from '~/namespace_select';
describe('NamespaceSelect', () => {
beforeEach(() => {
2020-03-13 15:44:24 +05:30
jest.spyOn($.fn, 'glDropdown').mockImplementation(() => {});
2018-03-17 18:26:18 +05:30
});
it('initializes glDropdown', () => {
const dropdown = document.createElement('div');
// eslint-disable-next-line no-new
new NamespaceSelect({ dropdown });
expect($.fn.glDropdown).toHaveBeenCalled();
});
describe('as input', () => {
let glDropdownOptions;
beforeEach(() => {
const dropdown = document.createElement('div');
// eslint-disable-next-line no-new
new NamespaceSelect({ dropdown });
2020-03-13 15:44:24 +05:30
[[glDropdownOptions]] = $.fn.glDropdown.mock.calls;
2018-03-17 18:26:18 +05:30
});
it('prevents click events', () => {
const dummyEvent = new Event('dummy');
2020-03-13 15:44:24 +05:30
jest.spyOn(dummyEvent, 'preventDefault').mockImplementation(() => {});
2018-03-17 18:26:18 +05:30
glDropdownOptions.clicked({ e: dummyEvent });
expect(dummyEvent.preventDefault).toHaveBeenCalled();
});
});
describe('as filter', () => {
let glDropdownOptions;
beforeEach(() => {
const dropdown = document.createElement('div');
dropdown.dataset.isFilter = 'true';
// eslint-disable-next-line no-new
new NamespaceSelect({ dropdown });
2020-03-13 15:44:24 +05:30
[[glDropdownOptions]] = $.fn.glDropdown.mock.calls;
2018-03-17 18:26:18 +05:30
});
it('does not prevent click events', () => {
const dummyEvent = new Event('dummy');
2020-03-13 15:44:24 +05:30
jest.spyOn(dummyEvent, 'preventDefault').mockImplementation(() => {});
2018-03-17 18:26:18 +05:30
glDropdownOptions.clicked({ e: dummyEvent });
expect(dummyEvent.preventDefault).not.toHaveBeenCalled();
});
it('sets URL of dropdown items', () => {
const dummyNamespace = { id: 'eal' };
const itemUrl = glDropdownOptions.url(dummyNamespace);
expect(itemUrl).toContain(`namespace_id=${dummyNamespace.id}`);
});
});
});