Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Migration scripts added to repo (fixes #318) #320

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
24 changes: 24 additions & 0 deletions migrations/v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
let narratives;

describe('Narrative - v2.0.7 to v2.0.8', async () => {
whereFromPlugin('Narrative - from v2.0.7', { name: 'adapt-contrib-narrative', version: '<2.0.7' });
whereContent('Narrative - where narratives', async (content) => {
narratives = content.filter(({ _component }) => _component === 'narrative');
if (narratives) return true;
});
mutateContent('Narrative - add ._graphic.attribution attribute', async (content) => {
narratives.forEach(item => {
item._items.forEach(_items => {
_items._graphic.attribution = '';
});
});
return true;
});
checkContent('Narrative - check ._graphic.attribution attribute', async (content) => {
const isInvalid = narratives.includes(({ attribution }) => attribution);
joe-allen-89 marked this conversation as resolved.
Show resolved Hide resolved
if (isInvalid) throw new Error('found invalid data attribute');
return true;
});
updatePlugin('Narrative - update to v2.0.8', { name: 'adapt-contrib-narrative', version: '2.0.8', framework: '>=2.0.0' });
});
41 changes: 41 additions & 0 deletions migrations/v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
let narratives, course, courseNarrativeGlobals;

describe('Narrative - v3.0.3 to v4.0.0', async () => {
whereFromPlugin('Narrative - from v3.0.3', { name: 'adapt-contrib-narrative', version: '<3.0.3' });
whereContent('Narrative - where narrative', async content => {
narratives = content.filter(({ _component }) => _component === 'narrative');
if (narratives) return true;
});
mutateContent('Narrative - add item _ariaLevel attribute', async (content) => {
narratives.forEach(item => {
item._items.forEach(_items => {
_items._ariaLevel = 0;
});
});
return true;
});
mutateContent('Narrative - modify globals ariaRegion attribute', async (content) => {
course = content.filter(({ _type }) => _type === 'course');
courseNarrativeGlobals = course?._globals?._components?._narrative;
if (courseNarrativeGlobals) {
courseNarrativeGlobals.ariaRegion = 'Narrative. Select the next button to progress.';
}
return true;
});
checkContent('Narrative - check globals ariaRegion attribute', async (content) => {
if (courseNarrativeGlobals) {
const isValid = courseNarrativeGlobals.filter(({ ariaRegion }) => ariaRegion === 'Narrative. Select the next button to progress.');
console.log(isValid);
if (!isValid) throw new Error('Narrative - ariaRegion attribute missing');
}
return true;
});
checkContent('Narrative - check item _ariaLevel', async (content) => {
console.log(narratives);
const isValid = narratives.filter(({ _ariaLevel }) => _ariaLevel === 0);
if (!isValid) throw new Error('Narrative - _ariaLevel attribute missing');
return true;
});
updatePlugin('Narrative - update to v4.0.0', { name: 'adapt-contrib-narrative', version: '4.0.0', framework: '>=4.0.0' });
});
57 changes: 57 additions & 0 deletions migrations/v6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
let narratives, course, courseNarrativeGlobals;

describe('Narrative - v6.1.0 to v6.2.0', async () => {
whereFromPlugin('Narrative - from v6.1.0', { name: 'adapt-contrib-narrative', version: '<6.1.0' });
whereContent('Narrative - where narrative globals', async (content) => {
course = content.filter(({ _type }) => _type === 'course');
courseNarrativeGlobals = course?._globals?._components?._narrative;
if (courseNarrativeGlobals) return true;
});
mutateContent('Narrative - add previous globals', async (content) => {
courseNarrativeGlobals.previous = '{{#if title}}Back to {{title}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}}';
return true;
});
mutateContent('Narrative - add next globals', async (content) => {
courseNarrativeGlobals.next = '{{#if title}}Forward to {{title}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}}';
return true;
});
checkContent('Narrative - check narrative globals previous', async (content) => {
const isValid = courseNarrativeGlobals.includes(({ previous }) => previous);
if (!isValid) throw new Error('Narrative globals previous missing');
return true;
});
checkContent('Narrative - check narrative globals next', async (content) => {
const isValid = courseNarrativeGlobals.includes(({ next }) => next);
if (!isValid) throw new Error('Narrative globals next missing');
return true;
});
updatePlugin('Narrative - update to v6.2.0', { name: 'adapt-contrib-narrative', version: '6.2.0', framework: '>=5.5.0' });
});

describe('Narrative - v6.3.0 to v6.4.0', async () => {
whereFromPlugin('Narrative - from v6.3.0', { name: 'adapt-contrib-narrative', version: '<6.3.0' });
whereContent('Narrative - where narrative', async (content) => {
narratives = content.filter(({ _component }) => _component === 'narrative');
if (narratives) return true;
});
mutateContent('Narrative - add _isTextBelowImage attribute', async (content) => {
narratives.forEach(item => (item._isTextBelowImage = false));
return true;
});
mutateContent('Narrative - add _isMobileTextBelowImage attribute', async (content) => {
narratives.forEach(item => (item._isMobileTextBelowImage = false));
return true;
});
checkContent('Narrative - check _isTextBelowImage attribute', async (content) => {
const isValid = narratives.some((narrative) => narrative._isTextBelowImage === false);
if (!isValid) throw new Error('found invalid _isTextBelowImage attribute');
return true;
});
checkContent('Narrative - check _isMobileTextBelowImage attribute', async (content) => {
const isValid = narratives.some((narrative) => narrative._isMobileTextBelowImage === false);
if (!isValid) throw new Error('found invalid _isMobileTextBelowImage attribute');
return true;
});
updatePlugin('Narrative - update to v6.4.0', { name: 'adapt-contrib-narrative', version: '6.4.0', framework: '>=5.8.0' });
});
114 changes: 114 additions & 0 deletions migrations/v7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
let narratives;

describe('Narrative - v7.3.1 to v7.4.0', async () => {
whereFromPlugin('Narrative - from v7.3.1', { name: 'adapt-contrib-narrative', version: '<7.3.1' });
whereContent('Narrative - where narrative', async (content) => {
narratives = content.filter(({ _component }) => _component === 'narrative');
if (narratives) return true;
});
mutateContent('Narrative - update default instruction text', async (content) => {
narratives.forEach(item => {
if (item.instruction === 'Select the forward arrows to move through the narrative on a desktop, or swipe the images and select the plus icons to do so on mobile.') {
item.instruction = 'Select the next and back arrows to find out more.';
}
});
return true;
});
mutateContent('Narrative - update default mobile instruction text', async (content) => {
narratives.forEach(item => {
if (item.mobileInstruction === 'This is optional instruction text that will be shown when viewed on mobile.') {
item.mobileInstruction = 'Select the plus icon followed by the next arrow to find out more.';
}
});
return true;
});
checkContent('Narrative - check default instruction text', async (content) => {
const isInvalid = narratives.some(({ instruction }) => instruction === 'Select the forward arrows to move through the narrative on a desktop, or swipe the images and select the plus icons to do so on mobile.');
if (isInvalid) throw new Error('Narrative - default instruction is invalid');
return true;
});
checkContent('Narrative - check default mobileInstruction text', async (content) => {
const isInvalid = narratives.some(({ mobileInstruction }) => mobileInstruction === 'This is optional instruction text that will be shown when viewed on mobile.');
if (isInvalid) throw new Error('Narrative - default mobile instruction is invalid');
return true;
});
updatePlugin('Narrative - update to v7.4.0', { name: 'adapt-contrib-narrative', version: '7.4.0', framework: '>=5.20.1' });
});

describe('Narrative - v7.4.10 to v7.4.11', async () => {
whereFromPlugin('Narrative - from v7.4.10', { name: 'adapt-contrib-narrative', version: '<7.4.10' });
whereContent('Narrative - where narrative', async (content) => {
narratives = content.filter(({ _component }) => _component === 'narrative');
if (narratives) return true;
});
mutateContent('Narrative - add _isStackedOnMobile attribute', async (content) => {
narratives.forEach(item => {
item._isStackedOnMobile = false;
});
return true;
});
checkContent('Narrative - check _isStackedOnMobile attribute', async (content) => {
const isInvalid = narratives.some(({ _isStackedOnMobile }) => _isStackedOnMobile);
if (isInvalid) throw new Error('Narrative - _isStackedOnMobile is invalid');
return true;
});
updatePlugin('Narrative - update to v7.4.11', { name: 'adapt-contrib-narrative', version: '7.4.11', framework: '>=5.31.2' });
});

describe('Narrative - v7.4.13 to v7.5.0', async () => {
whereFromPlugin('Narrative - from v7.4.13', { name: 'adapt-contrib-narrative', version: '<7.4.13' });
whereContent('Narrative - where narrative', async (content) => {
narratives = content.filter(({ _component }) => _component === 'narrative');
if (narratives) return true;
});
mutateContent('Narrative - remove _ariaLevel override attribute', async (content) => {
narratives.forEach(narrative => {
const narrativeItems = narrative._items.filter((item) => item._ariaLevel);
narrativeItems.forEach((item) => {
delete item._ariaLevel;
});
});
return true;
});
checkContent('Narrative - check _isStackedOnMobile attribute', async (content) => {
const isInvalid = narratives.some((narrative) => narrative._items._ariaLevel);
if (isInvalid) throw new Error('Narrative - _isStackedOnMobile is invalid');
return true;
});
updatePlugin('Narrative - update to v7.5.0', { name: 'adapt-contrib-narrative', version: '7.5.0', framework: '>=5.31.2' });
});

describe('Narrative - v7.7.1 to v7.8.0', async () => {
const originalPreviousMsg = '{{#if title}}Back to {{{title}}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}}';
const originalNextMsg = '{{#if title}}Forward to {{{title}}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}}';
let course, courseNarrativeGlobals;
whereFromPlugin('Narrative - from v7.7.1', { name: 'adapt-contrib-narrative', version: '<7.7.1' });
whereContent('Narrative - where narrative', async (content) => {
course = content.filter(({ _type }) => _type === 'course');
courseNarrativeGlobals = course?._globals?._components?._narrative;

if (courseNarrativeGlobals?.previous || courseNarrativeGlobals?.next) return true;
});
mutateContent('Narrative - update global previous text', async (content) => {
if (courseNarrativeGlobals.previous === originalPreviousMsg) courseNarrativeGlobals.previous = '{{#if title}}Back to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}} (item {{itemNumber}} of {{totalItems}})';

return true;
});
mutateContent('Narrative - update global next text', async (content) => {
if (courseNarrativeGlobals.next === originalNextMsg) courseNarrativeGlobals.next = '{{#if title}}Forward to {{{title}}}{{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}} (item {{itemNumber}} of {{totalItems}})';

return true;
});
checkContent('Narrative - check global previous text', async (content) => {
const isInvalid = courseNarrativeGlobals.previous === originalPreviousMsg;
if (isInvalid) throw new Error('Narrative - global narrative previous text is invalid');
return true;
});
checkContent('Narrative - check global next text', async (content) => {
const isInvalid = courseNarrativeGlobals.next === originalNextMsg;
if (isInvalid) throw new Error('Narrative - global narrative next text is invalid');
return true;
});
updatePlugin('Narrative - update to v7.8.0', { name: 'adapt-contrib-narrative', version: '7.9.3', framework: '>=5.31.2' });
});