Commit 99e4431c authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Update unit tests

parent 9cee280d
import DropLab from '@gitlab-org/droplab'; import DropLab from '~/droplab/drop_lab';
import InputSetter from '@gitlab-org/droplab/dist/plugins/InputSetter'; import InputSetter from '~/droplab/plugins/input_setter';
class CommentTypeToggle { class CommentTypeToggle {
constructor(dropdownTrigger, dropdownList, noteTypeInput, submitButton, closeButton) { constructor(dropdownTrigger, dropdownList, noteTypeInput, submitButton, closeButton) {
...@@ -33,7 +33,7 @@ class CommentTypeToggle { ...@@ -33,7 +33,7 @@ class CommentTypeToggle {
} }
this.droplab.init(this.dropdownTrigger, this.dropdownList, [InputSetter], { this.droplab.init(this.dropdownTrigger, this.dropdownList, [InputSetter], {
InputSetter: inputSetterConfig InputSetter: inputSetterConfig,
}); });
} }
} }
......
...@@ -738,7 +738,7 @@ require('./task_list'); ...@@ -738,7 +738,7 @@ require('./task_list');
Notes.prototype.replyToDiscussionNote = function(e) { Notes.prototype.replyToDiscussionNote = function(e) {
var form, replyLink; var form, replyLink;
form = this.cleanForm(this.formClone.clone()); form = this.cleanForm(this.formClone.clone());
replyLink = $(e.target).closest(".js-discussion-reply-button"); replyLink = $(e.target).closest(".js-discussion-reply-button");
// insert the form after the button // insert the form after the button
replyLink replyLink
...@@ -1060,7 +1060,7 @@ require('./task_list'); ...@@ -1060,7 +1060,7 @@ require('./task_list');
.remove(); .remove();
return $form; return $form;
} };
return Notes; return Notes;
})(); })();
......
import CommentTypeToggle from '~/comment_type_toggle'; import CommentTypeToggle from '~/comment_type_toggle';
import DropLab from '@gitlab-org/droplab'; import * as dropLabSrc from '~/droplab/drop_lab';
import InputSetter from '@gitlab-org/droplab/dist/plugins/InputSetter'; import InputSetter from '~/droplab/plugins/input_setter';
describe('CommentTypeToggle', function () { describe('CommentTypeToggle', function () {
describe('class constructor', function () { describe('class constructor', function () {
beforeEach(function () { beforeEach(function () {
this.trigger = {}; this.dropdownTrigger = {};
this.list = {}; this.dropdownList = {};
this.input = {}; this.noteTypeInput = {};
this.button = {}; this.submitButton = {};
this.closeButton = {};
this.commentTypeToggle = new CommentTypeToggle( this.commentTypeToggle = new CommentTypeToggle(
this.trigger, this.dropdownTrigger,
this.list, this.dropdownList,
this.input, this.noteTypeInput,
this.button, this.submitButton,
this.closeButton,
); );
}); });
it('should set .trigger', function () { it('should set .dropdownTrigger', function () {
expect(this.commentTypeToggle.trigger).toBe(this.trigger); expect(this.commentTypeToggle.dropdownTrigger).toBe(this.dropdownTrigger);
}); });
it('should set .list', function () { it('should set .dropdownList', function () {
expect(this.commentTypeToggle.list).toBe(this.list); expect(this.commentTypeToggle.dropdownList).toBe(this.dropdownList);
}); });
it('should set .input', function () { it('should set .noteTypeInput', function () {
expect(this.commentTypeToggle.input).toBe(this.input); expect(this.commentTypeToggle.noteTypeInput).toBe(this.noteTypeInput);
}); });
it('should set .button', function () { it('should set .submitButton', function () {
expect(this.commentTypeToggle.button).toBe(this.button); expect(this.commentTypeToggle.submitButton).toBe(this.submitButton);
});
it('should set .closeButton', function () {
expect(this.commentTypeToggle.closeButton).toBe(this.closeButton);
}); });
}); });
describe('initDroplab', function () { describe('initDroplab', function () {
beforeEach(function () { beforeEach(function () {
this.commentTypeToggle = { this.commentTypeToggle = {
trigger: {}, dropdownTrigger: {},
list: {}, dropdownList: {},
input: {}, noteTypeInput: {},
button: {}, submitButton: {},
closeButton: {},
}; };
this.droplab = jasmine.createSpyObj('droplab', ['addHook']); this.droplab = jasmine.createSpyObj('droplab', ['init']);
spyOn(window, 'DropLab').and.returnValue(this.droplab); spyOn(dropLabSrc, 'default').and.returnValue(this.droplab);
this.initDroplab = CommentTypeToggle.prototype.initDroplab.call(this.commentTypeToggle); this.initDroplab = CommentTypeToggle.prototype.initDroplab.call(this.commentTypeToggle);
}); });
it('should instantiate a DropLab instance', function () { it('should instantiate a DropLab instance', function () {
expect(window.DropLab).toHaveBeenCalled(); expect(dropLabSrc.default).toHaveBeenCalled();
}); });
it('should set .droplab', function () { it('should set .droplab', function () {
expect(this.commentTypeToggle.droplab).toBe(this.droplab); expect(this.commentTypeToggle.droplab).toBe(this.droplab);
}); });
it('should call DropLab.prototype.addHook', function () { it('should call DropLab.prototype.init', function () {
expect(this.droplab.addHook).toHaveBeenCalledWith( expect(this.droplab.init).toHaveBeenCalledWith(
this.commentTypeToggle.trigger, this.commentTypeToggle.dropdownTrigger,
this.commentTypeToggle.list, this.commentTypeToggle.dropdownList,
[InputSetter], [InputSetter],
{ {
InputSetter: [{ InputSetter: [{
input: this.commentTypeToggle.input, input: this.commentTypeToggle.noteTypeInput,
valueAttribute: 'data-value', valueAttribute: 'data-value',
}, { }, {
input: this.commentTypeToggle.button, input: this.commentTypeToggle.submitButton,
valueAttribute: 'data-button-text', valueAttribute: 'data-button-text',
},
{
input: this.commentTypeToggle.closeButton,
valueAttribute: 'data-secondary-button-text',
}, {
input: this.commentTypeToggle.closeButton,
valueAttribute: 'data-secondary-button-text',
inputAttribute: 'data-alternative-text',
}], }],
}, },
); );
}); });
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',
}],
},
);
});
});
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment