mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-14 00:26:21 +00: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:
33
src-ui/src/app/pipes/custom-date.pipe.spec.ts
Normal file
33
src-ui/src/app/pipes/custom-date.pipe.spec.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
import { CustomDatePipe } from './custom-date.pipe'
|
||||
import { SettingsService } from '../services/settings.service'
|
||||
import {
|
||||
HttpClientTestingModule,
|
||||
HttpTestingController,
|
||||
} from '@angular/common/http/testing'
|
||||
import { DatePipe } from '@angular/common'
|
||||
|
||||
describe('CustomDatePipe', () => {
|
||||
let datePipe: CustomDatePipe
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [CustomDatePipe, SettingsService, DatePipe],
|
||||
imports: [HttpClientTestingModule],
|
||||
})
|
||||
|
||||
datePipe = TestBed.inject(CustomDatePipe)
|
||||
})
|
||||
|
||||
it('should parse date strings with additional options', () => {
|
||||
expect(datePipe.transform('5/4/23')).toEqual('May 4, 2023')
|
||||
expect(
|
||||
datePipe.transform(
|
||||
'5/4/23',
|
||||
'mediumDate',
|
||||
'America/Los_Angeles',
|
||||
'iso-8601'
|
||||
)
|
||||
).toEqual('2023-05-04')
|
||||
})
|
||||
})
|
@@ -1,8 +1,9 @@
|
||||
import { DocumentTitlePipe } from './document-title.pipe'
|
||||
|
||||
describe('DocumentTitlePipe', () => {
|
||||
it('create an instance', () => {
|
||||
it('should return a value if not null', () => {
|
||||
const pipe = new DocumentTitlePipe()
|
||||
expect(pipe).toBeTruthy()
|
||||
expect(pipe.transform('some string')).toEqual('some string')
|
||||
expect(pipe.transform(null)).toEqual('(no title)')
|
||||
})
|
||||
})
|
||||
|
@@ -1,8 +1,20 @@
|
||||
import { FileSizePipe } from './file-size.pipe'
|
||||
|
||||
describe('FileSizePipe', () => {
|
||||
it('create an instance', () => {
|
||||
it('should return file size', () => {
|
||||
const pipe = new FileSizePipe()
|
||||
expect(pipe).toBeTruthy()
|
||||
expect(pipe.transform(1024, 1)).toEqual('1.0 KB')
|
||||
expect(pipe.transform(1024 * 1024, 1)).toEqual('1.0 MB')
|
||||
expect(
|
||||
pipe.transform(1024, {
|
||||
bytes: 0,
|
||||
KB: 3,
|
||||
MB: 1,
|
||||
GB: 1,
|
||||
TB: 2,
|
||||
PB: 2,
|
||||
})
|
||||
).toEqual('1.000 KB')
|
||||
expect(pipe.transform(NaN, 1)).toEqual('?')
|
||||
})
|
||||
})
|
||||
|
28
src-ui/src/app/pipes/filter.pipe.spec.ts
Normal file
28
src-ui/src/app/pipes/filter.pipe.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { MatchingModel } from '../data/matching-model'
|
||||
import { FilterPipe } from './filter.pipe'
|
||||
|
||||
describe('FilterPipe', () => {
|
||||
it('should filter matchingmodel items', () => {
|
||||
const pipe = new FilterPipe()
|
||||
const items: MatchingModel[] = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Hello World',
|
||||
slug: 'slug-1',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Hello',
|
||||
slug: 'slug-2',
|
||||
},
|
||||
]
|
||||
let itemsReturned = pipe.transform(items, 'world')
|
||||
expect(itemsReturned).toEqual([items[0]])
|
||||
|
||||
itemsReturned = pipe.transform(null, 'world')
|
||||
expect(itemsReturned).toEqual([])
|
||||
|
||||
itemsReturned = pipe.transform(items, null)
|
||||
expect(itemsReturned).toEqual(items)
|
||||
})
|
||||
})
|
24
src-ui/src/app/pipes/safehtml.pipe.spec.ts
Normal file
24
src-ui/src/app/pipes/safehtml.pipe.spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
import { SafeHtmlPipe } from './safehtml.pipe'
|
||||
import { BrowserModule, DomSanitizer } from '@angular/platform-browser'
|
||||
|
||||
describe('SafeHtmlPipe', () => {
|
||||
let pipe: SafeHtmlPipe
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [SafeHtmlPipe],
|
||||
imports: [BrowserModule],
|
||||
})
|
||||
pipe = TestBed.inject(SafeHtmlPipe)
|
||||
})
|
||||
|
||||
it('should bypass security and trust the url', () => {
|
||||
const html = '<div>some content</div>'
|
||||
const domSanitizer = TestBed.inject(DomSanitizer)
|
||||
const sanitizerSpy = jest.spyOn(domSanitizer, 'bypassSecurityTrustHtml')
|
||||
let safeHtml = pipe.transform(html)
|
||||
expect(safeHtml).not.toBeNull()
|
||||
expect(sanitizerSpy).toHaveBeenCalled()
|
||||
})
|
||||
})
|
32
src-ui/src/app/pipes/safeurl.pipe.spec.ts
Normal file
32
src-ui/src/app/pipes/safeurl.pipe.spec.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
import { SafeUrlPipe } from './safeurl.pipe'
|
||||
import { BrowserModule, DomSanitizer } from '@angular/platform-browser'
|
||||
|
||||
describe('SafeUrlPipe', () => {
|
||||
let pipe: SafeUrlPipe
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [SafeUrlPipe],
|
||||
imports: [BrowserModule],
|
||||
})
|
||||
pipe = TestBed.inject(SafeUrlPipe)
|
||||
})
|
||||
|
||||
it('should bypass security and trust the url', () => {
|
||||
const url = 'https://example.com'
|
||||
const domSanitizer = TestBed.inject(DomSanitizer)
|
||||
const sanitizerSpy = jest.spyOn(
|
||||
domSanitizer,
|
||||
'bypassSecurityTrustResourceUrl'
|
||||
)
|
||||
|
||||
let safeResourceUrl = pipe.transform(url)
|
||||
expect(safeResourceUrl).not.toBeNull()
|
||||
expect(sanitizerSpy).toHaveBeenCalled()
|
||||
|
||||
safeResourceUrl = pipe.transform(null)
|
||||
expect(safeResourceUrl).not.toBeNull()
|
||||
expect(sanitizerSpy).toHaveBeenCalled()
|
||||
})
|
||||
})
|
73
src-ui/src/app/pipes/username.pipe.spec.ts
Normal file
73
src-ui/src/app/pipes/username.pipe.spec.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
import { UsernamePipe } from './username.pipe'
|
||||
import {
|
||||
HttpClientTestingModule,
|
||||
HttpTestingController,
|
||||
} from '@angular/common/http/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { PermissionsService } from '../services/permissions.service'
|
||||
import { UserService } from '../services/rest/user.service'
|
||||
|
||||
describe('UsernamePipe', () => {
|
||||
let pipe: UsernamePipe
|
||||
let httpTestingController: HttpTestingController
|
||||
let permissionsService: PermissionsService
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [UsernamePipe, PermissionsService],
|
||||
imports: [HttpClientTestingModule],
|
||||
})
|
||||
|
||||
httpTestingController = TestBed.inject(HttpTestingController)
|
||||
permissionsService = TestBed.inject(PermissionsService)
|
||||
const permissionsSpy = jest.spyOn(permissionsService, 'currentUserCan')
|
||||
permissionsSpy.mockImplementation((action, type) => {
|
||||
return true
|
||||
})
|
||||
pipe = TestBed.inject(UsernamePipe)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
httpTestingController.verify()
|
||||
})
|
||||
|
||||
it('should transform user id to username', () => {
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}users/?page=1&page_size=100000`
|
||||
)
|
||||
req.flush({
|
||||
results: [
|
||||
{
|
||||
id: 2,
|
||||
username: 'username2',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
username: 'username3',
|
||||
first_name: 'User',
|
||||
last_name: 'Name3',
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
let username = pipe.transform(2)
|
||||
expect(username).toEqual('username2')
|
||||
|
||||
username = pipe.transform(3)
|
||||
expect(username).toEqual('User Name3')
|
||||
|
||||
username = pipe.transform(4)
|
||||
expect(username).toEqual('')
|
||||
})
|
||||
|
||||
it('should show generic label when no users retrieved', () => {
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}users/?page=1&page_size=100000`
|
||||
)
|
||||
req.flush(null)
|
||||
|
||||
let username = pipe.transform(4)
|
||||
expect(username).toEqual('Shared')
|
||||
})
|
||||
})
|
@@ -1,8 +1,9 @@
|
||||
import { YesNoPipe } from './yes-no.pipe'
|
||||
|
||||
describe('YesNoPipe', () => {
|
||||
it('create an instance', () => {
|
||||
it('should convert booleans to yes / no', () => {
|
||||
const pipe = new YesNoPipe()
|
||||
expect(pipe).toBeTruthy()
|
||||
expect(pipe.transform(true)).toEqual('Yes')
|
||||
expect(pipe.transform(false)).toEqual('No')
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user