Skip to content
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
72 changes: 71 additions & 1 deletion migrations/v3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, getComponents, testStopWhere, testSuccessWhere } from 'adapt-migrations';
import { describe, getCourse, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin, getComponents, testStopWhere, testSuccessWhere } from 'adapt-migrations';
import _ from 'lodash';

describe('adapt-youtube - 3.3.5 to 3.3.6', async () => {
Expand Down Expand Up @@ -95,3 +95,73 @@ describe('adapt-youtube - 3.3.5 to 3.3.6', async () => {
content: [{ _component: 'other' }]
});
});

describe('adapt-youtube - @@CURRENT_VERSION to @@RELEASE_VERSION', async () => {
let course;

whereFromPlugin('adapt-youtube - from @@CURRENT_VERSION', { name: 'adapt-youtube', version: '<@@RELEASE_VERSION' });

whereContent('adapt-youtube - where course has flat _globals._youtube', async content => {
course = getCourse();
return _.has(course, '_globals._youtube');
});

mutateContent('adapt-youtube - move _globals._youtube to _globals._components._youtube', async content => {
const flat = course._globals._youtube;
const nested = _.get(course, '_globals._components._youtube');
_.set(course, '_globals._components._youtube', { ...(_.isPlainObject(nested) ? nested : {}), ...(_.isPlainObject(flat) ? flat : {}) });
delete course._globals._youtube;
return true;
});

checkContent('adapt-youtube - check _globals._youtube moved to _globals._components._youtube', async content => {
if (_.has(course, '_globals._youtube')) throw new Error('adapt-youtube - _globals._youtube was not removed');
if (!_.isPlainObject(_.get(course, '_globals._components._youtube'))) throw new Error('adapt-youtube - _globals._components._youtube was not created');
return true;
});

updatePlugin('adapt-youtube - update to @@RELEASE_VERSION', { name: 'adapt-youtube', version: '@@RELEASE_VERSION', framework: '>=5.19.1' });

testSuccessWhere('course with flat _globals._youtube', {
fromPlugins: [{ name: 'adapt-youtube', version: '@@CURRENT_VERSION' }],
content: [
{ _id: 'c-100', _component: 'youtube' },
{ _type: 'course', _globals: { _youtube: { ariaRegion: 'Custom region', skipToTranscript: 'Custom skip' } } }
]
});

testSuccessWhere('course with flat and nested _globals._youtube, flat values win', {
fromPlugins: [{ name: 'adapt-youtube', version: '@@CURRENT_VERSION' }],
content: [
{ _id: 'c-100', _component: 'youtube' },
{ _type: 'course', _globals: { _youtube: { skipToTranscript: 'Edited skip' }, _components: { _youtube: { ariaRegion: 'Nested region', skipToTranscript: 'Nested skip' } } } }
]
});

testStopWhere('course with nested _globals._components._youtube only', {
fromPlugins: [{ name: 'adapt-youtube', version: '@@CURRENT_VERSION' }],
content: [
{ _id: 'c-100', _component: 'youtube' },
{ _type: 'course', _globals: { _components: { _youtube: { skipToTranscript: 'Skip to transcript' } } } }
]
});

testStopWhere('course with no _globals', {
fromPlugins: [{ name: 'adapt-youtube', version: '@@CURRENT_VERSION' }],
content: [
{ _id: 'c-100', _component: 'youtube' },
{ _type: 'course' }
]
});

testStopWhere('plugin not installed', {
fromPlugins: [{ name: 'adapt-contrib-text', version: '1.0.0' }],
content: [
{ _type: 'course', _globals: { _youtube: { skipToTranscript: 'Edited skip' } } }
]
});

testStopWhere('incorrect version', {
fromPlugins: [{ name: 'adapt-youtube', version: '@@RELEASE_VERSION' }]
});
});
30 changes: 18 additions & 12 deletions schema/course.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@
"type": "object",
"default": {},
"properties": {
"_youtube": {
"_components": {
"type": "object",
"default": {},
"properties": {
"ariaRegion": {
"type": "string",
"title": "YouTube: ARIA region",
"default": "This is a media component which displays a YouTube video. Select the play / pause button to watch it.{{#any _transcript._inlineTranscript _transcript._externalTranscript}} An alternative transcript is also available.{{/any}}"
},
"skipToTranscript": {
"type": "string",
"title": "Skip to transcript",
"default": "Skip to transcript",
"_adapt": {
"translatable": true
"_youtube": {
"type": "object",
"default": {},
"properties": {
"ariaRegion": {
"type": "string",
"title": "YouTube: ARIA region",
"default": "This is a media component which displays a YouTube video. Select the play / pause button to watch it.{{#any _transcript._inlineTranscript _transcript._externalTranscript}} An alternative transcript is also available.{{/any}}"
},
"skipToTranscript": {
"type": "string",
"title": "Skip to transcript",
"default": "Skip to transcript",
"_adapt": {
"translatable": true
}
}
}
}
}
Expand Down
Loading