From 00d67d53bfef1544024820f5cf9ca686954667a3 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 5 Jan 2023 00:36:03 -0800 Subject: [PATCH] Add tests for mail rules / accounts, partial tags, mobile preview --- .../e2e/documents/document-detail.cy.ts | 17 +- .../e2e/documents/documents-list.cy.ts | 26 ++ src-ui/cypress/e2e/settings/settings.cy.ts | 98 +++++- .../fixtures/documents/selection_data.json | 293 ++++++++++++++++++ .../fixtures/mail_rules/mail_rules.json | 3 +- src-ui/cypress/support/e2e.ts | 6 +- .../document-detail.component.html | 6 +- 7 files changed, 433 insertions(+), 16 deletions(-) create mode 100644 src-ui/cypress/fixtures/documents/selection_data.json diff --git a/src-ui/cypress/e2e/documents/document-detail.cy.ts b/src-ui/cypress/e2e/documents/document-detail.cy.ts index a836ffa92..0cacbd81f 100644 --- a/src-ui/cypress/e2e/documents/document-detail.cy.ts +++ b/src-ui/cypress/e2e/documents/document-detail.cy.ts @@ -44,7 +44,7 @@ describe('document-detail', () => { }) cy.viewport(1024, 1024) - cy.visit('/documents/1/') + cy.visit('/documents/1/').wait('@ui-settings') }) it('should activate / deactivate save button when changes are saved', () => { @@ -66,8 +66,21 @@ describe('document-detail', () => { cy.contains('You have unsaved changes').should('not.exist') }) + it('should show a mobile preview', () => { + cy.viewport(440, 1000) + cy.get('a') + .contains('Preview') + .scrollIntoView({ offset: { top: 150, left: 0 } }) + .click() + cy.get('pdf-viewer').should('be.visible') + }) + it('should show a list of comments', () => { - cy.wait(1000).get('a').contains('Comments').click().wait(1000) + cy.wait(1000) + .get('a') + .contains('Comments') + .click({ force: true }) + .wait(1000) cy.get('app-document-comments').find('.card').its('length').should('eq', 3) }) diff --git a/src-ui/cypress/e2e/documents/documents-list.cy.ts b/src-ui/cypress/e2e/documents/documents-list.cy.ts index ccce51950..84b396625 100644 --- a/src-ui/cypress/e2e/documents/documents-list.cy.ts +++ b/src-ui/cypress/e2e/documents/documents-list.cy.ts @@ -52,6 +52,10 @@ describe('documents-list', () => { req.reply(response) }) + + cy.intercept('http://localhost:8000/api/documents/selection_data/', { + fixture: 'documents/selection_data.json', + }).as('selection-data') }) cy.viewport(1280, 1024) @@ -76,6 +80,28 @@ describe('documents-list', () => { cy.get('app-document-card-large') }) + it('should show partial tag selection', () => { + cy.get('app-document-card-small:nth-child(1)').click() + cy.get('app-document-card-small:nth-child(4)').click() + cy.get('app-bulk-editor button') + .contains('Tags') + .click() + .wait('@selection-data') + cy.get('svg.bi-dash').should('be.visible') + cy.get('svg.bi-check').should('be.visible') + }) + + it('should allow bulk removal', () => { + cy.get('app-document-card-small:nth-child(1)').click() + cy.get('app-document-card-small:nth-child(4)').click() + cy.get('app-bulk-editor').within(() => { + cy.get('button').contains('Tags').click().wait('@selection-data') + cy.get('button').contains('Another Sample Tag').click() + cy.get('button').contains('Apply').click() + }) + cy.contains('operation will remove the tag') + }) + it('should filter tags', () => { cy.get('app-filter-editor app-filterable-dropdown[title="Tags"]').within( () => { diff --git a/src-ui/cypress/e2e/settings/settings.cy.ts b/src-ui/cypress/e2e/settings/settings.cy.ts index aa59997d4..95443bbe2 100644 --- a/src-ui/cypress/e2e/settings/settings.cy.ts +++ b/src-ui/cypress/e2e/settings/settings.cy.ts @@ -35,16 +35,58 @@ describe('settings', () => { req.reply(response) } ).as('savedViews') + }) - cy.intercept('http://localhost:8000/api/mail_accounts/*', { - fixture: 'mail_accounts/mail_accounts.json', - }) - cy.intercept('http://localhost:8000/api/mail_rules/*', { - fixture: 'mail_rules/mail_rules.json', - }).as('mailRules') - cy.intercept('http://localhost:8000/api/tasks/', { - fixture: 'tasks/tasks.json', - }) + this.newMailAccounts = [] + + cy.intercept( + 'POST', + 'http://localhost:8000/api/mail_accounts/', + (req) => { + const newRule = req.body + newRule.id = 3 + this.newMailAccounts.push(newRule) // store this for later + req.reply({ result: 'OK' }) + } + ).as('saveAccount') + + cy.fixture('mail_accounts/mail_accounts.json').then( + (mailAccountsJson) => { + cy.intercept( + 'GET', + 'http://localhost:8000/api/mail_accounts/*', + (req) => { + console.log(req, this.newMailAccounts) + + let response = { ...mailAccountsJson } + if (this.newMailAccounts.length) { + response.results = response.results.concat(this.newMailAccounts) + } + + req.reply(response) + } + ).as('getAccounts') + } + ) + + this.newMailRules = [] + + cy.intercept('POST', 'http://localhost:8000/api/mail_rules/', (req) => { + const newRule = req.body + newRule.id = 2 + this.newMailRules.push(newRule) // store this for later + req.reply({ result: 'OK' }) + }).as('saveRule') + + cy.fixture('mail_rules/mail_rules.json').then((mailRulesJson) => { + cy.intercept('GET', 'http://localhost:8000/api/mail_rules/*', (req) => { + let response = { ...mailRulesJson } + if (this.newMailRules.length) { + response.results = response.results.concat(this.newMailRules) + } + + req.reply(response) + }).as('getRules') }) cy.fixture('documents/documents.json').then((documentsJson) => { @@ -99,4 +141,42 @@ describe('settings', () => { cy.visit('/dashboard') cy.get('app-saved-view-widget').contains('Inbox').should('not.exist') }) + + it('should show a list of mail accounts & rules & support creation', () => { + cy.contains('a', 'Mail').click() + cy.get('app-settings .tab-content ul li').its('length').should('eq', 5) // 2 headers, 2 accounts, 1 rule + cy.contains('button', 'Add Account').click() + cy.contains('Create new mail account') + cy.get('app-input-text[formcontrolname="name"]').type( + 'Example Mail Account' + ) + cy.get('app-input-text[formcontrolname="imap_server"]').type( + 'mail.example.com' + ) + cy.get('app-input-text[formcontrolname="imap_port"]').type('993') + cy.get('app-input-text[formcontrolname="username"]').type('username') + cy.get('app-input-password[formcontrolname="password"]').type('pass') + cy.contains('app-mail-account-edit-dialog button', 'Save') + .click() + .wait('@saveAccount') + .wait('@getAccounts') + cy.contains('Saved account') + + cy.wait(1000) + cy.contains('button', 'Add Rule').click() + cy.contains('Create new mail rule') + cy.get('app-input-text[formcontrolname="name"]').type('Example Rule') + cy.get('app-input-select[formcontrolname="account"]').type('Example{enter}') + cy.get('app-input-number[formcontrolname="maximum_age"]').type('30') + cy.get('app-input-text[formcontrolname="filter_subject"]').type( + '[paperless]' + ) + cy.contains('app-mail-rule-edit-dialog button', 'Save') + .click() + .wait('@saveRule') + .wait('@getRules') + cy.contains('Saved rule').wait(1000) + + cy.get('app-settings .tab-content ul li').its('length').should('eq', 7) + }) }) diff --git a/src-ui/cypress/fixtures/documents/selection_data.json b/src-ui/cypress/fixtures/documents/selection_data.json new file mode 100644 index 000000000..a01957e42 --- /dev/null +++ b/src-ui/cypress/fixtures/documents/selection_data.json @@ -0,0 +1,293 @@ +{ + "selected_correspondents": [ + { + "id": 62, + "document_count": 0 + }, + { + "id": 75, + "document_count": 0 + }, + { + "id": 55, + "document_count": 0 + }, + { + "id": 56, + "document_count": 0 + }, + { + "id": 73, + "document_count": 0 + }, + { + "id": 58, + "document_count": 0 + }, + { + "id": 44, + "document_count": 0 + }, + { + "id": 42, + "document_count": 0 + }, + { + "id": 74, + "document_count": 0 + }, + { + "id": 54, + "document_count": 0 + }, + { + "id": 29, + "document_count": 0 + }, + { + "id": 71, + "document_count": 0 + }, + { + "id": 68, + "document_count": 0 + }, + { + "id": 82, + "document_count": 0 + }, + { + "id": 34, + "document_count": 0 + }, + { + "id": 41, + "document_count": 0 + }, + { + "id": 51, + "document_count": 0 + }, + { + "id": 46, + "document_count": 0 + }, + { + "id": 40, + "document_count": 0 + }, + { + "id": 43, + "document_count": 0 + }, + { + "id": 80, + "document_count": 0 + }, + { + "id": 70, + "document_count": 0 + }, + { + "id": 52, + "document_count": 0 + }, + { + "id": 67, + "document_count": 0 + }, + { + "id": 53, + "document_count": 0 + }, + { + "id": 32, + "document_count": 0 + }, + { + "id": 63, + "document_count": 0 + }, + { + "id": 35, + "document_count": 0 + }, + { + "id": 45, + "document_count": 0 + }, + { + "id": 38, + "document_count": 0 + }, + { + "id": 79, + "document_count": 0 + }, + { + "id": 48, + "document_count": 0 + }, + { + "id": 72, + "document_count": 0 + }, + { + "id": 78, + "document_count": 0 + }, + { + "id": 39, + "document_count": 0 + }, + { + "id": 57, + "document_count": 0 + }, + { + "id": 61, + "document_count": 0 + }, + { + "id": 81, + "document_count": 0 + }, + { + "id": 77, + "document_count": 0 + }, + { + "id": 69, + "document_count": 0 + }, + { + "id": 36, + "document_count": 3 + }, + { + "id": 31, + "document_count": 0 + }, + { + "id": 30, + "document_count": 0 + }, + { + "id": 50, + "document_count": 0 + }, + { + "id": 49, + "document_count": 0 + }, + { + "id": 60, + "document_count": 0 + }, + { + "id": 47, + "document_count": 0 + }, + { + "id": 66, + "document_count": 0 + }, + { + "id": 37, + "document_count": 0 + }, + { + "id": 28, + "document_count": 0 + }, + { + "id": 59, + "document_count": 0 + }, + { + "id": 33, + "document_count": 0 + }, + { + "id": 76, + "document_count": 0 + } + ], + "selected_tags": [ + { + "id": 4, + "document_count": 2 + }, + { + "id": 7, + "document_count": 0 + }, + { + "id": 5, + "document_count": 1 + }, + { + "id": 6, + "document_count": 0 + }, + { + "id": 3, + "document_count": 0 + }, + { + "id": 2, + "document_count": 1 + }, + { + "id": 1, + "document_count": 0 + }, + { + "id": 8, + "document_count": 0 + } + ], + "selected_document_types": [ + { + "id": 4, + "document_count": 0 + }, + { + "id": 10, + "document_count": 0 + }, + { + "id": 2, + "document_count": 0 + }, + { + "id": 11, + "document_count": 0 + }, + { + "id": 9, + "document_count": 0 + }, + { + "id": 7, + "document_count": 2 + }, + { + "id": 3, + "document_count": 0 + }, + { + "id": 1, + "document_count": 0 + }, + { + "id": 5, + "document_count": 0 + }, + { + "id": 8, + "document_count": 1 + } + ], + "selected_storage_paths": [] +} diff --git a/src-ui/cypress/fixtures/mail_rules/mail_rules.json b/src-ui/cypress/fixtures/mail_rules/mail_rules.json index a2c59c5c6..7767940e7 100644 --- a/src-ui/cypress/fixtures/mail_rules/mail_rules.json +++ b/src-ui/cypress/fixtures/mail_rules/mail_rules.json @@ -23,7 +23,8 @@ "assign_correspondent": 2, "assign_document_type": null, "order": 0, - "attachment_type": 2 + "attachment_type": 2, + "consumption_scope": 1 } ] } diff --git a/src-ui/cypress/support/e2e.ts b/src-ui/cypress/support/e2e.ts index 4004aa8a0..1d17409c2 100644 --- a/src-ui/cypress/support/e2e.ts +++ b/src-ui/cypress/support/e2e.ts @@ -3,7 +3,7 @@ beforeEach(() => { cy.intercept('http://localhost:8000/api/ui_settings/', { fixture: 'ui_settings/settings.json', - }) + }).as('ui-settings') cy.intercept('http://localhost:8000/api/remote_version/', { fixture: 'remote_version/remote_version.json', @@ -29,6 +29,10 @@ beforeEach(() => { fixture: 'storage_paths/storage_paths.json', }) + cy.intercept('http://localhost:8000/api/tasks/', { + fixture: 'tasks/tasks.json', + }) + cy.intercept('http://localhost:8000/api/documents/1/metadata/', { fixture: 'documents/1/metadata.json', }) diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html index 92b40014c..19ae590a7 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.html +++ b/src-ui/src/app/components/document-detail/document-detail.component.html @@ -180,9 +180,9 @@
- - - + + +