2018-03-17 18:26:18 +05:30
|
|
|
import NamespaceSelect from '~/namespace_select';
|
2020-11-24 15:15:51 +05:30
|
|
|
import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
jest.mock('~/deprecated_jquery_dropdown');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('NamespaceSelect', () => {
|
|
|
|
it('initializes deprecatedJQueryDropdown', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const dropdown = document.createElement('div');
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new NamespaceSelect({ dropdown });
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(initDeprecatedJQueryDropdown).toHaveBeenCalled();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('as input', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
let deprecatedJQueryDropdownOptions;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const dropdown = document.createElement('div');
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new NamespaceSelect({ dropdown });
|
2020-11-24 15:15:51 +05:30
|
|
|
[[, deprecatedJQueryDropdownOptions]] = initDeprecatedJQueryDropdown.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
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
// expect(foo).toContain('test');
|
|
|
|
deprecatedJQueryDropdownOptions.clicked({ e: dummyEvent });
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(dummyEvent.preventDefault).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('as filter', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
let deprecatedJQueryDropdownOptions;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const dropdown = document.createElement('div');
|
|
|
|
dropdown.dataset.isFilter = 'true';
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new NamespaceSelect({ dropdown });
|
2020-11-24 15:15:51 +05:30
|
|
|
[[, deprecatedJQueryDropdownOptions]] = initDeprecatedJQueryDropdown.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
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
deprecatedJQueryDropdownOptions.clicked({ e: dummyEvent });
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(dummyEvent.preventDefault).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets URL of dropdown items', () => {
|
|
|
|
const dummyNamespace = { id: 'eal' };
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
const itemUrl = deprecatedJQueryDropdownOptions.url(dummyNamespace);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(itemUrl).toContain(`namespace_id=${dummyNamespace.id}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|