]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Add frontend testing of multi-object filtering 2893/head
authorshamoon <4887959+shamoon@users.noreply.github.com>
Wed, 15 Mar 2023 05:37:41 +0000 (22:37 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Sat, 18 Mar 2023 00:57:54 +0000 (17:57 -0700)
src-ui/cypress/e2e/documents/documents-list.cy.ts
src-ui/cypress/e2e/documents/query-params.cy.ts
src-ui/cypress/fixtures/correspondents/correspondents.json
src-ui/cypress/fixtures/document_types/doctypes.json
src-ui/cypress/fixtures/documents/documents.json

index 84b39662551c6f3ca8d8f8c10a4316f564fda1f7..5c17ef5d9f71edccf4e4f824500f092b9eca62f3 100644 (file)
@@ -48,6 +48,26 @@ describe('documents-list', () => {
             (d.tags as Array<number>).includes(tag_id)
           )
           response.count = response.results.length
+        } else if (req.query.hasOwnProperty('correspondent__id__in')) {
+          // filtering e.g. http://localhost:8000/api/documents/?page=1&page_size=50&ordering=-created&correspondent__id__in=9,14
+          const correspondent_ids = req.query['correspondent__id__in']
+            .toString()
+            .split(',')
+            .map((c) => +c)
+          response.results = (documentsJson.results as Array<any>).filter((d) =>
+            correspondent_ids.includes(d.correspondent)
+          )
+          response.count = response.results.length
+        } else if (req.query.hasOwnProperty('correspondent__id__none')) {
+          // filtering e.g. http://localhost:8000/api/documents/?page=1&page_size=50&ordering=-created&correspondent__id__none=9,14
+          const correspondent_ids = req.query['correspondent__id__none']
+            .toString()
+            .split(',')
+            .map((c) => +c)
+          response.results = (documentsJson.results as Array<any>).filter(
+            (d) => !correspondent_ids.includes(d.correspondent)
+          )
+          response.count = response.results.length
         }
 
         req.reply(response)
@@ -112,6 +132,27 @@ describe('documents-list', () => {
     cy.contains('One document')
   })
 
+  it('should filter including multiple correspondents', () => {
+    cy.get('app-filter-editor app-filterable-dropdown[title="Correspondent"]')
+      .click()
+      .within(() => {
+        cy.contains('button', 'ABC Test Correspondent').click()
+        cy.contains('button', 'Corresp 11').click()
+      })
+    cy.contains('3 documents')
+  })
+
+  it('should filter excluding multiple correspondents', () => {
+    cy.get('app-filter-editor app-filterable-dropdown[title="Correspondent"]')
+      .click()
+      .within(() => {
+        cy.contains('button', 'ABC Test Correspondent').click()
+        cy.contains('button', 'Corresp 11').click()
+        cy.contains('label', 'Exclude').click()
+      })
+    cy.contains('One document')
+  })
+
   it('should apply tags', () => {
     cy.get('app-document-card-small:first-of-type').click()
     cy.get('app-bulk-editor app-filterable-dropdown[title="Tags"]').within(
index a31e43c8a3d136fa0ce06b73161e424236888b49..eb160e9de380fe4494e8bda6de0447665ee065da 100644 (file)
@@ -232,6 +232,11 @@ describe('documents query params', () => {
 
   it('should show a list of documents filtered by document type', () => {
     cy.visit('/documents?sort=created&reverse=true&document_type__id=1')
+    cy.contains('2 documents')
+  })
+
+  it('should show a list of documents filtered by multiple correspondents', () => {
+    cy.visit('/documents?sort=created&reverse=true&document_type__id__in=1,2')
     cy.contains('3 documents')
   })
 
@@ -245,9 +250,14 @@ describe('documents query params', () => {
     cy.contains('2 documents')
   })
 
+  it('should show a list of documents filtered by multiple correspondents', () => {
+    cy.visit('/documents?sort=created&reverse=true&correspondent__id__in=9,14')
+    cy.contains('3 documents')
+  })
+
   it('should show a list of documents filtered by no correspondent', () => {
     cy.visit('/documents?sort=created&reverse=true&correspondent__isnull=1')
-    cy.contains('2 documents')
+    cy.contains('One document')
   })
 
   it('should show a list of documents filtered by storage path', () => {
index fe9fa1d5f019f38d020e100cb09c61b42468a3f0..d43ff664598c9e765ddcc3283be97c551e587789 100644 (file)
@@ -1 +1,257 @@
-{"count":27,"next":"http://localhost:8000/api/correspondents/?page=2","previous":null,"results":[{"id":9,"slug":"abc-test-correspondent","name":"ABC Test Correspondent","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":13,"slug":"corresp-10","name":"Corresp 10","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":14,"slug":"corresp-11","name":"Corresp 11","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":15,"slug":"corresp-12","name":"Corresp 12","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":16,"slug":"corresp-13","name":"Corresp 13","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":18,"slug":"corresp-15","name":"Corresp 15","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":19,"slug":"corresp-16","name":"Corresp 16","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":20,"slug":"corresp-17","name":"Corresp 17","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":21,"slug":"corresp-18","name":"Corresp 18","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":22,"slug":"corresp-19","name":"Corresp 19","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":23,"slug":"corresp-20","name":"Corresp 20","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":24,"slug":"corresp-21","name":"Corresp 21","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":25,"slug":"corresp-22","name":"Corresp 22","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":26,"slug":"corresp-23","name":"Corresp 23","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":5,"slug":"corresp-3","name":"Corresp 3","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":6,"slug":"corresp-4","name":"Corresp 4","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":7,"slug":"corresp-5","name":"Corresp 5","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":8,"slug":"corresp-6","name":"Corresp 6","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":10,"slug":"corresp-7","name":"Corresp 7","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":11,"slug":"corresp-8","name":"Corresp 8","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":12,"slug":"corresp-9","name":"Corresp 9","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":17,"slug":"correspondent-14","name":"Correspondent 14","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0,"last_correspondence":null},{"id":2,"slug":"correspondent-2","name":"Correspondent 2","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":7,"last_correspondence":"2021-01-20T23:37:58.204614Z"},{"id":27,"slug":"michael-shamoon","name":"Michael Shamoon","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":1,"last_correspondence":"2022-03-16T03:48:50.089624Z"},{"id":4,"slug":"newest-correspondent","name":"Newest Correspondent","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":1,"last_correspondence":"2021-02-07T08:00:00Z"}]}
+{
+    "count": 27,
+    "next": "http://localhost:8000/api/correspondents/?page=2",
+    "previous": null,
+    "results": [
+        {
+            "id": 9,
+            "slug": "abc-test-correspondent",
+            "name": "ABC Test Correspondent",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 13,
+            "slug": "corresp-10",
+            "name": "Corresp 10",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 14,
+            "slug": "corresp-11",
+            "name": "Corresp 11",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 15,
+            "slug": "corresp-12",
+            "name": "Corresp 12",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 16,
+            "slug": "corresp-13",
+            "name": "Corresp 13",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 18,
+            "slug": "corresp-15",
+            "name": "Corresp 15",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 19,
+            "slug": "corresp-16",
+            "name": "Corresp 16",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 20,
+            "slug": "corresp-17",
+            "name": "Corresp 17",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 21,
+            "slug": "corresp-18",
+            "name": "Corresp 18",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 22,
+            "slug": "corresp-19",
+            "name": "Corresp 19",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 23,
+            "slug": "corresp-20",
+            "name": "Corresp 20",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 24,
+            "slug": "corresp-21",
+            "name": "Corresp 21",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 25,
+            "slug": "corresp-22",
+            "name": "Corresp 22",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 26,
+            "slug": "corresp-23",
+            "name": "Corresp 23",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 5,
+            "slug": "corresp-3",
+            "name": "Corresp 3",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 6,
+            "slug": "corresp-4",
+            "name": "Corresp 4",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 7,
+            "slug": "corresp-5",
+            "name": "Corresp 5",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 8,
+            "slug": "corresp-6",
+            "name": "Corresp 6",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 10,
+            "slug": "corresp-7",
+            "name": "Corresp 7",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 11,
+            "slug": "corresp-8",
+            "name": "Corresp 8",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 12,
+            "slug": "corresp-9",
+            "name": "Corresp 9",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 17,
+            "slug": "correspondent-14",
+            "name": "Correspondent 14",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 0,
+            "last_correspondence": null
+        },
+        {
+            "id": 2,
+            "slug": "correspondent-2",
+            "name": "Correspondent 2",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 7,
+            "last_correspondence": "2021-01-20T23:37:58.204614Z"
+        },
+        {
+            "id": 27,
+            "slug": "correspondent-slug",
+            "name": "Correspondent Slug",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 1,
+            "last_correspondence": "2022-03-16T03:48:50.089624Z"
+        },
+        {
+            "id": 4,
+            "slug": "newest-correspondent",
+            "name": "Newest Correspondent",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 1,
+            "last_correspondence": "2021-02-07T08:00:00Z"
+        }
+    ]
+}
index 36c75f2ff236c9e761f9134f408cd2d026664ebb..eb2d74a0ea454eed40133a93362d082bc85b4972 100644 (file)
@@ -1 +1,25 @@
-{"count":1,"next":null,"previous":null,"results":[{"id":1,"slug":"test","name":"Test Doc Type","match":"","matching_algorithm":1,"is_insensitive":true,"document_count":0}]}
+{
+    "count": 2,
+    "next": null,
+    "previous": null,
+    "results": [
+        {
+            "id": 1,
+            "slug": "test",
+            "name": "Test Doc Type",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 1
+        },
+        {
+            "id": 2,
+            "slug": "test2",
+            "name": "Test Doc Type 2",
+            "match": "",
+            "matching_algorithm": 1,
+            "is_insensitive": true,
+            "document_count": 1
+        }
+    ]
+}
index 211401b4bccd23c060042ada59353ee9d314b18d..e7275b4b5d5b444b860ff9b7034357ba41ea8309 100644 (file)
@@ -43,7 +43,7 @@
         },
         {
             "id": 3,
-            "correspondent": null,
+            "correspondent": 14,
             "document_type": 1,
             "storage_path": null,
             "title": "dolor",
@@ -64,7 +64,7 @@
         {
             "id": 4,
             "correspondent": 9,
-            "document_type": 1,
+            "document_type": 2,
             "storage_path": null,
             "title": "sit amet",
             "content": "Test document PDF",