1
|
|
|
import chai from 'chai' |
2
|
|
|
import path from 'path' |
3
|
|
|
import sinonChai from'sinon-chai' |
4
|
|
|
chai.use(sinonChai) |
5
|
|
|
import sinon from 'sinon' |
6
|
|
|
|
7
|
|
|
import { |
8
|
|
|
cmsEditor, |
9
|
|
|
abeExtend, |
10
|
|
|
config |
11
|
|
|
} from '../../../../src/cli' |
12
|
|
|
config.set({root: path.join(process.cwd(), 'test', 'fixtures')}) |
13
|
|
|
|
14
|
|
|
import data from '../../../fixtures/editor/index' |
15
|
|
|
|
16
|
|
|
var classAttr = 'form-control form-abe' |
17
|
|
|
|
18
|
|
|
describe('printInput', function() { |
19
|
|
|
|
20
|
|
|
// getAttributes, |
21
|
|
|
// getLabel, |
22
|
|
|
// createInputSource, |
23
|
|
|
// createInputRich, |
24
|
|
|
// createInputFile, |
25
|
|
|
// createInputTextarea, |
26
|
|
|
// createInputLink, |
27
|
|
|
// createInputImage, |
28
|
|
|
// createInputText |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* cmsEditor.getLabel |
32
|
|
|
* |
33
|
|
|
*/ |
34
|
|
|
it('cmsEditor.getLabel()', function() { |
35
|
|
|
var result = cmsEditor.getLabel(data.label) |
36
|
|
|
chai.expect(result).to.be.a('string') |
37
|
|
|
var label = /<label(\r|\t|\n|.)*?<\/label>/.test(result) |
38
|
|
|
chai.expect(label).to.be.true |
|
|
|
|
39
|
|
|
}) |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* cmsEditor.getAttributes |
43
|
|
|
* |
44
|
|
|
*/ |
45
|
|
|
it('cmsEditor.getAttributes()', function() { |
46
|
|
|
var result = cmsEditor.getAttributes(data.attributes) |
47
|
|
|
chai.expect(result).to.be.a('string') |
48
|
|
|
chai.expect(result).to.be.equal('id="key" data-id="key" value="value" maxlength="max-length" data-maxlength="max-length" reload="reload" tabIndex="order" data-required="required" data-display="display" data-visible="visible" data-autocomplete="autocomplete" placeholder="placeholder" data-size="thumbs" multiple disabled') |
49
|
|
|
}) |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* cmsEditor.createInputSource |
53
|
|
|
* |
54
|
|
|
*/ |
55
|
|
|
it('cmsEditor.createInputSource()', function() { |
56
|
|
|
var result0 = cmsEditor.createInputSource(data.source[0].attributes, classAttr, data.source[0].params) |
57
|
|
|
var select = /<select(\r|\t|\n|.)*?<\/select>/.test(result0) |
58
|
|
|
chai.expect(result0).to.be.a('string') |
59
|
|
|
chai.expect(select).to.be.true |
|
|
|
|
60
|
|
|
|
61
|
|
|
var result1 = cmsEditor.createInputSource(data.source[1].attributes, classAttr, data.source[1].params) |
62
|
|
|
var test1 = result1.indexOf('multiple') |
63
|
|
|
chai.expect(test1).to.be.above(-1) |
64
|
|
|
|
65
|
|
|
var result2 = cmsEditor.createInputSource(data.source[2].attributes, classAttr, data.source[2].params) |
66
|
|
|
var test2 = result2.indexOf('data-autocomplete') |
67
|
|
|
chai.expect(test2).to.be.above(-1) |
68
|
|
|
|
69
|
|
|
var result3 = cmsEditor.createInputSource(data.source[3].attributes, classAttr, data.source[3].params) |
70
|
|
|
var test3 = result3.indexOf('{"id":1,"name":"test 1","lang":"de"}') |
71
|
|
|
chai.expect(test3).to.be.above(-1) |
72
|
|
|
}) |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* cmsEditor.createInputRich |
76
|
|
|
* |
77
|
|
|
*/ |
78
|
|
|
it('cmsEditor.createInputRich()', function() { |
79
|
|
|
var result = cmsEditor.createInputRich(data.rich.attributes, classAttr, data.rich.params) |
80
|
|
|
chai.expect(result).to.be.a('string') |
81
|
|
|
}) |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* cmsEditor.createInputFile |
85
|
|
|
* |
86
|
|
|
*/ |
87
|
|
|
it('cmsEditor.createInputFile()', function() { |
88
|
|
|
var result = cmsEditor.createInputFile(data.file.attributes, classAttr, data.file.params) |
89
|
|
|
var input = /<input(\r|\t|\n|.)*?type=\"file\"(\r|\t|\n|.)*?>/.test(result) |
90
|
|
|
chai.expect(result).to.be.a('string') |
91
|
|
|
chai.expect(input).to.be.true |
|
|
|
|
92
|
|
|
}) |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* cmsEditor.createInputTextarea |
96
|
|
|
* |
97
|
|
|
*/ |
98
|
|
|
it('cmsEditor.createInputTextarea()', function() { |
99
|
|
|
var result = cmsEditor.createInputTextarea(data.textarea.attributes, classAttr, data.textarea.params) |
100
|
|
|
var textarea = /<textarea(\r|\t|\n|.)*?<\/textarea>/.test(result) |
101
|
|
|
chai.expect(result).to.be.a('string') |
102
|
|
|
chai.expect(textarea).to.be.true |
|
|
|
|
103
|
|
|
}) |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* cmsEditor.createInputLink |
107
|
|
|
* |
108
|
|
|
*/ |
109
|
|
|
it('cmsEditor.createInputLink()', function() { |
110
|
|
|
var result = cmsEditor.createInputLink(data.link.attributes, classAttr, data.link.params) |
111
|
|
|
var link = result.indexOf('glyphicon glyphicon-link') |
112
|
|
|
chai.expect(result).to.be.a('string') |
113
|
|
|
chai.expect(link).to.be.above(-1) |
114
|
|
|
}) |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* cmsEditor.createInputImage |
118
|
|
|
* |
119
|
|
|
*/ |
120
|
|
|
it('cmsEditor.createInputImage()', function() { |
121
|
|
|
var result = cmsEditor.createInputImage(data.image.attributes, classAttr, data.image.params) |
122
|
|
|
var image = result.indexOf('glyphicon glyphicon-picture') |
123
|
|
|
chai.expect(result).to.be.a('string') |
124
|
|
|
chai.expect(image).to.be.above(-1) |
125
|
|
|
}) |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* cmsEditor.createInputText |
129
|
|
|
* |
130
|
|
|
*/ |
131
|
|
|
it('cmsEditor.createInputText()', function() { |
132
|
|
|
var result = cmsEditor.createInputText(data.txt.attributes, classAttr, data.txt.params) |
133
|
|
|
var txt = result.indexOf('glyphicon glyphicon-font') |
134
|
|
|
chai.expect(result).to.be.a('string') |
135
|
|
|
chai.expect(txt).to.be.above(-1) |
136
|
|
|
}) |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* cmsEditor.printInput |
140
|
|
|
* |
141
|
|
|
*/ |
142
|
|
|
it('cmsEditor.printInput()', function() { |
143
|
|
|
var val = data.text; |
144
|
|
|
this.sinon = sinon.sandbox.create(); |
145
|
|
|
this.sinon.stub(abeExtend.hooks.instance, 'trigger', function(param, html){ |
146
|
|
|
return (param === 'beforeEditorInput') ? val : html; |
147
|
|
|
}) |
148
|
|
|
var result = cmsEditor.printInput(val, {}) |
149
|
|
|
chai.expect(result).to.be.a('string') |
150
|
|
|
var value = result.match(/value="[a-zA-Z0-9-]*"/ig)[0] |
151
|
|
|
chai.expect(value).to.equal('value="val2"') |
152
|
|
|
var reload = result.match(/reload="[a-zA-Z0-9-]*"/ig)[0] |
153
|
|
|
chai.expect(reload).to.equal('reload="val3"') |
154
|
|
|
var tabIndex = result.match(/tabIndex="[a-zA-Z0-9-]*"/ig)[0] |
155
|
|
|
chai.expect(tabIndex).to.equal('tabIndex="val4"') |
156
|
|
|
var dataRequired = result.match(/data-required="[a-zA-Z0-9-]*"/ig)[0] |
157
|
|
|
chai.expect(dataRequired).to.equal('data-required="val5"') |
158
|
|
|
var dataDisplay = result.match(/data-display="[a-zA-Z0-9-]*"/ig)[0] |
159
|
|
|
chai.expect(dataDisplay).to.equal('data-display="val6"') |
160
|
|
|
var dataVisible = result.match(/data-visible="[a-zA-Z0-9-]*"/ig)[0] |
161
|
|
|
chai.expect(dataVisible).to.equal('data-visible="val7"') |
162
|
|
|
var dataAutocomplete = result.match(/data-autocomplete="[a-zA-Z0-9-]*"/ig)[0] |
163
|
|
|
chai.expect(dataAutocomplete).to.equal('data-autocomplete="val8"') |
164
|
|
|
var placeholder = result.match(/placeholder="[a-zA-Z0-9-]*"/ig)[0] |
165
|
|
|
chai.expect(placeholder).to.equal('placeholder="val9"') |
166
|
|
|
|
167
|
|
|
this.sinon.restore() |
168
|
|
|
}); |
169
|
|
|
}); |
170
|
|
|
|