-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2499 from Inist-CNRS/feat/2330-delete-annotation-api
Feat(annotation): Add annotation deletion support
- Loading branch information
Showing
13 changed files
with
593 additions
and
38 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 |
---|---|---|
|
@@ -140,7 +140,7 @@ describe('Annotation', () => { | |
|
||
describe('resources', () => { | ||
describe('create list and update an Annotation', () => { | ||
it.only('should create an annotation on resource field', () => { | ||
it('should create an annotation on resource field', () => { | ||
cy.findByText('Search').click(); | ||
searchDrawer.search('Terminator 2'); | ||
searchDrawer.waitForLoading(); | ||
|
@@ -181,7 +181,7 @@ describe('Annotation', () => { | |
'Internal Comment', | ||
'Administrator', | ||
'Contributor', | ||
'Comment', | ||
'Contributor Comment', | ||
'Submission date', | ||
'Last modified on', | ||
]); | ||
|
@@ -284,7 +284,9 @@ describe('Annotation', () => { | |
'exist', | ||
); | ||
|
||
cy.findByText('Annotations').click(); | ||
cy.findByRole('link', { | ||
name: 'Cancel', | ||
}).click(); | ||
|
||
cy.wait(1000); | ||
cy.findByRole('progressbar').should('not.exist'); | ||
|
@@ -336,6 +338,123 @@ describe('Annotation', () => { | |
name: `Add an annotation to Liste des films field`, | ||
}).should('not.exist'); | ||
}); | ||
|
||
it('should delete an annotation on resource field', () => { | ||
cy.findByText('Search').click(); | ||
searchDrawer.search('Terminator 2'); | ||
searchDrawer.waitForLoading(); | ||
cy.findByTitle('Terminator 2').click(); | ||
annotation.createTitleAnnotation({ | ||
fieldLabel: 'actors', | ||
comment: 'This is a comment', | ||
authorName: 'John Doe', | ||
authorEmail: '[email protected]', | ||
}); | ||
|
||
cy.findByText('Search').click(); | ||
searchDrawer.search('RoboCop'); | ||
searchDrawer.waitForLoading(); | ||
cy.findByTitle('RoboCop').click(); | ||
annotation.createTitleAnnotation({ | ||
fieldLabel: 'rating', | ||
comment: 'This is another comment', | ||
authorName: 'Jane Smith', | ||
authorEmail: '[email protected]', | ||
}); | ||
cy.findByText('More').click(); | ||
menu.goToAdminDashboard(); | ||
cy.findByText('Annotations').click(); | ||
|
||
cy.findAllByRole('cell').then((cells) => { | ||
const firstUri = cells[0].textContent; | ||
const secondUri = cells[14].textContent; | ||
|
||
expect(firstUri).to.match(/uid:\//); | ||
expect(secondUri).to.match(/uid:\//); | ||
|
||
expect( | ||
cells.toArray().map((cell) => cell.textContent), | ||
).to.deep.equal([ | ||
firstUri, | ||
'RoboCop', | ||
'rating', | ||
'[bZE+]', | ||
'', | ||
'', | ||
'', | ||
'To Review', | ||
'', | ||
'', | ||
'Jane Smith', | ||
'This is another comment', | ||
new Date().toLocaleDateString(), | ||
new Date().toLocaleDateString(), | ||
secondUri, | ||
'Terminator 2', | ||
'actors', | ||
'[K8Lu]', | ||
'', | ||
'', | ||
'', | ||
'To Review', | ||
'', | ||
'', | ||
'John Doe', | ||
'This is a comment', | ||
new Date().toLocaleDateString(), | ||
new Date().toLocaleDateString(), | ||
]); | ||
}); | ||
|
||
cy.findByText('Terminator 2').click(); | ||
|
||
cy.findByRole('heading', { | ||
name: /^Annotation: uid:\//, | ||
}).should('be.visible'); | ||
cy.findByRole('heading', { | ||
name: 'Terminator 2', | ||
}).should('be.visible'); | ||
|
||
cy.findByRole('button', { | ||
name: 'Delete the annotation', | ||
}).click(); | ||
|
||
cy.findByRole('button', { | ||
name: 'Delete', | ||
}).click(); | ||
|
||
cy.findByRole('alert', {}).should( | ||
'have.text', | ||
'The annotation has been deleted.', | ||
); | ||
|
||
cy.wait(500); | ||
|
||
cy.findAllByRole('cell').then((cells) => { | ||
const firstUri = cells[0].textContent; | ||
|
||
expect(firstUri).to.match(/uid:\//); | ||
|
||
expect( | ||
cells.toArray().map((cell) => cell.textContent), | ||
).to.deep.equal([ | ||
firstUri, | ||
'RoboCop', | ||
'rating', | ||
'[bZE+]', | ||
'', | ||
'', | ||
'', | ||
'To Review', | ||
'', | ||
'', | ||
'Jane Smith', | ||
'This is another comment', | ||
new Date().toLocaleDateString(), | ||
new Date().toLocaleDateString(), | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
|
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import createFieldModel from '../../models/field'; | |
import createPublishedDatasetModel from '../../models/publishedDataset'; | ||
import { | ||
createAnnotation, | ||
deleteAnnotation, | ||
getAnnotation, | ||
getAnnotations, | ||
updateAnnotation, | ||
|
@@ -1336,11 +1337,27 @@ describe('annotation', () => { | |
internalComment: 'All done', | ||
administrator: 'The Tester', | ||
updatedAt: expect.any(Date), | ||
field: { | ||
_id: field._id, | ||
label: 'Annotated field', | ||
name: 'GvaF', | ||
position: 2, | ||
}, | ||
resource: { | ||
title: 'resource title', | ||
uri: 'uid:/1234', | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect(await annotationModel.findLimitFromSkip()).toStrictEqual([ | ||
ctx.response.body.data, | ||
{ | ||
...annotation, | ||
status: 'validated', | ||
internalComment: 'All done', | ||
administrator: 'The Tester', | ||
updatedAt: expect.any(Date), | ||
}, | ||
]); | ||
}); | ||
|
||
|
@@ -1407,4 +1424,67 @@ describe('annotation', () => { | |
]); | ||
}); | ||
}); | ||
|
||
describe('DELETE /annotations/:id', () => { | ||
let annotation; | ||
beforeEach(async () => { | ||
annotation = await annotationModel.create({ | ||
resourceUri: null, | ||
itemPath: [], | ||
fieldId: null, | ||
authorName: 'Developer', | ||
authorEmail: '[email protected]', | ||
comment: 'This is a comment', | ||
status: 'ongoing', | ||
internalComment: null, | ||
createdAt: new Date('03-01-2025'), | ||
updatedAt: new Date('03-01-2025'), | ||
}); | ||
}); | ||
|
||
it('should succeed with a 200 if annotation does not exist', async () => { | ||
const ctx = { | ||
request: { | ||
body: {}, | ||
}, | ||
response: {}, | ||
annotation: annotationModel, | ||
publishedDataset: publishedDatasetModel, | ||
field: fieldModel, | ||
}; | ||
|
||
await deleteAnnotation(ctx, annotation._id); | ||
|
||
expect(ctx.response).toStrictEqual({ | ||
status: 200, | ||
body: { | ||
success: true, | ||
}, | ||
}); | ||
|
||
expect(await annotationModel.findLimitFromSkip()).toStrictEqual([]); | ||
}); | ||
|
||
it('should fail with a 404 if annotation does not exist', async () => { | ||
const ctx = { | ||
request: { | ||
body: {}, | ||
}, | ||
response: {}, | ||
annotation: annotationModel, | ||
publishedDataset: publishedDatasetModel, | ||
field: fieldModel, | ||
}; | ||
|
||
await deleteAnnotation(ctx, '404404404404404404404404'); | ||
|
||
expect(ctx.response).toStrictEqual({ | ||
status: 404, | ||
}); | ||
|
||
expect(await annotationModel.findLimitFromSkip()).toStrictEqual([ | ||
annotation, | ||
]); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.