]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Add tests for mail rules / accounts, partial tags, mobile preview 2352/head
authorMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Thu, 5 Jan 2023 08:36:03 +0000 (00:36 -0800)
committerMichael Shamoon <4887959+shamoon@users.noreply.github.com>
Thu, 5 Jan 2023 08:36:03 +0000 (00:36 -0800)
src-ui/cypress/e2e/documents/document-detail.cy.ts
src-ui/cypress/e2e/documents/documents-list.cy.ts
src-ui/cypress/e2e/settings/settings.cy.ts
src-ui/cypress/fixtures/documents/selection_data.json [new file with mode: 0644]
src-ui/cypress/fixtures/mail_rules/mail_rules.json
src-ui/cypress/support/e2e.ts
src-ui/src/app/components/document-detail/document-detail.component.html

index a836ffa92af5c6b5919673d08cb74da164753428..0cacbd81f6c3ba328066416c60585c414390ff02 100644 (file)
@@ -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)
   })
 
index ccce51950c6f430922d14432102d53719513c4bb..84b39662551c6f3ca8d8f8c10a4316f564fda1f7 100644 (file)
@@ -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(
       () => {
index aa59997d4c5e4098c03759f809480858d63b9689..95443bbe2e56dcc2cae15a6f8842b14463b71bea 100644 (file)
@@ -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 (file)
index 0000000..a01957e
--- /dev/null
@@ -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": []
+}
index a2c59c5c6129a906e65a32d004c6e06136c62d5a..7767940e7646cc780c77d58617f00209b9a1eb20 100644 (file)
@@ -23,7 +23,8 @@
             "assign_correspondent": 2,
             "assign_document_type": null,
             "order": 0,
-            "attachment_type": 2
+            "attachment_type": 2,
+            "consumption_scope": 1
         }
     ]
 }
index 4004aa8a0c4250d34e8b8e64ed14d82939bae8e9..1d17409c2c1522229f59564ef3d47f681d3e6c53 100644 (file)
@@ -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',
   })
index 92b40014c6ccd5ae507f2eb61dcc894267d72063..19ae590a728160f20e21741769516ede51fd657c 100644 (file)
 
             <div [ngbNavOutlet]="nav" class="mt-2"></div>
 
-            <button type="button" class="btn btn-outline-secondary" (click)="discard()" i18n [disabled]="networkActive || (isDirty$ | async) === false">Discard</button>&nbsp;
-            <button type="button" class="btn btn-outline-primary" (click)="saveEditNext()" *ngIf="hasNext()" i18n [disabled]="networkActive || (isDirty$ | async) === false || error">Save & next</button>&nbsp;
-            <button type="submit" class="btn btn-primary" i18n [disabled]="networkActive || (isDirty$ | async) === false || error">Save</button>&nbsp;
+            <button type="button" class="btn btn-outline-secondary" (click)="discard()" i18n [disabled]="networkActive || (isDirty$ | async) !== true">Discard</button>&nbsp;
+            <button type="button" class="btn btn-outline-primary" (click)="saveEditNext()" *ngIf="hasNext()" i18n [disabled]="networkActive || (isDirty$ | async) !== true || error">Save & next</button>&nbsp;
+            <button type="submit" class="btn btn-primary" i18n [disabled]="networkActive || (isDirty$ | async) !== true || error">Save</button>&nbsp;
         </form>
     </div>