From 24e863b29891a441e0bc8290f30b2bdf418b46ce Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Fri, 14 Mar 2025 13:23:42 -0700
Subject: [PATCH] Coverage

---
 .../services/rest/saved-view.service.spec.ts  | 66 +++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/src-ui/src/app/services/rest/saved-view.service.spec.ts b/src-ui/src/app/services/rest/saved-view.service.spec.ts
index 7b12e8533..cc206de08 100644
--- a/src-ui/src/app/services/rest/saved-view.service.spec.ts
+++ b/src-ui/src/app/services/rest/saved-view.service.spec.ts
@@ -156,6 +156,72 @@ describe(`Additional service tests for SavedViewService`, () => {
     httpTestingController.verify() // no reload
   })
 
+  it('should reload after create, delete, patch and patchMany', () => {
+    const reloadSpy = jest.spyOn(service, 'reload')
+    service
+      .create({
+        name: 'New Saved View',
+        show_on_dashboard: true,
+        show_in_sidebar: true,
+        sort_field: 'name',
+        sort_reverse: true,
+        filter_rules: [],
+      })
+      .subscribe()
+    httpTestingController
+      .expectOne(`${environment.apiBaseUrl}${endpoint}/`)
+      .flush({})
+    expect(reloadSpy).toHaveBeenCalled()
+    reloadSpy.mockClear()
+    httpTestingController
+      .expectOne(
+        `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
+      )
+      .flush({
+        results: saved_views,
+      })
+    service.delete(saved_views[0]).subscribe()
+    httpTestingController
+      .expectOne(`${environment.apiBaseUrl}${endpoint}/1/`)
+      .flush({})
+    expect(reloadSpy).toHaveBeenCalled()
+    reloadSpy.mockClear()
+    httpTestingController
+      .expectOne(
+        `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
+      )
+      .flush({
+        results: saved_views,
+      })
+    service.patch(saved_views[0], true).subscribe()
+    httpTestingController
+      .expectOne(`${environment.apiBaseUrl}${endpoint}/1/`)
+      .flush({})
+    expect(reloadSpy).toHaveBeenCalled()
+    httpTestingController
+      .expectOne(
+        `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
+      )
+      .flush({
+        results: saved_views,
+      })
+    service.patchMany(saved_views).subscribe()
+    saved_views.forEach((saved_view) => {
+      const req = httpTestingController.expectOne(
+        `${environment.apiBaseUrl}${endpoint}/${saved_view.id}/`
+      )
+      req.flush({})
+    })
+    expect(reloadSpy).toHaveBeenCalled()
+    httpTestingController
+      .expectOne(
+        `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
+      )
+      .flush({
+        results: saved_views,
+      })
+  })
+
   beforeEach(() => {
     // Dont need to setup again