]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Mock some API methods in settings spec
authorMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Thu, 24 Mar 2022 04:20:17 +0000 (21:20 -0700)
committerMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Wed, 30 Mar 2022 03:02:19 +0000 (20:02 -0700)
src-ui/cypress/fixtures/settings/savedviews_saved.json [deleted file]
src-ui/cypress/integration/settings.spec.ts

diff --git a/src-ui/cypress/fixtures/settings/savedviews_saved.json b/src-ui/cypress/fixtures/settings/savedviews_saved.json
deleted file mode 100644 (file)
index 486f0dd..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"count":3,"next":null,"previous":null,"results":[{"id":1,"name":"Inbox","show_on_dashboard":false,"show_in_sidebar":false,"sort_field":"created","sort_reverse":true,"filter_rules":[{"rule_type":6,"value":"18"}]},{"id":2,"name":"Recently Added","show_on_dashboard":true,"show_in_sidebar":false,"sort_field":"created","sort_reverse":true,"filter_rules":[]},{"id":11,"name":"Taxes","show_on_dashboard":false,"show_in_sidebar":true,"sort_field":"created","sort_reverse":true,"filter_rules":[{"rule_type":6,"value":"39"}]}]}
index d61d70b1915771a062a4952c2d7df8ffb7778441..5e0d2b8ffb1b0b9340390f0194f2faddc078cc75 100644 (file)
@@ -1,8 +1,33 @@
 describe('settings', () => {
   beforeEach(() => {
-    cy.intercept('http://localhost:8000/api/saved_views/*', {
-      fixture: 'settings/savedviews.json',
+    this.modifiedViews = []
+
+    // mock API methods
+    cy.fixture('settings/savedviews.json').then((savedViewsJson) => {
+      // saved views PATCH
+      cy.intercept(
+        'PATCH',
+        'http://localhost:8000/api/saved_views/*',
+        (req) => {
+          this.modifiedViews.push(req.body) // store this for later
+          req.reply({ result: 'OK' })
+        }
+      )
+
+      cy.intercept('GET', 'http://localhost:8000/api/saved_views/*', (req) => {
+        let response = { ...savedViewsJson }
+        if (this.modifiedViews.length) {
+          response.results = response.results.map((v) => {
+            if (this.modifiedViews.find((mv) => mv.id == v.id))
+              v = this.modifiedViews.find((mv) => mv.id == v.id)
+            return v
+          })
+        }
+
+        req.reply(response)
+      })
     })
+
     cy.viewport(1024, 1024)
     cy.visit('/settings')
   })
@@ -35,9 +60,6 @@ describe('settings', () => {
   it('should remove saved view from sidebar when unset', () => {
     cy.contains('a', 'Saved views').click()
     cy.get('#show_in_sidebar_1').click()
-    cy.intercept('http://localhost:8000/api/saved_views/*', {
-      fixture: 'settings/savedviews_saved.json',
-    })
     cy.contains('button', 'Save').click()
     cy.contains('li', 'Inbox').should('not.exist')
   })
@@ -45,9 +67,6 @@ describe('settings', () => {
   it('should remove saved view from dashboard when unset', () => {
     cy.contains('a', 'Saved views').click()
     cy.get('#show_on_dashboard_1').click()
-    cy.intercept('http://localhost:8000/api/saved_views/*', {
-      fixture: 'settings/savedviews_saved.json',
-    })
     cy.contains('button', 'Save').click()
     cy.visit('/dashboard')
     cy.get('app-saved-view-widget').contains('Inbox').should('not.exist')