-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathv7.js
More file actions
198 lines (161 loc) · 7.64 KB
/
Copy pathv7.js
File metadata and controls
198 lines (161 loc) · 7.64 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere, getConfig, getCourse } from 'adapt-migrations';
import _ from 'lodash';
describe('Trickle - v7.1.3 to v7.2.0', async () => {
// https://github.com/adaptlearning/adapt-contrib-trickle/compare/v7.1.3..v7.2.0
let configuredBlocks, configuredArticles;
const disabledText = '';
const disabledAriaLabel = '';
whereFromPlugin('Trickle - from v7.1.3', { name: 'adapt-contrib-trickle', version: '<7.2.0' });
whereContent('Trickle is configured', content => {
configuredBlocks = content.filter(({ _type, _trickle }) => _trickle && _type === 'block');
configuredArticles = content.filter(({ _type, _trickle }) => _trickle && _type === 'article');
return configuredBlocks.length || configuredArticles.length;
});
mutateContent('Trickle - add article attribute disabledText', async (content) => {
configuredArticles.forEach(article => {
if (!_.has(article._trickle, '_button')) _.set(article._trickle, '_button', {});
article._trickle._button.disabledText = disabledText;
});
return true;
});
mutateContent('Trickle - add article attribute disabledAriaLabel', async (content) => {
configuredArticles.forEach(article => {
if (!_.has(article._trickle, '_button')) _.set(article._trickle, '_button', {});
article._trickle._button.disabledAriaLabel = disabledAriaLabel;
});
return true;
});
mutateContent('Trickle - add block attribute disabledText', async (content) => {
configuredBlocks.forEach(block => {
if (!_.has(block._trickle, '_button')) _.set(block._trickle, '_button', {});
block._trickle._button.disabledText = disabledText;
});
return true;
});
mutateContent('Trickle - add block attribute disabledAriaLabel', async (content) => {
configuredBlocks.forEach(block => {
if (!_.has(block._trickle, '_button')) _.set(block._trickle, '_button', {});
block._trickle._button.disabledAriaLabel = disabledAriaLabel;
});
return true;
});
checkContent('Trickle - check article attribute disabledText', async (content) => {
const isValid = configuredArticles.every(article => article._trickle._button.disabledText === disabledText);
if (!isValid) throw new Error('Trickle - article attribute disabledText');
return true;
});
checkContent('Trickle - check article attribute disabledAriaLabel', async (content) => {
const isValid = configuredArticles.every(article => article._trickle._button.disabledAriaLabel === disabledAriaLabel);
if (!isValid) throw new Error('Trickle - article attribute disabledAriaLabel');
return true;
});
checkContent('Trickle - check block attribute disabledText', async (content) => {
const isValid = configuredBlocks.every(block => block._trickle._button.disabledText === disabledText);
if (!isValid) throw new Error('Trickle - block attribute disabledText');
return true;
});
checkContent('Trickle - check block attribute disabledAriaLabel', async (content) => {
const isValid = configuredBlocks.every(block => block._trickle._button.disabledAriaLabel === disabledAriaLabel);
if (!isValid) throw new Error('Trickle - block attribute disabledAriaLabel');
return true;
});
updatePlugin('Trickle - update to v7.2.0', { name: 'adapt-contrib-trickle', version: '7.2.0', framework: '>=5.31.24' });
testSuccessWhere('trickle with both configured/non configured articles/blocks and empty/no article/block._trickle._button', {
fromPlugins: [{ name: 'adapt-contrib-trickle', version: '7.1.3' }],
content: [
{ _type: 'article', _trickle: { _button: {} } },
{ _type: 'article', _trickle: {} },
{ _type: 'article' },
{ _type: 'block', _trickle: { _button: {} } },
{ _type: 'block', _trickle: {} },
{ _type: 'block' },
{ _type: 'config', _trickle: {} }
]
});
testStopWhere('trickle with no configured article/blocks', {
fromPlugins: [{ name: 'adapt-contrib-trickle', version: '7.1.3' }],
content: [
{ _type: 'article' },
{ _type: 'block' }
]
});
testStopWhere('trickle incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-trickle', version: '7.2.0' }]
});
});
describe('Trickle - v7.5.0 to v7.5.1', async () => {
// https://github.com/adaptlearning/adapt-contrib-trickle/compare/v7.5.0..v7.5.1
let config;
whereFromPlugin('Trickle - from v7.5.0', { name: 'adapt-contrib-trickle', version: '<7.5.1' });
whereContent('Trickle is configured', content => {
config = getConfig();
return config._trickle;
});
mutateContent('Trickle - add config attribute _isEnabled', async (content) => {
if (!_.has(config._trickle, '_isEnabled')) config._trickle._isEnabled = true;
return true;
});
checkContent('Trickle - check config attribute _isEnabled', async (content) => {
const isValid = _.has(config._trickle, '_isEnabled');
if (!isValid) throw new Error('Trickle - config attribute _isEnabled');
return true;
});
updatePlugin('Trickle - update to v7.5.1', { name: 'adapt-contrib-trickle', version: '7.5.1', framework: '">=5.19.1' });
testSuccessWhere('trickle with empty course._trickle', {
fromPlugins: [{ name: 'adapt-contrib-trickle', version: '7.5.0' }],
content: [
{ _type: 'config', _trickle: {} }
]
});
testStopWhere('trickle with empty config', {
fromPlugins: [{ name: 'adapt-contrib-trickle', version: '7.5.0' }],
content: [
{ _type: 'article' },
{ _type: 'block' },
{ _type: 'config' }
]
});
testStopWhere('trickle incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-trickle', version: '7.5.1' }]
});
});
describe('Trickle - @@CURRENT_VERSION to @@RELEASE_VERSION', async () => {
// https://github.com/adaptlearning/adapt-contrib-trickle/compare/@@CURRENT_VERSION..@@RELEASE_VERSION
let course, courseTrickleGlobals;
const additionalContentLoaded = 'Loading.';
whereFromPlugin('Trickle - from @@CURRENT_VERSION', { name: 'adapt-contrib-trickle', version: '<@@RELEASE_VERSION' });
whereContent('Trickle - where course is present', async (content) => {
course = getCourse();
return course;
});
mutateContent('Trickle - add globals if missing', async (content) => {
if (!_.has(course, '_globals._extensions._trickle')) _.set(course, '_globals._extensions._trickle', {});
courseTrickleGlobals = course._globals._extensions._trickle;
return true;
});
mutateContent('Trickle - add global attribute additionalContentLoaded', async (content) => {
if (!_.has(courseTrickleGlobals, 'additionalContentLoaded')) courseTrickleGlobals.additionalContentLoaded = additionalContentLoaded;
return true;
});
checkContent('Trickle - check global attribute additionalContentLoaded', async (content) => {
const isValid = _.has(courseTrickleGlobals, 'additionalContentLoaded');
if (!isValid) throw new Error('Trickle - global attribute additionalContentLoaded');
return true;
});
updatePlugin('Trickle - update to @@RELEASE_VERSION', { name: 'adapt-contrib-trickle', version: '@@RELEASE_VERSION', framework: '>=5.46.4' });
testSuccessWhere('trickle with course, no globals', {
fromPlugins: [{ name: 'adapt-contrib-trickle', version: '@@CURRENT_VERSION' }],
content: [
{ _type: 'course' }
]
});
testSuccessWhere('trickle with course, with other globals', {
fromPlugins: [{ name: 'adapt-contrib-trickle', version: '@@CURRENT_VERSION' }],
content: [
{ _type: 'course', _globals: { _extensions: { _trickle: {} } } }
]
});
testStopWhere('trickle incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-trickle', version: '@@RELEASE_VERSION' }]
});
});