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 (fixes #158) #159

Merged
merged 40 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b84e4cf
Initial migration scripts for v1 & 2
joe-replin Jan 14, 2025
e683d55
all migration scripts for adapt-contrib-accordion
joe-replin Jan 15, 2025
4900d7e
Remove v3.js
joe-replin Jan 15, 2025
5640369
Added template comments
joe-replin Jan 17, 2025
c15d411
v2 & v4 too early for v2.4.0 of FW
joe-replin Jan 28, 2025
e4c246f
Globals Attribute
joe-replin Jan 28, 2025
c847a36
Updates to accordion migrations
joe-replin Jan 29, 2025
535198f
Chris' review
joe-replin Jan 29, 2025
b292981
Update v7.js
joe-replin Jan 29, 2025
df25a2e
Remove Comment
joe-replin Jan 29, 2025
02e9d33
Update migrations/v2.js
joe-replin Jan 30, 2025
8a7df4e
Update migrations/v2.js
joe-replin Jan 30, 2025
7cadc9a
Update migrations/v2.js
joe-replin Jan 30, 2025
cbbc778
Update migrations/v2.js
joe-replin Jan 30, 2025
f366db3
Update migrations/v2.js
joe-replin Jan 30, 2025
5a89b21
Update migrations/v2.js
joe-replin Jan 30, 2025
8c65953
Update migrations/v4.js
joe-replin Jan 30, 2025
f55a611
Update migrations/v7.js
joe-replin Jan 30, 2025
f1e082a
Update migrations/v7.js
joe-replin Jan 30, 2025
25f11d7
Update migrations/v7.js
joe-replin Jan 30, 2025
d2923be
Update migrations/v7.js
joe-replin Jan 30, 2025
e71a29a
Update migrations/v7.js
joe-replin Jan 30, 2025
3c3cdc1
Apply suggestions from code review
joe-replin Jan 30, 2025
6ebd41a
Accordion length and global lodash fix
joe-replin Jan 30, 2025
6eee52a
Update v2.js
joe-replin Jan 30, 2025
7e6e4c0
Remove migration from v1 to v2
joe-replin Feb 10, 2025
1748d4e
whereContent return adjustments
joe-replin Feb 10, 2025
56321cb
Removing comments.
joe-replin Feb 14, 2025
6be48d7
Migration Script Test
joe-replin Feb 21, 2025
1f4b734
adding helpers
joe-replin Feb 21, 2025
98ac887
auomated testing added to migrations
joe-allen-89 Mar 3, 2025
b1a3217
amends to automated tests
joe-allen-89 Mar 5, 2025
5e78c35
review amends completed
joe-allen-89 Mar 5, 2025
aa18166
correct/incorrect _supportedLayout added to test
joe-allen-89 Mar 5, 2025
d33bf6c
review amends completed
joe-allen-89 Mar 5, 2025
a8863ca
Updating conditional logic.
joe-replin Mar 10, 2025
a47a73e
Update v7.js
joe-replin Mar 10, 2025
7f90202
Amending for early return
joe-replin Mar 10, 2025
c48b29e
optional chaining added for accordion._items?.forEach
joe-allen-89 Mar 26, 2025
2548e0b
component with no items added to each test
joe-allen-89 Mar 26, 2025
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
143 changes: 143 additions & 0 deletions migrations/v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, getComponents, testStopWhere, testSuccessWhere } from 'adapt-migrations';
import _ from 'lodash';

