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 #163) #165

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions migrations/v3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
import _ from 'lodash';

describe('Hot Grid - v2.1.3 to v3.0.0', async () => {
let hotgrids, course, courseHotgridGlobals;
const previousAriaRegion = 'This component contains selectable grid items. Select an item to trigger a popup that includes an image with display text. Select the close button to close the popup.';
const newAriaRegion = 'Selectable image component. Select each item to show more information.';
whereFromPlugin('Hot Grid - from v2.1.3', { name: 'adapt-hotgrid', version: '<3.0.0' });
whereContent('Hot Grid - where hotgrid', async content => {
hotgrids = content.filter(({ _component }) => _component === 'hotgrid');
return hotgrids.length;
});
mutateContent('Hot Grid - add globals if missing', async (content) => {
course = content.find(({ _type }) => _type === 'course');
if (!_.has(course, '_globals._components._hotgrid')) _.set(course, '_globals._components._hotgrid', {});
courseHotgridGlobals = course._globals._components._hotgrid;
return true;
});
mutateContent('Hot Grid - add globals popupPagination attribute', async content => {
courseHotgridGlobals.popupPagination = '{{itemNumber}} / {{totalItems}}';
return true;
});
mutateContent('Hot Grid - update globals ariaRegion', async content => {
if (courseHotgridGlobals.ariaRegion === previousAriaRegion) courseHotgridGlobals.ariaRegion = newAriaRegion;
return true;
});
mutateContent('Hot Grid - add _hidePagination', async (content) => {
hotgrids.forEach(hotgrid => (hotgrid._hidePagination = false));
return true;
});
mutateContent('Hot Grid - add _canCycleThroughPagination', async (content) => {
hotgrids.forEach(hotgrid => (hotgrid._canCycleThroughPagination = false));
return true;
});
checkContent('Hot Grid - check globals _hotgrid attribute', async content => {
if (courseHotgridGlobals === undefined) throw new Error('Hot Grid - globals _hotgrid invalid');
return true;
});
checkContent('Hot Grid - check globals popupPagination attribute', async content => {
const isValid = courseHotgridGlobals?.popupPagination === '{{itemNumber}} / {{totalItems}}';
if (!isValid) throw new Error('Hot Grid - globals popupPagination invalid');
return true;
});
checkContent('Hot Grid - check globals ariaRegion attribute', async content => {
const isValid = courseHotgridGlobals?.ariaRegion === newAriaRegion;
if (!isValid) throw new Error('Hot Grid - globals ariaRegion invalid');
return true;
});
checkContent('Hot Grid - check _hidePagination attribute', async content => {
const isValid = hotgrids.every(hotgrid => (hotgrid._hidePagination === false));
if (!isValid) throw new Error('Hot Grid - _hidePagination invalid');
return true;
});
checkContent('Hot Grid - check _canCycleThroughPagination attribute', async content => {
const isValid = hotgrids.every(hotgrid => (hotgrid._canCycleThroughPagination === false));
if (!isValid) throw new Error('Hot Grid - _canCycleThroughPagination invalid');
return true;
});
updatePlugin('Hot Grid - update to v3.0.0', { name: 'adapt-contrib-hotgrid', version: '3.0.0', framework: '>=3.2.0' });
});

describe('Hot Grid - v3.0.0 to v3.1.0', async () => {
let hotgrids;
whereFromPlugin('Hot Grid - from v3.0.0', { name: 'adapt-hotgrid', version: '<3.1.0' });
whereContent('Hot Grid - where hotgrid', async content => {
hotgrids = content.filter(({ _component }) => _component === 'hotgrid');
return hotgrids.length;
});
mutateContent('Hot Grid - update _supportedLayout', async (content) => {
hotgrids.forEach(hotgrid => {
if (hotgrid._supportedLayout === 'half-width') hotgrid._supportedLayout = 'full-width';
});
return true;
});
mutateContent('Hot Grid - add attribution to _itemGraphic', async (content) => {
hotgrids.forEach(({ _items }) => {
_items.forEach(({ _itemGraphic }) => { _.set(_itemGraphic, 'attribution', ''); });
});
return true;
});
checkContent('Hot Grid - check _supportedLayout attribute', async content => {
const isValid = hotgrids.every(hotgrid => (hotgrid._supportedLayout !== 'half-width'));
if (!isValid) throw new Error('Hot Grid - _supportedLayout invalid');
return true;
});
checkContent('Hot Grid - check _itemGraphic attribution', async content => {
const isValid = hotgrids.every(({ _items }) => {
return _items.every(item => item._itemGraphic?.attribution !== undefined);
});
if (!isValid) throw new Error('Hot Grid - _itemGraphic attribution invalid');
return true;
});
updatePlugin('Hot Grid - update to v3.1.0', { name: 'adapt-contrib-hotgrid', version: '3.1.0', framework: '>=3.2.0' });
});

