-
Notifications
You must be signed in to change notification settings - Fork 15
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: added migration scripts (fixes #79) #80
Open
chris-steele
wants to merge
3
commits into
master
Choose a base branch
from
issue/79
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; | ||
import _ from 'lodash'; | ||
|
||
const getCourse = content => { | ||
const course = content.find(({ _type }) => _type === 'course'); | ||
return course; | ||
}; | ||
|
||
const getGlobals = content => { | ||
return getCourse(content)?._globals?._extensions?._glossary; | ||
}; | ||
|
||
describe('Glossary - v2.0.3 to v2.1.0', async () => { | ||
// https://github.com/adaptlearning/adapt-contrib-glossary/compare/v2.0.3..v2.1.0 | ||
|
||
let course; | ||
|
||
whereFromPlugin('Glossary - from v2.0.3', { name: 'adapt-contrib-glossary', version: '<2.1.0' }); | ||
|
||
whereContent('Glossary - where configured', async (content) => { | ||
course = getCourse(content); | ||
return course._glossary; | ||
}); | ||
|
||
mutateContent('Glossary - add course attribute _drawerOrder', async (content) => { | ||
course._glossary._drawerOrder = 0; | ||
return true; | ||
}); | ||
|
||
checkContent('Glossary - check course attribute _drawerOrder', async (content) => { | ||
const isValid = course._glossary._drawerOrder === 0; | ||
if (!isValid) throw new Error('Glossary - course attribute _drawerOrder'); | ||
return true; | ||
}); | ||
|
||
updatePlugin('Glossary - update to v2.1.0', { name: 'adapt-contrib-glossary', version: '2.1.0', framework: '">=2.2.0' }); | ||
}); | ||
|
||
describe('Glossary - v2.1.0 to v2.1.1', async () => { | ||
// https://github.com/adaptlearning/adapt-contrib-glossary/compare/v2.1.0..v2.1.1 | ||
|
||
let course, courseGlossaryGlobals; | ||
|
||
whereFromPlugin('Glossary - from v2.1.0', { name: 'adapt-contrib-glossary', version: '<2.1.1' }); | ||
|
||
whereContent('Glossary - where configured', async (content) => { | ||
course = getCourse(content); | ||
return course._glossary; | ||
}); | ||
|
||
mutateContent('Glossary - add globals if missing', async (content) => { | ||
if (!_.has(course, '_globals._extensions._glossary')) _.set(course, '_globals._extensions._glossary', {}); | ||
courseGlossaryGlobals = course._globals._extensions._glossary; | ||
return true; | ||
}); | ||
|
||
mutateContent('Glossary - add global attribute glossary', async (content) => { | ||
courseGlossaryGlobals.glossary = 'Glossary'; | ||
return true; | ||
}); | ||
|
||
mutateContent('Glossary - add course attribute clearSearch', async (content) => { | ||
course._glossary.clearSearch = ''; | ||
return true; | ||
}); | ||
|
||
mutateContent('Glossary - add course attribute searchItemsAlert', async (content) => { | ||
course._glossary.searchItemsAlert = '{{filteredItems.length}} found.'; | ||
return true; | ||
}); | ||
|
||
checkContent('Glossary - check global attribute glossary', async (content) => { | ||
const isValid = getGlobals(content).glossary === 'Glossary'; | ||
if (!isValid) throw new Error('Glossary - global attribute glossary'); | ||
return true; | ||
}); | ||
|
||
checkContent('Glossary - check course attribute clearSearch', async (content) => { | ||
const isValid = course._glossary.clearSearch === ''; | ||
if (!isValid) throw new Error('Glossary - course attribute clearSearch'); | ||
return true; | ||
}); | ||
|
||
checkContent('Glossary - check course attribute searchItemsAlert', async (content) => { | ||
const isValid = course._glossary.searchItemsAlert === '{{filteredItems.length}} found.'; | ||
if (!isValid) throw new Error('Glossary - course attribute searchItemsAlert'); | ||
return true; | ||
}); | ||
|
||
updatePlugin('Glossary - update to v2.1.1', { name: 'adapt-contrib-glossary', version: '2.1.1', framework: '">=2.2.5' }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,159 @@ | ||||||||||||
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; | ||||||||||||
import _ from 'lodash'; | ||||||||||||
|
||||||||||||
const getCourse = content => { | ||||||||||||
const course = content.find(({ _type }) => _type === 'course'); | ||||||||||||
return course; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
const getGlobals = content => { | ||||||||||||
return getCourse(content)?._globals?._extensions?._glossary; | ||||||||||||
}; | ||||||||||||
|
||||||||||||
describe('Glossary - v2.1.3 to v3.0.0', async () => { | ||||||||||||
// https://github.com/adaptlearning/adapt-contrib-glossary/compare/v2.1.3..v3.0.0 | ||||||||||||
|
||||||||||||
let course, courseGlossaryGlobals; | ||||||||||||
|
||||||||||||
whereFromPlugin('Glossary - from v2.1.3', { name: 'adapt-contrib-glossary', version: '<3.0.0' }); | ||||||||||||
|
||||||||||||
whereContent('Glossary - where configured', async (content) => { | ||||||||||||
course = getCourse(content); | ||||||||||||
return course._glossary; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - add globals if missing', async (content) => { | ||||||||||||
if (!_.has(course, '_globals._extensions._glossary')) _.set(course, '_globals._extensions._glossary', {}); | ||||||||||||
courseGlossaryGlobals = course._globals._extensions._glossary; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - add global attribute labelLink', async (content) => { | ||||||||||||
courseGlossaryGlobals.labelLink = 'Terms beginning with'; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - add global attribute labelNavigation', async (content) => { | ||||||||||||
courseGlossaryGlobals.labelNavigation = 'Glossary navigation'; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - change default title', async (content) => { | ||||||||||||
if (course._glossary.title !== '') return true; | ||||||||||||
course._glossary.title = 'Glossary'; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - change default description', async (content) => { | ||||||||||||
if (course._glossary.description !== '') return true; | ||||||||||||
course._glossary.description = 'Select here to view the glossary for this course'; | ||||||||||||
return true; | ||||||||||||
Comment on lines
+48
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think we can condense this slightly, thoughts?
Suggested change
|
||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - change default clearSearch', async (content) => { | ||||||||||||
if (course._glossary.clearSearch !== '') return true; | ||||||||||||
course._glossary.clearSearch = 'Clear search'; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - change default searchItemsAlert', async (content) => { | ||||||||||||
if (course._glossary.searchItemsAlert !== '{{filteredItems.length}} found.') return true; | ||||||||||||
course._glossary.searchItemsAlert = '{{filteredItems.length}} found'; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - change default searchPlaceholder', async (content) => { | ||||||||||||
if (course._glossary.searchPlaceholder !== '') return true; | ||||||||||||
course._glossary.searchPlaceholder = 'Search'; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - change default searchWithInDescriptionLabel', async (content) => { | ||||||||||||
if (course._glossary.searchWithInDescriptionLabel !== '') return true; | ||||||||||||
course._glossary.searchWithInDescriptionLabel = 'Search within Description'; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - add attribute _isSearchEnabled', async (content) => { | ||||||||||||
course._glossary._isSearchEnabled = true; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - add attribute _isIndexEnabled', async (content) => { | ||||||||||||
course._glossary._isIndexEnabled = false; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
mutateContent('Glossary - add attribute _isGroupHeadersEnabled', async (content) => { | ||||||||||||
course._glossary._isGroupHeadersEnabled = false; | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check global attribute labelLink', async (content) => { | ||||||||||||
const isValid = getGlobals(content).labelLink === 'Terms beginning with'; | ||||||||||||
if (!isValid) throw new Error('Glossary - global attribute labelLink'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check global attribute labelNavigation', async (content) => { | ||||||||||||
const isValid = getGlobals(content).labelNavigation === 'Glossary navigation'; | ||||||||||||
if (!isValid) throw new Error('Glossary - global attribute labelNavigation'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check course attribute title', async (content) => { | ||||||||||||
const isValid = course._glossary.title !== ''; | ||||||||||||
if (!isValid) throw new Error('Glossary - course attribute title'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check course attribute description', async (content) => { | ||||||||||||
const isValid = course._glossary.description !== ''; | ||||||||||||
if (!isValid) throw new Error('Glossary - course attribute description'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check default clearSearch', async (content) => { | ||||||||||||
const isValid = course._glossary.clearSearch !== ''; | ||||||||||||
if (!isValid) throw new Error('Glossary - course attribute clearSearch'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check default searchItemsAlert', async (content) => { | ||||||||||||
const isValid = course._glossary.searchItemsAlert !== '{{filteredItems.length}} found.'; | ||||||||||||
if (!isValid) throw new Error('Glossary - course attribute searchItemsAlert'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check default searchPlaceholder', async (content) => { | ||||||||||||
const isValid = course._glossary.searchPlaceholder !== ''; | ||||||||||||
if (!isValid) throw new Error('Glossary - course attribute searchPlaceholder'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check default searchWithInDescriptionLabel', async (content) => { | ||||||||||||
const isValid = course._glossary.searchWithInDescriptionLabel !== ''; | ||||||||||||
if (!isValid) throw new Error('Glossary - course attribute searchWithInDescriptionLabel'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check attribute _isSearchEnabled', async (content) => { | ||||||||||||
const isValid = course._glossary._isSearchEnabled === true; | ||||||||||||
if (!isValid) throw new Error('Glossary - course attribute _isSearchEnabled'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check attribute _isIndexEnabled', async (content) => { | ||||||||||||
const isValid = course._glossary._isIndexEnabled === false; | ||||||||||||
if (!isValid) throw new Error('Glossary - course attribute _isIndexEnabled'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
checkContent('Glossary - check attribute _isGroupHeadersEnabled', async (content) => { | ||||||||||||
const isValid = course._glossary._isGroupHeadersEnabled === false; | ||||||||||||
if (!isValid) throw new Error('Glossary - course attribute _isGroupHeadersEnabled'); | ||||||||||||
return true; | ||||||||||||
}); | ||||||||||||
|
||||||||||||
updatePlugin('Glossary - update to v3.0.0', { name: 'adapt-contrib-glossary', version: '3.0.0', framework: '">=5' }); | ||||||||||||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { describe, whereContent, whereFromPlugin, mutateContent, checkContent, updatePlugin } from 'adapt-migrations'; | ||
|
||
const getCourse = content => { | ||
const course = content.find(({ _type }) => _type === 'course'); | ||
return course; | ||
}; | ||
|
||
describe('Glossary - v4.3.1 to v4.4.0', async () => { | ||
// https://github.com/adaptlearning/adapt-contrib-glossary/compare/v4.3.1..v4.4.0 | ||
|
||
let course; | ||
|
||
whereFromPlugin('Glossary - from v4.3.1', { name: 'adapt-contrib-glossary', version: '<4.4.0' }); | ||
|
||
whereContent('Glossary has items', async content => { | ||
course = getCourse(content); | ||
return course._glossary?._items?.length; | ||
}); | ||
|
||
mutateContent('Glossary - add item attribute termAriaLabel', async (content) => { | ||
course._glossary._items.forEach(item => (item.termAriaLabel = '')); | ||
return true; | ||
}); | ||
|
||
checkContent('Glossary - check item attribute termAriaLabel', async (content) => { | ||
const isValid = course._glossary._items.every(item => item.termAriaLabel === ''); | ||
if (!isValid) throw new Error('Glossary - item attribute termAriaLabel'); | ||
return true; | ||
}); | ||
|
||
updatePlugin('Glossary - update to v4.4.0', { name: 'adapt-contrib-glossary', version: '4.4.0', framework: '">=5.19.1' }); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an advantage to moving this to a function? The common practice so far has been to keep the find function within the whereContent.
Best to use find rather than filter as we'll only have a single instance of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joe-allen-89 I just moved it to a function as I use it several times.