Skip to content
Snippets Groups Projects
Commit ca4fc051 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#543 - added basic integration test for transfer transactions + externalized transaction assertion

parent d5f06f67
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import de.deadlocker8.budgetmaster.Main; ...@@ -4,6 +4,7 @@ import de.deadlocker8.budgetmaster.Main;
import de.deadlocker8.budgetmaster.authentication.UserService; import de.deadlocker8.budgetmaster.authentication.UserService;
import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper; import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper;
import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest; import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest;
import de.deadlocker8.budgetmaster.integration.helpers.TransactionTestHelper;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -23,9 +24,7 @@ import org.springframework.boot.web.server.LocalServerPort; ...@@ -23,9 +24,7 @@ import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -35,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -35,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@SeleniumTest @SeleniumTest
public class NewTransactionTest public class NewTransactionNormalTest
{ {
private IntegrationTestHelper helper; private IntegrationTestHelper helper;
private WebDriver driver; private WebDriver driver;
...@@ -58,7 +57,7 @@ public class NewTransactionTest ...@@ -58,7 +57,7 @@ public class NewTransactionTest
@Override @Override
protected void failed(Throwable e, Description description) protected void failed(Throwable e, Description description)
{ {
IntegrationTestHelper.saveScreenshots(driver, name, NewTransactionTest.class); IntegrationTestHelper.saveScreenshots(driver, name, NewTransactionNormalTest.class);
} }
}; };
...@@ -75,9 +74,6 @@ public class NewTransactionTest ...@@ -75,9 +74,6 @@ public class NewTransactionTest
helper.login(UserService.DEFAULT_PASSWORD); helper.login(UserService.DEFAULT_PASSWORD);
helper.hideBackupReminder(); helper.hideBackupReminder();
String path = getClass().getClassLoader().getResource("SearchDatabase.json").getFile().replace("/", File.separator);
helper.uploadDatabase(path, Arrays.asList("DefaultAccount0815", "sfsdf"), Arrays.asList("DefaultAccount0815", "Account2"));
// open transactions page // open transactions page
driver.get(helper.getUrl() + "/transactions"); driver.get(helper.getUrl() + "/transactions");
driver.findElement(By.id("button-new-transaction")).click(); driver.findElement(By.id("button-new-transaction")).click();
...@@ -136,7 +132,7 @@ public class NewTransactionTest ...@@ -136,7 +132,7 @@ public class NewTransactionTest
// check columns // check columns
final String dateString = new SimpleDateFormat("dd.MM.").format(new Date()); final String dateString = new SimpleDateFormat("dd.MM.").format(new Date());
assertTransactionColumns(columns, dateString, "N", "rgb(255, 255, 255)", false, name, description, amount); TransactionTestHelper.assertTransactionColumns(columns, dateString, "N", "rgb(255, 255, 255)", false, false, name, description, amount);
} }
@Test @Test
...@@ -173,33 +169,6 @@ public class NewTransactionTest ...@@ -173,33 +169,6 @@ public class NewTransactionTest
// check columns // check columns
final String dateString = new SimpleDateFormat("dd.MM.").format(new Date()); final String dateString = new SimpleDateFormat("dd.MM.").format(new Date());
assertTransactionColumns(columns, dateString, "N", "rgb(255, 255, 255)", false, name, description, "-" + amount); TransactionTestHelper.assertTransactionColumns(columns, dateString, "N", "rgb(255, 255, 255)", false, false, name, description, "-" + amount);
}
private void assertTransactionColumns(List<WebElement> columns, String shortDate, String categoryLetter, String categoryColor, boolean repeatIconVisible, String name, String description, String amount)
{
// date
assertThat(columns.get(0)).hasFieldOrPropertyWithValue("text", shortDate);
// category
final WebElement categoryCircle = columns.get(1).findElement(By.className("category-circle"));
assertThat(categoryCircle.getCssValue("background-color")).isEqualTo(categoryColor);
assertThat(categoryCircle.findElement(By.tagName("span"))).hasFieldOrPropertyWithValue("text", categoryLetter);
// icon
final List<WebElement> icons = columns.get(2).findElements(By.tagName("i"));
assertThat(icons).hasSize(1);
assertThat(icons.get(0).isDisplayed()).isEqualTo(repeatIconVisible);
// name
assertThat(columns.get(3).findElement(By.className("transaction-text")).getText())
.isEqualTo(name);
//description
assertThat(columns.get(3).findElement(By.className("italic")).getText())
.isEqualTo(description);
// amount
assertThat(columns.get(4).getText()).contains(amount);
} }
} }
\ No newline at end of file
package de.deadlocker8.budgetmaster.integration;
import de.deadlocker8.budgetmaster.Main;
import de.deadlocker8.budgetmaster.authentication.UserService;
import de.deadlocker8.budgetmaster.integration.helpers.IntegrationTestHelper;
import de.deadlocker8.budgetmaster.integration.helpers.SeleniumTest;
import de.deadlocker8.budgetmaster.integration.helpers.TransactionTestHelper;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@SeleniumTest
public class NewTransactionTransferTest
{
private IntegrationTestHelper helper;
private WebDriver driver;
@LocalServerPort
int port;
@Rule
public TestName name = new TestName();
@Rule
public TestWatcher testWatcher = new TestWatcher()
{
@Override
protected void finished(Description description)
{
driver.quit();
}
@Override
protected void failed(Throwable e, Description description)
{
IntegrationTestHelper.saveScreenshots(driver, name, NewTransactionTransferTest.class);
}
};
@Before
public void prepare()
{
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
driver = new FirefoxDriver(options);
// prepare
helper = new IntegrationTestHelper(driver, port);
helper.start();
helper.login(UserService.DEFAULT_PASSWORD);
helper.hideBackupReminder();
String path = getClass().getClassLoader().getResource("SearchDatabase.json").getFile().replace("/", File.separator);
helper.uploadDatabase(path, Arrays.asList("DefaultAccount0815", "sfsdf"), Arrays.asList("DefaultAccount0815", "Account2"));
// open transactions page
driver.get(helper.getUrl() + "/transactions");
driver.findElement(By.id("button-new-transaction")).click();
}
@Test
public void newTransaction_transfer_cancel()
{
// open new transaction page
driver.findElement(By.xpath("//div[contains(@class, 'new-transaction-button')]//a[contains(text(),'Transfer')]")).click();
// click cancel button
driver.findElement(By.xpath("//a[contains(text(),'Cancel')]")).click();
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".headline-date")));
// assert
assertThat(driver.getCurrentUrl()).endsWith("/transactions");
List<WebElement> transactionsRows = driver.findElements(By.cssSelector(".transaction-container .hide-on-med-and-down.transaction-row-top"));
assertThat(transactionsRows).hasSize(1);
}
@Test
public void newTransaction_transfer()
{
// open new transaction page
driver.findElement(By.xpath("//div[contains(@class, 'new-transaction-button')]//a[contains(text(),'Transfer')]")).click();
String name = "My transfer transaction";
String amount = "15.00";
String description = "Lorem Ipsum dolor sit amet";
// fill form
driver.findElement(By.id("transaction-name")).sendKeys(name);
driver.findElement(By.id("transaction-amount")).sendKeys(amount);
driver.findElement(By.id("transaction-description")).sendKeys(description);
// submit form
driver.findElement(By.xpath("//button[@type='submit']")).click();
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".headline-date")));
// assert
assertThat(driver.getCurrentUrl()).endsWith("/transactions");
List<WebElement> transactionsRows = driver.findElements(By.cssSelector(".transaction-container .hide-on-med-and-down.transaction-row-top"));
assertThat(transactionsRows).hasSize(2);
final WebElement row = transactionsRows.get(0);
final List<WebElement> columns = row.findElements(By.className("col"));
assertThat(columns).hasSize(6);
// check columns
final String dateString = new SimpleDateFormat("dd.MM.").format(new Date());
TransactionTestHelper.assertTransactionColumns(columns, dateString, "N", "rgb(255, 255, 255)", false, true, name, description, amount);
}
}
\ No newline at end of file
package de.deadlocker8.budgetmaster.integration.helpers;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TransactionTestHelper
{
public static void assertTransactionColumns(List<WebElement> columns, String shortDate, String categoryLetter, String categoryColor, boolean repeatIconVisible, boolean transferIconIsVisible, String name, String description, String amount)
{
// date
assertThat(columns.get(0)).hasFieldOrPropertyWithValue("text", shortDate);
// category
final WebElement categoryCircle = columns.get(1).findElement(By.className("category-circle"));
assertThat(categoryCircle.getCssValue("background-color")).isEqualTo(categoryColor);
assertThat(categoryCircle.findElement(By.tagName("span"))).hasFieldOrPropertyWithValue("text", categoryLetter);
// icon
final List<WebElement> icons = columns.get(2).findElements(By.tagName("i"));
assertThat(icons).hasSize(1);
assertThat(icons.get(0).isDisplayed()).isEqualTo(repeatIconVisible || transferIconIsVisible);
if(repeatIconVisible)
{
assertThat(icons.get(0)).hasFieldOrPropertyWithValue("text", "repeat");
}
else if(transferIconIsVisible)
{
assertThat(icons.get(0)).hasFieldOrPropertyWithValue("text", "swap_horiz");
}
// name
assertThat(columns.get(3).findElement(By.className("transaction-text")).getText())
.isEqualTo(name);
//description
assertThat(columns.get(3).findElement(By.className("italic")).getText())
.isEqualTo(description);
// amount
assertThat(columns.get(4).getText()).contains(amount);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment