Skip to content

Commit b84e4cf

Browse files
committed
Initial migration scripts for v1 & 2
1 parent af30545 commit b84e4cf

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

migrations/v1.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
2+
3+
describe('adapt-contrib-accordion - v1.0.0 > v1.1.0', async () => {
4+
let accordions;
5+
6+
whereFromPlugin('adapt-contrib-accordion - from v1', { name: 'adapt-contrib-accordion', version: '<=1.1' });
7+
8+
whereContent('adapt-contrib-accordion - where accordion', async content => {
9+
accordions = content.filter(({ _component }) => _component === 'accordion');
10+
if (accordions) return true;
11+
});
12+
13+
mutateContent('adapt-contrib-accordion - update accordion.items attribute with accordion._items', async () => {
14+
accordions.forEach(accordion => {
15+
if (accordion.items) {
16+
accordion.items = accordion._items;
17+
}
18+
});
19+
return true;
20+
});
21+
22+
checkContent('adapt-contrib-accordion - check accordion._items atrribute', async () => {
23+
const isValid = accordions.every(({ items, _items }) => items === _items);
24+
if (!isValid) throw new Error('adapt-contrib-accordion - accordion.items not updated to accordion._items');
25+
return true;
26+
});
27+
28+
updatePlugin('adapt-contrib-accordion - update to v1.1.0', { name: 'adapt-contrib-accordion', version: '1.1.0', framework: '1.1.0' });
29+
});

