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
|
|
|
|
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
|
|
|
});
|
|
|
|
|
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
|
|
|
});
|
2017-04-07 13:09:15 +00:00
|
|
|
|
|
|
|
it('should set .reopenButton', function () {
|
|
|
|
expect(this.commentTypeToggle.reopenButton).toBe(this.reopenButton);
|
|
|
|
});
|
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-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
|
|
|
|
2017-04-06 13:48:10 +00:00
|
|
|
spyOn(dropLabSrc, 'default').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
|
|
|
});
|
|
|
|
|
|
|
|
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-07 13:09:15 +00:00
|
|
|
it('should call .setConfig', function () {
|
|
|
|
expect(this.commentTypeToggle.setConfig).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
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],
|
2017-04-07 13:09:15 +00:00
|
|
|
this.config,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setConfig', function () {
|
|
|
|
describe('if no .closeButton is provided', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.commentTypeToggle = {
|
|
|
|
dropdownTrigger: {},
|
|
|
|
dropdownList: {},
|
|
|
|
noteTypeInput: {},
|
|
|
|
submitButton: {},
|
|
|
|
reopenButton: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setConfig = CommentTypeToggle.prototype.setConfig.call(this.commentTypeToggle);
|
|
|
|
});
|
|
|
|
|
2017-04-07 14:31:14 +00:00
|
|
|
it('should not add .closeButton related InputSetter config', function () {
|
2017-04-07 13:09:15 +00:00
|
|
|
expect(this.setConfig).toEqual({
|
2017-04-05 15:58:01 +00:00
|
|
|
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-07 13:09:15 +00:00
|
|
|
valueAttribute: 'data-submit-text',
|
2017-04-07 14:31:14 +00:00
|
|
|
}, {
|
|
|
|
input: this.commentTypeToggle.reopenButton,
|
|
|
|
valueAttribute: 'data-reopen-text',
|
|
|
|
}, {
|
|
|
|
input: this.commentTypeToggle.reopenButton,
|
|
|
|
valueAttribute: 'data-reopen-text',
|
|
|
|
inputAttribute: 'data-alternative-text',
|
2017-04-05 15:58:01 +00:00
|
|
|
}],
|
2017-04-07 13:09:15 +00:00
|
|
|
});
|
|
|
|
});
|
2017-04-05 15:58:01 +00:00
|
|
|
});
|
2017-04-06 13:48:10 +00:00
|
|
|
|
2017-04-07 13:09:15 +00:00
|
|
|
describe('if no .reopenButton is provided', function () {
|
2017-04-06 13:48:10 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2017-04-07 14:31:14 +00:00
|
|
|
it('should not add .reopenButton related InputSetter config', function () {
|
2017-04-07 13:09:15 +00:00
|
|
|
expect(this.setConfig).toEqual({
|
|
|
|
InputSetter: [{
|
|
|
|
input: this.commentTypeToggle.noteTypeInput,
|
|
|
|
valueAttribute: 'data-value',
|
|
|
|
}, {
|
|
|
|
input: this.commentTypeToggle.submitButton,
|
|
|
|
valueAttribute: 'data-submit-text',
|
2017-04-07 14:31:14 +00:00
|
|
|
}, {
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|