mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -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
213 lines
6.9 KiB
TypeScript
213 lines
6.9 KiB
TypeScript
import { TestBed } from '@angular/core/testing'
|
|
import { SettingsService } from './settings.service'
|
|
import {
|
|
HttpClientTestingModule,
|
|
HttpTestingController,
|
|
} from '@angular/common/http/testing'
|
|
import { RouterTestingModule } from '@angular/router/testing'
|
|
import { environment } from 'src/environments/environment'
|
|
import { Subscription } from 'rxjs'
|
|
import { PaperlessUiSettings } from '../data/paperless-uisettings'
|
|
import { SETTINGS_KEYS } from '../data/paperless-uisettings'
|
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
|
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
|
import { AppModule } from '../app.module'
|
|
|
|
describe('SettingsService', () => {
|
|
let httpTestingController: HttpTestingController
|
|
let settingsService: SettingsService
|
|
let subscription: Subscription
|
|
|
|
const ui_settings: PaperlessUiSettings = {
|
|
user: {
|
|
username: 'testuser',
|
|
first_name: 'Test',
|
|
last_name: 'User',
|
|
id: 1,
|
|
is_superuser: true,
|
|
},
|
|
settings: {
|
|
language: '',
|
|
bulk_edit: { confirmation_dialogs: true, apply_on_close: false },
|
|
documentListSize: 50,
|
|
dark_mode: { use_system: true, enabled: 'false', thumb_inverted: 'true' },
|
|
theme: { color: '#9fbf2f' },
|
|
document_details: { native_pdf_viewer: false },
|
|
date_display: { date_locale: '', date_format: 'mediumDate' },
|
|
notifications: {
|
|
consumer_new_documents: true,
|
|
consumer_success: true,
|
|
consumer_failed: true,
|
|
consumer_suppress_on_dashboard: true,
|
|
},
|
|
comments_enabled: true,
|
|
slim_sidebar: false,
|
|
update_checking: { enabled: false, backend_setting: 'default' },
|
|
saved_views: { warn_on_unsaved_change: true },
|
|
notes_enabled: true,
|
|
tour_complete: false,
|
|
},
|
|
permissions: [],
|
|
}
|
|
|
|
beforeEach(() => {
|
|
TestBed.configureTestingModule({
|
|
declarations: [],
|
|
providers: [SettingsService],
|
|
imports: [
|
|
HttpClientTestingModule,
|
|
RouterTestingModule,
|
|
NgbModule,
|
|
FormsModule,
|
|
ReactiveFormsModule,
|
|
AppModule,
|
|
],
|
|
})
|
|
|
|
httpTestingController = TestBed.inject(HttpTestingController)
|
|
settingsService = TestBed.inject(SettingsService)
|
|
})
|
|
|
|
afterEach(() => {
|
|
subscription?.unsubscribe()
|
|
httpTestingController.verify()
|
|
})
|
|
|
|
it('calls ui_settings api endpoint on initialize', () => {
|
|
const req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}ui_settings/`
|
|
)
|
|
expect(req.request.method).toEqual('GET')
|
|
})
|
|
|
|
it('calls ui_settings api endpoint with POST on store', () => {
|
|
let req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}ui_settings/`
|
|
)
|
|
req.flush(ui_settings)
|
|
|
|
subscription = settingsService.storeSettings().subscribe()
|
|
req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}ui_settings/`
|
|
)
|
|
expect(req.request.method).toEqual('POST')
|
|
expect(req.request.body).toEqual({
|
|
settings: ui_settings.settings,
|
|
})
|
|
})
|
|
|
|
it('correctly loads settings of various types', () => {
|
|
const req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}ui_settings/`
|
|
)
|
|
req.flush(ui_settings)
|
|
|
|
expect(settingsService.displayName).toEqual('Test')
|
|
expect(settingsService.getLanguage()).toEqual('')
|
|
expect(settingsService.get(SETTINGS_KEYS.DARK_MODE_ENABLED)).toBeFalsy()
|
|
expect(
|
|
settingsService.get(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_NEW_DOCUMENT)
|
|
).toBeTruthy()
|
|
expect(settingsService.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE)).toEqual(50)
|
|
expect(settingsService.get(SETTINGS_KEYS.THEME_COLOR)).toEqual('#9fbf2f')
|
|
})
|
|
|
|
it('correctly allows updating settings of various types', () => {
|
|
const req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}ui_settings/`
|
|
)
|
|
req.flush(ui_settings)
|
|
|
|
settingsService.setLanguage('de-de')
|
|
settingsService.set(SETTINGS_KEYS.DARK_MODE_ENABLED, true)
|
|
settingsService.set(
|
|
SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_NEW_DOCUMENT,
|
|
false
|
|
)
|
|
settingsService.set(SETTINGS_KEYS.DOCUMENT_LIST_SIZE, 25)
|
|
settingsService.set(SETTINGS_KEYS.THEME_COLOR, '#000000')
|
|
|
|
expect(settingsService.getLanguage()).toEqual('de-de')
|
|
expect(settingsService.get(SETTINGS_KEYS.DARK_MODE_ENABLED)).toBeTruthy()
|
|
expect(
|
|
settingsService.get(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_NEW_DOCUMENT)
|
|
).toBeFalsy()
|
|
expect(settingsService.get(SETTINGS_KEYS.DOCUMENT_LIST_SIZE)).toEqual(25)
|
|
expect(settingsService.get(SETTINGS_KEYS.THEME_COLOR)).toEqual('#000000')
|
|
})
|
|
|
|
it('updates appearnce settings', () => {
|
|
const req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}ui_settings/`
|
|
)
|
|
req.flush(ui_settings)
|
|
|
|
expect(
|
|
document.body.style.getPropertyValue('--pngx-primary-lightness')
|
|
).toEqual('')
|
|
|
|
const addClassSpy = jest.spyOn(settingsService.renderer, 'addClass')
|
|
const removeClassSpy = jest.spyOn(settingsService.renderer, 'removeClass')
|
|
|
|
settingsService.updateAppearanceSettings(true, true, '#fff000')
|
|
expect(addClassSpy).toHaveBeenCalledWith(document.body, 'primary-light')
|
|
expect(addClassSpy).toHaveBeenCalledWith(
|
|
document.body,
|
|
'color-scheme-system'
|
|
)
|
|
expect(
|
|
document.body.style.getPropertyValue('--pngx-primary-lightness')
|
|
).toEqual('50%')
|
|
|
|
settingsService.updateAppearanceSettings(false, false, '#000000')
|
|
expect(addClassSpy).toHaveBeenCalledWith(document.body, 'primary-light')
|
|
expect(removeClassSpy).toHaveBeenCalledWith(
|
|
document.body,
|
|
'color-scheme-system'
|
|
)
|
|
expect(
|
|
document.body.style.getPropertyValue('--pngx-primary-lightness')
|
|
).toEqual('0%')
|
|
|
|
settingsService.updateAppearanceSettings(false, true, '#ffffff')
|
|
expect(addClassSpy).toHaveBeenCalledWith(document.body, 'primary-dark')
|
|
expect(removeClassSpy).toHaveBeenCalledWith(
|
|
document.body,
|
|
'color-scheme-system'
|
|
)
|
|
expect(addClassSpy).toHaveBeenCalledWith(document.body, 'color-scheme-dark')
|
|
expect(
|
|
document.body.style.getPropertyValue('--pngx-primary-lightness')
|
|
).toEqual('100%')
|
|
})
|
|
|
|
it('migrates settings automatically', () => {
|
|
const oldSettings = Object.assign({}, ui_settings)
|
|
delete oldSettings.settings['documentListSize']
|
|
window.localStorage.setItem(SETTINGS_KEYS.DOCUMENT_LIST_SIZE, '50')
|
|
let req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}ui_settings/`
|
|
)
|
|
req.flush(oldSettings)
|
|
|
|
req = httpTestingController.match(
|
|
`${environment.apiBaseUrl}ui_settings/`
|
|
)[0]
|
|
expect(req.request.method).toEqual('POST')
|
|
})
|
|
|
|
it('updates settings on complete tour', () => {
|
|
let req = httpTestingController.expectOne(
|
|
`${environment.apiBaseUrl}ui_settings/`
|
|
)
|
|
req.flush(ui_settings)
|
|
|
|
settingsService.completeTour()
|
|
|
|
req = httpTestingController.match(
|
|
`${environment.apiBaseUrl}ui_settings/`
|
|
)[0]
|
|
expect(req.request.method).toEqual('POST')
|
|
})
|
|
})
|