describe('adapt-contrib-accordion - v2.0.3 > v2.0.4', async () => {
let accordions;

whereFromPlugin('adapt-contrib-accordion - from v2.0.3', { name: 'adapt-contrib-accordion', version: '>=2.0.0 <2.0.4' });

whereContent('adapt-contrib-accordion - where accordion', async content => {
accordions = getComponents('accordion');
return accordions.length;
});

mutateContent('adapt-contrib-accordion - add accordion._items._classes attribute', async () => {
accordions.forEach(accordion => {
accordion._items.forEach(item => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test with missing _items will error here.

 { _id: 'c-110', _component: 'accordion' }

Is this ok?

item._classes = '';
});
});
return true;
});

checkContent('adapt-contrib-accordion - check accordion._items._classes attribute', async () => {
const isValid = accordions.every(accordion =>
accordion._items.every(item =>
item && item._classes !== undefined
)
);
if (!isValid) throw new Error('adapt-contrib-accordion - _classes not added to every instance of accordion._items');
return true;
});

updatePlugin('adapt-contrib-accordion - update to v2.0.4', { name: 'adapt-contrib-accordion', version: '2.0.4', framework: '>=2.0.0' });

testSuccessWhere('correct version with accordion components', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.0.3' }],
content: [
{ _id: 'c-100', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _id: 'c-105', _component: 'accordion', _items: [{ title: 'item 1' }] }
]
});

testStopWhere('no accordion components', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.0.3' }],
content: [{ _component: 'other' }]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.0.4' }]
});
});

describe('adapt-contrib-accordion - v2.0.4 > v2.0.5', async () => {
let accordions;

whereFromPlugin('adapt-contrib-accordion - from v2.0.4', { name: 'adapt-contrib-accordion', version: '<2.0.5' });

whereContent('adapt-contrib-accordion - where accordion', async content => {
accordions = getComponents('accordion');
return accordions.length;
});

mutateContent('adapt-contrib-accordion - add accordion._shouldCollapseItems attribute', async () => {
accordions.forEach(accordion => {
accordion._shouldCollapseItems = true;
});
return true;
});

checkContent('adapt-contrib-accordion - check accordion._shouldCollapseItems attribute', async () => {
const isValid = accordions.every(({ _shouldCollapseItems }) => _shouldCollapseItems === true);
if (!isValid) throw new Error('adapt-contrib-accordion - _shouldCollapseItems not added to every instance of accordion and set to true.');
return true;
});

updatePlugin('adapt-contrib-accordion - update to v2.0.5', { name: 'adapt-contrib-accordion', version: '2.0.5', framework: '>=2.0.0' });

testSuccessWhere('correct version with accordion components', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.0.4' }],
content: [
{ _id: 'c-100', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _id: 'c-105', _component: 'accordion' }
]
});

testStopWhere('no accordion components', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.0.4' }],
content: [{ _component: 'other' }]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.0.5' }]
});
});

describe('adapt-contrib-accordion - v2.0.5 > v2.1.0', async () => {
let accordions;

whereFromPlugin('adapt-contrib-accordion - from v2.0.5', { name: 'adapt-contrib-accordion', version: '<2.1.0' });

whereContent('adapt-contrib-accordion - where accordion', async content => {
accordions = getComponents('accordion');
return accordions.length;
});

mutateContent('adapt-contrib-accordion - add accordion._items._graphic.attribution', async () => {
accordions.forEach(accordion => {
accordion._items.forEach(item => {
_.set(item, '_graphic.attribution', '');
});
});
return true;
});

checkContent('adapt-contrib-accordion - check accordion._items._graphic.attribution atrribute', async () => {
const isValid = accordions.every(accordion =>
accordion._items.every(item =>
item._graphic && item._graphic.attribution !== undefined
)
);
if (!isValid) throw new Error('adapt-contrib-accordion - _graphic.attribution not added to every instance of accordion._items');
return true;
});

updatePlugin('adapt-contrib-accordion - update to v2.1.0', { name: 'adapt-contrib-accordion', version: '2.1.0', framework: '>=2.0.0' });

testSuccessWhere('correct version with accordion components with/without _graphic', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.0.5' }],
content: [
{ _id: 'c-100', _component: 'accordion', _items: [{ title: 'item 1', _graphic: {} }] },
{ _id: 'c-105', _component: 'accordion', _items: [{ title: 'item 1' }] }
]
});

testStopWhere('no accordion components', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.0.5' }],
content: [{ _component: 'other' }]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.1.0' }]
});
});
82 changes: 82 additions & 0 deletions migrations/v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, getCourse, getComponents, testStopWhere, testSuccessWhere } from 'adapt-migrations';
import _ from 'lodash';

