From aaddd21eae1e44d0f1e7c4aff46c129609245c09 Mon Sep 17 00:00:00 2001
From: Robert Goldmann <deadlocker@gmx.de>
Date: Tue, 19 Oct 2021 22:38:34 +0200
Subject: [PATCH] #577 - added test

---
 .../NewTransactionFromExistingOneTest.java    | 32 ++++++++++++++
 .../NewTransactionFromExistingOneTest.json    | 42 +++++++++++++------
 2 files changed, 61 insertions(+), 13 deletions(-)

diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionFromExistingOneTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionFromExistingOneTest.java
index eaddcace4..4d13aba96 100644
--- a/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionFromExistingOneTest.java
+++ b/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/NewTransactionFromExistingOneTest.java
@@ -169,4 +169,36 @@ class NewTransactionFromExistingOneTest extends SeleniumTestBase
 		// assert
 		assertThat(driver.getCurrentUrl()).endsWith("/transactions");
 	}
+
+	@Test
+	void test_newTransactionFromExisting_transactionFromReadonlyAccount()
+	{
+		TransactionTestHelper.selectGlobalAccountByName(driver, "Readonly Account");
+
+		gotoSpecificYearAndMonth(2021, "October");
+
+		List<WebElement> transactionsRows = driver.findElements(By.cssSelector(".transaction-container .hide-on-med-and-down.transaction-row-top"));
+		List<WebElement> columns = transactionsRows.get(0).findElements(By.className("col"));
+		columns.get(5).findElement(By.className("button-new-from-existing")).click();
+
+		WebDriverWait wait = new WebDriverWait(driver, 5);
+		wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector(".headline"), "New Transaction"));
+
+		// assert
+		assertThat(driver.findElement(By.className("buttonExpenditure")).getAttribute("class")).contains("background-red");
+		assertThat(driver.findElement(By.id("transaction-name")).getAttribute("value")).isEqualTo("Transaction in readonly account");
+		assertThat(driver.findElement(By.id("transaction-amount")).getAttribute("value")).isEqualTo("12.00");
+
+		// should fall back to default account as the readonly account will not allow new transactions
+		assertThat(driver.findElement(By.cssSelector(".account-select-wrapper .custom-select-selected-item .category-circle")).getAttribute("data-value")).isEqualTo("3");
+
+		// submit form
+		driver.findElement(By.id("button-save-transaction")).click();
+
+		wait = new WebDriverWait(driver, 5);
+		wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".headline-date")));
+
+		// assert
+		assertThat(driver.getCurrentUrl()).endsWith("/transactions");
+	}
 }
\ No newline at end of file
diff --git a/src/test/resources/NewTransactionFromExistingOneTest.json b/src/test/resources/NewTransactionFromExistingOneTest.json
index 6cfb50e8b..70fd1e9d8 100644
--- a/src/test/resources/NewTransactionFromExistingOneTest.json
+++ b/src/test/resources/NewTransactionFromExistingOneTest.json
@@ -3,19 +3,19 @@
     "VERSION": 7,
     "categories": [
         {
-            "ID": 192,
+            "ID": 3,
             "name": "Custom Category",
             "color": "#ff9500",
             "type": "CUSTOM"
         },
         {
-            "ID": 190,
+            "ID": 1,
             "name": "No Category",
             "color": "#FFFFFF",
             "type": "NONE"
         },
         {
-            "ID": 191,
+            "ID": 2,
             "name": "Rest",
             "color": "#FFFF00",
             "type": "REST"
@@ -23,22 +23,28 @@
     ],
     "accounts": [
         {
-            "ID": 169,
+            "ID": 1,
             "name": "Placeholder",
             "accountState": "FULL_ACCESS",
             "type": "ALL"
         },
         {
-            "ID": 170,
+            "ID": 2,
             "name": "Default Account",
             "accountState": "FULL_ACCESS",
             "type": "CUSTOM"
         },
         {
-            "ID": 171,
+            "ID": 3,
             "name": "Second Account",
             "accountState": "FULL_ACCESS",
             "type": "CUSTOM"
+        },
+        {
+            "ID": 4,
+            "name": "Readonly Account",
+            "accountState": "READ_ONLY",
+            "type": "CUSTOM"
         }
     ],
     "transactions": [
@@ -46,8 +52,8 @@
             "amount": -1200,
             "isExpenditure": true,
             "date": "2021-10-17",
-            "accountID": 170,
-            "categoryID": 192,
+            "accountID": 2,
+            "categoryID": 3,
             "name": "Full normal",
             "description": "lorem ipsum",
             "tags": [
@@ -60,8 +66,8 @@
             "amount": -1500,
             "isExpenditure": true,
             "date": "2021-09-17",
-            "accountID": 170,
-            "categoryID": 192,
+            "accountID": 2,
+            "categoryID": 3,
             "name": "Full transfer",
             "description": "dolor sit amet",
             "tags": [
@@ -69,14 +75,14 @@
                     "name": "456"
                 }
             ],
-            "transferAccountID": 171
+            "transferAccountID": 3
         },
         {
             "amount": -200,
             "isExpenditure": true,
             "date": "2021-06-17",
-            "accountID": 170,
-            "categoryID": 192,
+            "accountID": 2,
+            "categoryID": 3,
             "name": "normal recurring",
             "description": "apple",
             "tags": [
@@ -95,6 +101,16 @@
                     "times": 1
                 }
             }
+        },
+        {
+            "amount": -1200,
+            "isExpenditure": true,
+            "date": "2021-10-19",
+            "accountID": 4,
+            "categoryID": 1,
+            "name": "Transaction in readonly account",
+            "description": "",
+            "tags": []
         }
     ],
     "templates": [],
-- 
GitLab