From f03a0f6e7331f1da06e7f8fcc7338e54cdec7bb2 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 1 Jun 2022 12:38:23 -0700 Subject: [PATCH] Add documents query params e2e tests --- .../cypress/fixtures/documents/documents.json | 74 +++- .../remote_version/remote_version.json | 1 + .../fixtures/storage_paths/storage_paths.json | 17 + src-ui/cypress/fixtures/tags/tags.json | 104 +++++- .../documents/documents-list.spec.ts | 1 + .../documents/query-params.spec.ts | 350 ++++++++++++++++++ 6 files changed, 545 insertions(+), 2 deletions(-) create mode 100644 src-ui/cypress/fixtures/remote_version/remote_version.json create mode 100644 src-ui/cypress/fixtures/storage_paths/storage_paths.json create mode 100644 src-ui/cypress/integration/documents/query-params.spec.ts diff --git a/src-ui/cypress/fixtures/documents/documents.json b/src-ui/cypress/fixtures/documents/documents.json index 618a3f07c..bcf122ecc 100644 --- a/src-ui/cypress/fixtures/documents/documents.json +++ b/src-ui/cypress/fixtures/documents/documents.json @@ -1 +1,73 @@ -{"count":3,"next":null,"previous":null,"results":[{"id":1,"correspondent":9,"document_type":1,"title":"lorem-ipsum","content":"Test document PDF \n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla est purus, ultrices in porttitor \nin, accumsan non quam. Nam consectetur porttitor rhoncus. Curabitur eu est et leo feugiat \nauctor vel quis lorem. Ut et ligula dolor, sit amet consequat lorem. Aliquam porta eros sed \nvelit imperdiet egestas. Maecenas tempus eros ut diam ullamcorper id dictum libero \ntempor. Donec quis augue quis magna condimentum lobortis. Quisque imperdiet ipsum vel \nmagna viverra rutrum. Cras viverra molestie urna, vitae vestibulum turpis varius id. \nVestibulum mollis, arcu iaculis bibendum varius, velit sapien blandit metus, ac posuere lorem \nnulla ac dolor. Maecenas urna elit, tincidunt in dapibus nec, vehicula eu dui. Duis lacinia \nfringilla massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur \nridiculus mus. Ut consequat ultricies est, non rhoncus mauris congue porta. Vivamus viverra \nsuscipit felis eget condimentum. Cum sociis natoque penatibus et magnis dis parturient \nmontes, nascetur ridiculus mus. Integer bibendum sagittis ligula, non faucibus nulla volutpat \nvitae. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. \nIn aliquet quam et velit bibendum accumsan. Cum sociis natoque penatibus et magnis dis \nparturient montes, nascetur ridiculus mus. Vestibulum vitae ipsum nec arcu semper \nadipiscing at ac lacus. Praesent id pellentesque orci. Morbi congue viverra nisl nec rhoncus. \nInteger mattis, ipsum a tincidunt commodo, lacus arcu elementum elit, at mollis eros ante ac \nrisus. In volutpat, ante at pretium ultricies, velit magna suscipit enim, aliquet blandit massa \norci nec lorem. Nulla facilisi. Duis eu vehicula arcu. Nulla facilisi. Maecenas pellentesque \nvolutpat felis, quis tristique ligula luctus vel. Sed nec mi eros. Integer augue enim, sollicitudin \nullamcorper mattis eget, aliquam in est. Morbi sollicitudin libero nec augue dignissim ut \nconsectetur dui volutpat. Nulla facilisi. Mauris egestas vestibulum neque cursus tincidunt. \nDonec sit amet pulvinar orci. \nQuisque volutpat pharetra tincidunt. Fusce sapien arcu, molestie eget varius egestas, \nfaucibus ac urna. Sed at nisi in velit egestas aliquam ut a felis. Aenean malesuada iaculis nisl, \nut tempor lacus egestas consequat. Nam nibh lectus, gravida sed egestas ut, feugiat quis \ndolor. Donec eu leo enim, non laoreet ante. Morbi dictum tempor vulputate. Phasellus \nultricies risus vel augue sagittis euismod. Vivamus tincidunt placerat nisi in aliquam. Cras \nquis mi ac nunc pretium aliquam. Aenean elementum erat ac metus commodo rhoncus. \nAliquam nulla augue, porta non sagittis quis, accumsan vitae sem. Phasellus id lectus tortor, \neget pulvinar augue. Etiam eget velit ac purus fringilla blandit. Donec odio odio, sagittis sed \niaculis sed, consectetur eget sem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. \nMaecenas accumsan velit vel turpis rutrum in sodales diam placerat. \nQuisque luctus ullamcorper velit sit amet lobortis. Etiam ligula felis, vulputate quis rhoncus \nnec, fermentum eget odio. Vivamus vel ipsum ac augue sodales mollis euismod nec tellus. \nFusce et augue rutrum nunc semper vehicula vel semper nisl. Nam laoreet euismod quam at \nvarius. Sed aliquet auctor nibh. Curabitur malesuada fermentum lacus vel accumsan. Duis \nornare scelerisque nulla, ac pulvinar ligula tempus sit amet. In placerat nulla ac ante \nscelerisque posuere. Phasellus at ante felis. Sed hendrerit risus a metus posuere rutrum. \nPhasellus eu augue dui. Proin in vestibulum ipsum. Aenean accumsan mollis sapien, ut \neleifend sem blandit at. Vivamus luctus mi eget lorem lobortis pharetra. Phasellus at tortor \nquam, a volutpat purus. Etiam sollicitudin arcu vel elit bibendum et imperdiet risus tincidunt. \nEtiam elit velit, posuere ut pulvinar ac, condimentum eget justo. Fusce a erat velit. Vivamus \nimperdiet ultrices orci in hendrerit.","tags":[4],"created":"2022-03-22T07:24:18Z","modified":"2022-03-22T07:24:23.264859Z","added":"2022-03-22T07:24:22.922631Z","archive_serial_number":null,"original_file_name":"2022-03-22 lorem-ipsum.pdf","archived_file_name":"2022-03-22 lorem-ipsum.pdf"},{"id":2,"correspondent":null,"document_type":null,"title":"lorem-ipsum","content":"Test document PDF","tags":[],"created":"2022-03-23T07:24:18Z","modified":"2022-03-23T07:24:23.264859Z","added":"2022-03-23T07:24:22.922631Z","archive_serial_number":null,"original_file_name":"2022-03-23 lorem-ipsum.pdf","archived_file_name":"2022-03-23 lorem-ipsum.pdf"},{"id":3,"correspondent":null,"document_type":1,"title":"lorem-ipsum","content":"Test document PDF","tags":[2],"created":"2022-03-24T07:24:18Z","modified":"2022-03-24T07:24:23.264859Z","added":"2022-03-24T07:24:22.922631Z","archive_serial_number":null,"original_file_name":"2022-03-24 lorem-ipsum.pdf","archived_file_name":"2022-03-24 lorem-ipsum.pdf"}]} +{ + "count": 3, + "next": null, + "previous": null, + "results": [ + { + "id": 1, + "correspondent": 9, + "document_type": 1, + "storage_path": null, + "title": "No latin title", + "content": "Test document PDF \n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla est purus, ultrices in porttitor \nin, accumsan non quam. Nam consectetur porttitor rhoncus. Curabitur eu est et leo feugiat \nauctor vel quis lorem. Ut et ligula dolor, sit amet consequat lorem. Aliquam porta eros sed \nvelit imperdiet egestas. Maecenas tempus eros ut diam ullamcorper id dictum libero \ntempor. Donec quis augue quis magna condimentum lobortis. Quisque imperdiet ipsum vel \nmagna viverra rutrum. Cras viverra molestie urna, vitae vestibulum turpis varius id. \nVestibulum mollis, arcu iaculis bibendum varius, velit sapien blandit metus, ac posuere lorem \nnulla ac dolor. Maecenas urna elit, tincidunt in dapibus nec, vehicula eu dui. Duis lacinia \nfringilla massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur \nridiculus mus. Ut consequat ultricies est, non rhoncus mauris congue porta. Vivamus viverra \nsuscipit felis eget condimentum. Cum sociis natoque penatibus et magnis dis parturient \nmontes, nascetur ridiculus mus. Integer bibendum sagittis ligula, non faucibus nulla volutpat \nvitae. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. \nIn aliquet quam et velit bibendum accumsan. Cum sociis natoque penatibus et magnis dis \nparturient montes, nascetur ridiculus mus. Vestibulum vitae ipsum nec arcu semper \nadipiscing at ac lacus. Praesent id pellentesque orci. Morbi congue viverra nisl nec rhoncus. \nInteger mattis, ipsum a tincidunt commodo, lacus arcu elementum elit, at mollis eros ante ac \nrisus. In volutpat, ante at pretium ultricies, velit magna suscipit enim, aliquet blandit massa \norci nec lorem. Nulla facilisi. Duis eu vehicula arcu. Nulla facilisi. Maecenas pellentesque \nvolutpat felis, quis tristique ligula luctus vel. Sed nec mi eros. Integer augue enim, sollicitudin \nullamcorper mattis eget, aliquam in est. Morbi sollicitudin libero nec augue dignissim ut \nconsectetur dui volutpat. Nulla facilisi. Mauris egestas vestibulum neque cursus tincidunt. \nDonec sit amet pulvinar orci. \nQuisque volutpat pharetra tincidunt. Fusce sapien arcu, molestie eget varius egestas, \nfaucibus ac urna. Sed at nisi in velit egestas aliquam ut a felis. Aenean malesuada iaculis nisl, \nut tempor lacus egestas consequat. Nam nibh lectus, gravida sed egestas ut, feugiat quis \ndolor. Donec eu leo enim, non laoreet ante. Morbi dictum tempor vulputate. Phasellus \nultricies risus vel augue sagittis euismod. Vivamus tincidunt placerat nisi in aliquam. Cras \nquis mi ac nunc pretium aliquam. Aenean elementum erat ac metus commodo rhoncus. \nAliquam nulla augue, porta non sagittis quis, accumsan vitae sem. Phasellus id lectus tortor, \neget pulvinar augue. Etiam eget velit ac purus fringilla blandit. Donec odio odio, sagittis sed \niaculis sed, consectetur eget sem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. \nMaecenas accumsan velit vel turpis rutrum in sodales diam placerat. \nQuisque luctus ullamcorper velit sit amet lobortis. Etiam ligula felis, vulputate quis rhoncus \nnec, fermentum eget odio. Vivamus vel ipsum ac augue sodales mollis euismod nec tellus. \nFusce et augue rutrum nunc semper vehicula vel semper nisl. Nam laoreet euismod quam at \nvarius. Sed aliquet auctor nibh. Curabitur malesuada fermentum lacus vel accumsan. Duis \nornare scelerisque nulla, ac pulvinar ligula tempus sit amet. In placerat nulla ac ante \nscelerisque posuere. Phasellus at ante felis. Sed hendrerit risus a metus posuere rutrum. \nPhasellus eu augue dui. Proin in vestibulum ipsum. Aenean accumsan mollis sapien, ut \neleifend sem blandit at. Vivamus luctus mi eget lorem lobortis pharetra. Phasellus at tortor \nquam, a volutpat purus. Etiam sollicitudin arcu vel elit bibendum et imperdiet risus tincidunt. \nEtiam elit velit, posuere ut pulvinar ac, condimentum eget justo. Fusce a erat velit. Vivamus \nimperdiet ultrices orci in hendrerit.", + "tags": [ + 4 + ], + "created": "2022-03-22T07:24:18Z", + "modified": "2022-03-22T07:24:23.264859Z", + "added": "2022-03-22T07:24:22.922631Z", + "archive_serial_number": null, + "original_file_name": "2022-03-22 no latin title.pdf", + "archived_file_name": "2022-03-22 no latin title.pdf" + }, + { + "id": 2, + "correspondent": null, + "document_type": null, + "storage_path": 2, + "title": "lorem ipsum dolor sit amet", + "content": "Test document PDF", + "tags": [], + "created": "2022-03-23T07:24:18Z", + "modified": "2022-03-23T07:24:23.264859Z", + "added": "2022-03-23T07:24:22.922631Z", + "archive_serial_number": 12345, + "original_file_name": "2022-03-23 lorem ipsum dolor sit amet.pdf", + "archived_file_name": "2022-03-23 llorem ipsum dolor sit amet.pdf" + }, + { + "id": 3, + "correspondent": null, + "document_type": 1, + "storage_path": null, + "title": "dolor", + "content": "Test document PDF", + "tags": [ + 2 + ], + "created": "2022-03-24T07:24:18Z", + "modified": "2022-03-24T07:24:23.264859Z", + "added": "2022-03-24T07:24:22.922631Z", + "archive_serial_number": null, + "original_file_name": "2022-03-24 dolor.pdf", + "archived_file_name": "2022-03-24 dolor.pdf" + }, + { + "id": 4, + "correspondent": 9, + "document_type": 1, + "storage_path": null, + "title": "sit amet", + "content": "Test document PDF", + "tags": [ + 4, 5 + ], + "created": "2022-06-01T07:24:18Z", + "modified": "2022-06-01T07:24:23.264859Z", + "added": "2022-06-01T07:24:22.922631Z", + "archive_serial_number": 12347, + "original_file_name": "2022-06-01 sit amet.pdf", + "archived_file_name": "2022-06-01 sit amet.pdf" + } + ] +} diff --git a/src-ui/cypress/fixtures/remote_version/remote_version.json b/src-ui/cypress/fixtures/remote_version/remote_version.json new file mode 100644 index 000000000..4ed755564 --- /dev/null +++ b/src-ui/cypress/fixtures/remote_version/remote_version.json @@ -0,0 +1 @@ +{"version":"v1.7.1","update_available":false,"feature_is_set":true} diff --git a/src-ui/cypress/fixtures/storage_paths/storage_paths.json b/src-ui/cypress/fixtures/storage_paths/storage_paths.json new file mode 100644 index 000000000..86ae9b79d --- /dev/null +++ b/src-ui/cypress/fixtures/storage_paths/storage_paths.json @@ -0,0 +1,17 @@ +{ + "count": 1, + "next": null, + "previous": null, + "results": [ + { + "id": 2, + "slug": "year-title", + "name": "Year - Title", + "path": "{created_year}/{title}", + "match": "", + "matching_algorithm": 6, + "is_insensitive": true, + "document_count": 1 + } + ] +} diff --git a/src-ui/cypress/fixtures/tags/tags.json b/src-ui/cypress/fixtures/tags/tags.json index e48049f93..eefee9097 100644 --- a/src-ui/cypress/fixtures/tags/tags.json +++ b/src-ui/cypress/fixtures/tags/tags.json @@ -1 +1,103 @@ -{"count":8,"next":null,"previous":null,"results":[{"id":4,"slug":"another-sample-tag","name":"Another Sample Tag","color":"#a6cee3","text_color":"#000000","match":"","matching_algorithm":6,"is_insensitive":true,"is_inbox_tag":false,"document_count":3},{"id":7,"slug":"newone","name":"NewOne","color":"#9e4ad1","text_color":"#ffffff","match":"","matching_algorithm":1,"is_insensitive":true,"is_inbox_tag":false,"document_count":2},{"id":6,"slug":"partial-tag","name":"Partial Tag","color":"#72dba7","text_color":"#000000","match":"","matching_algorithm":1,"is_insensitive":true,"is_inbox_tag":false,"document_count":1},{"id":2,"slug":"tag-2","name":"Tag 2","color":"#612db7","text_color":"#ffffff","match":"","matching_algorithm":1,"is_insensitive":true,"is_inbox_tag":false,"document_count":3},{"id":3,"slug":"tag-3","name":"Tag 3","color":"#b2df8a","text_color":"#000000","match":"","matching_algorithm":1,"is_insensitive":true,"is_inbox_tag":false,"document_count":4},{"id":5,"slug":"tagwithpartial","name":"TagWithPartial","color":"#3b2db4","text_color":"#ffffff","match":"","matching_algorithm":6,"is_insensitive":true,"is_inbox_tag":false,"document_count":2},{"id":8,"slug":"test-another","name":"Test Another","color":"#3ccea5","text_color":"#000000","match":"","matching_algorithm":4,"is_insensitive":true,"is_inbox_tag":false,"document_count":0},{"id":1,"slug":"test-tag","name":"Test Tag","color":"#fb9a99","text_color":"#000000","match":"","matching_algorithm":1,"is_insensitive":true,"is_inbox_tag":false,"document_count":4}]} +{ + "count": 8, + "next": null, + "previous": null, + "results": [ + { + "id": 4, + "slug": "another-sample-tag", + "name": "Another Sample Tag", + "color": "#a6cee3", + "text_color": "#000000", + "match": "", + "matching_algorithm": 6, + "is_insensitive": true, + "is_inbox_tag": false, + "document_count": 3 + }, + { + "id": 7, + "slug": "newone", + "name": "NewOne", + "color": "#9e4ad1", + "text_color": "#ffffff", + "match": "", + "matching_algorithm": 1, + "is_insensitive": true, + "is_inbox_tag": false, + "document_count": 2 + }, + { + "id": 6, + "slug": "partial-tag", + "name": "Partial Tag", + "color": "#72dba7", + "text_color": "#000000", + "match": "", + "matching_algorithm": 1, + "is_insensitive": true, + "is_inbox_tag": false, + "document_count": 1 + }, + { + "id": 2, + "slug": "tag-2", + "name": "Tag 2", + "color": "#612db7", + "text_color": "#ffffff", + "match": "", + "matching_algorithm": 1, + "is_insensitive": true, + "is_inbox_tag": false, + "document_count": 3 + }, + { + "id": 3, + "slug": "tag-3", + "name": "Tag 3", + "color": "#b2df8a", + "text_color": "#000000", + "match": "", + "matching_algorithm": 1, + "is_insensitive": true, + "is_inbox_tag": false, + "document_count": 4 + }, + { + "id": 5, + "slug": "tagwithpartial", + "name": "TagWithPartial", + "color": "#3b2db4", + "text_color": "#ffffff", + "match": "", + "matching_algorithm": 6, + "is_insensitive": true, + "is_inbox_tag": false, + "document_count": 2 + }, + { + "id": 8, + "slug": "test-another", + "name": "Test Another", + "color": "#3ccea5", + "text_color": "#000000", + "match": "", + "matching_algorithm": 4, + "is_insensitive": true, + "is_inbox_tag": false, + "document_count": 0 + }, + { + "id": 1, + "slug": "test-tag", + "name": "Test Tag", + "color": "#fb9a99", + "text_color": "#000000", + "match": "", + "matching_algorithm": 1, + "is_insensitive": true, + "is_inbox_tag": false, + "document_count": 4 + } + ] +} diff --git a/src-ui/cypress/integration/documents/documents-list.spec.ts b/src-ui/cypress/integration/documents/documents-list.spec.ts index 217923e2f..6429dbc65 100644 --- a/src-ui/cypress/integration/documents/documents-list.spec.ts +++ b/src-ui/cypress/integration/documents/documents-list.spec.ts @@ -72,6 +72,7 @@ describe('documents-list', () => { fixture: 'document_types/doctypes.json', }) + cy.viewport(1280, 1024) cy.visit('/documents') }) diff --git a/src-ui/cypress/integration/documents/query-params.spec.ts b/src-ui/cypress/integration/documents/query-params.spec.ts new file mode 100644 index 000000000..b9f6bd30c --- /dev/null +++ b/src-ui/cypress/integration/documents/query-params.spec.ts @@ -0,0 +1,350 @@ +import { PaperlessDocument } from 'src/app/data/paperless-document' + +describe('documents query params', () => { + beforeEach(() => { + cy.intercept('http://localhost:8000/api/ui_settings/', { + fixture: 'ui_settings/settings.json', + }) + cy.intercept('http://localhost:8000/api/remote_version/', { + fixture: 'remote_version/remote_version.json', + }) + cy.intercept('http://localhost:8000/api/correspondents/*', { + fixture: 'correspondents/correspondents.json', + }) + cy.intercept('http://localhost:8000/api/document_types/*', { + fixture: 'document_types/doctypes.json', + }) + cy.intercept('http://localhost:8000/api/saved_views/*', { + fixture: 'saved_views/savedviews.json', + }) + cy.intercept('http://localhost:8000/api/storage_paths/*', { + fixture: 'storage_paths/storage_paths.json', + }) + cy.intercept('http://localhost:8000/api/tags/*', { + fixture: 'tags/tags.json', + }) + cy.fixture('documents/documents.json').then((documentsJson) => { + // mock api filtering + cy.intercept('GET', 'http://localhost:8000/api/documents/*', (req) => { + let response = { ...documentsJson } + + if (req.query.hasOwnProperty('ordering')) { + const sort_field = req.query['ordering'].toString().replace('-', '') + const reverse = req.query['ordering'].toString().indexOf('-') !== -1 + response.results = ( + documentsJson.results as Array + ).sort((docA, docB) => { + let result = 0 + switch (sort_field) { + case 'created': + case 'added': + result = + new Date(docA[sort_field]) < new Date(docB[sort_field]) + ? -1 + : 1 + break + case 'archive_serial_number': + result = docA[sort_field] < docB[sort_field] ? -1 : 1 + break + } + if (reverse) result = -result + return result + }) + } + + if (req.query.hasOwnProperty('tags__id__in')) { + const tag_ids: Array = req.query['tags__id__in'] + .toString() + .split(',') + .map((v) => +v) + response.results = ( + documentsJson.results as Array + ).filter( + (d) => + d.tags.length > 0 && + d.tags.filter((t) => tag_ids.includes(t)).length > 0 + ) + response.count = response.results.length + } else if (req.query.hasOwnProperty('tags__id__none')) { + const tag_ids: Array = req.query['tags__id__none'] + .toString() + .split(',') + .map((v) => +v) + response.results = ( + documentsJson.results as Array + ).filter((d) => d.tags.filter((t) => tag_ids.includes(t)).length == 0) + response.count = response.results.length + } else if ( + req.query.hasOwnProperty('is_tagged') && + req.query['is_tagged'] == '0' + ) { + response.results = ( + documentsJson.results as Array + ).filter((d) => d.tags.length == 0) + response.count = response.results.length + } + + if (req.query.hasOwnProperty('document_type__id')) { + const doctype_id = +req.query['document_type__id'] + response.results = ( + documentsJson.results as Array + ).filter((d) => d.document_type == doctype_id) + response.count = response.results.length + } else if ( + req.query.hasOwnProperty('document_type__isnull') && + req.query['document_type__isnull'] == '1' + ) { + response.results = ( + documentsJson.results as Array + ).filter((d) => d.document_type == undefined) + response.count = response.results.length + } + + if (req.query.hasOwnProperty('correspondent__id')) { + const correspondent_id = +req.query['correspondent__id'] + response.results = ( + documentsJson.results as Array + ).filter((d) => d.correspondent == correspondent_id) + response.count = response.results.length + } else if ( + req.query.hasOwnProperty('correspondent__isnull') && + req.query['correspondent__isnull'] == '1' + ) { + response.results = ( + documentsJson.results as Array + ).filter((d) => d.correspondent == undefined) + response.count = response.results.length + } + + if (req.query.hasOwnProperty('storage_path__id')) { + const storage_path_id = +req.query['storage_path__id'] + response.results = ( + documentsJson.results as Array + ).filter((d) => d.storage_path == storage_path_id) + response.count = response.results.length + } else if ( + req.query.hasOwnProperty('storage_path__isnull') && + req.query['storage_path__isnull'] == '1' + ) { + response.results = ( + documentsJson.results as Array + ).filter((d) => d.storage_path == undefined) + response.count = response.results.length + } + + if (req.query.hasOwnProperty('created__date__gt')) { + const date = new Date(req.query['created__date__gt']) + response.results = ( + documentsJson.results as Array + ).filter((d) => new Date(d.created) > date) + response.count = response.results.length + } else if (req.query.hasOwnProperty('created__date__lt')) { + const date = new Date(req.query['created__date__lt']) + response.results = ( + documentsJson.results as Array + ).filter((d) => new Date(d.created) < date) + response.count = response.results.length + } + + if (req.query.hasOwnProperty('added__date__gt')) { + const date = new Date(req.query['added__date__gt']) + response.results = ( + documentsJson.results as Array + ).filter((d) => new Date(d.added) > date) + response.count = response.results.length + } else if (req.query.hasOwnProperty('added__date__lt')) { + const date = new Date(req.query['added__date__lt']) + response.results = ( + documentsJson.results as Array + ).filter((d) => new Date(d.added) < date) + response.count = response.results.length + } + + if (req.query.hasOwnProperty('title_content')) { + const title_content_regexp = new RegExp( + req.query['title_content'].toString(), + 'i' + ) + response.results = ( + documentsJson.results as Array + ).filter( + (d) => + title_content_regexp.test(d.title) || + title_content_regexp.test(d.content) + ) + response.count = response.results.length + } + + if (req.query.hasOwnProperty('archive_serial_number')) { + const asn = +req.query['archive_serial_number'] + response.results = ( + documentsJson.results as Array + ).filter((d) => d.archive_serial_number == asn) + response.count = response.results.length + } else if (req.query.hasOwnProperty('archive_serial_number__isnull')) { + const isnull = req.query['storage_path__isnull'] == '1' + response.results = ( + documentsJson.results as Array + ).filter((d) => + isnull + ? d.archive_serial_number == undefined + : d.archive_serial_number != undefined + ) + response.count = response.results.length + } else if (req.query.hasOwnProperty('archive_serial_number__gt')) { + const asn = +req.query['archive_serial_number__gt'] + response.results = ( + documentsJson.results as Array + ).filter( + (d) => d.archive_serial_number > 0 && d.archive_serial_number > asn + ) + response.count = response.results.length + } else if (req.query.hasOwnProperty('archive_serial_number__lt')) { + const asn = +req.query['archive_serial_number__lt'] + response.results = ( + documentsJson.results as Array + ).filter( + (d) => d.archive_serial_number > 0 && d.archive_serial_number < asn + ) + response.count = response.results.length + } + + req.reply(response) + }) + }) + }) + + it('should show a list of documents sorted by created', () => { + cy.visit('/documents?sort=created') + cy.get('app-document-card-small').first().contains('No latin title') + }) + + it('should show a list of documents reverse sorted by created', () => { + cy.visit('/documents?sort=created&reverse=true') + cy.get('app-document-card-small').first().contains('sit amet') + }) + + it('should show a list of documents sorted by added', () => { + cy.visit('/documents?sort=added') + cy.get('app-document-card-small').first().contains('No latin title') + }) + + it('should show a list of documents reverse sorted by added', () => { + cy.visit('/documents?sort=added&reverse=true') + cy.get('app-document-card-small').first().contains('sit amet') + }) + + it('should show a list of documents filtered by any tags', () => { + cy.visit('/documents?sort=created&reverse=true&tags__id__in=2,4,5') + cy.contains('3 documents') + }) + + it('should show a list of documents filtered by excluded tags', () => { + cy.visit('/documents?sort=created&reverse=true&tags__id__none=2,4') + cy.contains('One document') + }) + + it('should show a list of documents filtered by no tags', () => { + cy.visit('/documents?sort=created&reverse=true&is_tagged=0') + cy.contains('One document') + }) + + it('should show a list of documents filtered by document type', () => { + cy.visit('/documents?sort=created&reverse=true&document_type__id=1') + cy.contains('3 documents') + }) + + it('should show a list of documents filtered by no document type', () => { + cy.visit('/documents?sort=created&reverse=true&document_type__isnull=1') + cy.contains('One document') + }) + + it('should show a list of documents filtered by correspondent', () => { + cy.visit('/documents?sort=created&reverse=true&correspondent__id=9') + cy.contains('2 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') + }) + + it('should show a list of documents filtered by storage path', () => { + cy.visit('/documents?sort=created&reverse=true&storage_path__id=2') + cy.contains('One document') + }) + + it('should show a list of documents filtered by no storage path', () => { + cy.visit('/documents?sort=created&reverse=true&storage_path__isnull=1') + cy.contains('3 documents') + }) + + it('should show a list of documents filtered by title or content', () => { + cy.visit('/documents?sort=created&reverse=true&title_content=lorem') + cy.contains('2 documents') + }) + + it('should show a list of documents filtered by asn', () => { + cy.visit('/documents?sort=created&reverse=true&archive_serial_number=12345') + cy.contains('One document') + }) + + it('should show a list of documents filtered by empty asn', () => { + cy.visit( + '/documents?sort=created&reverse=true&archive_serial_number__isnull=1' + ) + cy.contains('2 documents') + }) + + it('should show a list of documents filtered by non-empty asn', () => { + cy.visit( + '/documents?sort=created&reverse=true&archive_serial_number__isnull=0' + ) + cy.contains('2 documents') + }) + + it('should show a list of documents filtered by asn greater than', () => { + cy.visit( + '/documents?sort=created&reverse=true&archive_serial_number__gt=12346' + ) + cy.contains('One document') + }) + + it('should show a list of documents filtered by asn less than', () => { + cy.visit( + '/documents?sort=created&reverse=true&archive_serial_number__lt=12346' + ) + cy.contains('One document') + }) + + it('should show a list of documents filtered by created date greater than', () => { + cy.visit( + '/documents?sort=created&reverse=true&created__date__gt=2022-03-23' + ) + cy.contains('3 documents') + }) + + it('should show a list of documents filtered by created date less than', () => { + cy.visit( + '/documents?sort=created&reverse=true&created__date__lt=2022-03-23' + ) + cy.contains('One document') + }) + + it('should show a list of documents filtered by added date greater than', () => { + cy.visit('/documents?sort=created&reverse=true&added__date__gt=2022-03-24') + cy.contains('2 documents') + }) + + it('should show a list of documents filtered by added date less than', () => { + cy.visit('/documents?sort=created&reverse=true&added__date__lt=2022-03-24') + cy.contains('2 documents') + }) + + it('should show a list of documents filtered by multiple filters', () => { + cy.visit( + '/documents?sort=created&reverse=true&document_type__id=1&correspondent__id=9&tags__id__in=4,5' + ) + cy.contains('2 documents') + }) +})