mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00

toasts component testing conditional import of angular setup-jest for vscode-jest support Update jest.config.js Create open-documents.service.spec.ts Add unit tests for all REST services settings service test Remove component from settings service test Create permissions.service.spec.ts upload documents service tests Update package.json Create toast.service.spec.ts Tasks service test Statistics widget component tests Update permissions.service.ts Create app.component.spec.ts settings component testing tasks component unit testing Management list component generic tests Some management component tests document notes component unit tests Create document-list.component.spec.ts Create save-view-config-dialog.component.spec.ts Create filter-editor.component.spec.ts small and large document cards unit testing Create bulk-editor.component.spec.ts document detail unit tests saving work on documentdetail component spec Create document-asn.component.spec.ts dashboard & widgets unit testing Fix ResizeObserver mock common component unit tests fix some merge errors Update app-frame.component.spec.ts Create page-header.component.spec.ts input component unit tests FilterableDropdownComponent unit testing and found minor errors update taskservice unit tests Edit dialogs unit tests Create date-dropdown.component.spec.ts Remove selectors from guard tests confirm dialog component tests app frame component test Miscellaneous component tests Update document-list-view.service.spec.ts directives unit tests Remove unused resizeobserver mock guard unit tests Update query-params.spec.ts try to fix flaky playwright filter rules utils & testing Interceptor unit tests Pipes unit testing Utils unit tests Update upload-documents.service.spec.ts consumer status service tests Update setup-jest.ts Create document-list-view.service.spec.ts Update app-routing.module.ts
100 lines
3.1 KiB
TypeScript
100 lines
3.1 KiB
TypeScript
import {
|
|
ComponentFixture,
|
|
TestBed,
|
|
discardPeriodicTasks,
|
|
fakeAsync,
|
|
tick,
|
|
} from '@angular/core/testing'
|
|
import { ConfirmDialogComponent } from './confirm-dialog.component'
|
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
|
import { SafeHtmlPipe } from 'src/app/pipes/safehtml.pipe'
|
|
import { Subject } from 'rxjs'
|
|
|
|
describe('ConfirmDialogComponent', () => {
|
|
let component: ConfirmDialogComponent
|
|
let modal: NgbActiveModal
|
|
let fixture: ComponentFixture<ConfirmDialogComponent>
|
|
|
|
beforeEach(async () => {
|
|
TestBed.configureTestingModule({
|
|
declarations: [ConfirmDialogComponent, SafeHtmlPipe],
|
|
providers: [NgbActiveModal, SafeHtmlPipe],
|
|
imports: [],
|
|
}).compileComponents()
|
|
|
|
modal = TestBed.inject(NgbActiveModal)
|
|
|
|
fixture = TestBed.createComponent(ConfirmDialogComponent)
|
|
component = fixture.componentInstance
|
|
component.title = 'Confirm delete'
|
|
component.messageBold = 'Do you really want to delete document file.pdf?'
|
|
component.message =
|
|
'The files for this document will be deleted permanently. This operation cannot be undone.'
|
|
component.btnClass = 'btn-danger'
|
|
component.btnCaption = 'Delete document'
|
|
|
|
fixture.detectChanges()
|
|
})
|
|
|
|
it('should support alternative', () => {
|
|
let alternativeClickedResult
|
|
let alternativeSubjectResult
|
|
component.alternativeClicked.subscribe((result) => {
|
|
alternativeClickedResult = true
|
|
})
|
|
component.alternative()
|
|
// with subject
|
|
const subject = new Subject<boolean>()
|
|
component.alternativeSubject = subject
|
|
subject.asObservable().subscribe((result) => {
|
|
alternativeSubjectResult = result
|
|
})
|
|
component.alternative()
|
|
expect(alternativeClickedResult).toBeTruthy()
|
|
expect(alternativeSubjectResult).toBeTruthy()
|
|
})
|
|
|
|
it('should support confirm', () => {
|
|
let confirmClickedResult
|
|
let confirmSubjectResult
|
|
component.confirmClicked.subscribe((result) => {
|
|
confirmClickedResult = true
|
|
})
|
|
component.confirm()
|
|
// with subject
|
|
const subject = new Subject<boolean>()
|
|
component.confirmSubject = subject
|
|
subject.asObservable().subscribe((result) => {
|
|
confirmSubjectResult = result
|
|
})
|
|
component.confirm()
|
|
expect(confirmClickedResult).toBeTruthy()
|
|
expect(confirmSubjectResult).toBeTruthy()
|
|
})
|
|
|
|
it('should support cancel & close modal', () => {
|
|
let confirmSubjectResult
|
|
const closeModalSpy = jest.spyOn(modal, 'close')
|
|
component.cancel()
|
|
const subject = new Subject<boolean>()
|
|
component.confirmSubject = subject
|
|
subject.asObservable().subscribe((result) => {
|
|
confirmSubjectResult = result
|
|
})
|
|
component.cancel()
|
|
// with subject
|
|
expect(closeModalSpy).toHaveBeenCalled()
|
|
expect(confirmSubjectResult).toBeFalsy()
|
|
})
|
|
|
|
it('should support delay confirm', fakeAsync(() => {
|
|
component.confirmButtonEnabled = false
|
|
component.delayConfirm(1)
|
|
expect(component.confirmButtonEnabled).toBeFalsy()
|
|
tick(1500)
|
|
fixture.detectChanges()
|
|
expect(component.confirmButtonEnabled).toBeTruthy()
|
|
discardPeriodicTasks()
|
|
}))
|
|
})
|