From 4eddad479fd47fe68aea6f40e5d0a1119ea08d6b Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Fri, 24 Jan 2025 10:00:24 +0000 Subject: [PATCH 01/14] Added migration scripts --- migrations/v3.js | 36 ++++++++++++++++++++++++++++++++++++ migrations/v4.js | 42 ++++++++++++++++++++++++++++++++++++++++++ migrations/v6.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 migrations/v3.js create mode 100644 migrations/v4.js create mode 100644 migrations/v6.js diff --git a/migrations/v3.js b/migrations/v3.js new file mode 100644 index 0000000..3d0b6cf --- /dev/null +++ b/migrations/v3.js @@ -0,0 +1,36 @@ +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; + +const getCourse = content => { + const [course] = content.filter(({ _type }) => _type === 'course'); + return course; +}; + +const getGlobals = content => { + return getCourse(content)?._globals?._menu?._boxMenu; +}; + +describe('Box menu - v2.0.0 to v3.0.0', async () => { + let courseBoxMenuGlobals; + const durationLabel = 'Duration:'; + + whereFromPlugin('Box menu - from v2.0.0', { name: 'adapt-contrib-boxMenu', version: '<3.0.0' }); + + mutateContent('Box menu - add globals if missing', async (content) => { + courseBoxMenuGlobals = getGlobals(content); + if (courseBoxMenuGlobals) return true; + const course = getCourse(content); + course._globals._menu = course._globals._menu || {}; + courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + return true; + }); + mutateContent('Box menu - add new globals', async (content) => { + courseBoxMenuGlobals.durationLabel = durationLabel; + return true; + }); + + checkContent('Box menu - check new globals', async (content) => { + return getGlobals(content).durationLabel === durationLabel; + }); + + updatePlugin('Box menu - update to v3.0.0', { name: 'adapt-contrib-boxMenu', version: '3.0.0', framework: '">=2.1' }); +}); diff --git a/migrations/v4.js b/migrations/v4.js new file mode 100644 index 0000000..e29efe0 --- /dev/null +++ b/migrations/v4.js @@ -0,0 +1,42 @@ +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; + +const getCourse = content => { + const [course] = content.filter(({ _type }) => _type === 'course'); + return course; +}; + +const getGlobals = content => { + return getCourse(content)?._globals?._menu?._boxMenu; +}; + +describe('Box menu - v3.0.0 to v4.0.1', async () => { + let courseBoxMenuGlobals; + + whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.1' }); + + mutateContent('Box menu - add globals if missing', async (content) => { + courseBoxMenuGlobals = getGlobals(content); + if (courseBoxMenuGlobals) return true; + const course = getCourse(content); + course._globals._menu = course._globals._menu || {}; + courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + return true; + }); + mutateContent('Box menu - remove globals', async (content) => { + delete courseBoxMenuGlobals.ariaRegion; + delete courseBoxMenuGlobals.menuItem; + delete courseBoxMenuGlobals.menuEnd; + return true; + }); + + checkContent('Box menu - check globals', async (content) => { + const globals = getGlobals(content); + return ( + Object.hasOwn(globals, 'ariaRegion') === false && + Object.hasOwn(globals, 'menuItem') === false && + Object.hasOwn(globals, 'menuEnd') === false + ); + }); + + updatePlugin('Box menu - update to v4.0.1', { name: 'adapt-contrib-boxMenu', version: '4.0.1', framework: '">=4' }); +}); diff --git a/migrations/v6.js b/migrations/v6.js new file mode 100644 index 0000000..a907af5 --- /dev/null +++ b/migrations/v6.js @@ -0,0 +1,36 @@ +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; + +const getCourse = content => { + const [course] = content.filter(({ _type }) => _type === 'course'); + return course; +}; + +const getGlobals = content => { + return getCourse(content)?._globals?._menu?._boxMenu; +}; + +describe('Box menu - v5.5.0 to v6.7.0', async () => { + let courseBoxMenuGlobals; + const itemCount = 'Item {{_nthChild}} of {{_totalChild}}'; + + whereFromPlugin('Box menu - from v5.5.0', { name: 'adapt-contrib-boxMenu', version: '<6.7.0' }); + + mutateContent('Box menu - add globals if missing', async (content) => { + courseBoxMenuGlobals = getGlobals(content); + if (courseBoxMenuGlobals) return true; + const course = getCourse(content); + course._globals._menu = course._globals._menu || {}; + courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + return true; + }); + mutateContent('Box menu - add new globals', async (content) => { + courseBoxMenuGlobals.itemCount = itemCount; + return true; + }); + + checkContent('Box menu - check new globals', async (content) => { + return getGlobals(content).itemCount === itemCount; + }); + + updatePlugin('Box menu - update to v6.7.0', { name: 'adapt-contrib-boxMenu', version: '6.7.0', framework: '">=5.24.2' }); +}); From fa3b64320252ed64e97f4f9faaa18a91f3d901cd Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Tue, 28 Jan 2025 12:03:35 +0000 Subject: [PATCH 02/14] Migration corrections --- migrations/{v3.js => v2.js} | 9 ++- migrations/v4.js | 9 ++- migrations/v5.js | 82 +++++++++++++++++++++++++ migrations/v6.js | 116 +++++++++++++++++++++++++++++++++++- 4 files changed, 207 insertions(+), 9 deletions(-) rename migrations/{v3.js => v2.js} (74%) create mode 100644 migrations/v5.js diff --git a/migrations/v3.js b/migrations/v2.js similarity index 74% rename from migrations/v3.js rename to migrations/v2.js index 3d0b6cf..c8e4dd5 100644 --- a/migrations/v3.js +++ b/migrations/v2.js @@ -9,11 +9,14 @@ const getGlobals = content => { return getCourse(content)?._globals?._menu?._boxMenu; }; -describe('Box menu - v2.0.0 to v3.0.0', async () => { +describe('Box menu - v2.0.2 to v2.0.3', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v2.0.2..v2.0.3 + let courseBoxMenuGlobals; const durationLabel = 'Duration:'; - whereFromPlugin('Box menu - from v2.0.0', { name: 'adapt-contrib-boxMenu', version: '<3.0.0' }); + whereFromPlugin('Box menu - from v2.0.2', { name: 'adapt-contrib-boxMenu', version: '<2.0.3' }); mutateContent('Box menu - add globals if missing', async (content) => { courseBoxMenuGlobals = getGlobals(content); @@ -32,5 +35,5 @@ describe('Box menu - v2.0.0 to v3.0.0', async () => { return getGlobals(content).durationLabel === durationLabel; }); - updatePlugin('Box menu - update to v3.0.0', { name: 'adapt-contrib-boxMenu', version: '3.0.0', framework: '">=2.1' }); + updatePlugin('Box menu - update to v2.0.3', { name: 'adapt-contrib-boxMenu', version: '2.0.3', framework: '">=2.0.0' }); }); diff --git a/migrations/v4.js b/migrations/v4.js index e29efe0..7d48642 100644 --- a/migrations/v4.js +++ b/migrations/v4.js @@ -9,10 +9,13 @@ const getGlobals = content => { return getCourse(content)?._globals?._menu?._boxMenu; }; -describe('Box menu - v3.0.0 to v4.0.1', async () => { +describe('Box menu - v3.0.0 to v4.0.0', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v3.0.0..v4.0.0 + let courseBoxMenuGlobals; - whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.1' }); + whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.0' }); mutateContent('Box menu - add globals if missing', async (content) => { courseBoxMenuGlobals = getGlobals(content); @@ -38,5 +41,5 @@ describe('Box menu - v3.0.0 to v4.0.1', async () => { ); }); - updatePlugin('Box menu - update to v4.0.1', { name: 'adapt-contrib-boxMenu', version: '4.0.1', framework: '">=4' }); + updatePlugin('Box menu - update to v4.0.0', { name: 'adapt-contrib-boxMenu', version: '4.0.0', framework: '">=4' }); }); diff --git a/migrations/v5.js b/migrations/v5.js new file mode 100644 index 0000000..2003e57 --- /dev/null +++ b/migrations/v5.js @@ -0,0 +1,82 @@ +import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; + +const getCourse = content => { + const [course] = content.filter(({ _type }) => _type === 'course'); + return course; +}; + +const getGlobals = content => { + return getCourse(content)?._globals?._menu?._boxMenu; +}; + +describe('Box menu - v4.0.1 to v5.0.0', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v4.0.1..v5.0.0 + + const defaults = { + _backgroundImage: { + _large: '', + _medium: '', + _small: '' + }, + _backgroundStyles: { + _backgroundSize: '', + _backgroundRepeat: '', + _backgroundPosition: '' + }, + _menuHeader: { + _backgroundImage: { + _large: '', + _medium: '', + _small: '' + }, + _backgroundStyles: { + _backgroundSize: '', + _backgroundRepeat: '', + _backgroundPosition: '' + } + } + }; + + whereFromPlugin('Box menu - from v4.0.1', { name: 'adapt-contrib-boxMenu', version: '<5.5.0' }); + + mutateContent('Box menu - add config to course', async (content) => { + getCourse(content)._boxMenu = defaults; + return true; + }); + + checkContent('Box menu - check course config', async (content) => { + return getCourse(content)._boxMenu === defaults; + }); + + updatePlugin('Box menu - update to v5.0.0', { name: 'adapt-contrib-boxMenu', version: '5.0.0', framework: '">=5' }); +}); + +describe('Box menu - v5.0.0 to v5.1.0', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v5.0.0..v5.1.0 + + const defaults = { + _renderAsGroup: false + }; + + let contentObjects; + + whereFromPlugin('Box menu - from v5.0.0', { name: 'adapt-contrib-boxMenu', version: '<5.5.0' }); + + whereContent('Box menu - where content objects', async (content) => { + contentObjects = content.filter(({ _type }) => ['menu', 'page'].includes(_type)); + if (contentObjects.length > 0) return true; + }); + + mutateContent('Box menu - add config to content objects', async (content) => { + contentObjects.forEach(co => (co._boxMenu = defaults)); + return true; + }); + + checkContent('Box menu - check content objects config', async (content) => { + return contentObjects.every(co => co._boxMenu === defaults); + }); + + updatePlugin('Box menu - update to v5.1.0', { name: 'adapt-contrib-boxMenu', version: '5.1.0', framework: '">=5.7' }); +}); diff --git a/migrations/v6.js b/migrations/v6.js index a907af5..b810ca1 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -9,11 +9,120 @@ const getGlobals = content => { return getCourse(content)?._globals?._menu?._boxMenu; }; -describe('Box menu - v5.5.0 to v6.7.0', async () => { +describe('Box menu - v6.0.2 to v6.1.0', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.0.2..v6.1.0 + + let course; + const defaultTextAlignment = { + _title: '', + _body: '', + _instruction: '' + }; + + whereFromPlugin('Box menu - from v6.0.2', { name: 'adapt-contrib-boxMenu', version: '<6.1.0' }); + + whereContent('Box menu - where course has _menuHeader', async (content) => { + course = getCourse(content); + return course?._boxMenu?._menuHeader; + }); + + mutateContent('Box menu - add _textAlignment attribute', async (content) => { + course._boxMenu._menuHeader._textAlignment = defaultTextAlignment; + return true; + }); + + checkContent('Box menu - check _textAlignment attribute', async (content) => { + return course._boxMenu._menuHeader._textAlignment === defaultTextAlignment; + }); + + updatePlugin('Box menu - update to v6.1.0', { name: 'adapt-contrib-boxMenu', version: '6.1.0', framework: '">=5.22.6' }); +}); + +describe('Box menu - v6.2.0 to v6.2.1', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.2.0..v6.2.1 + + let course; + const defaultGraphic = { + _src: '', + alt: '' + }; + + whereFromPlugin('Box menu - from v6.2.0', { name: 'adapt-contrib-boxMenu', version: '<6.2.1' }); + + whereContent('Box menu - where course has _boxMenu', async (content) => { + course = getCourse(content); + return course?._boxMenu; + }); + + mutateContent('Box menu - add _graphic attribute', async (content) => { + course._boxMenu._graphic = defaultGraphic; + return true; + }); + + checkContent('Box menu - check _graphic attribute', async (content) => { + return course._boxMenu._graphic === defaultGraphic; + }); + + updatePlugin('Box menu - update to v6.2.1', { name: 'adapt-contrib-boxMenu', version: '6.2.1', framework: '">=5.24.2' }); +}); + +describe('Box menu - v6.3.8 to v6.3.9', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.3.8..v6.3.9 + + let course; + + whereFromPlugin('Box menu - from v6.3.8', { name: 'adapt-contrib-boxMenu', version: '<6.3.9' }); + + whereContent('Box menu - where course has _backgroundImage', async (content) => { + course = getCourse(content); + return ( + course?._boxMenu?._backgroundImage || + course?._boxMenu?._menuHeader?._backgroundImage + ); + }); + + mutateContent('Box menu - add _xlarge attribute', async (content) => { + if (course._boxMenu._backgroundImage) { + course._boxMenu._backgroundImage._xlarge = ''; + } + return true; + }); + + mutateContent('Box menu - add _xlarge attribute to _menuHeader', async (content) => { + if (course._boxMenu._menuHeader._backgroundImage) { + course._boxMenu._menuHeader._backgroundImage._xlarge = ''; + } + return true; + }); + + checkContent('Box menu - check _xlarge attribute', async (content) => { + return ( + !course._boxMenu._backgroundImage || + course._boxMenu._backgroundImage._xlarge === '' + ); + }); + + checkContent('Box menu - check _xlarge attribute for _menuHeader', async (content) => { + return ( + !course._boxMenu._menuHeader?._backgroundImage || + course._boxMenu._menuHeader._backgroundImage._xlarge === '' + ); + }); + + updatePlugin('Box menu - update to v6.3.9', { name: 'adapt-contrib-boxMenu', version: '6.3.9', framework: '">=5.24.2' }); +}); + +describe('Box menu - v6.3.9 to v6.3.10', async () => { + + // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.3.9..v6.3.10 + let courseBoxMenuGlobals; const itemCount = 'Item {{_nthChild}} of {{_totalChild}}'; - whereFromPlugin('Box menu - from v5.5.0', { name: 'adapt-contrib-boxMenu', version: '<6.7.0' }); + whereFromPlugin('Box menu - from v6.3.9', { name: 'adapt-contrib-boxMenu', version: ' { courseBoxMenuGlobals = getGlobals(content); @@ -23,6 +132,7 @@ describe('Box menu - v5.5.0 to v6.7.0', async () => { courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; return true; }); + mutateContent('Box menu - add new globals', async (content) => { courseBoxMenuGlobals.itemCount = itemCount; return true; @@ -32,5 +142,5 @@ describe('Box menu - v5.5.0 to v6.7.0', async () => { return getGlobals(content).itemCount === itemCount; }); - updatePlugin('Box menu - update to v6.7.0', { name: 'adapt-contrib-boxMenu', version: '6.7.0', framework: '">=5.24.2' }); + updatePlugin('Box menu - update to v6.3.10', { name: 'adapt-contrib-boxMenu', version: 'v6.3.10', framework: '">=5.24.2' }); }); From 915d06376d4cbd3cb72f1e5bf4b90bb204f78042 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Wed, 29 Jan 2025 10:31:13 +0000 Subject: [PATCH 03/14] Migration corrections --- migrations/v5.js | 82 ------------------------------------------------ 1 file changed, 82 deletions(-) delete mode 100644 migrations/v5.js diff --git a/migrations/v5.js b/migrations/v5.js deleted file mode 100644 index 2003e57..0000000 --- a/migrations/v5.js +++ /dev/null @@ -1,82 +0,0 @@ -import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; - -const getCourse = content => { - const [course] = content.filter(({ _type }) => _type === 'course'); - return course; -}; - -const getGlobals = content => { - return getCourse(content)?._globals?._menu?._boxMenu; -}; - -describe('Box menu - v4.0.1 to v5.0.0', async () => { - - // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v4.0.1..v5.0.0 - - const defaults = { - _backgroundImage: { - _large: '', - _medium: '', - _small: '' - }, - _backgroundStyles: { - _backgroundSize: '', - _backgroundRepeat: '', - _backgroundPosition: '' - }, - _menuHeader: { - _backgroundImage: { - _large: '', - _medium: '', - _small: '' - }, - _backgroundStyles: { - _backgroundSize: '', - _backgroundRepeat: '', - _backgroundPosition: '' - } - } - }; - - whereFromPlugin('Box menu - from v4.0.1', { name: 'adapt-contrib-boxMenu', version: '<5.5.0' }); - - mutateContent('Box menu - add config to course', async (content) => { - getCourse(content)._boxMenu = defaults; - return true; - }); - - checkContent('Box menu - check course config', async (content) => { - return getCourse(content)._boxMenu === defaults; - }); - - updatePlugin('Box menu - update to v5.0.0', { name: 'adapt-contrib-boxMenu', version: '5.0.0', framework: '">=5' }); -}); - -describe('Box menu - v5.0.0 to v5.1.0', async () => { - - // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v5.0.0..v5.1.0 - - const defaults = { - _renderAsGroup: false - }; - - let contentObjects; - - whereFromPlugin('Box menu - from v5.0.0', { name: 'adapt-contrib-boxMenu', version: '<5.5.0' }); - - whereContent('Box menu - where content objects', async (content) => { - contentObjects = content.filter(({ _type }) => ['menu', 'page'].includes(_type)); - if (contentObjects.length > 0) return true; - }); - - mutateContent('Box menu - add config to content objects', async (content) => { - contentObjects.forEach(co => (co._boxMenu = defaults)); - return true; - }); - - checkContent('Box menu - check content objects config', async (content) => { - return contentObjects.every(co => co._boxMenu === defaults); - }); - - updatePlugin('Box menu - update to v5.1.0', { name: 'adapt-contrib-boxMenu', version: '5.1.0', framework: '">=5.7' }); -}); From 61cafe9b431fa4590b702d7ae25f8385f69cf8d6 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Thu, 6 Feb 2025 14:14:59 +0000 Subject: [PATCH 04/14] Review amendments --- migrations/v2.js | 18 ++++++++++-------- migrations/v4.js | 20 +++++++++++--------- migrations/v6.js | 33 +++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/migrations/v2.js b/migrations/v2.js index c8e4dd5..e353146 100644 --- a/migrations/v2.js +++ b/migrations/v2.js @@ -1,7 +1,8 @@ import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import _ from 'lodash'; const getCourse = content => { - const [course] = content.filter(({ _type }) => _type === 'course'); + const course = content.find(({ _type }) => _type === 'course'); return course; }; @@ -13,26 +14,27 @@ describe('Box menu - v2.0.2 to v2.0.3', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v2.0.2..v2.0.3 - let courseBoxMenuGlobals; + let course, courseBoxMenuGlobals; const durationLabel = 'Duration:'; whereFromPlugin('Box menu - from v2.0.2', { name: 'adapt-contrib-boxMenu', version: '<2.0.3' }); mutateContent('Box menu - add globals if missing', async (content) => { - courseBoxMenuGlobals = getGlobals(content); - if (courseBoxMenuGlobals) return true; - const course = getCourse(content); - course._globals._menu = course._globals._menu || {}; - courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + course = getCourse(content); + if (!_.has(course, '_globals._menu._boxMenu')) _.set(course, '_globals._menu._boxMenu', {}); + courseBoxMenuGlobals = course._globals._menu._boxMenu; return true; }); + mutateContent('Box menu - add new globals', async (content) => { courseBoxMenuGlobals.durationLabel = durationLabel; return true; }); checkContent('Box menu - check new globals', async (content) => { - return getGlobals(content).durationLabel === durationLabel; + const isValid = getGlobals(content).durationLabel === durationLabel; + if (!isValid) throw new Error('Box menu - global attribute durationLabel'); + return true; }); updatePlugin('Box menu - update to v2.0.3', { name: 'adapt-contrib-boxMenu', version: '2.0.3', framework: '">=2.0.0' }); diff --git a/migrations/v4.js b/migrations/v4.js index 7d48642..206f87b 100644 --- a/migrations/v4.js +++ b/migrations/v4.js @@ -1,7 +1,8 @@ import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import _ from 'lodash'; const getCourse = content => { - const [course] = content.filter(({ _type }) => _type === 'course'); + const course = content.find(({ _type }) => _type === 'course'); return course; }; @@ -12,19 +13,18 @@ const getGlobals = content => { describe('Box menu - v3.0.0 to v4.0.0', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v3.0.0..v4.0.0 - - let courseBoxMenuGlobals; + + let course, courseBoxMenuGlobals; whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.0' }); mutateContent('Box menu - add globals if missing', async (content) => { - courseBoxMenuGlobals = getGlobals(content); - if (courseBoxMenuGlobals) return true; - const course = getCourse(content); - course._globals._menu = course._globals._menu || {}; - courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + course = getCourse(content); + if (!_.has(course, '_globals._menu._boxMenu')) _.set(course, '_globals._menu._boxMenu', {}); + courseBoxMenuGlobals = course._globals._menu._boxMenu; return true; }); + mutateContent('Box menu - remove globals', async (content) => { delete courseBoxMenuGlobals.ariaRegion; delete courseBoxMenuGlobals.menuItem; @@ -34,11 +34,13 @@ describe('Box menu - v3.0.0 to v4.0.0', async () => { checkContent('Box menu - check globals', async (content) => { const globals = getGlobals(content); - return ( + const isValid = ( Object.hasOwn(globals, 'ariaRegion') === false && Object.hasOwn(globals, 'menuItem') === false && Object.hasOwn(globals, 'menuEnd') === false ); + if (!isValid) throw new Error('Box menu - global attributes ariaRegion menuItem menuEnd'); + return true; }); updatePlugin('Box menu - update to v4.0.0', { name: 'adapt-contrib-boxMenu', version: '4.0.0', framework: '">=4' }); diff --git a/migrations/v6.js b/migrations/v6.js index b810ca1..d7340c6 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -1,7 +1,8 @@ import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import _ from 'lodash'; const getCourse = content => { - const [course] = content.filter(({ _type }) => _type === 'course'); + const course = content.find(({ _type }) => _type === 'course'); return course; }; @@ -33,7 +34,9 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { }); checkContent('Box menu - check _textAlignment attribute', async (content) => { - return course._boxMenu._menuHeader._textAlignment === defaultTextAlignment; + const isValid = _.isEqual(course._boxMenu._menuHeader._textAlignment, defaultTextAlignment); + if (!isValid) throw new Error('Box menu - course attribute _textAlignment'); + return true; }); updatePlugin('Box menu - update to v6.1.0', { name: 'adapt-contrib-boxMenu', version: '6.1.0', framework: '">=5.22.6' }); @@ -62,7 +65,9 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { }); checkContent('Box menu - check _graphic attribute', async (content) => { - return course._boxMenu._graphic === defaultGraphic; + const isValid = _.isEqual(course._boxMenu._graphic, defaultGraphic); + if (!isValid) throw new Error('Box menu - course attribute _graphic'); + return true; }); updatePlugin('Box menu - update to v6.2.1', { name: 'adapt-contrib-boxMenu', version: '6.2.1', framework: '">=5.24.2' }); @@ -99,17 +104,21 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { }); checkContent('Box menu - check _xlarge attribute', async (content) => { - return ( + const isValid = ( !course._boxMenu._backgroundImage || course._boxMenu._backgroundImage._xlarge === '' ); + if (!isValid) throw new Error('Box menu - course attribute _xlarge'); + return true; }); checkContent('Box menu - check _xlarge attribute for _menuHeader', async (content) => { - return ( + const isValid = ( !course._boxMenu._menuHeader?._backgroundImage || course._boxMenu._menuHeader._backgroundImage._xlarge === '' ); + if (!isValid) throw new Error('Box menu - course attribute _xlarge'); + return true; }); updatePlugin('Box menu - update to v6.3.9', { name: 'adapt-contrib-boxMenu', version: '6.3.9', framework: '">=5.24.2' }); @@ -119,17 +128,15 @@ describe('Box menu - v6.3.9 to v6.3.10', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.3.9..v6.3.10 - let courseBoxMenuGlobals; + let course, courseBoxMenuGlobals; const itemCount = 'Item {{_nthChild}} of {{_totalChild}}'; whereFromPlugin('Box menu - from v6.3.9', { name: 'adapt-contrib-boxMenu', version: ' { - courseBoxMenuGlobals = getGlobals(content); - if (courseBoxMenuGlobals) return true; - const course = getCourse(content); - course._globals._menu = course._globals._menu || {}; - courseBoxMenuGlobals = course._globals._menu._boxMenu = {}; + course = getCourse(content); + if (!_.has(course, '_globals._menu._boxMenu')) _.set(course, '_globals._menu._boxMenu', {}); + courseBoxMenuGlobals = course._globals._menu._boxMenu; return true; }); @@ -139,7 +146,9 @@ describe('Box menu - v6.3.9 to v6.3.10', async () => { }); checkContent('Box menu - check new globals', async (content) => { - return getGlobals(content).itemCount === itemCount; + const isValid = getGlobals(content).itemCount === itemCount; + if (!isValid) throw new Error('Box menu - global attribute itemCount'); + return true; }); updatePlugin('Box menu - update to v6.3.10', { name: 'adapt-contrib-boxMenu', version: 'v6.3.10', framework: '">=5.24.2' }); From 1cb30e695998f17673a12eb81ecd6292c4b62dbc Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Fri, 21 Feb 2025 16:00:33 +0000 Subject: [PATCH 05/14] Migration scripts review amendments --- migrations/v2.js | 17 ++++------------- migrations/v4.js | 46 ++++++++++++++++++++++++++-------------------- migrations/v6.js | 25 ++++++++----------------- 3 files changed, 38 insertions(+), 50 deletions(-) diff --git a/migrations/v2.js b/migrations/v2.js index e353146..7cfcb73 100644 --- a/migrations/v2.js +++ b/migrations/v2.js @@ -1,15 +1,6 @@ -import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import { describe, getCourse, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; import _ from 'lodash'; -const getCourse = content => { - const course = content.find(({ _type }) => _type === 'course'); - return course; -}; - -const getGlobals = content => { - return getCourse(content)?._globals?._menu?._boxMenu; -}; - describe('Box menu - v2.0.2 to v2.0.3', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v2.0.2..v2.0.3 @@ -17,10 +8,10 @@ describe('Box menu - v2.0.2 to v2.0.3', async () => { let course, courseBoxMenuGlobals; const durationLabel = 'Duration:'; - whereFromPlugin('Box menu - from v2.0.2', { name: 'adapt-contrib-boxMenu', version: '<2.0.3' }); + whereFromPlugin('Box menu - from v2.0.2', { name: 'adapt-contrib-boxMenu', version: '>=2.0.0 <2.0.3' }); mutateContent('Box menu - add globals if missing', async (content) => { - course = getCourse(content); + course = getCourse(); if (!_.has(course, '_globals._menu._boxMenu')) _.set(course, '_globals._menu._boxMenu', {}); courseBoxMenuGlobals = course._globals._menu._boxMenu; return true; @@ -32,7 +23,7 @@ describe('Box menu - v2.0.2 to v2.0.3', async () => { }); checkContent('Box menu - check new globals', async (content) => { - const isValid = getGlobals(content).durationLabel === durationLabel; + const isValid = courseBoxMenuGlobals.durationLabel === durationLabel; if (!isValid) throw new Error('Box menu - global attribute durationLabel'); return true; }); diff --git a/migrations/v4.js b/migrations/v4.js index 206f87b..fe4c01b 100644 --- a/migrations/v4.js +++ b/migrations/v4.js @@ -1,15 +1,6 @@ -import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import { describe, getCourse, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; import _ from 'lodash'; -const getCourse = content => { - const course = content.find(({ _type }) => _type === 'course'); - return course; -}; - -const getGlobals = content => { - return getCourse(content)?._globals?._menu?._boxMenu; -}; - describe('Box menu - v3.0.0 to v4.0.0', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v3.0.0..v4.0.0 @@ -19,27 +10,42 @@ describe('Box menu - v3.0.0 to v4.0.0', async () => { whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.0' }); mutateContent('Box menu - add globals if missing', async (content) => { - course = getCourse(content); + course = getCourse(); if (!_.has(course, '_globals._menu._boxMenu')) _.set(course, '_globals._menu._boxMenu', {}); courseBoxMenuGlobals = course._globals._menu._boxMenu; return true; }); - mutateContent('Box menu - remove globals', async (content) => { + mutateContent('Box menu - remove global attribute ariaRegion', async (content) => { delete courseBoxMenuGlobals.ariaRegion; + return true; + }); + + mutateContent('Box menu - remove globas attribute menuItem', async (content) => { delete courseBoxMenuGlobals.menuItem; + return true; + }); + + mutateContent('Box menu - remove globas attribute menuEnd', async (content) => { delete courseBoxMenuGlobals.menuEnd; return true; }); - checkContent('Box menu - check globals', async (content) => { - const globals = getGlobals(content); - const isValid = ( - Object.hasOwn(globals, 'ariaRegion') === false && - Object.hasOwn(globals, 'menuItem') === false && - Object.hasOwn(globals, 'menuEnd') === false - ); - if (!isValid) throw new Error('Box menu - global attributes ariaRegion menuItem menuEnd'); + checkContent('Box menu - check global attribute ariaRegion', async (content) => { + const isValid = Object.hasOwn(courseBoxMenuGlobals, 'ariaRegion') === false; + if (!isValid) throw new Error('Box menu - global attributes ariaRegion'); + return true; + }); + + checkContent('Box menu - check global attribute menuItem', async (content) => { + const isValid = Object.hasOwn(courseBoxMenuGlobals, 'menuItem') === false; + if (!isValid) throw new Error('Box menu - global attributes menuItem'); + return true; + }); + + checkContent('Box menu - check global attribute menuEnd', async (content) => { + const isValid = Object.hasOwn(courseBoxMenuGlobals, 'menuEnd') === false; + if (!isValid) throw new Error('Box menu - global attributes menuEnd'); return true; }); diff --git a/migrations/v6.js b/migrations/v6.js index d7340c6..7c4fc1d 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -1,15 +1,6 @@ -import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import { describe, getCourse, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; import _ from 'lodash'; -const getCourse = content => { - const course = content.find(({ _type }) => _type === 'course'); - return course; -}; - -const getGlobals = content => { - return getCourse(content)?._globals?._menu?._boxMenu; -}; - describe('Box menu - v6.0.2 to v6.1.0', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.0.2..v6.1.0 @@ -24,7 +15,7 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { whereFromPlugin('Box menu - from v6.0.2', { name: 'adapt-contrib-boxMenu', version: '<6.1.0' }); whereContent('Box menu - where course has _menuHeader', async (content) => { - course = getCourse(content); + course = getCourse(); return course?._boxMenu?._menuHeader; }); @@ -55,7 +46,7 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { whereFromPlugin('Box menu - from v6.2.0', { name: 'adapt-contrib-boxMenu', version: '<6.2.1' }); whereContent('Box menu - where course has _boxMenu', async (content) => { - course = getCourse(content); + course = getCourse(); return course?._boxMenu; }); @@ -82,7 +73,7 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { whereFromPlugin('Box menu - from v6.3.8', { name: 'adapt-contrib-boxMenu', version: '<6.3.9' }); whereContent('Box menu - where course has _backgroundImage', async (content) => { - course = getCourse(content); + course = getCourse(); return ( course?._boxMenu?._backgroundImage || course?._boxMenu?._menuHeader?._backgroundImage @@ -131,10 +122,10 @@ describe('Box menu - v6.3.9 to v6.3.10', async () => { let course, courseBoxMenuGlobals; const itemCount = 'Item {{_nthChild}} of {{_totalChild}}'; - whereFromPlugin('Box menu - from v6.3.9', { name: 'adapt-contrib-boxMenu', version: ' { - course = getCourse(content); + course = getCourse(); if (!_.has(course, '_globals._menu._boxMenu')) _.set(course, '_globals._menu._boxMenu', {}); courseBoxMenuGlobals = course._globals._menu._boxMenu; return true; @@ -146,10 +137,10 @@ describe('Box menu - v6.3.9 to v6.3.10', async () => { }); checkContent('Box menu - check new globals', async (content) => { - const isValid = getGlobals(content).itemCount === itemCount; + const isValid = courseBoxMenuGlobals.itemCount === itemCount; if (!isValid) throw new Error('Box menu - global attribute itemCount'); return true; }); - updatePlugin('Box menu - update to v6.3.10', { name: 'adapt-contrib-boxMenu', version: 'v6.3.10', framework: '">=5.24.2' }); + updatePlugin('Box menu - update to v6.3.10', { name: 'adapt-contrib-boxMenu', version: '6.3.10', framework: '">=5.24.2' }); }); From 7632560439235dd71a6cc361598a2da97f549724 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Fri, 21 Feb 2025 16:44:50 +0000 Subject: [PATCH 06/14] Migration scripts review amendments --- migrations/v4.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/migrations/v4.js b/migrations/v4.js index fe4c01b..a2b33d4 100644 --- a/migrations/v4.js +++ b/migrations/v4.js @@ -32,19 +32,19 @@ describe('Box menu - v3.0.0 to v4.0.0', async () => { }); checkContent('Box menu - check global attribute ariaRegion', async (content) => { - const isValid = Object.hasOwn(courseBoxMenuGlobals, 'ariaRegion') === false; + const isValid = !_.has(courseBoxMenuGlobals, 'ariaRegion'); if (!isValid) throw new Error('Box menu - global attributes ariaRegion'); return true; }); checkContent('Box menu - check global attribute menuItem', async (content) => { - const isValid = Object.hasOwn(courseBoxMenuGlobals, 'menuItem') === false; + const isValid = !_.has(courseBoxMenuGlobals, 'menuItem'); if (!isValid) throw new Error('Box menu - global attributes menuItem'); return true; }); checkContent('Box menu - check global attribute menuEnd', async (content) => { - const isValid = Object.hasOwn(courseBoxMenuGlobals, 'menuEnd') === false; + const isValid = !_.has(courseBoxMenuGlobals, 'menuEnd'); if (!isValid) throw new Error('Box menu - global attributes menuEnd'); return true; }); From 9a9f10dceb079dc92ac83ac51486f73d770dba1f Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Fri, 21 Feb 2025 16:45:55 +0000 Subject: [PATCH 07/14] Migration scripts review amendments --- migrations/v4.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/migrations/v4.js b/migrations/v4.js index a2b33d4..7223d31 100644 --- a/migrations/v4.js +++ b/migrations/v4.js @@ -33,19 +33,19 @@ describe('Box menu - v3.0.0 to v4.0.0', async () => { checkContent('Box menu - check global attribute ariaRegion', async (content) => { const isValid = !_.has(courseBoxMenuGlobals, 'ariaRegion'); - if (!isValid) throw new Error('Box menu - global attributes ariaRegion'); + if (!isValid) throw new Error('Box menu - global attribute ariaRegion'); return true; }); checkContent('Box menu - check global attribute menuItem', async (content) => { const isValid = !_.has(courseBoxMenuGlobals, 'menuItem'); - if (!isValid) throw new Error('Box menu - global attributes menuItem'); + if (!isValid) throw new Error('Box menu - global attribute menuItem'); return true; }); checkContent('Box menu - check global attribute menuEnd', async (content) => { const isValid = !_.has(courseBoxMenuGlobals, 'menuEnd'); - if (!isValid) throw new Error('Box menu - global attributes menuEnd'); + if (!isValid) throw new Error('Box menu - global attribute menuEnd'); return true; }); From 196246aa43f99c6ee3f0960450f4e47791ffa68c Mon Sep 17 00:00:00 2001 From: joe-allen-89 <85872286+joe-allen-89@users.noreply.github.com> Date: Thu, 27 Feb 2025 12:06:30 +0000 Subject: [PATCH 08/14] automated testing added to migrations --- migrations/v2.js | 20 ++++++++++- migrations/v4.js | 46 ++++++++++++++++++++++--- migrations/v6.js | 87 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 146 insertions(+), 7 deletions(-) diff --git a/migrations/v2.js b/migrations/v2.js index 7cfcb73..7eefc90 100644 --- a/migrations/v2.js +++ b/migrations/v2.js @@ -1,4 +1,4 @@ -import { describe, getCourse, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import { describe, getCourse, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere } from 'adapt-migrations'; import _ from 'lodash'; describe('Box menu - v2.0.2 to v2.0.3', async () => { @@ -29,4 +29,22 @@ describe('Box menu - v2.0.2 to v2.0.3', async () => { }); updatePlugin('Box menu - update to v2.0.3', { name: 'adapt-contrib-boxMenu', version: '2.0.3', framework: '">=2.0.0' }); + + testSuccessWhere('boxMenu with empty course', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '2.0.2' }], + content: [ + { _type: 'course' } + ] + }); + + testSuccessWhere('boxMenu with course globals', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '2.0.2' }], + content: [ + { _type: 'course', _globals: { _menu: { _boxMenu: {} } } } + ] + }); + + testStopWhere('incorrect version', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '2.0.3' }] + }); }); diff --git a/migrations/v4.js b/migrations/v4.js index 7223d31..6b65ed9 100644 --- a/migrations/v4.js +++ b/migrations/v4.js @@ -1,4 +1,4 @@ -import { describe, getCourse, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import { describe, getCourse, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere, whereContent } from 'adapt-migrations'; import _ from 'lodash'; describe('Box menu - v3.0.0 to v4.0.0', async () => { @@ -9,9 +9,9 @@ describe('Box menu - v3.0.0 to v4.0.0', async () => { whereFromPlugin('Box menu - from v3.0.0', { name: 'adapt-contrib-boxMenu', version: '<4.0.0' }); - mutateContent('Box menu - add globals if missing', async (content) => { + whereContent('Box menu - where globals', async (content) => { course = getCourse(); - if (!_.has(course, '_globals._menu._boxMenu')) _.set(course, '_globals._menu._boxMenu', {}); + if (!_.has(course, '_globals._menu._boxMenu')) return false; courseBoxMenuGlobals = course._globals._menu._boxMenu; return true; }); @@ -21,12 +21,12 @@ describe('Box menu - v3.0.0 to v4.0.0', async () => { return true; }); - mutateContent('Box menu - remove globas attribute menuItem', async (content) => { + mutateContent('Box menu - remove globals attribute menuItem', async (content) => { delete courseBoxMenuGlobals.menuItem; return true; }); - mutateContent('Box menu - remove globas attribute menuEnd', async (content) => { + mutateContent('Box menu - remove globals attribute menuEnd', async (content) => { delete courseBoxMenuGlobals.menuEnd; return true; }); @@ -50,4 +50,40 @@ describe('Box menu - v3.0.0 to v4.0.0', async () => { }); updatePlugin('Box menu - update to v4.0.0', { name: 'adapt-contrib-boxMenu', version: '4.0.0', framework: '">=4' }); + + testStopWhere('boxMenu with empty course', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '3.0.0' }], + content: [ + { _type: 'course' } + ] + }); + + testSuccessWhere('boxMenu with course globals', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '3.0.0' }], + content: [ + { + _type: 'course', + _globals: { + _menu: { + _boxMenu: { + ariaRegion: 'ariaRegion', + menuItem: 'menuItem', + menuEnd: 'menuEnd' + } + } + } + } + ] + }); + + testSuccessWhere('boxMenu with empty course globals', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '3.0.0' }], + content: [ + { _type: 'course', _globals: { _menu: { _boxMenu: {} } } } + ] + }); + + testStopWhere('incorrect version', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '4.0.0' }] + }); }); diff --git a/migrations/v6.js b/migrations/v6.js index 7c4fc1d..fd93b8a 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -1,4 +1,4 @@ -import { describe, getCourse, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; +import { describe, getCourse, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere } from 'adapt-migrations'; import _ from 'lodash'; describe('Box menu - v6.0.2 to v6.1.0', async () => { @@ -31,6 +31,29 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { }); updatePlugin('Box menu - update to v6.1.0', { name: 'adapt-contrib-boxMenu', version: '6.1.0', framework: '">=5.22.6' }); + + testSuccessWhere('boxMenu with course _boxMenu._menuHeader', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.0.2' }], + content: [ { _type: 'course', _boxMenu: { _menuHeader: {} } }] + }); + + testStopWhere('boxMenu with empty course', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.0.2' }], + content: [ + { _type: 'course' } + ] + }); + + testStopWhere('boxMenu with empty course _boxMenu', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.0.2' }], + content: [ + { _type: 'course', _boxMenu: {} } + ] + }); + + testStopWhere('incorrect version', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.1.0' }] + }); }); describe('Box menu - v6.2.0 to v6.2.1', async () => { @@ -62,6 +85,22 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { }); updatePlugin('Box menu - update to v6.2.1', { name: 'adapt-contrib-boxMenu', version: '6.2.1', framework: '">=5.24.2' }); + + testSuccessWhere('boxMenu with course _boxMenu', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.2.0' }], + content: [ { _type: 'course', _boxMenu: {} }] + }); + + testStopWhere('boxMenu with empty course', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.2.0' }], + content: [ + { _type: 'course' } + ] + }); + + testStopWhere('incorrect version', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.2.1' }] + }); }); describe('Box menu - v6.3.8 to v6.3.9', async () => { @@ -113,6 +152,34 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { }); updatePlugin('Box menu - update to v6.3.9', { name: 'adapt-contrib-boxMenu', version: '6.3.9', framework: '">=5.24.2' }); + + testSuccessWhere('boxMenu with course._boxMenu._backgroundImage', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], + content: [ { _type: 'course', _boxMenu: { _backgroundImage: '' } }] + }); + + testSuccessWhere('boxMenu with course._boxMenu._menuHeader._backgroundImage', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], + content: [ { _type: 'course', _boxMenu: { _menuHeader: { _backgroundImage: {} } } }] + }); + + testStopWhere('boxMenu with empty course', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], + content: [ + { _type: 'course' } + ] + }); + + testStopWhere('boxMenu with course._boxMenu', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], + content: [ + { _type: 'course', _boxMenu: {} } + ] + }); + + testStopWhere('incorrect version', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.9' }] + }); }); describe('Box menu - v6.3.9 to v6.3.10', async () => { @@ -143,4 +210,22 @@ describe('Box menu - v6.3.9 to v6.3.10', async () => { }); updatePlugin('Box menu - update to v6.3.10', { name: 'adapt-contrib-boxMenu', version: '6.3.10', framework: '">=5.24.2' }); + + testSuccessWhere('boxMenu with empty course', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.9' }], + content: [ + { _type: 'course' } + ] + }); + + testSuccessWhere('boxMenu with course globals', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.9' }], + content: [ + { _type: 'course', _globals: { _menu: { _boxMenu: {} } } } + ] + }); + + testStopWhere('incorrect version', { + fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.10' }] + }); }); From 57d74ced99687b299d5ce92030686e339f90a507 Mon Sep 17 00:00:00 2001 From: joe-allen-89 <85872286+joe-allen-89@users.noreply.github.com> Date: Wed, 5 Mar 2025 15:54:50 +0000 Subject: [PATCH 09/14] amended check for _boxMenu._backgroundImage --- migrations/v6.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/migrations/v6.js b/migrations/v6.js index fd93b8a..d2e63fc 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -120,14 +120,14 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { }); mutateContent('Box menu - add _xlarge attribute', async (content) => { - if (course._boxMenu._backgroundImage) { + if (_.has(course, '_boxMenu._backgroundImage')) { course._boxMenu._backgroundImage._xlarge = ''; } return true; }); mutateContent('Box menu - add _xlarge attribute to _menuHeader', async (content) => { - if (course._boxMenu._menuHeader._backgroundImage) { + if (_.has(course, '_boxMenu._menuHeader._backgroundImage')) { course._boxMenu._menuHeader._backgroundImage._xlarge = ''; } return true; @@ -155,7 +155,7 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { testSuccessWhere('boxMenu with course._boxMenu._backgroundImage', { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], - content: [ { _type: 'course', _boxMenu: { _backgroundImage: '' } }] + content: [ { _type: 'course', _boxMenu: { _backgroundImage: {} } }] }); testSuccessWhere('boxMenu with course._boxMenu._menuHeader._backgroundImage', { From a7932261bd82f71af8cd064ed0171d61e6f42a59 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Mon, 31 Mar 2025 16:14:08 +0100 Subject: [PATCH 10/14] Extend migrations to content objects --- migrations/v6.js | 76 ++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/migrations/v6.js b/migrations/v6.js index d2e63fc..fc947ad 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -5,7 +5,7 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.0.2..v6.1.0 - let course; + let menusWithHeaders; const defaultTextAlignment = { _title: '', _body: '', @@ -14,18 +14,19 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { whereFromPlugin('Box menu - from v6.0.2', { name: 'adapt-contrib-boxMenu', version: '<6.1.0' }); - whereContent('Box menu - where course has _menuHeader', async (content) => { - course = getCourse(); - return course?._boxMenu?._menuHeader; + whereContent('Box menu - where menus have _menuHeader', async (content) => { + const candidates = [getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))]; + menusWithHeaders = candidates.filter(({ _boxMenu }) => _boxMenu?._menuHeader); + return menusWithHeaders.length; }); mutateContent('Box menu - add _textAlignment attribute', async (content) => { - course._boxMenu._menuHeader._textAlignment = defaultTextAlignment; + menusWithHeaders.forEach(({ _boxMenu }) => (_boxMenu._menuHeader._textAlignment = defaultTextAlignment)); return true; }); checkContent('Box menu - check _textAlignment attribute', async (content) => { - const isValid = _.isEqual(course._boxMenu._menuHeader._textAlignment, defaultTextAlignment); + const isValid = menusWithHeaders.every(({ _boxMenu }) => _.isEqual(_boxMenu._menuHeader._textAlignment, defaultTextAlignment)); if (!isValid) throw new Error('Box menu - course attribute _textAlignment'); return true; }); @@ -34,7 +35,10 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { testSuccessWhere('boxMenu with course _boxMenu._menuHeader', { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.0.2' }], - content: [ { _type: 'course', _boxMenu: { _menuHeader: {} } }] + content: [ + { _type: 'course', _boxMenu: { _menuHeader: {} } }, + { _type: 'contentObject', _boxMenu: { _menuHeader: {} } } + ] }); testStopWhere('boxMenu with empty course', { @@ -60,7 +64,7 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.2.0..v6.2.1 - let course; + let menusWithGraphics; const defaultGraphic = { _src: '', alt: '' @@ -68,18 +72,19 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { whereFromPlugin('Box menu - from v6.2.0', { name: 'adapt-contrib-boxMenu', version: '<6.2.1' }); - whereContent('Box menu - where course has _boxMenu', async (content) => { - course = getCourse(); - return course?._boxMenu; + whereContent('Box menu - where menus are configured', async (content) => { + const candidates = [getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))]; + menusWithGraphics = candidates.filter(({ _boxMenu }) => _boxMenu); + return menusWithGraphics.length; }); mutateContent('Box menu - add _graphic attribute', async (content) => { - course._boxMenu._graphic = defaultGraphic; + menusWithGraphics.forEach(({ _boxMenu }) => (_boxMenu._graphic = defaultGraphic)); return true; }); checkContent('Box menu - check _graphic attribute', async (content) => { - const isValid = _.isEqual(course._boxMenu._graphic, defaultGraphic); + const isValid = menusWithGraphics.every(({ _boxMenu }) => _.isEqual(_boxMenu._graphic, defaultGraphic)); if (!isValid) throw new Error('Box menu - course attribute _graphic'); return true; }); @@ -107,46 +112,49 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.3.8..v6.3.9 - let course; + let menusWithBgImage; whereFromPlugin('Box menu - from v6.3.8', { name: 'adapt-contrib-boxMenu', version: '<6.3.9' }); - whereContent('Box menu - where course has _backgroundImage', async (content) => { - course = getCourse(); - return ( - course?._boxMenu?._backgroundImage || - course?._boxMenu?._menuHeader?._backgroundImage - ); + whereContent('Box menu - where menus have _backgroundImage', async (content) => { + const candidates = [getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))]; + menusWithBgImage = candidates.filter(({ _boxMenu }) => ( + _boxMenu?._backgroundImage || + _boxMenu?._menuHeader?._backgroundImage + )); + return menusWithBgImage.length; }); mutateContent('Box menu - add _xlarge attribute', async (content) => { - if (_.has(course, '_boxMenu._backgroundImage')) { - course._boxMenu._backgroundImage._xlarge = ''; - } + menusWithBgImage.forEach(({ _boxMenu }) => { + if (_.has(_boxMenu, '_backgroundImage')) { + _boxMenu._backgroundImage._xlarge = ''; + } + }); return true; }); mutateContent('Box menu - add _xlarge attribute to _menuHeader', async (content) => { - if (_.has(course, '_boxMenu._menuHeader._backgroundImage')) { - course._boxMenu._menuHeader._backgroundImage._xlarge = ''; - } + menusWithBgImage.forEach(({ _boxMenu }) => { + if (_.has(_boxMenu, '_menuHeader._backgroundImage')) { + _boxMenu._menuHeader._backgroundImage._xlarge = ''; + } + }); return true; }); checkContent('Box menu - check _xlarge attribute', async (content) => { - const isValid = ( - !course._boxMenu._backgroundImage || - course._boxMenu._backgroundImage._xlarge === '' - ); + const isValid = menusWithBgImage.every(({ _boxMenu }) => ( + !_boxMenu._backgroundImage || _boxMenu._backgroundImage._xlarge === '' + )); if (!isValid) throw new Error('Box menu - course attribute _xlarge'); return true; }); checkContent('Box menu - check _xlarge attribute for _menuHeader', async (content) => { - const isValid = ( - !course._boxMenu._menuHeader?._backgroundImage || - course._boxMenu._menuHeader._backgroundImage._xlarge === '' - ); + const isValid = menusWithBgImage.every(({ _boxMenu }) => ( + !_boxMenu._menuHeader?._backgroundImage || _boxMenu._menuHeader._backgroundImage._xlarge === '' + )); if (!isValid) throw new Error('Box menu - course attribute _xlarge'); return true; }); From 427d6301ed3744ee82881f3e2df672f2e3bd48f4 Mon Sep 17 00:00:00 2001 From: Chris Steele Date: Mon, 31 Mar 2025 17:02:59 +0100 Subject: [PATCH 11/14] Rename variable --- migrations/v6.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/migrations/v6.js b/migrations/v6.js index fc947ad..cf12609 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -64,7 +64,7 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.2.0..v6.2.1 - let menusWithGraphics; + let menus; const defaultGraphic = { _src: '', alt: '' @@ -74,17 +74,17 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { whereContent('Box menu - where menus are configured', async (content) => { const candidates = [getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))]; - menusWithGraphics = candidates.filter(({ _boxMenu }) => _boxMenu); - return menusWithGraphics.length; + menus = candidates.filter(({ _boxMenu }) => _boxMenu); + return menus.length; }); mutateContent('Box menu - add _graphic attribute', async (content) => { - menusWithGraphics.forEach(({ _boxMenu }) => (_boxMenu._graphic = defaultGraphic)); + menus.forEach(({ _boxMenu }) => (_boxMenu._graphic = defaultGraphic)); return true; }); checkContent('Box menu - check _graphic attribute', async (content) => { - const isValid = menusWithGraphics.every(({ _boxMenu }) => _.isEqual(_boxMenu._graphic, defaultGraphic)); + const isValid = menus.every(({ _boxMenu }) => _.isEqual(_boxMenu._graphic, defaultGraphic)); if (!isValid) throw new Error('Box menu - course attribute _graphic'); return true; }); From f446fb215d39c69079aa5b152d2c7515d9662f0d Mon Sep 17 00:00:00 2001 From: joe-allen-89 <85872286+joe-allen-89@users.noreply.github.com> Date: Tue, 1 Apr 2025 16:06:41 +0100 Subject: [PATCH 12/14] additional tests added --- migrations/v6.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/migrations/v6.js b/migrations/v6.js index cf12609..f09c86d 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -37,7 +37,7 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.0.2' }], content: [ { _type: 'course', _boxMenu: { _menuHeader: {} } }, - { _type: 'contentObject', _boxMenu: { _menuHeader: {} } } + { _type: 'menu', _boxMenu: { _menuHeader: {} } } ] }); @@ -93,13 +93,17 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { testSuccessWhere('boxMenu with course _boxMenu', { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.2.0' }], - content: [ { _type: 'course', _boxMenu: {} }] + content: [ + { _type: 'course', _boxMenu: {} }, + { _type: 'menu', _boxMenu: {} } + ] }); testStopWhere('boxMenu with empty course', { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.2.0' }], content: [ - { _type: 'course' } + { _type: 'course' }, + { _type: 'menu' } ] }); @@ -163,12 +167,18 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { testSuccessWhere('boxMenu with course._boxMenu._backgroundImage', { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], - content: [ { _type: 'course', _boxMenu: { _backgroundImage: {} } }] + content: [ + { _type: 'course', _boxMenu: { _backgroundImage: {} } }, + { _type: 'menu', _boxMenu: { _backgroundImage: {} } } + ] }); testSuccessWhere('boxMenu with course._boxMenu._menuHeader._backgroundImage', { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], - content: [ { _type: 'course', _boxMenu: { _menuHeader: { _backgroundImage: {} } } }] + content: [ + { _type: 'course', _boxMenu: { _menuHeader: { _backgroundImage: {} } } }, + { _type: 'menu', _boxMenu: { _menuHeader: { _backgroundImage: {} } } } + ] }); testStopWhere('boxMenu with empty course', { From 6c6eae0075f4a39480ca4be6f23ec7ec4b12140e Mon Sep 17 00:00:00 2001 From: joe-allen-89 <85872286+joe-allen-89@users.noreply.github.com> Date: Fri, 4 Apr 2025 10:21:07 +0100 Subject: [PATCH 13/14] nested ifs replaced with return early --- migrations/v6.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/migrations/v6.js b/migrations/v6.js index f09c86d..b8aaf59 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -33,7 +33,7 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { updatePlugin('Box menu - update to v6.1.0', { name: 'adapt-contrib-boxMenu', version: '6.1.0', framework: '">=5.22.6' }); - testSuccessWhere('boxMenu with course _boxMenu._menuHeader', { + testSuccessWhere('boxMenu with course/menu _boxMenu._menuHeader', { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.0.2' }], content: [ { _type: 'course', _boxMenu: { _menuHeader: {} } }, @@ -131,18 +131,16 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { mutateContent('Box menu - add _xlarge attribute', async (content) => { menusWithBgImage.forEach(({ _boxMenu }) => { - if (_.has(_boxMenu, '_backgroundImage')) { - _boxMenu._backgroundImage._xlarge = ''; - } + if (!_.has(_boxMenu, '_backgroundImage')) return true; + _boxMenu._backgroundImage._xlarge = ''; }); return true; }); mutateContent('Box menu - add _xlarge attribute to _menuHeader', async (content) => { menusWithBgImage.forEach(({ _boxMenu }) => { - if (_.has(_boxMenu, '_menuHeader._backgroundImage')) { - _boxMenu._menuHeader._backgroundImage._xlarge = ''; - } + if (!_.has(_boxMenu, '_menuHeader._backgroundImage')) return true; + _boxMenu._menuHeader._backgroundImage._xlarge = ''; }); return true; }); From f5d8ec4d13405148333c301779bfd9932c27362d Mon Sep 17 00:00:00 2001 From: joe-allen-89 <85872286+joe-allen-89@users.noreply.github.com> Date: Fri, 4 Apr 2025 13:48:16 +0100 Subject: [PATCH 14/14] simplified menu check as per review --- migrations/v6.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/migrations/v6.js b/migrations/v6.js index b8aaf59..cb16db9 100644 --- a/migrations/v6.js +++ b/migrations/v6.js @@ -1,6 +1,12 @@ import { describe, getCourse, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, testStopWhere, testSuccessWhere } from 'adapt-migrations'; import _ from 'lodash'; +function getBoxMenus(content) { + return content.filter(({ _type, _component }) => + (_type === 'menu' || _type === 'course') && + (!_component || _component === 'boxMenu')); +} + describe('Box menu - v6.0.2 to v6.1.0', async () => { // https://github.com/adaptlearning/adapt-contrib-boxMenu/compare/v6.0.2..v6.1.0 @@ -15,8 +21,7 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { whereFromPlugin('Box menu - from v6.0.2', { name: 'adapt-contrib-boxMenu', version: '<6.1.0' }); whereContent('Box menu - where menus have _menuHeader', async (content) => { - const candidates = [getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))]; - menusWithHeaders = candidates.filter(({ _boxMenu }) => _boxMenu?._menuHeader); + menusWithHeaders = getBoxMenus(content).filter(({ _boxMenu }) => _boxMenu?._menuHeader); return menusWithHeaders.length; }); @@ -37,7 +42,8 @@ describe('Box menu - v6.0.2 to v6.1.0', async () => { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.0.2' }], content: [ { _type: 'course', _boxMenu: { _menuHeader: {} } }, - { _type: 'menu', _boxMenu: { _menuHeader: {} } } + { _type: 'menu', _boxMenu: { _menuHeader: {} } }, + { _type: 'menu', _boxMenu: { } } ] }); @@ -73,8 +79,7 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { whereFromPlugin('Box menu - from v6.2.0', { name: 'adapt-contrib-boxMenu', version: '<6.2.1' }); whereContent('Box menu - where menus are configured', async (content) => { - const candidates = [getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))]; - menus = candidates.filter(({ _boxMenu }) => _boxMenu); + menus = getBoxMenus(content).filter(({ _boxMenu }) => _boxMenu); return menus.length; }); @@ -95,7 +100,8 @@ describe('Box menu - v6.2.0 to v6.2.1', async () => { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.2.0' }], content: [ { _type: 'course', _boxMenu: {} }, - { _type: 'menu', _boxMenu: {} } + { _type: 'menu', _boxMenu: {} }, + { _type: 'menu' } ] }); @@ -121,8 +127,7 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { whereFromPlugin('Box menu - from v6.3.8', { name: 'adapt-contrib-boxMenu', version: '<6.3.9' }); whereContent('Box menu - where menus have _backgroundImage', async (content) => { - const candidates = [getCourse(), ...content.filter(({ _type, _component }) => _type === 'menu' && (!_component || _component === 'boxMenu'))]; - menusWithBgImage = candidates.filter(({ _boxMenu }) => ( + menusWithBgImage = getBoxMenus(content).filter(({ _boxMenu }) => ( _boxMenu?._backgroundImage || _boxMenu?._menuHeader?._backgroundImage )); @@ -167,7 +172,8 @@ describe('Box menu - v6.3.8 to v6.3.9', async () => { fromPlugins: [{ name: 'adapt-contrib-boxMenu', version: '6.3.8' }], content: [ { _type: 'course', _boxMenu: { _backgroundImage: {} } }, - { _type: 'menu', _boxMenu: { _backgroundImage: {} } } + { _type: 'menu', _boxMenu: { _backgroundImage: {} } }, + { _type: 'menu', _boxMenu: {} } ] });