describe('adapt-contrib-accordion - v2.1.0 > v4.0.0', async () => {

let course, courseAccordionGlobals, accordions;
const oldAriaRegion = 'This component requires you to answer the question by selecting the relevant value. After selecting a value select the submit button below.';

whereFromPlugin('adapt-contrib-accordion - from v2.1.0', { name: 'adapt-contrib-accordion', version: '<4.0.0' });

whereContent('adapt-contrib-accordion - where accordion', async content => {
accordions = getComponents('accordion');
return accordions.length;
});

mutateContent('adapt-contrib-accordion - modify globals ariaRegion attribute', async (content) => {
course = getCourse();
if (!_.has(course, '_globals._components._accordion')) _.set(course, '_globals._components._accordion', { ariaRegion: oldAriaRegion });
courseAccordionGlobals = course._globals._components._accordion;
if (courseAccordionGlobals.ariaRegion === oldAriaRegion) {
courseAccordionGlobals.ariaRegion = 'Accordion. Select each button to expand the content.';
}
return true;
});

mutateContent('adapt-contrib-accordion - add accordion._setCompletionOn and set attribute', async () => {
accordions.forEach(accordion => {
accordion._setCompletionOn = 'allItems';
});
return true;
});

checkContent('adapt-contrib-accordion - modify globals ariaRegion attribute', async (content) => {
const isValid = courseAccordionGlobals.ariaRegion !== oldAriaRegion;
if (!isValid) throw new Error('Accordion globals ariaRegion attribute not modified.');
return true;
});

checkContent('adapt-contrib-accordion - check accordion._setCompletionOn attribute', async () => {
const isValid = accordions.every(({ _setCompletionOn }) => _setCompletionOn === 'allItems');
if (!isValid) throw new Error('adapt-contrib-accordion - _setCompletionOn not added to every instance of accordion and set to "allItems"');
return true;
});

updatePlugin('adapt-contrib-accordion - update to v4.0.0', { name: 'adapt-contrib-accordion', version: '4.0.0', framework: '>=3.3.0' });

testSuccessWhere('correct version with accordion components and empty course', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.1.0' }],
content: [
{ _id: 'c-100', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _id: 'c-105', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _type: 'course' }
]
});

testSuccessWhere('correct version with accordion components and course globals', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.1.0' }],
content: [
{ _id: 'c-100', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _id: 'c-105', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _type: 'course', _globals: { _components: { _accordion: {} } } }
]
});

testSuccessWhere('correct version with accordion components and custom course globals', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.1.0' }],
content: [
{ _id: 'c-100', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _id: 'c-105', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _type: 'course', _globals: { _components: { _accordion: { ariaRegion: 'custom aria region' } } } }
]
});

testStopWhere('no accordion components', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.1.0' }],
content: [{ _component: 'other' }]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '4.0.0' }]
});
});
128 changes: 128 additions & 0 deletions migrations/v5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, getCourse, getComponents, testStopWhere, testSuccessWhere } from 'adapt-migrations';
import _ from 'lodash';

