mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
frontend unit tests
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
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { Component } from '@angular/core'
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
import { IfObjectPermissionsDirective } from './if-object-permissions.directive'
|
||||
import { PermissionsService } from '../services/permissions.service'
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<div>
|
||||
<button
|
||||
*appIfObjectPermissions="{
|
||||
object: { id: 2, owner: user1 },
|
||||
action: 'view'
|
||||
}"
|
||||
>
|
||||
Some Text
|
||||
</button>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
class TestComponent {}
|
||||
|
||||
describe('IfObjectPermissionsDirective', () => {
|
||||
let fixture: ComponentFixture<TestComponent>
|
||||
let permissionsService: PermissionsService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [IfObjectPermissionsDirective, TestComponent],
|
||||
providers: [PermissionsService],
|
||||
})
|
||||
permissionsService = TestBed.inject(PermissionsService)
|
||||
})
|
||||
|
||||
it('should create element if user has object permissions', () => {
|
||||
jest
|
||||
.spyOn(permissionsService, 'currentUserHasObjectPermissions')
|
||||
.mockImplementation(() => {
|
||||
return true
|
||||
})
|
||||
|
||||
fixture = TestBed.createComponent(TestComponent)
|
||||
|
||||
fixture.detectChanges()
|
||||
|
||||
const rootEl = (fixture.nativeElement as HTMLDivElement).children[0]
|
||||
expect(rootEl.querySelectorAll('button').length).toEqual(1)
|
||||
})
|
||||
|
||||
it('should not create element if user does not have object permissions', () => {
|
||||
jest
|
||||
.spyOn(permissionsService, 'currentUserHasObjectPermissions')
|
||||
.mockImplementation(() => {
|
||||
return false
|
||||
})
|
||||
|
||||
fixture = TestBed.createComponent(TestComponent)
|
||||
|
||||
fixture.detectChanges()
|
||||
|
||||
const rootEl = (fixture.nativeElement as HTMLDivElement).children[0]
|
||||
expect(rootEl.querySelectorAll('button').length).toEqual(0)
|
||||
})
|
||||
})
|
56
src-ui/src/app/directives/if-owner.directive.spec.ts
Normal file
56
src-ui/src/app/directives/if-owner.directive.spec.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { Component } from '@angular/core'
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
import { IfOwnerDirective } from './if-owner.directive'
|
||||
import { PermissionsService } from '../services/permissions.service'
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<div>
|
||||
<button *appIfOwner="{ id: 2, owner: user1 }">Some Text</button>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
class TestComponent {}
|
||||
|
||||
describe('IfOwnerDirective', () => {
|
||||
let fixture: ComponentFixture<TestComponent>
|
||||
let permissionsService: PermissionsService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [IfOwnerDirective, TestComponent],
|
||||
providers: [PermissionsService],
|
||||
})
|
||||
permissionsService = TestBed.inject(PermissionsService)
|
||||
})
|
||||
|
||||
it('should create element if user owns object', () => {
|
||||
jest
|
||||
.spyOn(permissionsService, 'currentUserOwnsObject')
|
||||
.mockImplementation(() => {
|
||||
return true
|
||||
})
|
||||
|
||||
fixture = TestBed.createComponent(TestComponent)
|
||||
|
||||
fixture.detectChanges()
|
||||
|
||||
const rootEl = (fixture.nativeElement as HTMLDivElement).children[0]
|
||||
expect(rootEl.querySelectorAll('button').length).toEqual(1)
|
||||
})
|
||||
|
||||
it('should not create element if user does not own object', () => {
|
||||
jest
|
||||
.spyOn(permissionsService, 'currentUserOwnsObject')
|
||||
.mockImplementation(() => {
|
||||
return false
|
||||
})
|
||||
|
||||
fixture = TestBed.createComponent(TestComponent)
|
||||
|
||||
fixture.detectChanges()
|
||||
|
||||
const rootEl = (fixture.nativeElement as HTMLDivElement).children[0]
|
||||
expect(rootEl.querySelectorAll('button').length).toEqual(0)
|
||||
})
|
||||
})
|
54
src-ui/src/app/directives/if-permissions.directive.spec.ts
Normal file
54
src-ui/src/app/directives/if-permissions.directive.spec.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { Component } from '@angular/core'
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
import { IfPermissionsDirective } from './if-permissions.directive'
|
||||
import { PermissionsService } from '../services/permissions.service'
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<div>
|
||||
<button *appIfPermissions="{ action: 'add', type: '%s_user' }">
|
||||
Some Text
|
||||
</button>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
class TestComponent {}
|
||||
|
||||
describe('IfPermissionsDirective', () => {
|
||||
let fixture: ComponentFixture<TestComponent>
|
||||
let permissionsService: PermissionsService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [IfPermissionsDirective, TestComponent],
|
||||
providers: [PermissionsService],
|
||||
})
|
||||
permissionsService = TestBed.inject(PermissionsService)
|
||||
})
|
||||
|
||||
it('should create element if user has permissions', () => {
|
||||
jest.spyOn(permissionsService, 'currentUserCan').mockImplementation(() => {
|
||||
return true
|
||||
})
|
||||
|
||||
fixture = TestBed.createComponent(TestComponent)
|
||||
|
||||
fixture.detectChanges()
|
||||
|
||||
const rootEl = (fixture.nativeElement as HTMLDivElement).children[0]
|
||||
expect(rootEl.querySelectorAll('button').length).toEqual(1)
|
||||
})
|
||||
|
||||
it('should not create element if user has does not have permissions', () => {
|
||||
jest.spyOn(permissionsService, 'currentUserCan').mockImplementation(() => {
|
||||
return false
|
||||
})
|
||||
|
||||
fixture = TestBed.createComponent(TestComponent)
|
||||
|
||||
fixture.detectChanges()
|
||||
|
||||
const rootEl = (fixture.nativeElement as HTMLDivElement).children[0]
|
||||
expect(rootEl.querySelectorAll('button').length).toEqual(0)
|
||||
})
|
||||
})
|
93
src-ui/src/app/directives/sortable.directive.spec.ts
Normal file
93
src-ui/src/app/directives/sortable.directive.spec.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { Component, DebugElement } from '@angular/core'
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
import { SortEvent, SortableDirective } from './sortable.directive'
|
||||
import { By } from '@angular/platform-browser'
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<table class="table">
|
||||
<thead>
|
||||
<th></th>
|
||||
<th class="d-none d-lg-table-cell" appSortable="archive_serial_number">
|
||||
ASN
|
||||
</th>
|
||||
<th class="d-none d-md-table-cell" appSortable="correspondent__name">
|
||||
Correspondent
|
||||
</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
`,
|
||||
})
|
||||
class TestComponent {}
|
||||
|
||||
describe('SortableDirective', () => {
|
||||
let fixture: ComponentFixture<TestComponent>
|
||||
let directive: SortableDirective
|
||||
let des: DebugElement[] // the elements w/ the directive
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.configureTestingModule({
|
||||
declarations: [SortableDirective, TestComponent],
|
||||
}).createComponent(TestComponent)
|
||||
|
||||
fixture.detectChanges() // initial binding
|
||||
|
||||
// all elements with an attached SortableDirective
|
||||
des = fixture.debugElement.queryAll(By.directive(SortableDirective))
|
||||
|
||||
directive = des[1].injector.get(SortableDirective)
|
||||
directive.currentSortField = 'correspondent__name'
|
||||
})
|
||||
|
||||
it('should have three 2 sortable elements', () => {
|
||||
expect(des.length).toBe(2)
|
||||
})
|
||||
|
||||
it('should trigger sort on click', () => {
|
||||
const tableCell = des[1].nativeElement as HTMLTableCellElement
|
||||
|
||||
let sortEvent: SortEvent
|
||||
directive.sort.subscribe((event) => {
|
||||
directive.currentSortReverse = event.reverse
|
||||
sortEvent = event
|
||||
})
|
||||
|
||||
expect(directive.currentSortReverse).toBeFalsy()
|
||||
|
||||
tableCell.dispatchEvent(new MouseEvent('click'))
|
||||
fixture.detectChanges()
|
||||
|
||||
expect(sortEvent).not.toBeNull()
|
||||
expect(sortEvent.column).toEqual('correspondent__name')
|
||||
expect(sortEvent.reverse).toBeTruthy()
|
||||
|
||||
tableCell.dispatchEvent(new MouseEvent('click'))
|
||||
fixture.detectChanges()
|
||||
|
||||
expect(sortEvent.reverse).toBeFalsy()
|
||||
})
|
||||
|
||||
it('should change column to sort when clicked', () => {
|
||||
const tableCell = des[1].nativeElement as HTMLTableCellElement
|
||||
|
||||
let sortEvent: SortEvent
|
||||
directive.sort.subscribe((event) => {
|
||||
directive.currentSortReverse = event.reverse
|
||||
sortEvent = event
|
||||
})
|
||||
|
||||
directive.currentSortField = 'archive_serial_number'
|
||||
|
||||
tableCell.dispatchEvent(new MouseEvent('click'))
|
||||
fixture.detectChanges()
|
||||
|
||||
expect(sortEvent.column).toEqual('correspondent__name')
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user