2020-08-24 14:10:19 -04:00
|
|
|
import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown';
|
2021-02-14 13:09:20 -05:00
|
|
|
import NamespaceSelect from '~/namespace_select';
|
2017-10-26 08:47:17 -04:00
|
|
|
|
2020-08-24 14:10:19 -04:00
|
|
|
jest.mock('~/deprecated_jquery_dropdown');
|
2017-10-26 08:47:17 -04:00
|
|
|
|
2020-08-24 14:10:19 -04:00
|
|
|
describe('NamespaceSelect', () => {
|
|
|
|
it('initializes deprecatedJQueryDropdown', () => {
|
2017-10-26 08:47:17 -04:00
|
|
|
const dropdown = document.createElement('div');
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new NamespaceSelect({ dropdown });
|
|
|
|
|
2020-08-24 14:10:19 -04:00
|
|
|
expect(initDeprecatedJQueryDropdown).toHaveBeenCalled();
|
2017-10-26 08:47:17 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('as input', () => {
|
2020-08-24 14:10:19 -04:00
|
|
|
let deprecatedJQueryDropdownOptions;
|
2017-10-26 08:47:17 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const dropdown = document.createElement('div');
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new NamespaceSelect({ dropdown });
|
2020-08-24 14:10:19 -04:00
|
|
|
[[, deprecatedJQueryDropdownOptions]] = initDeprecatedJQueryDropdown.mock.calls;
|
2017-10-26 08:47:17 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('prevents click events', () => {
|
|
|
|
const dummyEvent = new Event('dummy');
|
2019-12-20 10:07:34 -05:00
|
|
|
jest.spyOn(dummyEvent, 'preventDefault').mockImplementation(() => {});
|
2017-10-26 08:47:17 -04:00
|
|
|
|
2020-08-24 14:10:19 -04:00
|
|
|
// expect(foo).toContain('test');
|
|
|
|
deprecatedJQueryDropdownOptions.clicked({ e: dummyEvent });
|
2017-10-26 08:47:17 -04:00
|
|
|
|
|
|
|
expect(dummyEvent.preventDefault).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('as filter', () => {
|
2020-08-24 14:10:19 -04:00
|
|
|
let deprecatedJQueryDropdownOptions;
|
2017-10-26 08:47:17 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const dropdown = document.createElement('div');
|
|
|
|
dropdown.dataset.isFilter = 'true';
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new NamespaceSelect({ dropdown });
|
2020-08-24 14:10:19 -04:00
|
|
|
[[, deprecatedJQueryDropdownOptions]] = initDeprecatedJQueryDropdown.mock.calls;
|
2017-10-26 08:47:17 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not prevent click events', () => {
|
|
|
|
const dummyEvent = new Event('dummy');
|
2019-12-20 10:07:34 -05:00
|
|
|
jest.spyOn(dummyEvent, 'preventDefault').mockImplementation(() => {});
|
2017-10-26 08:47:17 -04:00
|
|
|
|
2020-08-24 14:10:19 -04:00
|
|
|
deprecatedJQueryDropdownOptions.clicked({ e: dummyEvent });
|
2017-10-26 08:47:17 -04:00
|
|
|
|
|
|
|
expect(dummyEvent.preventDefault).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets URL of dropdown items', () => {
|
|
|
|
const dummyNamespace = { id: 'eal' };
|
|
|
|
|
2020-08-24 14:10:19 -04:00
|
|
|
const itemUrl = deprecatedJQueryDropdownOptions.url(dummyNamespace);
|
2017-10-26 08:47:17 -04:00
|
|
|
|
|
|
|
expect(itemUrl).toContain(`namespace_id=${dummyNamespace.id}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|