-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save context metadata provided by LMS app with new annotations
When the embedder frame (eg. our LMS app) provides context metadata to be saved with annotations via the `annotationMetadata` config property, save that with new annotations in the `metadata` field. We add this information only when an annotation is created, and not on subsequent edits, because the main use case in the LMS context is to record the assignment where the annotation was created. If the user edits that annotation subsequently in another assignment, we don't want it to be "moved" by updating the `metadata` field. Part of hypothesis/lms#5698
- Loading branch information
1 parent
088ed0a
commit 4fe2f5b
Showing
4 changed files
with
52 additions
and
2 deletions.
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
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ describe('AnnotationsService', () => { | |
let fakeAnnotationActivity; | ||
let fakeApi; | ||
let fakeMetadata; | ||
let fakeSettings; | ||
let fakeStore; | ||
|
||
let fakeDefaultPermissions; | ||
|
@@ -46,6 +47,8 @@ describe('AnnotationsService', () => { | |
isPublic: sinon.stub(), | ||
}; | ||
|
||
fakeSettings = {}; | ||
|
||
fakeStore = { | ||
addAnnotations: sinon.stub(), | ||
annotationSaveFinished: sinon.stub(), | ||
|
@@ -77,7 +80,12 @@ describe('AnnotationsService', () => { | |
}, | ||
}); | ||
|
||
svc = new AnnotationsService(fakeAnnotationActivity, fakeApi, fakeStore); | ||
svc = new AnnotationsService( | ||
fakeAnnotationActivity, | ||
fakeApi, | ||
fakeSettings, | ||
fakeStore, | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
|
@@ -118,6 +126,21 @@ describe('AnnotationsService', () => { | |
assert.equal(annotation.user, 'acct:[email protected]'); | ||
assert.isOk(annotation.$tag); | ||
assert.isString(annotation.$tag); | ||
|
||
// `annotationMetadata` config not set, so this field should also not be set. | ||
assert.isUndefined(annotation.metadata); | ||
}); | ||
|
||
it('adds metadata from `annotationMetadata` setting to annotation', () => { | ||
fakeStore.focusedGroupId.returns('mygroup'); | ||
fakeSettings.annotationMetadata = { | ||
lms: { assignment_id: '1234' }, | ||
}; | ||
|
||
svc.create({}, now); | ||
|
||
const annotation = getLastAddedAnnotation(); | ||
assert.deepEqual(annotation.metadata, fakeSettings.annotationMetadata); | ||
}); | ||
|
||
describe('annotation permissions', () => { | ||
|
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
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