migrations/v2.js

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations';
2+
3+
/**
4+
* Should we be adding changes to course aria attributes? - https://github.com/adaptlearning/adapt-contrib-accordion/commit/6dca48baf740d7117ab987378ce4270c8580395b
5+
*/
6+
describe('adapt-contrib-accordion - v1.0.0 > v2.0.0', async () => {
7+
let accordions;
8+
9+
whereFromPlugin('adapt-contrib-accordion - from v1', { name: 'adapt-contrib-accordion', version: '<=2.0.0' });
10+
11+
whereContent('adapt-contrib-accordion - where accordion', async content => {
12+
accordions = content.filter(({ _component }) => _component === 'accordion');
13+
if (accordions) return true;
14+
});
15+
16+
mutateContent('adapt-contrib-accordion - add accordion._supportedLayout', async () => {
17+
accordions.forEach(accordion => {
18+
accordion._supportedLayout = 'half-width';
19+
});
20+
return true;
21+
});
22+
23+
checkContent('adapt-contrib-accordion - check accordion._supportedLayout atrribute', async () => {
24+
const isValid = accordions.every(({ _supportedLayout }) => _supportedLayout !== undefined);
25+
if (!isValid) throw new Error('adapt-contrib-accordion - _supportedLayout not added to every instance of accordion');
26+
return true;
27+
});
28+
29+
// Is another whereContent needed if it is the same as the first call?
30+
whereContent('adapt-contrib-accordion - where accordion', async content => {
31+
accordions = content.filter(({ _component }) => _component === 'accordion');
32+
if (accordions) return true;
33+
});
34+
35+
mutateContent('adapt-contrib-accordion - add accordion.instruction', async () => {
36+
accordions.forEach(accordion => {
37+
accordion.instruction = '';
38+
});
39+
return true;
40+
});
41+
42+
checkContent('adapt-contrib-accordion - check accordion.instruction atrribute', async () => {
43+
const isValid = accordions.every(({ instruction }) => instruction !== undefined);
44+
if (!isValid) throw new Error('adapt-contrib-accordion - instruction not added to every instance of accordion');
45+
return true;
46+
});
47+
48+
// Is another whereContent needed if it is the same as the first call?
49+
whereContent('adapt-contrib-accordion - where accordion', async content => {
50+
accordions = content.filter(({ _component }) => _component === 'accordion');
51+
if (accordions) return true;
52+
});
53+
54+
mutateContent('adapt-contrib-accordion - add accordion._items._graphic.alt attribute', async () => {
55+
accordions.forEach(accordion => {
56+
accordion._items.forEach(item => {
57+
item._graphic.alt = '';
58+
});
59+
});
60+
return true;
61+
});
62+
63+
checkContent('adapt-contrib-accordion - check add accordion._items._graphic.alt atrribute', async () => {
64+
const isValid = accordions.every(accordion =>
65+
accordion._items.every(item =>
66+
item._graphic && item._graphic.alt !== undefined
67+
)
68+
);
69+
if (!isValid) throw new Error('adapt-contrib-accordion - _graphic.alt not added to every instance of accordion._items');
70+
return true;
71+
});
72+
73+
// Is another whereContent needed if it is the same as the first call?
74+
whereContent('adapt-contrib-accordion - where accordion', async content => {
75+
accordions = content.filter(({ _component }) => _component === 'accordion');
76+
if (accordions) return true;
77+
});
78+
79+
mutateContent('adapt-contrib-accordion - add accordion._items._graphic.src attribute', async () => {
80+
accordions.forEach(accordion => {
81+
accordion._items.forEach(item => {
82+
item._graphic.src = '';
83+
});
84+
});
85+
return true;
86+
});
87+
88+
checkContent('adapt-contrib-accordion - check add accordion._items._graphic.src atrribute', async () => {
89+
const isValid = accordions.every(accordion =>
90+
accordion._items.every(item =>
91+
item._graphic && item._graphic.src !== undefined
92+
)
93+
);
94+
if (!isValid) throw new Error('adapt-contrib-accordion - _graphic.src not added to every instance of accordion._items');
95+
return true;
96+
});
97+
98+
updatePlugin('adapt-contrib-accordion - update to v2.0.0', { name: 'adapt-contrib-accordion', version: '2.0.0', framework: '2.0.0' });
99+
});
100+
101+
describe('adapt-contrib-accordion - v2.0.0 > v2.0.4', async () => {
102+
let accordions;
103+
104+
whereFromPlugin('adapt-contrib-accordion - from v2.0.0', { name: 'adapt-contrib-accordion', version: '<=2.0.4' });
105+
106+
whereContent('adapt-contrib-accordion - where accordion', async content => {
107+
accordions = content.filter(({ _component }) => _component === 'accordion');
108+
if (accordions) return true;
109+
});
110+
111+
mutateContent('adapt-contrib-accordion - add accordion._classes', async () => {
112+
accordions.forEach(accordion => {
113+
accordion._classes = '';
114+
});
115+
return true;
116+
});
117+
118+
checkContent('adapt-contrib-accordion - check accordion._classes atrribute', async () => {
119+
const isValid = accordions.every(({ _classes }) => _classes !== undefined);
120+
if (!isValid) throw new Error('adapt-contrib-accordion - _classes not added to every instance of accordion');
121+
return true;
122+
});
123+
124+
updatePlugin('adapt-contrib-accordion - update to v2.0.4', { name: 'adapt-contrib-accordion', version: '2.0.4', framework: '>=2' });
125+
});
126+
127+
describe('adapt-contrib-accordion - v2.0.4 > v2.0.5', async () => {
128+
let accordions;
129+
130+
whereFromPlugin('adapt-contrib-accordion - from v2.0.4', { name: 'adapt-contrib-accordion', version: '<=2.0.5' });
131+
132+
whereContent('adapt-contrib-accordion - where accordion', async content => {
133+
accordions = content.filter(({ _component }) => _component === 'accordion');
134+
if (accordions) return true;
135+
});
136+
137+
mutateContent('adapt-contrib-accordion - add accordion._shouldCollapseItems', async () => {
138+
accordions.forEach(accordion => {
139+
accordion._shouldCollapseItems = false;
140+
});
141+
return true;
142+
});
143+
144+
checkContent('adapt-contrib-accordion - check accordion._shouldCollapseItems atrribute', async () => {
145+
const isValid = accordions.every(({ _classes }) => _classes !== undefined);
146+
if (!isValid) throw new Error('adapt-contrib-accordion - _shouldCollapseItems not added to every instance of accordion');
147+
return true;
148+
});
149+
150+
updatePlugin('adapt-contrib-accordion - update to v2.0.5', { name: 'adapt-contrib-accordion', version: '2.0.5', framework: '>=2' });
151+
});

0 commit comments

Comments
 (0)