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

169 lines
5.0 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 InputSetter from '~/droplab/plugins/input_setter';
2017-04-05 15:58:01 +00:00
2018-10-17 07:13:26 +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
2017-04-07 13:09:15 +00:00
this.commentTypeToggle = new CommentTypeToggle({
dropdownTrigger: this.dropdownTrigger,
dropdownList: this.dropdownList,
noteTypeInput: this.noteTypeInput,
submitButton: this.submitButton,
closeButton: this.closeButton,
});
2017-04-05 15:58:01 +00:00
});
2018-10-17 07:13:26 +00:00
it('should set .dropdownTrigger', function() {
2017-04-06 13:48:10 +00:00
expect(this.commentTypeToggle.dropdownTrigger).toBe(this.dropdownTrigger);
2017-04-05 15:58:01 +00:00
});
2018-10-17 07:13:26 +00:00
it('should set .dropdownList', function() {
2017-04-06 13:48:10 +00:00
expect(this.commentTypeToggle.dropdownList).toBe(this.dropdownList);
2017-04-05 15:58:01 +00:00
});
2018-10-17 07:13:26 +00:00
it('should set .noteTypeInput', function() {
2017-04-06 13:48:10 +00:00
expect(this.commentTypeToggle.noteTypeInput).toBe(this.noteTypeInput);
2017-04-05 15:58:01 +00:00
});
2018-10-17 07:13:26 +00:00
it('should set .submitButton', function() {
2017-04-06 13:48:10 +00:00
expect(this.commentTypeToggle.submitButton).toBe(this.submitButton);
});
2018-10-17 07:13:26 +00:00
it('should set .closeButton', function() {
2017-04-06 13:48:10 +00:00
expect(this.commentTypeToggle.closeButton).toBe(this.closeButton);
2017-04-05 15:58:01 +00:00
});
2017-04-07 13:09:15 +00:00
2018-10-17 07:13:26 +00:00
it('should set .reopenButton', function() {
2017-04-07 13:09:15 +00:00
expect(this.commentTypeToggle.reopenButton).toBe(this.reopenButton);
});
2017-04-05 15:58:01 +00:00
});
2018-10-17 07:13:26 +00:00
describe('initDroplab', function() {
beforeEach(function() {
2017-04-05 15:58:01 +00:00
this.commentTypeToggle = {
2017-04-06 13:48:10 +00:00
dropdownTrigger: {},
dropdownList: {},
noteTypeInput: {},
submitButton: {},
closeButton: {},
2017-04-07 13:09:15 +00:00
setConfig: () => {},
2017-04-05 15:58:01 +00:00
};
2017-04-07 13:09:15 +00:00
this.config = {};
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
2018-10-17 07:13:26 +00:00
this.droplabConstructor = spyOnDependency(CommentTypeToggle, 'DropLab').and.returnValue(
this.droplab,
);
2017-04-07 13:09:15 +00:00
spyOn(this.commentTypeToggle, 'setConfig').and.returnValue(this.config);
2017-04-05 15:58:01 +00:00
2017-04-07 13:09:15 +00:00
CommentTypeToggle.prototype.initDroplab.call(this.commentTypeToggle);
2017-04-05 15:58:01 +00:00
});
2018-10-17 07:13:26 +00:00
it('should instantiate a DropLab instance', function() {
expect(this.droplabConstructor).toHaveBeenCalled();
2017-04-05 15:58:01 +00:00
});
2018-10-17 07:13:26 +00:00
it('should set .droplab', function() {
2017-04-05 15:58:01 +00:00
expect(this.commentTypeToggle.droplab).toBe(this.droplab);
});
2018-10-17 07:13:26 +00:00
it('should call .setConfig', function() {
2017-04-07 13:09:15 +00:00
expect(this.commentTypeToggle.setConfig).toHaveBeenCalled();
});
2018-10-17 07:13:26 +00:00
it('should call DropLab.prototype.init', function() {
2017-04-06 13:48:10 +00:00
expect(this.droplab.init).toHaveBeenCalledWith(
this.commentTypeToggle.dropdownTrigger,
this.commentTypeToggle.dropdownList,
2017-04-05 15:58:01 +00:00
[InputSetter],
2017-04-07 13:09:15 +00:00
this.config,
);
});
});
2018-10-17 07:13:26 +00:00
describe('setConfig', function() {
describe('if no .closeButton is provided', function() {
beforeEach(function() {
2017-04-07 13:09:15 +00:00
this.commentTypeToggle = {
dropdownTrigger: {},
dropdownList: {},
noteTypeInput: {},
submitButton: {},
reopenButton: {},
};
this.setConfig = CommentTypeToggle.prototype.setConfig.call(this.commentTypeToggle);
});
2018-10-17 07:13:26 +00:00
it('should not add .closeButton related InputSetter config', function() {
2017-04-07 13:09:15 +00:00
expect(this.setConfig).toEqual({
2018-10-17 07:13:26 +00:00
InputSetter: [
{
input: this.commentTypeToggle.noteTypeInput,
valueAttribute: 'data-value',
},
{
input: this.commentTypeToggle.submitButton,
valueAttribute: 'data-submit-text',
},
{
input: this.commentTypeToggle.reopenButton,
valueAttribute: 'data-reopen-text',
},
{
input: this.commentTypeToggle.reopenButton,
valueAttribute: 'data-reopen-text',
inputAttribute: 'data-alternative-text',
},
],
2017-04-07 13:09:15 +00:00
});
});
2017-04-05 15:58:01 +00:00
});
2017-04-06 13:48:10 +00:00
2018-10-17 07:13:26 +00:00
describe('if no .reopenButton is provided', function() {
beforeEach(function() {
2017-04-06 13:48:10 +00:00
this.commentTypeToggle = {
dropdownTrigger: {},
dropdownList: {},
noteTypeInput: {},
submitButton: {},
2017-04-07 13:09:15 +00:00
closeButton: {},
2017-04-06 13:48:10 +00:00
};
2017-04-07 13:09:15 +00:00
this.setConfig = CommentTypeToggle.prototype.setConfig.call(this.commentTypeToggle);
2017-04-06 13:48:10 +00:00
});
2018-10-17 07:13:26 +00:00
it('should not add .reopenButton related InputSetter config', function() {
2017-04-07 13:09:15 +00:00
expect(this.setConfig).toEqual({
2018-10-17 07:13:26 +00:00
InputSetter: [
{
input: this.commentTypeToggle.noteTypeInput,
valueAttribute: 'data-value',
},
{
input: this.commentTypeToggle.submitButton,
valueAttribute: 'data-submit-text',
},
{
input: this.commentTypeToggle.closeButton,
valueAttribute: 'data-close-text',
},
{
input: this.commentTypeToggle.closeButton,
valueAttribute: 'data-close-text',
inputAttribute: 'data-alternative-text',
},
],
2017-04-07 13:09:15 +00:00
});
2017-04-06 13:48:10 +00:00
});
});
2017-04-05 15:58:01 +00:00
});
});