forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_module.js
More file actions
103 lines (82 loc) · 2.81 KB
/
text_module.js
File metadata and controls
103 lines (82 loc) · 2.81 KB
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
// text module
QUnit.test('test text module behaviour with group_ids', assert => {
// active textmodule without group_ids
App.TextModule.refresh([
{
id: 1,
name: 'main',
keywords: 'keywordsmain',
content: 'contentmain',
active: true,
},
{
id: 2,
name: 'test2',
keywords: 'keywords2',
content: 'content2',
active: false,
},
{
id: 3,
name: 'test3',
keywords: 'keywords3',
content: 'content3',
active: true,
group_ids: [1,2],
},
{
id: 4,
name: 'test4',
keywords: 'keywords4',
content: 'content4',
active: false,
group_ids: [1,2],
},
])
var textModule = new App.WidgetTextModule({
el: $('.js-textarea').parent(),
data:{
user: App.Session.get(),
config: App.Config.all(),
},
taskKey: 'test1',
})
var currentCollection = textModule.currentCollection();
assert.equal(currentCollection.length, 2, 'active textmodule')
assert.equal(currentCollection[0].id, 1)
assert.equal(currentCollection[1].id, 3)
// trigered TextModulePreconditionUpdate with group_id
var params = {
group_id: 1
}
App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test1', params: params })
currentCollection = textModule.currentCollection();
assert.equal(currentCollection.length, 2, 'trigered TextModulePreconditionUpdate with group_id')
assert.equal(currentCollection[0].id, 1)
assert.equal(currentCollection[1].id, 3)
// trigered TextModulePreconditionUpdate with wrong group_id
params = {
group_id: 3
}
App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test1', params: params })
currentCollection = textModule.currentCollection();
assert.equal(currentCollection.length, 1, 'trigered TextModulePreconditionUpdate with wrong group_id')
assert.equal(currentCollection[0].id, 1)
// trigered TextModulePreconditionUpdate with group_id but wrong taskKey
params = {
group_id: 3
}
App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test2', params: params })
currentCollection = textModule.currentCollection();
assert.equal(currentCollection.length, 1, 'trigered TextModulePreconditionUpdate with group_id but wrong taskKey - nothing has changed')
assert.equal(currentCollection[0].id, 1)
// trigered TextModulePreconditionUpdate without group_id
params = {
owner_id: 2
}
App.Event.trigger('TextModulePreconditionUpdate', { taskKey: 'test1', params: params })
currentCollection = textModule.currentCollection();
assert.equal(currentCollection.length, 2, 'trigered TextModulePreconditionUpdate without group_id')
assert.equal(currentCollection[0].id, 1)
assert.equal(currentCollection[1].id, 3)
});