describe('Hot Grid - v3.1.0 to v3.2.0', async () => {
let hotgrids;
whereFromPlugin('Hot Grid - from v3.1.0', { name: 'adapt-hotgrid', version: '<3.2.0' });
whereContent('Hot Grid - where hotgrid', async content => {
hotgrids = content.filter(({ _component }) => _component === 'hotgrid');
return hotgrids.length;
});
mutateContent('Hot Grid - add _setCompletionOn', async (content) => {
hotgrids.forEach(hotgrid => (hotgrid._setCompletionOn = 'allItems'));
return true;
});
checkContent('Hot Grid - check _setCompletionOn attribute', async content => {
const isValid = hotgrids.every(hotgrid => (hotgrid._setCompletionOn === 'allItems'));
if (!isValid) throw new Error('Hot Grid - _setCompletionOn invalid');
return true;
});
updatePlugin('Hot Grid - update to v3.2.0', { name: 'adapt-contrib-hotgrid', version: '3.2.0', framework: '>=3.3.0' });
});
127 changes: 127 additions & 0 deletions migrations/v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';

describe('Hot Grid - v3.2.0 to v4.0.0', async () => {
let hotgrids;
whereFromPlugin('Hot Grid - from v3.2.0', { name: 'adapt-hotgrid', version: '<4.0.0' });
whereContent('Hot Grid - where hotgrid', async content => {
hotgrids = content.filter(({ _component }) => _component === 'hotgrid');
return hotgrids.length;
});
mutateContent('Hot Grid - add _isRound attribute', async (content) => {
hotgrids.forEach(hotgrid => (hotgrid._isRound = false));
return true;
});
mutateContent('Hot Grid - add item _classes attribute', async (content) => {
hotgrids.forEach(({ _items }) => (_items.forEach(item => (item._classes = ''))));
return true;
});
checkContent('Hot Grid - check _isRound attribute', async content => {
const isValid = hotgrids.every(hotgrid => (hotgrid._isRound === false));
if (!isValid) throw new Error('Hot Grid - _isRound invalid');
return true;
});
checkContent('Hot Grid - check item _classes', async content => {
const isValid = hotgrids.every(({ _items }) => _items.every(item => item._classes !== undefined));
if (!isValid) throw new Error('Hot Grid - item _classes invalid');
return true;
});
updatePlugin('Hot Grid - update to v4.0.0', { name: 'adapt-contrib-hotgrid', version: '4.0.0', framework: '>=5.0.0' });
});

describe('Hot Grid - v4.0.0 to v4.3.0', async () => {
let hotgrids;
whereFromPlugin('Hot Grid - from v4.0.0', { name: 'adapt-hotgrid', version: '<4.3.0' });
whereContent('Hot Grid - where hotgrid', async content => {
hotgrids = content.filter(({ _component }) => _component === 'hotgrid');
return hotgrids.length;
});
mutateContent('Hot Grid - add item _imageAlignment attribute', async (content) => {
hotgrids.forEach(({ _items }) => (_items.forEach(item => (item._imageAlignment = 'right'))));
return true;
});
checkContent('Hot Grid - check item _imageAlignment', async content => {
const isValid = hotgrids.every(({ _items }) => _items.every(item => item._imageAlignment === 'right'));
if (!isValid) throw new Error('Hot Grid - item _imageAlignment invalid');
return true;
});
updatePlugin('Hot Grid - update to v4.3.0', { name: 'adapt-contrib-hotgrid', version: '4.3.0', framework: '>=5.22.4' });
});

