}),
dashboardViews: saved_views.filter((v) => v.show_on_dashboard),
allViews: saved_views,
+ setDocumentCount: jest.fn(),
},
},
provideHttpClient(withInterceptorsFromDi()),
} from 'src/app/services/permissions.service'
import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service'
import { DocumentService } from 'src/app/services/rest/document.service'
+import { SavedViewService } from 'src/app/services/rest/saved-view.service'
import { SettingsService } from 'src/app/services/settings.service'
import { WebsocketStatusService } from 'src/app/services/websocket-status.service'
import { WidgetFrameComponent } from '../widget-frame/widget-frame.component'
permissionsService = inject(PermissionsService)
private settingsService = inject(SettingsService)
private customFieldService = inject(CustomFieldsService)
+ private savedViewService = inject(SavedViewService)
public DisplayMode = DisplayMode
public DisplayField = DisplayField
this.show = true
this.documents = result.results
this.count = result.count
+ this.savedViewService.setDocumentCount(this.savedView, result.count)
}),
delay(500)
)
}
const queryParams = { id: view.id.toString() }
const getSavedViewSpy = jest.spyOn(savedViewService, 'getCached')
+ const setCountSpy = jest.spyOn(savedViewService, 'setDocumentCount')
+ jest.spyOn(documentService, 'listFiltered').mockReturnValue(
+ of({
+ results: docs,
+ count: 3,
+ all: docs.map((d) => d.id),
+ })
+ )
getSavedViewSpy.mockReturnValue(of(view))
const activateSavedViewSpy = jest.spyOn(
documentListService,
view,
convertToParamMap(queryParams)
)
+ expect(setCountSpy).toHaveBeenCalledWith(view, 3)
})
it('should 404 on load saved view from URL if no view', () => {
expect(getSavedViewSpy).toHaveBeenCalledWith(view.id)
})
+ it('should update saved view document count on load saved view from query params', () => {
+ jest.spyOn(savedViewService, 'getCached').mockReturnValue(
+ of({
+ id: 10,
+ sort_field: 'added',
+ sort_reverse: true,
+ filter_rules: [],
+ })
+ )
+ jest.spyOn(documentService, 'listFiltered').mockReturnValue(
+ of({
+ results: docs,
+ count: 3,
+ all: docs.map((d) => d.id),
+ })
+ )
+ const setCountSpy = jest.spyOn(savedViewService, 'setDocumentCount')
+ jest.spyOn(documentService, 'listFiltered').mockReturnValue(
+ of({
+ results: docs,
+ count: 3,
+ all: docs.map((d) => d.id),
+ })
+ )
+ component.loadViewConfig(10)
+ expect(setCountSpy).toHaveBeenCalledWith(expect.any(Object), 3)
+ })
+
it('should support 3 different display modes', () => {
jest.spyOn(documentListService, 'documents', 'get').mockReturnValue(docs)
fixture.detectChanges()
view,
convertToParamMap(this.route.snapshot.queryParams)
)
- this.list.reload()
+ this.list.reload(() => {
+ this.savedViewService.setDocumentCount(view, this.list.collectionSize)
+ })
this.updateDisplayCustomFields()
this.unmodifiedFilterRules = view.filter_rules
})
.subscribe((view) => {
this.unmodifiedSavedView = view
this.list.activateSavedView(view)
- this.list.reload()
+ this.list.reload(() => {
+ this.savedViewService.setDocumentCount(view, this.list.collectionSize)
+ })
})
}
)
.pipe(takeUntil(this.unsubscribeNotifier))
.subscribe((results: Results<Document>) => {
- this.savedViewDocumentCounts.set(view.id, results.count)
+ this.setDocumentCount(view, results.count)
})
})
}
+ public setDocumentCount(view: SavedView, count: number) {
+ this.savedViewDocumentCounts.set(view.id, count)
+ }
+
public getDocumentCount(view: SavedView): number {
return this.savedViewDocumentCounts.get(view.id)
}