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

#431 - added search tests

parent 83ab5c00
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,8 @@ 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 org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
......@@ -9,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.io.File;
import java.util.Arrays;
......
......@@ -2,6 +2,8 @@ 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.thecodelabs.utils.util.Localization;
import org.junit.Test;
import org.junit.runner.RunWith;
......
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.thecodelabs.utils.util.Localization;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SeleniumTest
public class SearchTest
{
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Autowired
private WebDriver driver;
@LocalServerPort
int port;
@Test
public void searchFromNavbar()
{
// prepare
IntegrationTestHelper 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);
List<String> sourceAccounts = Arrays.asList("DefaultAccount0815", "sfsdf");
List<String> destinationAccounts = Arrays.asList("DefaultAccount0815", "Account2");
helper.uploadDatabase(path, sourceAccounts, destinationAccounts);
// search
WebElement inputSearch = driver.findElement(By.id("search"));
inputSearch.sendKeys("e");
driver.findElement(By.id("buttonSearch")).click();
// validate
WebElement headline = driver.findElement(By.className("headline"));
String expected = Localization.getString("menu.search.results", 24);
assertEquals(expected, headline.getText());
// checkboxes
assertTrue(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchName\"]")).isSelected());
assertTrue(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchDescription\"]")).isSelected());
assertTrue(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchCategory\"]")).isSelected());
assertTrue(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchTags\"]")).isSelected());
// results
List<WebElement> results = driver.findElements(By.cssSelector(".search-container .card-panel"));
assertEquals(10, results.size());
}
@Test
public void pagination()
{
// prepare
IntegrationTestHelper 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);
List<String> sourceAccounts = Arrays.asList("DefaultAccount0815", "sfsdf");
List<String> destinationAccounts = Arrays.asList("DefaultAccount0815", "Account2");
helper.uploadDatabase(path, sourceAccounts, destinationAccounts);
// search
WebElement inputSearch = driver.findElement(By.id("search"));
inputSearch.sendKeys("e");
driver.findElement(By.id("buttonSearch")).click();
WebElement headline = driver.findElement(By.className("headline"));
String expected = Localization.getString("menu.search.results", 24);
assertEquals(expected, headline.getText());
// === PAGE 1 ===
List<WebElement> pages = driver.findElements(By.cssSelector(".pagination li"));
assertEquals(5, pages.size());
assertTrue(pages.get(0).getAttribute("class").contains("disabled"));
assertEquals("1", pages.get(1).findElement(By.className("page-link")).getText());
assertTrue(pages.get(1).getAttribute("class").contains("active"));
assertEquals("2", pages.get(2).findElement(By.className("page-link")).getText());
assertEquals("3", pages.get(3).findElement(By.className("page-link")).getText());
assertTrue(!pages.get(4).getAttribute("class").contains("disabled"));
// validate results
List<WebElement> results = driver.findElements(By.cssSelector(".search-container .card-panel"));
assertEquals(10, results.size());
// === PAGE 1 ===
pages.get(3).click();
pages = driver.findElements(By.cssSelector(".pagination li"));
assertEquals(5, pages.size());
// previous button should be enabled
assertTrue(!pages.get(0).getAttribute("class").contains("disabled"));
assertEquals("1", pages.get(1).findElement(By.className("page-link")).getText());
assertEquals("2", pages.get(2).findElement(By.className("page-link")).getText());
assertEquals("3", pages.get(3).findElement(By.className("page-link")).getText());
assertTrue(pages.get(3).getAttribute("class").contains("active"));
// next button should be disabled
assertTrue(pages.get(4).getAttribute("class").contains("disabled"));
// validate
results = driver.findElements(By.cssSelector(".search-container .card-panel"));
assertEquals(4, results.size());
}
}
\ No newline at end of file
package de.deadlocker8.budgetmaster.integration;
package de.deadlocker8.budgetmaster.integration.helpers;
import de.thecodelabs.utils.util.Localization;
import org.openqa.selenium.By;
......@@ -10,9 +10,9 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
class IntegrationTestHelper
public class IntegrationTestHelper
{
static String getTextNode(WebElement e)
public static String getTextNode(WebElement e)
{
String text = e.getText().trim();
List<WebElement> children = e.findElements(By.xpath("./*"));
......@@ -27,7 +27,7 @@ class IntegrationTestHelper
private WebDriver driver;
private String url;
IntegrationTestHelper(WebDriver driver, int port)
public IntegrationTestHelper(WebDriver driver, int port)
{
this.driver = driver;
this.url = BASE_URL + port;
......@@ -38,12 +38,12 @@ class IntegrationTestHelper
return url;
}
void start()
public void start()
{
driver.get(url);
}
void login(String password)
public void login(String password)
{
WebElement inputPassword = driver.findElement(By.id("login-password"));
inputPassword.sendKeys(password);
......@@ -51,7 +51,7 @@ class IntegrationTestHelper
buttonLogin.click();
}
void hideBackupReminder()
public void hideBackupReminder()
{
try
{
......@@ -63,7 +63,7 @@ class IntegrationTestHelper
}
}
void uploadDatabase(String path, List<String> sourceAccounts, List<String> destinationAccounts)
public void uploadDatabase(String path, List<String> sourceAccounts, List<String> destinationAccounts)
{
if(path.startsWith("\\"))
{
......@@ -92,6 +92,10 @@ class IntegrationTestHelper
driver.findElement(By.id("buttonImport")).click();
assertEquals(Localization.getString("menu.settings"), IntegrationTestHelper.getTextNode(driver.findElement(By.className("headline"))));
// open transactions page in order to update repeating transactions
driver.get(url + "/transactions");
start();
}
private void createAccountOnImport(String accountName)
......
package de.deadlocker8.budgetmaster.integration;
package de.deadlocker8.budgetmaster.integration.helpers;
import org.springframework.test.context.TestExecutionListeners;
......
package de.deadlocker8.budgetmaster.integration;
package de.deadlocker8.budgetmaster.integration.helpers;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
......@@ -45,7 +45,7 @@ public class SeleniumTestExecutionListener extends AbstractTestExecutionListener
{
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
// options.setHeadless(true);
webDriver = new FirefoxDriver(options);
ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) context;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment