|
| 1 | +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, getComponents, testStopWhere, testSuccessWhere } from 'adapt-migrations'; |
| 2 | +import _ from 'lodash'; |
| 3 | + |
| 4 | +describe('Media - v2.0.1 to v2.0.2', async () => { |
| 5 | + let mediaComponents; |
| 6 | + |
| 7 | + whereFromPlugin('Media - from v2.0.1', { name: 'adapt-contrib-media', version: '>= 2.0.0 <2.0.2' }); |
| 8 | + |
| 9 | + whereContent('Media - where media', async (content) => { |
| 10 | + mediaComponents = getComponents('media'); |
| 11 | + return mediaComponents.length; |
| 12 | + }); |
| 13 | + |
| 14 | + mutateContent('Media - add _startLanguage attribute to media component', async (content) => { |
| 15 | + mediaComponents.forEach(mediaComponent => { |
| 16 | + mediaComponent._startLanguage = 'en'; |
| 17 | + }); |
| 18 | + return true; |
| 19 | + }); |
| 20 | + |
| 21 | + checkContent('Media - check _startLanguage attribute', async (content) => { |
| 22 | + const isValid = mediaComponents.every(({ _startLanguage }) => _startLanguage !== undefined); |
| 23 | + if (!isValid) throw new Error('Media - _startLanguage attribute missing'); |
| 24 | + return true; |
| 25 | + }); |
| 26 | + |
| 27 | + updatePlugin('Media - update to v2.0.2', { name: 'adapt-contrib-media', version: '2.0.2', framework: '>=2.0.0' }); |
| 28 | + |
| 29 | + testSuccessWhere('correct version with media components', { |
| 30 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.1' }], |
| 31 | + content: [ |
| 32 | + { _id: 'c-100', _component: 'media' }, |
| 33 | + { _id: 'c-105', _component: 'media' } |
| 34 | + ] |
| 35 | + }); |
| 36 | + |
| 37 | + testStopWhere('incorrect version', { |
| 38 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.2' }] |
| 39 | + }); |
| 40 | + |
| 41 | + testStopWhere('no media components', { |
| 42 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.1' }], |
| 43 | + content: [{ _component: 'other' }] |
| 44 | + }); |
| 45 | +}); |
| 46 | + |
| 47 | +describe('Media - v2.0.2 to v2.0.3', async () => { |
| 48 | + let mediaComponents; |
| 49 | + |
| 50 | + whereFromPlugin('Media - from v2.0.2', { name: 'adapt-contrib-media', version: '<2.0.3' }); |
| 51 | + |
| 52 | + whereContent('Media - where media', async (content) => { |
| 53 | + mediaComponents = getComponents('media').filter(({ _transcript }) => _transcript); |
| 54 | + return mediaComponents.length; |
| 55 | + }); |
| 56 | + |
| 57 | + mutateContent('Media - add _setCompletionOnView attribute to media component transcript', async (content) => { |
| 58 | + mediaComponents.forEach(mediaComponent => { |
| 59 | + _.set(mediaComponent, '_transcript._setCompletionOnView', false); |
| 60 | + }); |
| 61 | + return true; |
| 62 | + }); |
| 63 | + |
| 64 | + checkContent('Media - check _setCompletionOnView attribute', async (content) => { |
| 65 | + const isValid = mediaComponents.every(({ _transcript }) => _transcript._setCompletionOnView !== undefined); |
| 66 | + if (!isValid) throw new Error('Media - _setCompletionOnView attribute missing'); |
| 67 | + return true; |
| 68 | + }); |
| 69 | + |
| 70 | + updatePlugin('Media - update to v2.0.3', { name: 'adapt-contrib-media', version: '2.0.3', framework: '>=2.0.0' }); |
| 71 | + |
| 72 | + testSuccessWhere('media components with/without _transcript', { |
| 73 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.2' }], |
| 74 | + content: [ |
| 75 | + { _id: 'c-100', _component: 'media', _transcript: {} }, |
| 76 | + { _id: 'c-105', _component: 'media' } |
| 77 | + ] |
| 78 | + }); |
| 79 | + |
| 80 | + testStopWhere('incorrect version', { |
| 81 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.3' }] |
| 82 | + }); |
| 83 | + |
| 84 | + testStopWhere('no media components', { |
| 85 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.2' }], |
| 86 | + content: [{ _component: 'other' }] |
| 87 | + }); |
| 88 | +}); |
| 89 | + |
| 90 | +describe('Media - v2.0.3 to v2.0.4', async () => { |
| 91 | + let mediaComponents; |
| 92 | + whereFromPlugin('Media - from v2.0.3', { name: 'adapt-contrib-media', version: '<2.0.4' }); |
| 93 | + |
| 94 | + whereContent('Media - where media', async (content) => { |
| 95 | + mediaComponents = getComponents('media'); |
| 96 | + return mediaComponents.length; |
| 97 | + }); |
| 98 | + |
| 99 | + mutateContent('Media - add _allowFullScreen attribute to media component', async (content) => { |
| 100 | + mediaComponents.forEach(mediaComponent => { |
| 101 | + mediaComponent._allowFullScreen = false; |
| 102 | + }); |
| 103 | + return true; |
| 104 | + }); |
| 105 | + |
| 106 | + checkContent('Media - check _allowFullScreen attribute', async (content) => { |
| 107 | + const isValid = mediaComponents.every(({ _allowFullScreen }) => _allowFullScreen !== undefined); |
| 108 | + if (!isValid) throw new Error('Media - _allowFullScreen attribute missing'); |
| 109 | + return true; |
| 110 | + }); |
| 111 | + |
| 112 | + updatePlugin('Media - update to v2.0.4', { name: 'adapt-contrib-media', version: '2.0.4', framework: '>=2.0.0' }); |
| 113 | + |
| 114 | + testSuccessWhere('correct version with media components', { |
| 115 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.3' }], |
| 116 | + content: [ |
| 117 | + { _id: 'c-100', _component: 'media' }, |
| 118 | + { _id: 'c-105', _component: 'media' } |
| 119 | + ] |
| 120 | + }); |
| 121 | + |
| 122 | + testStopWhere('incorrect version', { |
| 123 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.4' }] |
| 124 | + }); |
| 125 | + |
| 126 | + testStopWhere('no media components', { |
| 127 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.3' }], |
| 128 | + content: [{ _component: 'other' }] |
| 129 | + }); |
| 130 | +}); |
| 131 | + |
| 132 | +describe('Media - v2.0.4 to v2.0.5', async () => { |
| 133 | + let mediaComponents; |
| 134 | + |
| 135 | + whereFromPlugin('Media - from v2.0.4', { name: 'adapt-contrib-media', version: '<2.0.5' }); |
| 136 | + |
| 137 | + whereContent('Media - where media', async (content) => { |
| 138 | + mediaComponents = getComponents('media'); |
| 139 | + return mediaComponents.length; |
| 140 | + }); |
| 141 | + |
| 142 | + mutateContent('Media - add webm attribute to media component', async (content) => { |
| 143 | + mediaComponents.forEach(mediaComponent => { |
| 144 | + _.set(mediaComponent, '_media.webm', ''); |
| 145 | + }); |
| 146 | + return true; |
| 147 | + }); |
| 148 | + |
| 149 | + checkContent('Media - check webm attribute', async (content) => { |
| 150 | + const isInvalid = mediaComponents.some(({ _media }) => _media.webm === undefined); |
| 151 | + if (isInvalid) throw new Error('Media - webm attribute missing'); |
| 152 | + return true; |
| 153 | + }); |
| 154 | + |
| 155 | + updatePlugin('Media - update to v2.0.5', { name: 'adapt-contrib-media', version: '2.0.5', framework: '>=2.0.0' }); |
| 156 | + |
| 157 | + testSuccessWhere('media components with/without _media', { |
| 158 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.4' }], |
| 159 | + content: [ |
| 160 | + { _id: 'c-100', _component: 'media', _media: {} }, |
| 161 | + { _id: 'c-105', _component: 'media' } |
| 162 | + ] |
| 163 | + }); |
| 164 | + |
| 165 | + testStopWhere('incorrect version', { |
| 166 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.5' }] |
| 167 | + }); |
| 168 | + |
| 169 | + testStopWhere('no media components', { |
| 170 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.4' }], |
| 171 | + content: [{ _component: 'other' }] |
| 172 | + }); |
| 173 | +}); |
| 174 | + |
| 175 | +describe('Media - v2.0.5 to v2.0.6', async () => { |
| 176 | + let mediaComponents; |
| 177 | + |
| 178 | + whereFromPlugin('Media - from v2.0.5', { name: 'adapt-contrib-media', version: '<2.0.6' }); |
| 179 | + |
| 180 | + whereContent('Media - where media', async (content) => { |
| 181 | + mediaComponents = getComponents('media'); |
| 182 | + return mediaComponents.length; |
| 183 | + }); |
| 184 | + |
| 185 | + mutateContent('Media - add _playsinline attribute to media component', async (content) => { |
| 186 | + mediaComponents.forEach(mediaComponent => { |
| 187 | + mediaComponent._playsinline = false; |
| 188 | + }); |
| 189 | + return true; |
| 190 | + }); |
| 191 | + |
| 192 | + checkContent('Media - check _playsinline attribute', async (content) => { |
| 193 | + const isValid = mediaComponents.every(({ _playsinline }) => _playsinline !== undefined); |
| 194 | + if (!isValid) throw new Error('Media - _playsinline attribute missing'); |
| 195 | + return true; |
| 196 | + }); |
| 197 | + |
| 198 | + updatePlugin('Media - update to v2.0.6', { name: 'adapt-contrib-media', version: '2.0.6', framework: '>=2.0.13' }); |
| 199 | + |
| 200 | + testSuccessWhere('correct version with media components', { |
| 201 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.5' }], |
| 202 | + content: [ |
| 203 | + { _id: 'c-100', _component: 'media' }, |
| 204 | + { _id: 'c-105', _component: 'media' } |
| 205 | + ] |
| 206 | + }); |
| 207 | + |
| 208 | + testStopWhere('incorrect version', { |
| 209 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.6' }] |
| 210 | + }); |
| 211 | + |
| 212 | + testStopWhere('no media components', { |
| 213 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.5' }], |
| 214 | + content: [{ _component: 'other' }] |
| 215 | + }); |
| 216 | +}); |
| 217 | + |
| 218 | +describe('Media - v2.0.6 to v2.1.0', async () => { |
| 219 | + let mediaComponents; |
| 220 | + |
| 221 | + whereFromPlugin('Media - from v2.0.6', { name: 'adapt-contrib-media', version: '<2.1.0' }); |
| 222 | + |
| 223 | + whereContent('Media - where media', async (content) => { |
| 224 | + mediaComponents = getComponents('media'); |
| 225 | + return mediaComponents.length; |
| 226 | + }); |
| 227 | + |
| 228 | + mutateContent('Media - add _showVolumeControl attribute to media component', async (content) => { |
| 229 | + mediaComponents.forEach(mediaComponent => { |
| 230 | + mediaComponent._showVolumeControl = false; |
| 231 | + }); |
| 232 | + return true; |
| 233 | + }); |
| 234 | + |
| 235 | + mutateContent('Media - add _startVolume attribute to media component', async (content) => { |
| 236 | + mediaComponents.forEach(mediaComponent => { |
| 237 | + mediaComponent._startVolume = '80%'; |
| 238 | + }); |
| 239 | + return true; |
| 240 | + }); |
| 241 | + |
| 242 | + mutateContent('Media - add _preventForwardScrubbing attribute to media component', async (content) => { |
| 243 | + mediaComponents.forEach(mediaComponent => { |
| 244 | + mediaComponent._preventForwardScrubbing = false; |
| 245 | + }); |
| 246 | + return true; |
| 247 | + }); |
| 248 | + |
| 249 | + checkContent('Media - check _showVolumeControl attribute', async (content) => { |
| 250 | + const isValid = mediaComponents.every(({ _showVolumeControl }) => _showVolumeControl !== undefined); |
| 251 | + if (!isValid) throw new Error('Media - _showVolumeControl attribute missing'); |
| 252 | + return true; |
| 253 | + }); |
| 254 | + |
| 255 | + checkContent('Media - check _startVolume attribute', async (content) => { |
| 256 | + const isValid = mediaComponents.every(({ _startVolume }) => _startVolume !== undefined); |
| 257 | + if (!isValid) throw new Error('Media - _startVolume attribute missing'); |
| 258 | + return true; |
| 259 | + }); |
| 260 | + |
| 261 | + checkContent('Media - check _preventForwardScrubbing attribute', async (content) => { |
| 262 | + const isValid = mediaComponents.every(({ _preventForwardScrubbing }) => _preventForwardScrubbing !== undefined); |
| 263 | + if (!isValid) throw new Error('Media - _preventForwardScrubbing attribute missing'); |
| 264 | + return true; |
| 265 | + }); |
| 266 | + |
| 267 | + updatePlugin('Media - update to v2.1.0', { name: 'adapt-contrib-media', version: '2.1.0', framework: '>=2.0.13' }); |
| 268 | + |
| 269 | + testSuccessWhere('correct version with media components', { |
| 270 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.6' }], |
| 271 | + content: [ |
| 272 | + { _id: 'c-100', _component: 'media' }, |
| 273 | + { _id: 'c-105', _component: 'media' } |
| 274 | + ] |
| 275 | + }); |
| 276 | + |
| 277 | + testStopWhere('incorrect version', { |
| 278 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.1.0' }] |
| 279 | + }); |
| 280 | + |
| 281 | + testStopWhere('no media components', { |
| 282 | + fromPlugins: [{ name: 'adapt-contrib-media', version: '2.0.6' }], |
| 283 | + content: [{ _component: 'other' }] |
| 284 | + }); |
| 285 | +}); |
0 commit comments