|
| 1 | +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere, getComponents, getCourse } from 'adapt-migrations'; |
| 2 | +import _ from 'lodash'; |
| 3 | + |
| 4 | +describe('GMCQ - v2.0.1 to v2.0.2', async () => { |
| 5 | + let GMCQs; |
| 6 | + whereFromPlugin('GMCQ - from v2.0.1', { name: 'adapt-contrib-gmcq', version: '>=2.0.0 <2.0.2' }); |
| 7 | + whereContent('GMCQ - where GMCQ', async (content) => { |
| 8 | + GMCQs = getComponents('gmcq'); |
| 9 | + return GMCQs.length; |
| 10 | + }); |
| 11 | + mutateContent('GMCQ - add _recordInteraction attribute', async (content) => { |
| 12 | + GMCQs.forEach(GMCQ => { |
| 13 | + GMCQ._recordInteraction = true; |
| 14 | + }); |
| 15 | + return true; |
| 16 | + }); |
| 17 | + checkContent('GMCQ - check _recordInteraction attribute', async (content) => { |
| 18 | + const isValid = GMCQs.every(GMCQ => |
| 19 | + _.has(GMCQ, '_recordInteraction') |
| 20 | + ); |
| 21 | + if (!isValid) throw new Error('GMCQ - _recordInteraction not found'); |
| 22 | + return true; |
| 23 | + }); |
| 24 | + updatePlugin('GMCQ - update to v2.0.2', { name: 'adapt-contrib-gmcq', version: '2.0.2', framework: '>=2.0.0' }); |
| 25 | + |
| 26 | + testSuccessWhere('correct version with gmcq components', { |
| 27 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.1' }], |
| 28 | + content: [ |
| 29 | + { _id: 'c-100', _component: 'gmcq' }, |
| 30 | + { _id: 'c-105', _component: 'gmcq' } |
| 31 | + ] |
| 32 | + }); |
| 33 | + |
| 34 | + testStopWhere('incorrect version', { |
| 35 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.2' }] |
| 36 | + }); |
| 37 | + |
| 38 | + testStopWhere('no gmcq components', { |
| 39 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.1' }], |
| 40 | + content: [{ _component: 'other' }] |
| 41 | + }); |
| 42 | +}); |
| 43 | + |
| 44 | +describe('GMCQ - v2.0.2 to v2.0.3', async () => { |
| 45 | + let GMCQs; |
| 46 | + whereFromPlugin('GMCQ - from v2.0.2', { name: 'adapt-contrib-gmcq', version: '<2.0.3' }); |
| 47 | + whereContent('GMCQ - where GMCQ', async (content) => { |
| 48 | + GMCQs = getComponents('gmcq'); |
| 49 | + return GMCQs.length; |
| 50 | + }); |
| 51 | + mutateContent('GMCQ - add _canShowModelAnswer attribute', async (content) => { |
| 52 | + GMCQs.forEach(GMCQ => { |
| 53 | + GMCQ._canShowModelAnswer = true; |
| 54 | + }); |
| 55 | + return true; |
| 56 | + }); |
| 57 | + mutateContent('GMCQ - add _columns attribute', async (content) => { |
| 58 | + GMCQs.forEach(GMCQ => { |
| 59 | + GMCQ._columns = 0; |
| 60 | + }); |
| 61 | + return true; |
| 62 | + }); |
| 63 | + checkContent('GMCQ - check _canShowModelAnswer attribute', async (content) => { |
| 64 | + const isValid = GMCQs.every(GMCQ => |
| 65 | + _.has(GMCQ, '_canShowModelAnswer') |
| 66 | + ); |
| 67 | + if (!isValid) throw new Error('GMCQ - _canShowModelAnswer not found'); |
| 68 | + return true; |
| 69 | + }); |
| 70 | + checkContent('GMCQ - check _columns attribute', async (content) => { |
| 71 | + const isValid = GMCQs.every(GMCQ => |
| 72 | + _.has(GMCQ, '_columns') |
| 73 | + ); |
| 74 | + if (!isValid) throw new Error('GMCQ - _columns not found'); |
| 75 | + return true; |
| 76 | + }); |
| 77 | + updatePlugin('GMCQ - update to v2.0.3', { name: 'adapt-contrib-gmcq', version: '2.0.3', framework: '>=2.0.0' }); |
| 78 | + |
| 79 | + testSuccessWhere('correct version with gmcq components', { |
| 80 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.2' }], |
| 81 | + content: [ |
| 82 | + { _id: 'c-100', _component: 'gmcq' }, |
| 83 | + { _id: 'c-105', _component: 'gmcq' } |
| 84 | + ] |
| 85 | + }); |
| 86 | + |
| 87 | + testStopWhere('incorrect version', { |
| 88 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.3' }] |
| 89 | + }); |
| 90 | + |
| 91 | + testStopWhere('no gmcq components', { |
| 92 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.2' }], |
| 93 | + content: [{ _component: 'other' }] |
| 94 | + }); |
| 95 | +}); |
| 96 | + |
| 97 | +describe('GMCQ - v2.0.4 to v2.0.5', async () => { |
| 98 | + let GMCQs; |
| 99 | + whereFromPlugin('GMCQ - from v2.0.4', { name: 'adapt-contrib-gmcq', version: '<2.0.5' }); |
| 100 | + whereContent('GMCQ - where GMCQ', async (content) => { |
| 101 | + GMCQs = getComponents('gmcq'); |
| 102 | + return GMCQs.length; |
| 103 | + }); |
| 104 | + mutateContent('GMCQ - add _canShowMarking attribute', async (content) => { |
| 105 | + GMCQs.forEach(GMCQ => { |
| 106 | + GMCQ._canShowMarking = true; |
| 107 | + }); |
| 108 | + return true; |
| 109 | + }); |
| 110 | + checkContent('GMCQ - check _canShowMarking attribute', async (content) => { |
| 111 | + const isValid = GMCQs.every(GMCQ => |
| 112 | + _.has(GMCQ, '_canShowMarking') |
| 113 | + ); |
| 114 | + if (!isValid) throw new Error('GMCQ - _canShowMarking not found'); |
| 115 | + return true; |
| 116 | + }); |
| 117 | + updatePlugin('GMCQ - update to v2.0.5', { name: 'adapt-contrib-gmcq', version: '2.0.5', framework: '>=2.0.11' }); |
| 118 | + |
| 119 | + testSuccessWhere('correct version with gmcq components', { |
| 120 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.4' }], |
| 121 | + content: [ |
| 122 | + { _id: 'c-100', _component: 'gmcq' }, |
| 123 | + { _id: 'c-105', _component: 'gmcq' } |
| 124 | + ] |
| 125 | + }); |
| 126 | + |
| 127 | + testStopWhere('incorrect version', { |
| 128 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.5' }] |
| 129 | + }); |
| 130 | + |
| 131 | + testStopWhere('no gmcq components', { |
| 132 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.4' }], |
| 133 | + content: [{ _component: 'other' }] |
| 134 | + }); |
| 135 | +}); |
| 136 | + |
| 137 | +describe('GMCQ - v2.0.5 to v2.1.0', async () => { |
| 138 | + let GMCQs; |
| 139 | + whereFromPlugin('GMCQ - from v2.0.5', { name: 'adapt-contrib-gmcq', version: '<2.1.0' }); |
| 140 | + whereContent('GMCQ - where GMCQ', async (content) => { |
| 141 | + GMCQs = getComponents('gmcq'); |
| 142 | + return GMCQs.length; |
| 143 | + }); |
| 144 | + mutateContent('GMCQ - add _graphic attribution attribute', async (content) => { |
| 145 | + GMCQs.forEach(GMCQ => { |
| 146 | + GMCQ._items.forEach(item => { |
| 147 | + item._graphic.attribution = ''; |
| 148 | + }); |
| 149 | + }); |
| 150 | + return true; |
| 151 | + }); |
| 152 | + checkContent('GMCQ - check _graphic attribution attribute', async (content) => { |
| 153 | + const isValid = GMCQs.every(GMCQ => |
| 154 | + GMCQ._items.every(item => |
| 155 | + _.has(item._graphic, 'attribution') |
| 156 | + ) |
| 157 | + ); |
| 158 | + if (!isValid) throw new Error('GMCQ - _graphic attribution not found'); |
| 159 | + return true; |
| 160 | + }); |
| 161 | + updatePlugin('GMCQ - update to v2.1.0', { name: 'adapt-contrib-gmcq', version: '2.1.0', framework: '>=2.0.11' }); |
| 162 | + |
| 163 | + testSuccessWhere('correct version with gmcq components', { |
| 164 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.5' }], |
| 165 | + content: [ |
| 166 | + { _id: 'c-100', _component: 'gmcq', _items: [{ _graphic: { } }] }, |
| 167 | + { _id: 'c-105', _component: 'gmcq', _items: [{ _graphic: { } }] } |
| 168 | + ] |
| 169 | + }); |
| 170 | + |
| 171 | + testStopWhere('incorrect version', { |
| 172 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.1.0' }] |
| 173 | + }); |
| 174 | + |
| 175 | + testStopWhere('no gmcq components', { |
| 176 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.0.5' }], |
| 177 | + content: [{ _component: 'other' }] |
| 178 | + }); |
| 179 | +}); |
| 180 | + |
| 181 | +describe('GMCQ - v2.1.0 to v2.1.1', async () => { |
| 182 | + let course, courseGMCQGlobals, GMCQs; |
| 183 | + const originalAriaRegion = 'This component is a graphical multiple choice question. Once you have selected an option select the submit button below.'; |
| 184 | + whereFromPlugin('GMCQ - from v2.1.0', { name: 'adapt-contrib-gmcq', version: '<2.1.1' }); |
| 185 | + whereContent('GMCQ - where GMCQ', async (content) => { |
| 186 | + GMCQs = getComponents('gmcq'); |
| 187 | + return GMCQs.length; |
| 188 | + }); |
| 189 | + mutateContent('GMCQ - add globals if missing', async (content) => { |
| 190 | + course = getCourse(); |
| 191 | + if (!_.has(course, '_globals._components._gmcq.ariaRegion')) _.set(course, '_globals._components._gmcq.ariaRegion', originalAriaRegion); |
| 192 | + courseGMCQGlobals = course._globals._components._gmcq; |
| 193 | + return true; |
| 194 | + }); |
| 195 | + mutateContent('GMCQ - modify global ariaRegion default', async (content) => { |
| 196 | + if (courseGMCQGlobals.ariaRegion === originalAriaRegion) courseGMCQGlobals.ariaRegion = 'This is a graphical multiple choice question. Once you have selected an option, select the submit button below.'; |
| 197 | + return true; |
| 198 | + }); |
| 199 | + checkContent('GMCQ - check globals exist', async (content) => { |
| 200 | + const isValid = _.has(course, '_globals._components._gmcq.ariaRegion'); |
| 201 | + if (!isValid) throw new Error('GMCQ - globals do not exist'); |
| 202 | + return true; |
| 203 | + }); |
| 204 | + checkContent('GMCQ - check global ariaRegion default', async (content) => { |
| 205 | + const isValid = courseGMCQGlobals.ariaRegion !== originalAriaRegion; |
| 206 | + if (!isValid) throw new Error('GMCQ - global ariaRegion default not updated'); |
| 207 | + return true; |
| 208 | + }); |
| 209 | + |
| 210 | + updatePlugin('GMCQ - update to v2.1.1', { name: 'adapt-contrib-gmcq', version: '2.1.1', framework: '>=2.0.11' }); |
| 211 | + |
| 212 | + testSuccessWhere('gmcq components with empty course', { |
| 213 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.1.0' }], |
| 214 | + content: [ |
| 215 | + { _id: 'c-100', _component: 'gmcq', _items: [{ _graphic: { } }] }, |
| 216 | + { _id: 'c-105', _component: 'gmcq', _items: [{ _graphic: { } }] }, |
| 217 | + { _type: 'course' } |
| 218 | + ] |
| 219 | + }); |
| 220 | + |
| 221 | + testSuccessWhere('gmcq components with original ariaRegion', { |
| 222 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.1.0' }], |
| 223 | + content: [ |
| 224 | + { _id: 'c-100', _component: 'gmcq', _items: [{ _graphic: { } }] }, |
| 225 | + { _id: 'c-105', _component: 'gmcq', _items: [{ _graphic: { } }] }, |
| 226 | + { _type: 'course', _globals: { _components: { _gmcq: { ariaRegion: originalAriaRegion } } } } |
| 227 | + ] |
| 228 | + }); |
| 229 | + |
| 230 | + testSuccessWhere('gmcq components with custom ariaRegion', { |
| 231 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.1.0' }], |
| 232 | + content: [ |
| 233 | + { _id: 'c-100', _component: 'gmcq', _items: [{ _graphic: { } }] }, |
| 234 | + { _id: 'c-105', _component: 'gmcq', _items: [{ _graphic: { } }] }, |
| 235 | + { _type: 'course', _globals: { _components: { _gmcq: { ariaRegion: 'This component is a graphical multiple choice question. Once you have selected an option select the submit button below.' } } } } |
| 236 | + ] |
| 237 | + }); |
| 238 | + |
| 239 | + testStopWhere('incorrect version', { |
| 240 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.1.1' }] |
| 241 | + }); |
| 242 | + |
| 243 | + testStopWhere('no gmcq components', { |
| 244 | + fromPlugins: [{ name: 'adapt-contrib-gmcq', version: '2.1.0' }], |
| 245 | + content: [{ _component: 'other' }] |
| 246 | + }); |
| 247 | +}); |
0 commit comments