mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-23 17:52:23 -04:00
Adds custom fields of certain data types, attachable to documents and searchable Co-Authored-By: Trenton H <797416+stumpylog@users.noreply.github.com>
68 lines
2.5 KiB
TypeScript
68 lines
2.5 KiB
TypeScript
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
|
|
|
import { CustomFieldEditDialogComponent } from './custom-field-edit-dialog.component'
|
|
import { HttpClientTestingModule } from '@angular/common/http/testing'
|
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
|
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap'
|
|
import { NgSelectModule } from '@ng-select/ng-select'
|
|
import { IfOwnerDirective } from 'src/app/directives/if-owner.directive'
|
|
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
|
|
import { SafeHtmlPipe } from 'src/app/pipes/safehtml.pipe'
|
|
import { SettingsService } from 'src/app/services/settings.service'
|
|
import { SelectComponent } from '../../input/select/select.component'
|
|
import { TextComponent } from '../../input/text/text.component'
|
|
import { EditDialogMode } from '../edit-dialog.component'
|
|
|
|
describe('CustomFieldEditDialogComponent', () => {
|
|
let component: CustomFieldEditDialogComponent
|
|
let settingsService: SettingsService
|
|
let fixture: ComponentFixture<CustomFieldEditDialogComponent>
|
|
|
|
beforeEach(() => {
|
|
TestBed.configureTestingModule({
|
|
declarations: [
|
|
CustomFieldEditDialogComponent,
|
|
IfPermissionsDirective,
|
|
IfOwnerDirective,
|
|
SelectComponent,
|
|
TextComponent,
|
|
SafeHtmlPipe,
|
|
],
|
|
providers: [NgbActiveModal],
|
|
imports: [
|
|
HttpClientTestingModule,
|
|
FormsModule,
|
|
ReactiveFormsModule,
|
|
NgSelectModule,
|
|
NgbModule,
|
|
],
|
|
}).compileComponents()
|
|
|
|
fixture = TestBed.createComponent(CustomFieldEditDialogComponent)
|
|
settingsService = TestBed.inject(SettingsService)
|
|
settingsService.currentUser = { id: 99, username: 'user99' }
|
|
component = fixture.componentInstance
|
|
|
|
fixture.detectChanges()
|
|
})
|
|
|
|
it('should support create and edit modes', () => {
|
|
component.dialogMode = EditDialogMode.CREATE
|
|
const createTitleSpy = jest.spyOn(component, 'getCreateTitle')
|
|
const editTitleSpy = jest.spyOn(component, 'getEditTitle')
|
|
fixture.detectChanges()
|
|
expect(createTitleSpy).toHaveBeenCalled()
|
|
expect(editTitleSpy).not.toHaveBeenCalled()
|
|
component.dialogMode = EditDialogMode.EDIT
|
|
fixture.detectChanges()
|
|
expect(editTitleSpy).toHaveBeenCalled()
|
|
})
|
|
|
|
it('should disable data type select on edit', () => {
|
|
component.dialogMode = EditDialogMode.EDIT
|
|
fixture.detectChanges()
|
|
component.ngOnInit()
|
|
expect(component.objectForm.get('data_type').disabled).toBeTruthy()
|
|
})
|
|
})
|