mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-09-22 00:52:42 -05:00
Fix test
This commit is contained in:
@@ -139,6 +139,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
let deviceDetectorService: DeviceDetectorService
|
let deviceDetectorService: DeviceDetectorService
|
||||||
let httpTestingController: HttpTestingController
|
let httpTestingController: HttpTestingController
|
||||||
let componentRouterService: ComponentRouterService
|
let componentRouterService: ComponentRouterService
|
||||||
|
let tagService: TagService
|
||||||
|
|
||||||
let currentUserCan = true
|
let currentUserCan = true
|
||||||
let currentUserHasObjectPermissions = true
|
let currentUserHasObjectPermissions = true
|
||||||
@@ -288,6 +289,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
fixture = TestBed.createComponent(DocumentDetailComponent)
|
fixture = TestBed.createComponent(DocumentDetailComponent)
|
||||||
httpTestingController = TestBed.inject(HttpTestingController)
|
httpTestingController = TestBed.inject(HttpTestingController)
|
||||||
componentRouterService = TestBed.inject(ComponentRouterService)
|
componentRouterService = TestBed.inject(ComponentRouterService)
|
||||||
|
tagService = TestBed.inject(TagService)
|
||||||
component = fixture.componentInstance
|
component = fixture.componentInstance
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -400,17 +402,60 @@ describe('DocumentDetailComponent', () => {
|
|||||||
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')
|
||||||
component.createTag('NewTag12')
|
// temporarily add NewTag12 to listAll results
|
||||||
expect(modalSpy).toHaveBeenCalled()
|
const listAllSpy = jest
|
||||||
openModal.componentInstance.succeeded.next({
|
.spyOn(tagService, 'listAll')
|
||||||
id: 12,
|
.mockImplementation(() =>
|
||||||
name: 'NewTag12',
|
of({
|
||||||
is_inbox_tag: true,
|
count: 4,
|
||||||
color: '#ff0000',
|
all: [41, 42, 43, 12],
|
||||||
text_color: '#000000',
|
results: [
|
||||||
})
|
{
|
||||||
expect(component.documentForm.get('tags').value).toContain(12)
|
id: 41,
|
||||||
expect(component.suggestions.suggested_tags).not.toContain('NewTag12')
|
name: 'Tag41',
|
||||||
|
is_inbox_tag: true,
|
||||||
|
color: '#ff0000',
|
||||||
|
text_color: '#000000',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 42,
|
||||||
|
name: 'Tag42',
|
||||||
|
is_inbox_tag: true,
|
||||||
|
color: '#ff0000',
|
||||||
|
text_color: '#000000',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 43,
|
||||||
|
name: 'Tag43',
|
||||||
|
is_inbox_tag: true,
|
||||||
|
color: '#ff0000',
|
||||||
|
text_color: '#000000',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 12,
|
||||||
|
name: 'NewTag12',
|
||||||
|
is_inbox_tag: true,
|
||||||
|
color: '#ff0000',
|
||||||
|
text_color: '#000000',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
try {
|
||||||
|
component.createTag('NewTag12')
|
||||||
|
expect(modalSpy).toHaveBeenCalled()
|
||||||
|
openModal.componentInstance.succeeded.next({
|
||||||
|
id: 12,
|
||||||
|
name: 'NewTag12',
|
||||||
|
is_inbox_tag: true,
|
||||||
|
color: '#ff0000',
|
||||||
|
text_color: '#000000',
|
||||||
|
})
|
||||||
|
expect(component.tagsInput.value.includes(12)).toBeTruthy()
|
||||||
|
expect(component.suggestions.suggested_tags).not.toContain('NewTag12')
|
||||||
|
} finally {
|
||||||
|
listAllSpy.mockRestore()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support creating document type, remove from suggestions', () => {
|
it('should support creating document type, remove from suggestions', () => {
|
||||||
|
@@ -736,6 +736,8 @@ export class DocumentDetailComponent
|
|||||||
})
|
})
|
||||||
modal.componentInstance.dialogMode = EditDialogMode.CREATE
|
modal.componentInstance.dialogMode = EditDialogMode.CREATE
|
||||||
if (newName) modal.componentInstance.object = { name: newName }
|
if (newName) modal.componentInstance.object = { name: newName }
|
||||||
|
console.log('createTag called with', newName)
|
||||||
|
|
||||||
modal.componentInstance.succeeded
|
modal.componentInstance.succeeded
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap((newTag) => {
|
switchMap((newTag) => {
|
||||||
@@ -748,6 +750,8 @@ 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)
|
||||||
|
console.log(this.suggestions)
|
||||||
|
|
||||||
if (this.suggestions) {
|
if (this.suggestions) {
|
||||||
this.suggestions.suggested_tags =
|
this.suggestions.suggested_tags =
|
||||||
this.suggestions.suggested_tags.filter((tag) => tag !== newName)
|
this.suggestions.suggested_tags.filter((tag) => tag !== newName)
|
||||||
|
Reference in New Issue
Block a user