Restore split dialog accepts doc ID to prevent stale doc, fix frontend tests
This commit is contained in:
parent
3242f5b3b3
commit
c2fb37549b
@ -7,6 +7,7 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
|||||||
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
||||||
import { DocumentService } from 'src/app/services/rest/document.service'
|
import { DocumentService } from 'src/app/services/rest/document.service'
|
||||||
import { PdfViewerModule } from 'ng2-pdf-viewer'
|
import { PdfViewerModule } from 'ng2-pdf-viewer'
|
||||||
|
import { of } from 'rxjs'
|
||||||
|
|
||||||
describe('SplitConfirmDialogComponent', () => {
|
describe('SplitConfirmDialogComponent', () => {
|
||||||
let component: SplitConfirmDialogComponent
|
let component: SplitConfirmDialogComponent
|
||||||
@ -32,6 +33,14 @@ describe('SplitConfirmDialogComponent', () => {
|
|||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should load document on init', () => {
|
||||||
|
const getSpy = jest.spyOn(documentService, 'get')
|
||||||
|
component.documentID = 1
|
||||||
|
getSpy.mockReturnValue(of({ id: 1 } as any))
|
||||||
|
component.ngOnInit()
|
||||||
|
expect(documentService.get).toHaveBeenCalledWith(1)
|
||||||
|
})
|
||||||
|
|
||||||
it('should update pagesString when pages are added', () => {
|
it('should update pagesString when pages are added', () => {
|
||||||
component.totalPages = 5
|
component.totalPages = 5
|
||||||
component.page = 2
|
component.page = 2
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Component } from '@angular/core'
|
import { Component, OnInit } from '@angular/core'
|
||||||
import { ConfirmDialogComponent } from '../confirm-dialog.component'
|
import { ConfirmDialogComponent } from '../confirm-dialog.component'
|
||||||
import { Document } from 'src/app/data/document'
|
import { Document } from 'src/app/data/document'
|
||||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||||
@ -11,7 +11,10 @@ import { PDFDocumentProxy } from 'ng2-pdf-viewer'
|
|||||||
templateUrl: './split-confirm-dialog.component.html',
|
templateUrl: './split-confirm-dialog.component.html',
|
||||||
styleUrl: './split-confirm-dialog.component.scss',
|
styleUrl: './split-confirm-dialog.component.scss',
|
||||||
})
|
})
|
||||||
export class SplitConfirmDialogComponent extends ConfirmDialogComponent {
|
export class SplitConfirmDialogComponent
|
||||||
|
extends ConfirmDialogComponent
|
||||||
|
implements OnInit
|
||||||
|
{
|
||||||
public get pagesString(): string {
|
public get pagesString(): string {
|
||||||
let pagesStr = ''
|
let pagesStr = ''
|
||||||
|
|
||||||
@ -33,13 +36,14 @@ export class SplitConfirmDialogComponent extends ConfirmDialogComponent {
|
|||||||
|
|
||||||
private pages: Set<number> = new Set()
|
private pages: Set<number> = new Set()
|
||||||
|
|
||||||
public document: Document
|
public documentID: number
|
||||||
|
private document: Document
|
||||||
public page: number = 1
|
public page: number = 1
|
||||||
public totalPages: number
|
public totalPages: number
|
||||||
public deleteOriginal: boolean = false
|
public deleteOriginal: boolean = false
|
||||||
|
|
||||||
public get pdfSrc(): string {
|
public get pdfSrc(): string {
|
||||||
return this.documentService.getPreviewUrl(this.document.id)
|
return this.documentService.getPreviewUrl(this.documentID)
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -51,6 +55,12 @@ export class SplitConfirmDialogComponent extends ConfirmDialogComponent {
|
|||||||
this.confirmButtonEnabled = this.pages.size > 0
|
this.confirmButtonEnabled = this.pages.size > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.documentService.get(this.documentID).subscribe((r) => {
|
||||||
|
this.document = r
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pdfPreviewLoaded(pdf: PDFDocumentProxy) {
|
pdfPreviewLoaded(pdf: PDFDocumentProxy) {
|
||||||
this.totalPages = pdf.numPages
|
this.totalPages = pdf.numPages
|
||||||
}
|
}
|
||||||
|
@ -1099,7 +1099,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
expect(req.request.body).toEqual({
|
expect(req.request.body).toEqual({
|
||||||
documents: [doc.id],
|
documents: [doc.id],
|
||||||
method: 'split',
|
method: 'split',
|
||||||
parameters: { pages: '1-2,3-5' },
|
parameters: { pages: '1-2,3-5', delete_originals: false },
|
||||||
})
|
})
|
||||||
req.error(new ProgressEvent('failed'))
|
req.error(new ProgressEvent('failed'))
|
||||||
modal.componentInstance.confirm()
|
modal.componentInstance.confirm()
|
||||||
|
@ -1112,7 +1112,7 @@ export class DocumentDetailComponent
|
|||||||
modal.componentInstance.title = $localize`Split confirm`
|
modal.componentInstance.title = $localize`Split confirm`
|
||||||
modal.componentInstance.messageBold = $localize`This operation will split the selected document(s) into new documents.`
|
modal.componentInstance.messageBold = $localize`This operation will split the selected document(s) into new documents.`
|
||||||
modal.componentInstance.btnCaption = $localize`Proceed`
|
modal.componentInstance.btnCaption = $localize`Proceed`
|
||||||
modal.componentInstance.document = this.document
|
modal.componentInstance.documentID = this.document.id
|
||||||
modal.componentInstance.confirmClicked
|
modal.componentInstance.confirmClicked
|
||||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user