mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-01 11:19:32 -05:00
Cleaner auto-remove
This commit is contained in:
parent
3fc9992f4d
commit
a59fe0cb3c
@ -392,8 +392,11 @@ describe('DocumentDetailComponent', () => {
|
|||||||
currentUserCan = true
|
currentUserCan = true
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support creating tag', () => {
|
it('should support creating tag, remove from suggestions', () => {
|
||||||
initNormally()
|
initNormally()
|
||||||
|
component.suggestions = {
|
||||||
|
suggested_tags: ['Tag1', 'NewTag12'],
|
||||||
|
}
|
||||||
let openModal: NgbModalRef
|
let openModal: NgbModalRef
|
||||||
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
|
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
|
||||||
const modalSpy = jest.spyOn(modalService, 'open')
|
const modalSpy = jest.spyOn(modalService, 'open')
|
||||||
@ -407,10 +410,14 @@ describe('DocumentDetailComponent', () => {
|
|||||||
text_color: '#000000',
|
text_color: '#000000',
|
||||||
})
|
})
|
||||||
expect(component.documentForm.get('tags').value).toContain(12)
|
expect(component.documentForm.get('tags').value).toContain(12)
|
||||||
|
expect(component.suggestions.suggested_tags).not.toContain('NewTag12')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support creating document type', () => {
|
it('should support creating document type, remove from suggestions', () => {
|
||||||
initNormally()
|
initNormally()
|
||||||
|
component.suggestions = {
|
||||||
|
suggested_document_types: ['DocumentType1', 'NewDocType2'],
|
||||||
|
}
|
||||||
let openModal: NgbModalRef
|
let openModal: NgbModalRef
|
||||||
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
|
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
|
||||||
const modalSpy = jest.spyOn(modalService, 'open')
|
const modalSpy = jest.spyOn(modalService, 'open')
|
||||||
@ -418,10 +425,16 @@ describe('DocumentDetailComponent', () => {
|
|||||||
expect(modalSpy).toHaveBeenCalled()
|
expect(modalSpy).toHaveBeenCalled()
|
||||||
openModal.componentInstance.succeeded.next({ id: 12, name: 'NewDocType12' })
|
openModal.componentInstance.succeeded.next({ id: 12, name: 'NewDocType12' })
|
||||||
expect(component.documentForm.get('document_type').value).toEqual(12)
|
expect(component.documentForm.get('document_type').value).toEqual(12)
|
||||||
|
expect(component.suggestions.suggested_document_types).not.toContain(
|
||||||
|
'NewDocType2'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support creating correspondent', () => {
|
it('should support creating correspondent, remove from suggestions', () => {
|
||||||
initNormally()
|
initNormally()
|
||||||
|
component.suggestions = {
|
||||||
|
suggested_correspondents: ['Correspondent1', 'NewCorrrespondent12'],
|
||||||
|
}
|
||||||
let openModal: NgbModalRef
|
let openModal: NgbModalRef
|
||||||
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
|
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
|
||||||
const modalSpy = jest.spyOn(modalService, 'open')
|
const modalSpy = jest.spyOn(modalService, 'open')
|
||||||
@ -432,6 +445,9 @@ describe('DocumentDetailComponent', () => {
|
|||||||
name: 'NewCorrrespondent12',
|
name: 'NewCorrrespondent12',
|
||||||
})
|
})
|
||||||
expect(component.documentForm.get('correspondent').value).toEqual(12)
|
expect(component.documentForm.get('correspondent').value).toEqual(12)
|
||||||
|
expect(component.suggestions.suggested_correspondents).not.toContain(
|
||||||
|
'NewCorrrespondent12'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support creating storage path', () => {
|
it('should support creating storage path', () => {
|
||||||
@ -1076,30 +1092,6 @@ describe('DocumentDetailComponent', () => {
|
|||||||
expect(errorSpy).toHaveBeenCalled()
|
expect(errorSpy).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support removing suggestions', () => {
|
|
||||||
initNormally()
|
|
||||||
component.removeSuggestion('tag', 'Hello') // coverage
|
|
||||||
component.suggestions = {
|
|
||||||
tags: [42, 43],
|
|
||||||
suggested_tags: ['foo'],
|
|
||||||
document_types: [],
|
|
||||||
suggested_document_types: ['bar'],
|
|
||||||
correspondents: [],
|
|
||||||
suggested_correspondents: ['baz'],
|
|
||||||
}
|
|
||||||
component.removeSuggestion('tag', 'foo')
|
|
||||||
component.removeSuggestion('documentType', 'bar')
|
|
||||||
component.removeSuggestion('correspondent', 'baz')
|
|
||||||
expect(component.suggestions).toEqual({
|
|
||||||
tags: [42, 43],
|
|
||||||
suggested_tags: [],
|
|
||||||
document_types: [],
|
|
||||||
suggested_document_types: [],
|
|
||||||
correspondents: [],
|
|
||||||
suggested_correspondents: [],
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should warn when open document does not match doc retrieved from backend on init', () => {
|
it('should warn when open document does not match doc retrieved from backend on init', () => {
|
||||||
let openModal: NgbModalRef
|
let openModal: NgbModalRef
|
||||||
modalService.activeInstances.subscribe((modals) => (openModal = modals[0]))
|
modalService.activeInstances.subscribe((modals) => (openModal = modals[0]))
|
||||||
|
@ -700,25 +700,6 @@ export class DocumentDetailComponent
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeSuggestion(type: string, value: string) {
|
|
||||||
if (!this.suggestions) return
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case 'tag':
|
|
||||||
this.suggestions.suggested_tags =
|
|
||||||
this.suggestions.suggested_tags.filter((t) => t !== value)
|
|
||||||
break
|
|
||||||
case 'correspondent':
|
|
||||||
this.suggestions.suggested_correspondents =
|
|
||||||
this.suggestions.suggested_correspondents.filter((c) => c !== value)
|
|
||||||
break
|
|
||||||
case 'documentType':
|
|
||||||
this.suggestions.suggested_document_types =
|
|
||||||
this.suggestions.suggested_document_types.filter((dt) => dt !== value)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createTag(newName: string) {
|
createTag(newName: string) {
|
||||||
var modal = this.modalService.open(TagEditDialogComponent, {
|
var modal = this.modalService.open(TagEditDialogComponent, {
|
||||||
backdrop: 'static',
|
backdrop: 'static',
|
||||||
@ -737,7 +718,10 @@ export class DocumentDetailComponent
|
|||||||
.subscribe(({ newTag, tags }) => {
|
.subscribe(({ newTag, tags }) => {
|
||||||
this.tagsInput.tags = tags.results
|
this.tagsInput.tags = tags.results
|
||||||
this.tagsInput.addTag(newTag.id)
|
this.tagsInput.addTag(newTag.id)
|
||||||
this.removeSuggestion('tag', newName)
|
if (this.suggestions) {
|
||||||
|
this.suggestions.suggested_tags =
|
||||||
|
this.suggestions.suggested_tags.filter((tag) => tag !== newName)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -759,7 +743,12 @@ export class DocumentDetailComponent
|
|||||||
.subscribe(({ newDocumentType, documentTypes }) => {
|
.subscribe(({ newDocumentType, documentTypes }) => {
|
||||||
this.documentTypes = documentTypes.results
|
this.documentTypes = documentTypes.results
|
||||||
this.documentForm.get('document_type').setValue(newDocumentType.id)
|
this.documentForm.get('document_type').setValue(newDocumentType.id)
|
||||||
this.removeSuggestion('documentType', newName)
|
if (this.suggestions) {
|
||||||
|
this.suggestions.suggested_document_types =
|
||||||
|
this.suggestions.suggested_document_types.filter(
|
||||||
|
(dt) => dt !== newName
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,7 +772,12 @@ export class DocumentDetailComponent
|
|||||||
.subscribe(({ newCorrespondent, correspondents }) => {
|
.subscribe(({ newCorrespondent, correspondents }) => {
|
||||||
this.correspondents = correspondents.results
|
this.correspondents = correspondents.results
|
||||||
this.documentForm.get('correspondent').setValue(newCorrespondent.id)
|
this.documentForm.get('correspondent').setValue(newCorrespondent.id)
|
||||||
this.removeSuggestion('correspondent', newName)
|
if (this.suggestions) {
|
||||||
|
this.suggestions.suggested_correspondents =
|
||||||
|
this.suggestions.suggested_correspondents.filter(
|
||||||
|
(c) => c !== newName
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user