diff --git a/BudgetMasterServer/src/main/resources/templates/transactions/transactionsMacros.ftl b/BudgetMasterServer/src/main/resources/templates/transactions/transactionsMacros.ftl index 5580e2cec158ac355e6cb2fb2e4c601859ed9235..36de129f534c6ae25e24c0c5b40349112f69a886 100644 --- a/BudgetMasterServer/src/main/resources/templates/transactions/transactionsMacros.ftl +++ b/BudgetMasterServer/src/main/resources/templates/transactions/transactionsMacros.ftl @@ -51,7 +51,7 @@ <#macro transactionButtons transaction classes> <div class="col ${classes} transaction-buttons no-wrap"> <#if transaction.isEditable()> - <@header.buttonFlat url='/transactions/' + transaction.ID?c + '/edit' icon='edit' localizationKey='' classes="no-padding text-default"/> + <@header.buttonFlat url='/transactions/' + transaction.ID?c + '/edit' icon='edit' localizationKey='' classes="no-padding text-default button-edit"/> <@header.buttonFlat url='/transactions/' + transaction.ID?c + '/requestDelete' icon='delete' localizationKey='' classes="no-padding text-default button-request-delete-transaction" isDataUrl=true/> </#if> <#if transaction.isAllowedToFillNewTransaction()> diff --git a/BudgetMasterServer/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/EditFutureOccurrencesOfRepeatingTransactionTest.java b/BudgetMasterServer/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/EditFutureOccurrencesOfRepeatingTransactionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..3b19393e753da2c2284d05092f37382ce6585e1e --- /dev/null +++ b/BudgetMasterServer/src/test/java/de/deadlocker8/budgetmaster/integration/selenium/EditFutureOccurrencesOfRepeatingTransactionTest.java @@ -0,0 +1,92 @@ +package de.deadlocker8.budgetmaster.integration.selenium; + +import de.deadlocker8.budgetmaster.authentication.UserService; +import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; +import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTestBase; +import de.deadlocker8.budgetmaster.integration.helpers.TransactionTestHelper; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.io.File; +import java.time.Duration; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class EditFutureOccurrencesOfRepeatingTransactionTest extends SeleniumTestBase +{ + private static IntegrationTestHelper helper; + + @Override + protected void importDatabaseOnce() + { + helper = new IntegrationTestHelper(driver, port); + helper.start(); + helper.login(UserService.DEFAULT_PASSWORD); + helper.hideBackupReminder(); + helper.hideWhatsNewDialog(); + + String path = getClass().getClassLoader().getResource("EditFutureOccurrencesOfRepeatingTransactionTest.json").getFile().replace("/", File.separator); + helper.uploadDatabase(path); + } + + @Override + protected void runBeforeEachTest() + { + driver.get(helper.getUrl() + "/transactions"); + + TransactionTestHelper.selectGlobalAccountByName(driver, "Default Account First"); + } + + @Test + void test_editFutureOccurrencesOfRepeatingTransaction() + { + TransactionTestHelper.gotoSpecificYearAndMonth(driver, 2022, "October"); + + List<WebElement> transactionsRows = driver.findElements(By.cssSelector(".transaction-container .hide-on-med-and-down.transaction-row-top")); + List<WebElement> columns = transactionsRows.get(transactionsRows.size() - 4).findElements(By.className("col")); + columns.get(4).findElement(By.className("button-edit")).click(); + + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5)); + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector(".headline"), "Edit Transaction")); + + final WebElement buttonEditFutureOccurrences = driver.findElement(By.id("button-transaction-edit-future-occurrences")); + ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", buttonEditFutureOccurrences); + assertThat(buttonEditFutureOccurrences.isDisplayed()).isTrue(); + + buttonEditFutureOccurrences.click(); + wait = new WebDriverWait(driver, Duration.ofSeconds(5)); + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector(".headline"), "New Transaction")); + + final WebElement amountInput = driver.findElement(By.id("transaction-amount")); + amountInput.clear(); + amountInput.sendKeys("-20"); + driver.findElement(By.id("button-save-transaction")).click(); + + wait = new WebDriverWait(driver, Duration.ofSeconds(5)); + wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(text(), 'Rest')]"))); + + // assert + final List<WebElement> transactionDateGroups = driver.findElements(By.className("transaction-date-group")); + + assertTransaction(transactionDateGroups, transactionDateGroups.size() - 4, 1, "-20.00 €", 22); + assertTransaction(transactionDateGroups, transactionDateGroups.size() - 3, 1, "-20.00 €", 15); + assertTransaction(transactionDateGroups, transactionDateGroups.size() - 2, 1, "-10.00 €", 8); + assertTransaction(transactionDateGroups, transactionDateGroups.size() - 1, 2, "-10.00 €", 1); + } + + private void assertTransaction(List<WebElement> transactionDateGroups, int groupIndex, int expectedNumberOfTransactions, String expectedAmount, int day) + { + final WebElement dateGroup = transactionDateGroups.get(groupIndex); + assertThat(dateGroup.findElement(By.className("transaction-date"))).hasFieldOrPropertyWithValue("text", TransactionTestHelper.getDateString(day)); + final List<WebElement> transactionsInGroup = dateGroup.findElements(By.cssSelector(".transaction-container .hide-on-med-and-down.transaction-row-top")); + assertThat(transactionsInGroup).hasSize(expectedNumberOfTransactions); + final WebElement transactionRow = transactionsInGroup.get(0); + final List<WebElement> transactionColumns = transactionRow.findElements(By.className("col")); + assertThat(transactionColumns.get(3).getText()).contains(expectedAmount); + } +} \ No newline at end of file diff --git a/BudgetMasterServer/src/test/resources/EditFutureOccurrencesOfRepeatingTransactionTest.json b/BudgetMasterServer/src/test/resources/EditFutureOccurrencesOfRepeatingTransactionTest.json new file mode 100644 index 0000000000000000000000000000000000000000..4ec274ae8799f9e57dec27b0b2917767a5eea60f --- /dev/null +++ b/BudgetMasterServer/src/test/resources/EditFutureOccurrencesOfRepeatingTransactionTest.json @@ -0,0 +1,111 @@ +{ + "TYPE": "BUDGETMASTER_DATABASE", + "VERSION": 9, + "categories": [ + { + "ID": 312, + "name": "Keine Kategorie", + "color": "#FFFFFF", + "type": "NONE" + }, + { + "ID": 313, + "name": "Übertrag", + "color": "#FFFF00", + "type": "REST" + } + ], + "accounts": [ + { + "ID": 136, + "name": "Placeholder", + "accountState": "FULL_ACCESS", + "type": "ALL", + "iconReferenceID": 406 + }, + { + "ID": 137, + "name": "Default Account First", + "accountState": "FULL_ACCESS", + "type": "CUSTOM", + "iconReferenceID": 407 + } + ], + "transactions": [ + { + "amount": -1000, + "isExpenditure": true, + "date": "2022-10-01", + "accountID": 137, + "categoryID": 312, + "name": "Pizza", + "description": "", + "tags": [], + "repeatingOption": { + "startDate": "2022-10-01", + "modifier": { + "quantity": 7, + "localizationKey": "repeating.modifier.days" + }, + "endOption": { + "localizationKey": "repeating.end.key.afterXTimes", + "times": 3 + } + } + } + ], + "templateGroups": [ + { + "ID": 1, + "name": "Not grouped", + "type": "DEFAULT" + } + ], + "templates": [], + "charts": [], + "images": [], + "icons": [ + { + "ID": 406, + "builtinIdentifier": "fas fa-landmark" + }, + { + "ID": 407 + } + ], + "transactionNameKeywords": [ + { + "value": "einnahme" + }, + { + "value": "rückzahlung" + }, + { + "value": "erstattung" + }, + { + "value": "zinsen" + }, + { + "value": "lohn" + }, + { + "value": "gehalt" + }, + { + "value": "gutschrift" + }, + { + "value": "income" + }, + { + "value": "refund" + }, + { + "value": "interest" + }, + { + "value": "salary" + } + ] +} \ No newline at end of file