1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
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(
this.dropdownTrigger,
this.dropdownList,
this.noteTypeInput,
this.submitButton,
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);
});
});
describe('initDroplab', function () {
beforeEach(function () {
this.commentTypeToggle = {
dropdownTrigger: {},
dropdownList: {},
noteTypeInput: {},
submitButton: {},
closeButton: {},
};
this.droplab = jasmine.createSpyObj('droplab', ['init']);
spyOn(dropLabSrc, 'default').and.returnValue(this.droplab);
this.initDroplab = 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 DropLab.prototype.init', 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',
},
{
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',
}],
},
);
});
});
});
});
|