gitlab-org--gitlab-foss/spec/javascripts/comment_type_toggle_spec.js

125 lines
3.8 KiB
JavaScript
Raw Normal View History

2017-04-05 15:58:01 +00:00
import CommentTypeToggle from '~/comment_type_toggle';
2017-04-06 13:48:10 +00:00
import * as dropLabSrc from '~/droplab/drop_lab';
import InputSetter from '~/droplab/plugins/input_setter';
2017-04-05 15:58:01 +00:00
describe('CommentTypeToggle', function () {
describe('class constructor', function () {
beforeEach(function () {
2017-04-06 13:48:10 +00:00
this.dropdownTrigger = {};
this.dropdownList = {};
this.noteTypeInput = {};
this.submitButton = {};
this.closeButton = {};
2017-04-05 15:58:01 +00:00
this.commentTypeToggle = new CommentTypeToggle(
2017-04-06 13:48:10 +00:00
this.dropdownTrigger,
this.dropdownList,
this.noteTypeInput,
this.submitButton,
this.closeButton,
2017-04-05 15:58:01 +00:00
);
});
2017-04-06 13:48:10 +00:00
it('should set .dropdownTrigger', function () {
expect(this.commentTypeToggle.dropdownTrigger).toBe(this.dropdownTrigger);
2017-04-05 15:58:01 +00:00
});
2017-04-06 13:48:10 +00:00
it('should set .dropdownList', function () {
expect(this.commentTypeToggle.dropdownList).toBe(this.dropdownList);
2017-04-05 15:58:01 +00:00
});
2017-04-06 13:48:10 +00:00
it('should set .noteTypeInput', function () {
expect(this.commentTypeToggle.noteTypeInput).toBe(this.noteTypeInput);
2017-04-05 15:58:01 +00:00
});
2017-04-06 13:48:10 +00:00
it('should set .submitButton', function () {
expect(this.commentTypeToggle.submitButton).toBe(this.submitButton);
});
it('should set .closeButton', function () {
expect(this.commentTypeToggle.closeButton).toBe(this.closeButton);
2017-04-05 15:58:01 +00:00
});
});
describe('initDroplab', function () {
beforeEach(function () {
this.commentTypeToggle = {
2017-04-06 13:48:10 +00:00
dropdownTrigger: {},
dropdownList: {},
noteTypeInput: {},
submitButton: {},
closeButton: {},
2017-04-05 15:58:01 +00:00
};
2017-04-06 13:48:10 +00:00
this.droplab = jasmine.createSpyObj('droplab', ['init']);
2017-04-05 15:58:01 +00:00
2017-04-06 13:48:10 +00:00
spyOn(dropLabSrc, 'default').and.returnValue(this.droplab);
2017-04-05 15:58:01 +00:00
this.initDroplab = CommentTypeToggle.prototype.initDroplab.call(this.commentTypeToggle);
});
it('should instantiate a DropLab instance', function () {
2017-04-06 13:48:10 +00:00
expect(dropLabSrc.default).toHaveBeenCalled();
2017-04-05 15:58:01 +00:00
});
it('should set .droplab', function () {
expect(this.commentTypeToggle.droplab).toBe(this.droplab);
});
2017-04-06 13:48:10 +00:00
it('should call DropLab.prototype.init', function () {
expect(this.droplab.init).toHaveBeenCalledWith(
this.commentTypeToggle.dropdownTrigger,
this.commentTypeToggle.dropdownList,
2017-04-05 15:58:01 +00:00
[InputSetter],
{
InputSetter: [{
2017-04-06 13:48:10 +00:00
input: this.commentTypeToggle.noteTypeInput,
2017-04-05 15:58:01 +00:00
valueAttribute: 'data-value',
}, {
2017-04-06 13:48:10 +00:00
input: this.commentTypeToggle.submitButton,
2017-04-05 15:58:01 +00:00
valueAttribute: 'data-button-text',
2017-04-06 13:48:10 +00:00
},
{
input: this.commentTypeToggle.closeButton,
valueAttribute: 'data-secondary-button-text',
}, {
input: this.commentTypeToggle.closeButton,
valueAttribute: 'data-secondary-button-text',
inputAttribute: 'data-alternative-text',
2017-04-05 15:58:01 +00:00
}],
},
);
});
2017-04-06 13:48:10 +00:00
describe('if no .closeButton is provided', function () {
beforeEach(function () {
this.commentTypeToggle = {
dropdownTrigger: {},
dropdownList: {},
noteTypeInput: {},
submitButton: {},
};
this.initDroplab = CommentTypeToggle.prototype.initDroplab.call(this.commentTypeToggle);
});
it('should not add .closeButton related InputSetter config', function () {
expect(this.droplab.init).toHaveBeenCalledWith(
this.commentTypeToggle.dropdownTrigger,
this.commentTypeToggle.dropdownList,
[InputSetter],
{
InputSetter: [{
input: this.commentTypeToggle.noteTypeInput,
valueAttribute: 'data-value',
}, {
input: this.commentTypeToggle.submitButton,
valueAttribute: 'data-button-text',
}],
},
);
});
});
2017-04-05 15:58:01 +00:00
});
});