summaryrefslogtreecommitdiff
path: root/spec/javascripts/comment_type_toggle_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/comment_type_toggle_spec.js')
-rw-r--r--spec/javascripts/comment_type_toggle_spec.js157
1 files changed, 157 insertions, 0 deletions
diff --git a/spec/javascripts/comment_type_toggle_spec.js b/spec/javascripts/comment_type_toggle_spec.js
new file mode 100644
index 00000000000..dfd0810d52e
--- /dev/null
+++ b/spec/javascripts/comment_type_toggle_spec.js
@@ -0,0 +1,157 @@
+import CommentTypeToggle from '~/comment_type_toggle';
+import * as dropLabSrc from '~/droplab/drop_lab';
+import InputSetter from '~/droplab/plugins/input_setter';
+
+describe('CommentTypeToggle', function () {
+ describe('class constructor', function () {
+ beforeEach(function () {
+ this.dropdownTrigger = {};
+ this.dropdownList = {};
+ this.noteTypeInput = {};
+ this.submitButton = {};
+ this.closeButton = {};
+
+ this.commentTypeToggle = new CommentTypeToggle({
+ dropdownTrigger: this.dropdownTrigger,
+ dropdownList: this.dropdownList,
+ noteTypeInput: this.noteTypeInput,
+ submitButton: this.submitButton,
+ closeButton: this.closeButton,
+ });
+ });
+
+ it('should set .dropdownTrigger', function () {
+ expect(this.commentTypeToggle.dropdownTrigger).toBe(this.dropdownTrigger);
+ });
+
+ it('should set .dropdownList', function () {
+ expect(this.commentTypeToggle.dropdownList).toBe(this.dropdownList);
+ });
+
+ it('should set .noteTypeInput', function () {
+ expect(this.commentTypeToggle.noteTypeInput).toBe(this.noteTypeInput);
+ });
+
+ it('should set .submitButton', function () {
+ expect(this.commentTypeToggle.submitButton).toBe(this.submitButton);
+ });
+
+ it('should set .closeButton', function () {
+ expect(this.commentTypeToggle.closeButton).toBe(this.closeButton);
+ });
+
+ it('should set .reopenButton', function () {
+ expect(this.commentTypeToggle.reopenButton).toBe(this.reopenButton);
+ });
+ });
+
+ describe('initDroplab', function () {
+ beforeEach(function () {
+ this.commentTypeToggle = {
+ dropdownTrigger: {},
+ dropdownList: {},
+ noteTypeInput: {},
+ submitButton: {},
+ closeButton: {},
+ setConfig: () => {},
+ };
+ this.config = {};
+
+ this.droplab = jasmine.createSpyObj('droplab', ['init']);
+
+ spyOn(dropLabSrc, 'default').and.returnValue(this.droplab);
+ spyOn(this.commentTypeToggle, 'setConfig').and.returnValue(this.config);
+
+ CommentTypeToggle.prototype.initDroplab.call(this.commentTypeToggle);
+ });
+
+ it('should instantiate a DropLab instance', function () {
+ expect(dropLabSrc.default).toHaveBeenCalled();
+ });
+
+ it('should set .droplab', function () {
+ expect(this.commentTypeToggle.droplab).toBe(this.droplab);
+ });
+
+ it('should call .setConfig', function () {
+ expect(this.commentTypeToggle.setConfig).toHaveBeenCalled();
+ });
+
+ it('should call DropLab.prototype.init', function () {
+ expect(this.droplab.init).toHaveBeenCalledWith(
+ this.commentTypeToggle.dropdownTrigger,
+ this.commentTypeToggle.dropdownList,
+ [InputSetter],
+ 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);
+ });
+
+ it('should not add .closeButton related InputSetter config', function () {
+ expect(this.setConfig).toEqual({
+ 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',
+ }],
+ });
+ });
+ });
+
+ describe('if no .reopenButton is provided', function () {
+ beforeEach(function () {
+ this.commentTypeToggle = {
+ dropdownTrigger: {},
+ dropdownList: {},
+ noteTypeInput: {},
+ submitButton: {},
+ closeButton: {},
+ };
+
+ this.setConfig = CommentTypeToggle.prototype.setConfig.call(this.commentTypeToggle);
+ });
+
+ it('should not add .reopenButton related InputSetter config', function () {
+ expect(this.setConfig).toEqual({
+ 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',
+ }],
+ });
+ });
+ });
+ });
+});