mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-24 00:59:35 -06:00
Unify these
This commit is contained in:
@@ -549,9 +549,8 @@ describe('DocumentListComponent', () => {
|
||||
const modalSpy = jest.spyOn(modalService, 'open')
|
||||
const toastSpy = jest.spyOn(toastService, 'showInfo')
|
||||
const savedViewServiceCreate = jest.spyOn(savedViewService, 'create')
|
||||
const settingsSetSpy = jest.spyOn(settingsService, 'set')
|
||||
const settingsStoreSpy = jest
|
||||
.spyOn(settingsService, 'storeSettings')
|
||||
const updateVisibilitySpy = jest
|
||||
.spyOn(settingsService, 'updateSavedViewsVisibility')
|
||||
.mockReturnValue(of({ success: true }))
|
||||
savedViewServiceCreate.mockReturnValueOnce(of(modifiedView))
|
||||
component.saveViewConfigAs()
|
||||
@@ -586,15 +585,10 @@ describe('DocumentListComponent', () => {
|
||||
set_permissions: permissions.set_permissions,
|
||||
})
|
||||
)
|
||||
expect(settingsSetSpy).toHaveBeenCalledWith(
|
||||
SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS,
|
||||
expect(updateVisibilitySpy).toHaveBeenCalledWith(
|
||||
expect.arrayContaining([modifiedView.id]),
|
||||
expect.arrayContaining([modifiedView.id])
|
||||
)
|
||||
expect(settingsSetSpy).toHaveBeenCalledWith(
|
||||
SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS,
|
||||
expect.arrayContaining([modifiedView.id])
|
||||
)
|
||||
expect(settingsStoreSpy).toHaveBeenCalled()
|
||||
expect(modalSpy).toHaveBeenCalled()
|
||||
expect(toastSpy).toHaveBeenCalled()
|
||||
expect(modalCloseSpy).toHaveBeenCalled()
|
||||
@@ -628,7 +622,10 @@ describe('DocumentListComponent', () => {
|
||||
|
||||
let openModal: NgbModalRef
|
||||
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
|
||||
const settingsStoreSpy = jest.spyOn(settingsService, 'storeSettings')
|
||||
const updateVisibilitySpy = jest.spyOn(
|
||||
settingsService,
|
||||
'updateSavedViewsVisibility'
|
||||
)
|
||||
jest.spyOn(savedViewService, 'create').mockReturnValueOnce(
|
||||
throwError(
|
||||
() =>
|
||||
@@ -644,7 +641,7 @@ describe('DocumentListComponent', () => {
|
||||
showOnDashboard: true,
|
||||
showInSideBar: true,
|
||||
})
|
||||
expect(settingsStoreSpy).not.toHaveBeenCalled()
|
||||
expect(updateVisibilitySpy).not.toHaveBeenCalled()
|
||||
expect(openModal.componentInstance.error).toEqual({ filter_rules: ['11'] })
|
||||
})
|
||||
|
||||
|
||||
@@ -524,13 +524,10 @@ export class DocumentListComponent
|
||||
sidebarViewIds.push(createdView.id)
|
||||
}
|
||||
|
||||
this.settingsService.set(SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS, [
|
||||
...new Set(dashboardViewIds),
|
||||
])
|
||||
this.settingsService.set(SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS, [
|
||||
...new Set(sidebarViewIds),
|
||||
])
|
||||
return this.settingsService.storeSettings()
|
||||
return this.settingsService.updateSavedViewsVisibility(
|
||||
dashboardViewIds,
|
||||
sidebarViewIds
|
||||
)
|
||||
}
|
||||
|
||||
openDocumentDetail(document: Document | number) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import { NgbModal, NgbModule } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
||||
import { Subject, of, throwError } from 'rxjs'
|
||||
import { SavedView } from 'src/app/data/saved-view'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
|
||||
import { PermissionsGuard } from 'src/app/guards/permissions.guard'
|
||||
import { PermissionsService } from 'src/app/services/permissions.service'
|
||||
@@ -159,9 +158,8 @@ describe('SavedViewsComponent', () => {
|
||||
|
||||
it('should persist visibility changes to user settings', () => {
|
||||
const patchSpy = jest.spyOn(savedViewService, 'patchMany')
|
||||
const setSpy = jest.spyOn(settingsService, 'set')
|
||||
const storeSpy = jest
|
||||
.spyOn(settingsService, 'storeSettings')
|
||||
const updateVisibilitySpy = jest
|
||||
.spyOn(settingsService, 'updateSavedViewsVisibility')
|
||||
.mockReturnValue(of({ success: true }))
|
||||
|
||||
const dashboardControl = component.savedViewsForm
|
||||
@@ -174,15 +172,7 @@ describe('SavedViewsComponent', () => {
|
||||
component.save()
|
||||
|
||||
expect(patchSpy).not.toHaveBeenCalled()
|
||||
expect(setSpy).toHaveBeenCalledWith(
|
||||
SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS,
|
||||
[]
|
||||
)
|
||||
expect(setSpy).toHaveBeenCalledWith(
|
||||
SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS,
|
||||
[savedViews[0].id]
|
||||
)
|
||||
expect(storeSpy).toHaveBeenCalled()
|
||||
expect(updateVisibilitySpy).toHaveBeenCalledWith([], [savedViews[0].id])
|
||||
})
|
||||
|
||||
it('should support delete saved view', () => {
|
||||
|
||||
@@ -12,7 +12,6 @@ import { BehaviorSubject, Observable, of, switchMap, takeUntil } from 'rxjs'
|
||||
import { PermissionsDialogComponent } from 'src/app/components/common/permissions-dialog/permissions-dialog.component'
|
||||
import { DisplayMode } from 'src/app/data/document'
|
||||
import { SavedView } from 'src/app/data/saved-view'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
|
||||
import {
|
||||
PermissionAction,
|
||||
@@ -207,14 +206,13 @@ export class SavedViewsComponent
|
||||
}
|
||||
// Then save the visibility changes in the settings
|
||||
if (visibilityChanged) {
|
||||
this.settings.set(SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS, [
|
||||
...new Set(dashboardVisibleIds),
|
||||
])
|
||||
this.settings.set(SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS, [
|
||||
...new Set(sidebarVisibleIds),
|
||||
])
|
||||
saveOperation = saveOperation.pipe(
|
||||
switchMap(() => this.settings.storeSettings())
|
||||
switchMap(() =>
|
||||
this.settings.updateSavedViewsVisibility(
|
||||
dashboardVisibleIds,
|
||||
sidebarVisibleIds
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ describe('SettingsService', () => {
|
||||
expect(req.request.method).toEqual('POST')
|
||||
})
|
||||
|
||||
it('should update saved view sorting', () => {
|
||||
it('should update saved view sorting and visibility', () => {
|
||||
httpTestingController
|
||||
.expectOne(`${environment.apiBaseUrl}ui_settings/`)
|
||||
.flush(ui_settings)
|
||||
@@ -341,6 +341,15 @@ describe('SettingsService', () => {
|
||||
SETTINGS_KEYS.SIDEBAR_VIEWS_SORT_ORDER,
|
||||
[1, 4]
|
||||
)
|
||||
settingsService.updateSavedViewsVisibility([1, 4], [4, 1])
|
||||
expect(setSpy).toHaveBeenCalledWith(
|
||||
SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS,
|
||||
[1, 4]
|
||||
)
|
||||
expect(setSpy).toHaveBeenCalledWith(
|
||||
SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS,
|
||||
[4, 1]
|
||||
)
|
||||
httpTestingController
|
||||
.expectOne(`${environment.apiBaseUrl}ui_settings/`)
|
||||
.flush(ui_settings)
|
||||
|
||||
@@ -699,4 +699,17 @@ export class SettingsService {
|
||||
])
|
||||
return this.storeSettings()
|
||||
}
|
||||
|
||||
updateSavedViewsVisibility(
|
||||
dashboardVisibleViewIds: number[],
|
||||
sidebarVisibleViewIds: number[]
|
||||
): Observable<any> {
|
||||
this.set(SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS, [
|
||||
...new Set(dashboardVisibleViewIds),
|
||||
])
|
||||
this.set(SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS, [
|
||||
...new Set(sidebarVisibleViewIds),
|
||||
])
|
||||
return this.storeSettings()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user