gitlab-org--gitlab-foss/spec/javascripts/droplab/hook_spec.js

74 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-04-07 13:57:03 +00:00
import Hook from '~/droplab/hook';
2018-10-17 07:13:26 +00:00
describe('Hook', function() {
describe('class constructor', function() {
beforeEach(function() {
2017-04-07 13:57:03 +00:00
this.trigger = { id: 'id' };
this.list = {};
this.plugins = {};
this.config = {};
this.dropdown = {};
2018-04-13 22:19:09 +00:00
this.dropdownConstructor = spyOnDependency(Hook, 'DropDown').and.returnValue(this.dropdown);
2017-04-07 13:57:03 +00:00
this.hook = new Hook(this.trigger, this.list, this.plugins, this.config);
});
2018-10-17 07:13:26 +00:00
it('should set .trigger', function() {
2017-04-07 13:57:03 +00:00
expect(this.hook.trigger).toBe(this.trigger);
});
2018-10-17 07:13:26 +00:00
it('should set .list', function() {
2017-04-07 13:57:03 +00:00
expect(this.hook.list).toBe(this.dropdown);
});
2018-10-17 07:13:26 +00:00
it('should call DropDown constructor', function() {
2018-04-13 22:19:09 +00:00
expect(this.dropdownConstructor).toHaveBeenCalledWith(this.list, this.config);
2017-04-07 13:57:03 +00:00
});
2018-10-17 07:13:26 +00:00
it('should set .type', function() {
2017-04-07 13:57:03 +00:00
expect(this.hook.type).toBe('Hook');
});
2018-10-17 07:13:26 +00:00
it('should set .event', function() {
2017-04-07 13:57:03 +00:00
expect(this.hook.event).toBe('click');
});
2018-10-17 07:13:26 +00:00
it('should set .plugins', function() {
2017-04-07 13:57:03 +00:00
expect(this.hook.plugins).toBe(this.plugins);
});
2018-10-17 07:13:26 +00:00
it('should set .config', function() {
2017-04-07 13:57:03 +00:00
expect(this.hook.config).toBe(this.config);
});
2018-10-17 07:13:26 +00:00
it('should set .id', function() {
2017-04-07 13:57:03 +00:00
expect(this.hook.id).toBe(this.trigger.id);
});
2018-10-17 07:13:26 +00:00
describe('if config argument is undefined', function() {
beforeEach(function() {
2017-04-07 13:57:03 +00:00
this.config = undefined;
this.hook = new Hook(this.trigger, this.list, this.plugins, this.config);
});
2018-10-17 07:13:26 +00:00
it('should set .config to an empty object', function() {
2017-04-07 13:57:03 +00:00
expect(this.hook.config).toEqual({});
});
});
2018-10-17 07:13:26 +00:00
describe('if plugins argument is undefined', function() {
beforeEach(function() {
2017-04-07 13:57:03 +00:00
this.plugins = undefined;
this.hook = new Hook(this.trigger, this.list, this.plugins, this.config);
});
2018-10-17 07:13:26 +00:00
it('should set .plugins to an empty array', function() {
2017-04-07 13:57:03 +00:00
expect(this.hook.plugins).toEqual([]);
});
});
});
});