|
| 1 | +import { describe, getCourse, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere } from 'adapt-migrations'; |
| 2 | +import _ from 'lodash'; |
| 3 | + |
| 4 | +describe('Page level progress - v2.0.1 to v2.0.2', async () => { |
| 5 | + // https://github.com/adaptlearning/adapt-contrib-pageLevelProgress/compare/v2.0.1..v2.0.2 |
| 6 | + |
| 7 | + let course, coursePlpGlobals; |
| 8 | + const plpOptionalContentNew = 'Optional Content'; |
| 9 | + const plpIndicatorBarDefaultOld = 'You have completed '; |
| 10 | + const plpIndicatorBarDefaultNew = 'Progress bar. Select here to view your current progress, and select an item to navigate to it. You have completed '; |
| 11 | + |
| 12 | + whereFromPlugin('Page level progress - from v2.0.1', { name: 'adapt-contrib-pageLevelProgress', version: '>=2.0.0 <2.0.2' }); |
| 13 | + |
| 14 | + whereContent('Page level progress is configured', content => { |
| 15 | + course = getCourse(); |
| 16 | + return course._pageLevelProgress; |
| 17 | + }); |
| 18 | + |
| 19 | + mutateContent('Page level progress - add globals if missing', async (content) => { |
| 20 | + if (!_.has(course, '_globals._extensions._pageLevelProgress')) { |
| 21 | + _.set(course, '_globals._extensions._pageLevelProgress', {}); |
| 22 | + } |
| 23 | + coursePlpGlobals = course._globals._extensions._pageLevelProgress; |
| 24 | + if (!_.has(coursePlpGlobals, 'pageLevelProgressIndicatorBar')) { |
| 25 | + _.set(coursePlpGlobals, 'pageLevelProgressIndicatorBar', plpIndicatorBarDefaultNew); |
| 26 | + } |
| 27 | + return true; |
| 28 | + }); |
| 29 | + |
| 30 | + mutateContent('Page level progress - global attribute pageLevelProgressMenuBar', async (content) => { |
| 31 | + coursePlpGlobals.pageLevelProgressMenuBar = plpIndicatorBarDefaultOld; |
| 32 | + return true; |
| 33 | + }); |
| 34 | + |
| 35 | + mutateContent('Page level progress - global attribute optionalContent', async (content) => { |
| 36 | + coursePlpGlobals.optionalContent = plpOptionalContentNew; |
| 37 | + return true; |
| 38 | + }); |
| 39 | + |
| 40 | + mutateContent('Page level progress - update attribute default', async (content) => { |
| 41 | + if (coursePlpGlobals.pageLevelProgressIndicatorBar !== plpIndicatorBarDefaultOld) return true; |
| 42 | + coursePlpGlobals.pageLevelProgressIndicatorBar = plpIndicatorBarDefaultNew; |
| 43 | + return true; |
| 44 | + }); |
| 45 | + |
| 46 | + checkContent('Page level progress - check global attribute pageLevelProgressMenuBar', async (content) => { |
| 47 | + const isValid = coursePlpGlobals.pageLevelProgressMenuBar === plpIndicatorBarDefaultOld; |
| 48 | + if (!isValid) throw new Error('Page level progress - global attribute pageLevelProgressMenuBar'); |
| 49 | + return true; |
| 50 | + }); |
| 51 | + |
| 52 | + checkContent('Page level progress - check global attribute optionalContent', async (content) => { |
| 53 | + const isValid = coursePlpGlobals.optionalContent === plpOptionalContentNew; |
| 54 | + if (!isValid) throw new Error('Page level progress - global attribute optionalContent'); |
| 55 | + return true; |
| 56 | + }); |
| 57 | + |
| 58 | + checkContent('Page level progress - check global attribute pageLevelProgressIndicatorBar', async (content) => { |
| 59 | + const isValid = coursePlpGlobals.pageLevelProgressIndicatorBar !== plpIndicatorBarDefaultOld; |
| 60 | + if (!isValid) throw new Error('Page level progress - global attribute pageLevelProgressIndicatorBar'); |
| 61 | + return true; |
| 62 | + }); |
| 63 | + |
| 64 | + updatePlugin('Page level progress - update to v2.0.2', { name: 'adapt-contrib-pageLevelProgress', version: '2.0.2', framework: '=>2.0.0' }); |
| 65 | + |
| 66 | + testSuccessWhere('pageLevelProgress with no course globals', { |
| 67 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.1' }], |
| 68 | + content: [ |
| 69 | + { _type: 'course', _pageLevelProgress: {} } |
| 70 | + ] |
| 71 | + }); |
| 72 | + |
| 73 | + testSuccessWhere('pageLevelProgress with empty course globals', { |
| 74 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.1' }], |
| 75 | + content: [ |
| 76 | + { _type: 'course', _pageLevelProgress: {}, _globals: { _extensions: { _pageLevelProgress: {} } } } |
| 77 | + ] |
| 78 | + }); |
| 79 | + |
| 80 | + testSuccessWhere('pageLevelProgress with default course globals', { |
| 81 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.1' }], |
| 82 | + content: [ |
| 83 | + { _type: 'course', _pageLevelProgress: {}, _globals: { _extensions: { _pageLevelProgress: { pageLevelProgressIndicatorBar: plpIndicatorBarDefaultOld } } } } |
| 84 | + ] |
| 85 | + }); |
| 86 | + |
| 87 | + testSuccessWhere('pageLevelProgress with custom course globals', { |
| 88 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.1' }], |
| 89 | + content: [ |
| 90 | + { _type: 'course', _pageLevelProgress: {}, _globals: { _extensions: { _pageLevelProgress: { pageLevelProgressIndicatorBar: 'custom progress indicator' } } } } |
| 91 | + ] |
| 92 | + }); |
| 93 | + |
| 94 | + testStopWhere('no pageLevelProgress', { |
| 95 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.1' }], |
| 96 | + content: [ |
| 97 | + { _type: 'course' } |
| 98 | + ] |
| 99 | + }); |
| 100 | + |
| 101 | + testStopWhere('incorrect version', { |
| 102 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.2' }] |
| 103 | + }); |
| 104 | +}); |
| 105 | + |
| 106 | +describe('Page level progress - v2.0.3 to v2.0.4', async () => { |
| 107 | + // https://github.com/adaptlearning/adapt-contrib-pageLevelProgress/compare/v2.0.3..v2.0.4 |
| 108 | + |
| 109 | + let course, configuredContentObjects; |
| 110 | + |
| 111 | + whereFromPlugin('Page level progress - from v2.0.3', { name: 'adapt-contrib-pageLevelProgress', version: '<2.0.4' }); |
| 112 | + |
| 113 | + whereContent('Page level progress is configured', content => { |
| 114 | + course = getCourse(); |
| 115 | + configuredContentObjects = content.filter(({ _type, _pageLevelProgress }) => { |
| 116 | + if (!_pageLevelProgress) return false; |
| 117 | + return _type === 'page' || _type === 'menu'; |
| 118 | + }); |
| 119 | + return course._pageLevelProgress || configuredContentObjects.length; |
| 120 | + }); |
| 121 | + |
| 122 | + mutateContent('Page level progress - add course attribute _showPageCompletion', async (content) => { |
| 123 | + if (course._pageLevelProgress) course._pageLevelProgress._showPageCompletion = true; |
| 124 | + return true; |
| 125 | + }); |
| 126 | + |
| 127 | + mutateContent('Page level progress - add content object attribute _showPageCompletion', async (content) => { |
| 128 | + configuredContentObjects.forEach(co => (co._pageLevelProgress._showPageCompletion = true)); |
| 129 | + return true; |
| 130 | + }); |
| 131 | + |
| 132 | + checkContent('Page level progress - check course attribute _showPageCompletion', async (content) => { |
| 133 | + const isValid = !course._pageLevelProgress || course._pageLevelProgress._showPageCompletion === true; |
| 134 | + if (!isValid) throw new Error('Page level progress - course attribute _showPageCompletion'); |
| 135 | + return true; |
| 136 | + }); |
| 137 | + |
| 138 | + checkContent('Page level progress - check content object attribute _showPageCompletion', async (content) => { |
| 139 | + const isValid = configuredContentObjects.every(co => co._pageLevelProgress._showPageCompletion === true); |
| 140 | + if (!isValid) throw new Error('Page level progress - content object attribute _showPageCompletion'); |
| 141 | + return true; |
| 142 | + }); |
| 143 | + |
| 144 | + updatePlugin('Page level progress - update to v2.0.4', { name: 'adapt-contrib-pageLevelProgress', version: '2.0.4', framework: '=>2.0.0' }); |
| 145 | + |
| 146 | + testSuccessWhere('course pageLevelProgress and contentObject with/without pageLevelProgress', { |
| 147 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.3' }], |
| 148 | + content: [ |
| 149 | + { _type: 'course', _pageLevelProgress: {} }, |
| 150 | + { _type: 'page', _pageLevelProgress: {} }, |
| 151 | + { _type: 'page' } |
| 152 | + ] |
| 153 | + }); |
| 154 | + |
| 155 | + testSuccessWhere('course pageLevelProgress and contentObject without pageLevelProgress', { |
| 156 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.3' }], |
| 157 | + content: [ |
| 158 | + { _type: 'course', _pageLevelProgress: {} }, |
| 159 | + { _type: 'page' }, |
| 160 | + { _type: 'page' } |
| 161 | + ] |
| 162 | + }); |
| 163 | + |
| 164 | + testSuccessWhere('pageLevelProgress with no contentObjects', { |
| 165 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.3' }], |
| 166 | + content: [ |
| 167 | + { _type: 'course', _pageLevelProgress: {} } |
| 168 | + ] |
| 169 | + }); |
| 170 | + |
| 171 | + testStopWhere('no pageLevelProgress', { |
| 172 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.3' }], |
| 173 | + content: [ |
| 174 | + { _type: 'course' } |
| 175 | + ] |
| 176 | + }); |
| 177 | + |
| 178 | + testStopWhere('incorrect version', { |
| 179 | + fromPlugins: [{ name: 'adapt-contrib-pageLevelProgress', version: '2.0.4' }] |
| 180 | + }); |
| 181 | +}); |
0 commit comments