Unify these

This commit is contained in:
shamoon
2026-02-20 12:51:46 -08:00
parent 16767b1433
commit 4b4c2766e6
6 changed files with 45 additions and 41 deletions

View File

@@ -549,9 +549,8 @@ describe('DocumentListComponent', () => {
const modalSpy = jest.spyOn(modalService, 'open') const modalSpy = jest.spyOn(modalService, 'open')
const toastSpy = jest.spyOn(toastService, 'showInfo') const toastSpy = jest.spyOn(toastService, 'showInfo')
const savedViewServiceCreate = jest.spyOn(savedViewService, 'create') const savedViewServiceCreate = jest.spyOn(savedViewService, 'create')
const settingsSetSpy = jest.spyOn(settingsService, 'set') const updateVisibilitySpy = jest
const settingsStoreSpy = jest .spyOn(settingsService, 'updateSavedViewsVisibility')
.spyOn(settingsService, 'storeSettings')
.mockReturnValue(of({ success: true })) .mockReturnValue(of({ success: true }))
savedViewServiceCreate.mockReturnValueOnce(of(modifiedView)) savedViewServiceCreate.mockReturnValueOnce(of(modifiedView))
component.saveViewConfigAs() component.saveViewConfigAs()
@@ -586,15 +585,10 @@ describe('DocumentListComponent', () => {
set_permissions: permissions.set_permissions, set_permissions: permissions.set_permissions,
}) })
) )
expect(settingsSetSpy).toHaveBeenCalledWith( expect(updateVisibilitySpy).toHaveBeenCalledWith(
SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS, expect.arrayContaining([modifiedView.id]),
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(modalSpy).toHaveBeenCalled()
expect(toastSpy).toHaveBeenCalled() expect(toastSpy).toHaveBeenCalled()
expect(modalCloseSpy).toHaveBeenCalled() expect(modalCloseSpy).toHaveBeenCalled()
@@ -628,7 +622,10 @@ describe('DocumentListComponent', () => {
let openModal: NgbModalRef let openModal: NgbModalRef
modalService.activeInstances.subscribe((modal) => (openModal = modal[0])) modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
const settingsStoreSpy = jest.spyOn(settingsService, 'storeSettings') const updateVisibilitySpy = jest.spyOn(
settingsService,
'updateSavedViewsVisibility'
)
jest.spyOn(savedViewService, 'create').mockReturnValueOnce( jest.spyOn(savedViewService, 'create').mockReturnValueOnce(
throwError( throwError(
() => () =>
@@ -644,7 +641,7 @@ describe('DocumentListComponent', () => {
showOnDashboard: true, showOnDashboard: true,
showInSideBar: true, showInSideBar: true,
}) })
expect(settingsStoreSpy).not.toHaveBeenCalled() expect(updateVisibilitySpy).not.toHaveBeenCalled()
expect(openModal.componentInstance.error).toEqual({ filter_rules: ['11'] }) expect(openModal.componentInstance.error).toEqual({ filter_rules: ['11'] })
}) })

View File

@@ -524,13 +524,10 @@ export class DocumentListComponent
sidebarViewIds.push(createdView.id) sidebarViewIds.push(createdView.id)
} }
this.settingsService.set(SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS, [ return this.settingsService.updateSavedViewsVisibility(
...new Set(dashboardViewIds), dashboardViewIds,
]) sidebarViewIds
this.settingsService.set(SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS, [ )
...new Set(sidebarViewIds),
])
return this.settingsService.storeSettings()
} }
openDocumentDetail(document: Document | number) { openDocumentDetail(document: Document | number) {

View File

@@ -7,7 +7,6 @@ import { NgbModal, NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
import { Subject, of, throwError } from 'rxjs' import { Subject, of, throwError } from 'rxjs'
import { SavedView } from 'src/app/data/saved-view' 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 { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
import { PermissionsGuard } from 'src/app/guards/permissions.guard' import { PermissionsGuard } from 'src/app/guards/permissions.guard'
import { PermissionsService } from 'src/app/services/permissions.service' import { PermissionsService } from 'src/app/services/permissions.service'
@@ -159,9 +158,8 @@ describe('SavedViewsComponent', () => {
it('should persist visibility changes to user settings', () => { it('should persist visibility changes to user settings', () => {
const patchSpy = jest.spyOn(savedViewService, 'patchMany') const patchSpy = jest.spyOn(savedViewService, 'patchMany')
const setSpy = jest.spyOn(settingsService, 'set') const updateVisibilitySpy = jest
const storeSpy = jest .spyOn(settingsService, 'updateSavedViewsVisibility')
.spyOn(settingsService, 'storeSettings')
.mockReturnValue(of({ success: true })) .mockReturnValue(of({ success: true }))
const dashboardControl = component.savedViewsForm const dashboardControl = component.savedViewsForm
@@ -174,15 +172,7 @@ describe('SavedViewsComponent', () => {
component.save() component.save()
expect(patchSpy).not.toHaveBeenCalled() expect(patchSpy).not.toHaveBeenCalled()
expect(setSpy).toHaveBeenCalledWith( expect(updateVisibilitySpy).toHaveBeenCalledWith([], [savedViews[0].id])
SETTINGS_KEYS.DASHBOARD_VIEWS_VISIBLE_IDS,
[]
)
expect(setSpy).toHaveBeenCalledWith(
SETTINGS_KEYS.SIDEBAR_VIEWS_VISIBLE_IDS,
[savedViews[0].id]
)
expect(storeSpy).toHaveBeenCalled()
}) })
it('should support delete saved view', () => { it('should support delete saved view', () => {

View File

@@ -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 { PermissionsDialogComponent } from 'src/app/components/common/permissions-dialog/permissions-dialog.component'
import { DisplayMode } from 'src/app/data/document' import { DisplayMode } from 'src/app/data/document'
import { SavedView } from 'src/app/data/saved-view' 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 { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
import { import {
PermissionAction, PermissionAction,
@@ -207,14 +206,13 @@ export class SavedViewsComponent
} }
// Then save the visibility changes in the settings // Then save the visibility changes in the settings
if (visibilityChanged) { 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( saveOperation = saveOperation.pipe(
switchMap(() => this.settings.storeSettings()) switchMap(() =>
this.settings.updateSavedViewsVisibility(
dashboardVisibleIds,
sidebarVisibleIds
)
)
) )
} }

View File

@@ -320,7 +320,7 @@ describe('SettingsService', () => {
expect(req.request.method).toEqual('POST') expect(req.request.method).toEqual('POST')
}) })
it('should update saved view sorting', () => { it('should update saved view sorting and visibility', () => {
httpTestingController httpTestingController
.expectOne(`${environment.apiBaseUrl}ui_settings/`) .expectOne(`${environment.apiBaseUrl}ui_settings/`)
.flush(ui_settings) .flush(ui_settings)
@@ -341,6 +341,15 @@ describe('SettingsService', () => {
SETTINGS_KEYS.SIDEBAR_VIEWS_SORT_ORDER, SETTINGS_KEYS.SIDEBAR_VIEWS_SORT_ORDER,
[1, 4] [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 httpTestingController
.expectOne(`${environment.apiBaseUrl}ui_settings/`) .expectOne(`${environment.apiBaseUrl}ui_settings/`)
.flush(ui_settings) .flush(ui_settings)

View File

@@ -699,4 +699,17 @@ export class SettingsService {
]) ])
return this.storeSettings() 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()
}
} }