Fix: including ordering param for id__in retrievals from frontend (#6875)

This commit is contained in:
shamoon 2024-06-01 19:28:31 -07:00 committed by GitHub
parent 085447e7c4
commit d2883b83c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 24 additions and 5 deletions

View file

@ -66,6 +66,20 @@ describe('DocumentLinkComponent', () => {
expect(getSpy).toHaveBeenCalled()
})
it('shoud maintain ordering of selected documents', () => {
const getSpy = jest.spyOn(documentService, 'getFew')
getSpy.mockImplementation((ids) => {
const docs = documents.filter((d) => ids.includes(d.id))
return of({
count: docs.length,
all: docs.map((d) => d.id),
results: docs,
})
})
component.writeValue([12, 1])
expect(component.selectedDocuments).toEqual([documents[1], documents[0]])
})
it('should search API on select text input', () => {
const listSpy = jest.spyOn(documentService, 'listFiltered')
listSpy.mockImplementation(

View file

@ -65,7 +65,9 @@ export class DocumentLinkComponent
.pipe(takeUntil(this.unsubscribeNotifier))
.subscribe((documentResults) => {
this.loading = false
this.selectedDocuments = documentResults.results
this.selectedDocuments = documentIDs.map((id) =>
documentResults.results.find((d) => d.id === id)
)
super.writeValue(documentIDs)
})
}