describe('Hot Grid - v4.3.0 to v4.3.2', async () => {
let hotgrids, course, courseHotgridGlobals;
whereFromPlugin('Hot Grid - from v4.3.0', { name: 'adapt-hotgrid', version: '<4.3.2' });
whereContent('Hot Grid - where hotgrid', async content => {
hotgrids = content.filter(({ _component }) => _component === 'hotgrid');
return hotgrids.length;
});
mutateContent('Hot Grid - add globals item attribute', async content => {
course = content.find(({ _type }) => _type === 'course');
courseHotgridGlobals = course._globals._components._hotgrid;
courseHotgridGlobals.item = 'Item';
return true;
});
mutateContent('Hot Grid - add globals previous attribute', async content => {
courseHotgridGlobals.previous = '{{#if title}}Back to {{{title}}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}}';
return true;
});
mutateContent('Hot Grid - add globals next attribute', async content => {
courseHotgridGlobals.next = '{{#if title}}Forward to {{{title}}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}}';
return true;
});
checkContent('Hot Grid - check globals item', async content => {
const isValid = courseHotgridGlobals.item === 'Item';
if (!isValid) throw new Error('Hot Grid - globals item invalid');
return true;
});
checkContent('Hot Grid - check globals previous', async content => {
const isValid = courseHotgridGlobals.previous === '{{#if title}}Back to {{{title}}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.previous}}{{/if}}';
if (!isValid) throw new Error('Hot Grid - globals previous invalid');
return true;
});
checkContent('Hot Grid - check globals next', async content => {
const isValid = courseHotgridGlobals.next === '{{#if title}}Forward to {{{title}}} (item {{itemNumber}} of {{totalItems}}){{else}}{{_globals._accessibility._ariaLabels.next}}{{/if}}';
if (!isValid) throw new Error('Hot Grid - globals next invalid');
return true;
});
updatePlugin('Hot Grid - update to v4.3.2', { name: 'adapt-contrib-hotgrid', version: '4.3.2', framework: '>=5.22.4' });
});

describe('Hot Grid - v4.3.2 to v4.3.14', async () => {
let hotgrids;
whereFromPlugin('Hot Grid - from v4.3.2', { name: 'adapt-hotgrid', version: '<4.3.14' });
whereContent('Hot Grid - where hotgrid', async content => {
hotgrids = content.filter(({ _component }) => _component === 'hotgrid');
return hotgrids.length;
});
mutateContent('Hot Grid - update instruction attribute', async (content) => {
hotgrids.forEach(hotgrid => {
if (hotgrid.instruction === '') hotgrid.instruction = 'Select the images to find out more.';
});
return true;
});
checkContent('Hot Grid - check instruction attribute', async content => {
const isValid = hotgrids.every(hotgrid => hotgrid.instruction === 'Select the images to find out more.');
if (!isValid) throw new Error('Hot Grid - instruction attribute invalid');
return true;
});
updatePlugin('Hot Grid - update to v4.3.14', { name: 'adapt-contrib-hotgrid', version: '4.3.14', framework: '>=5.31.2' });
});

describe('Hot Grid - v4.3.14 to v4.4.2', async () => {
let hotgrids;
whereFromPlugin('Hot Grid - from v4.3.14', { name: 'adapt-hotgrid', version: '<4.4.2' });
whereContent('Hot Grid - where hotgrid', async content => {
hotgrids = content.filter(({ _component }) => _component === 'hotgrid');
return hotgrids.length;
});
mutateContent('Hot Grid - add _showPlusIcon attribute', async (content) => {
hotgrids.forEach(hotgrid => (hotgrid._showPlusIcon = true));
return true;
});
checkContent('Hot Grid - check _showPlusIcon attribute', async content => {
const isValid = hotgrids.every(hotgrid => (hotgrid._showPlusIcon === true));
if (!isValid) throw new Error('Hot Grid - _showPlusIcon invalid');
return true;
});
updatePlugin('Hot Grid - update to v4.4.2', { name: 'adapt-contrib-hotgrid', version: '4.4.2', framework: '>=5.31.2' });
});