describe('adapt-contrib-accordion - v4.0.0 > v5.0.0', async () => {
let course, courseAccordionGlobals, accordions;
const originalAriaRegion = 'Accordion. Select each button to expand the content.';
const newAriaRegion = 'List of expandable sections. Select each button to expand the content.';

whereFromPlugin('adapt-contrib-accordion - from v4.0.0', { name: 'adapt-contrib-accordion', version: '<5.0.0' });

whereContent('adapt-contrib-accordion - where accordion', async content => {
accordions = getComponents('accordion');
return accordions.length;
});

mutateContent('adapt-contrib-accordion - modify globals ariaRegion attribute', async (content) => {
course = getCourse();
if (!_.has(course, '_globals._components._accordion.ariaRegion')) _.set(course, '_globals._components._accordion', { ariaRegion: originalAriaRegion });
courseAccordionGlobals = course._globals._components._accordion;
if (courseAccordionGlobals.ariaRegion === originalAriaRegion) {
courseAccordionGlobals.ariaRegion = newAriaRegion;
}
return true;
});

mutateContent('adapt-contrib-accordion - update accordion._supportedLayout attribute to full-width if current isn\'t a supported value.', async () => {
accordions.forEach(accordion => {
if (accordion._supportedLayout !== 'full-width' || accordion._supportedLayout !== 'half-width' || accordion._supportedLayout !== 'both') {
accordion._supportedLayout = 'full-width';
}
});
return true;
});

checkContent('adapt-contrib-accordion - modify globals ariaRegion attribute', async (content) => {
const isValid = courseAccordionGlobals.ariaRegion !== originalAriaRegion;
if (!isValid) throw new Error('adapt-contrib-accordion - globals ariaRegion attribute not modified.');
return true;
});

checkContent('adapt-contrib-accordion - check accordion._supportedLayout attribute is now full-width', async () => {
const isValid = accordions.every(({ _supportedLayout }) => _supportedLayout === 'full-width' || _supportedLayout === 'half-width' || _supportedLayout === 'both');
if (!isValid) throw new Error('adapt-contrib-accordion - _supportedLayout attribute has not been modified to a supported value.');
return true;
});

updatePlugin('adapt-contrib-accordion - update to v5.0.0', { name: 'adapt-contrib-accordion', version: '5.0.0', framework: '>=5.0.0' });

testSuccessWhere('correct version with accordion components and empty course', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.1.0' }],
content: [
{ _id: 'c-100', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _id: 'c-105', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _type: 'course' }
]
});

testSuccessWhere('correct version with accordion components and course globals', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.1.0' }],
content: [
{ _id: 'c-100', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _id: 'c-105', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _type: 'course', _globals: { _components: { _accordion: {} } } }
]
});

testSuccessWhere('correct version with accordion components and custom course globals', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.1.0' }],
content: [
{ _id: 'c-100', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _id: 'c-105', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _type: 'course', _globals: { _components: { _accordion: { ariaRegion: 'custom aria region' } } } }
]
});

testStopWhere('no accordion components', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '2.1.0' }],
content: [{ _component: 'other' }]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '4.0.0' }]
});
});

describe('adapt-contrib-accordion - v5.0.0 > v5.3.0', async () => {
let accordions;

whereFromPlugin('adapt-contrib-accordion - from v5.0.0', { name: 'adapt-contrib-accordion', version: '<5.3.0' });

whereContent('adapt-contrib-accordion - where accordion', async content => {
accordions = getComponents('accordion');
return accordions.length;
});

mutateContent('adapt-contrib-accordion - add accordion._shouldExpandFirstItem', async () => {
accordions.forEach(accordion => {
accordion._shouldExpandFirstItem = false;
});
return true;
});

checkContent('adapt-contrib-accordion - check accordion._shouldExpandFirstItem atrribute', async () => {
const isValid = accordions.every(({ _shouldExpandFirstItem }) => _shouldExpandFirstItem === false);
if (!isValid) throw new Error('adapt-contrib-accordion - _shouldExpandFirstItem not added to every instance of accordion');
return true;
});

updatePlugin('adapt-contrib-accordion - update to v5.3.0', { name: 'adapt-contrib-accordion', version: '5.3.0', framework: '>=5.8.0' });

testSuccessWhere('correct version with accordion components and empty course', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '5.0.0' }],
content: [
{ _id: 'c-100', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _id: 'c-105', _component: 'accordion', _items: [{ title: 'item 1' }] },
{ _type: 'course' }
]
});

testStopWhere('no accordion components', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '5.0.0' }],
content: [{ _component: 'other' }]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-contrib-accordion', version: '5.3.0' }]
});
});
Loading