diff --git a/src/main/resources/templates/transactions/transactionsMacros.ftl b/src/main/resources/templates/transactions/transactionsMacros.ftl index bcbad2bbc2edc1da4b6c0450bc9f884b0fcfa7cc..9a6ce3a29ecb96643ffee62e9a60d082866aade2 100644 --- a/src/main/resources/templates/transactions/transactionsMacros.ftl +++ b/src/main/resources/templates/transactions/transactionsMacros.ftl @@ -68,7 +68,7 @@ <#macro transactionLinks transaction> <div class="col s4 l2 xl1 right-align transaction-buttons no-wrap"> - <a href="<@s.url '/transactions/${transaction.ID?c}/highlight'/>" class="btn-flat no-padding text-color"><i class="material-icons left">open_in_new</i></a> + <a href="<@s.url '/transactions/${transaction.ID?c}/highlight'/>" class="btn-flat no-padding text-color buttonHighlight"><i class="material-icons left">open_in_new</i></a> <a href="<@s.url '/transactions/${transaction.ID?c}/edit'/>" class="btn-flat no-padding text-color"><i class="material-icons left no-margin">edit</i></a> </div> </#macro> diff --git a/src/test/java/de/deadlocker8/budgetmaster/integration/SearchTest.java b/src/test/java/de/deadlocker8/budgetmaster/integration/SearchTest.java index 1b9b64acf87081b601942b56bd43dcd6e1fd66e6..f8fe97108630750308e5de45983804d191e88add 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/integration/SearchTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/integration/SearchTest.java @@ -5,11 +5,15 @@ 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.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; @@ -19,9 +23,9 @@ 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; +import static org.junit.Assert.assertFalse; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Main.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -35,8 +39,8 @@ public class SearchTest @LocalServerPort int port; - @Test - public void searchFromNavbar() + @Before + public void prepare() { // prepare IntegrationTestHelper helper = new IntegrationTestHelper(driver, port); @@ -45,16 +49,18 @@ public class SearchTest 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); + helper.uploadDatabase(path, Arrays.asList("DefaultAccount0815", "sfsdf"), Arrays.asList("DefaultAccount0815", "Account2")); // search WebElement inputSearch = driver.findElement(By.id("search")); inputSearch.sendKeys("e"); driver.findElement(By.id("buttonSearch")).click(); + } - // validate + @Test + public void searchFromNavbar() + { + // headline WebElement headline = driver.findElement(By.className("headline")); String expected = Localization.getString("menu.search.results", 24); assertEquals(expected, headline.getText()); @@ -73,26 +79,6 @@ public class SearchTest @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()); @@ -130,5 +116,41 @@ public class SearchTest assertEquals(4, results.size()); } - //TODO: test highlight, browser back, checkboxes + @Test + public void checkboxes() + { + // deselect some checkboxes (use JavascriptExecutor here as the checkbox is covered by a span) + JavascriptExecutor executor = (JavascriptExecutor) driver; + executor.executeScript("arguments[0].click();", driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchName\"]"))); + executor.executeScript("arguments[0].click();", driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchDescription\"]"))); + + // search + driver.findElement(By.cssSelector(".main-card #searchForm button[type=\"submit\"]")).click(); + + // validate + assertFalse(driver.findElement(By.cssSelector(".main-card #searchForm input[name=\"searchName\"]")).isSelected()); + assertFalse(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(2, results.size()); + } + + @Test + public void highlight() + { + driver.findElement(By.cssSelector(".main-card .search-result .hide-on-med-and-down .buttonHighlight")).click(); + + assertEquals("May 2019", driver.findElement(By.cssSelector(".headline-date")).getText()); + + List<WebElement> transactionsRows = driver.findElements(By.cssSelector(".transaction-container .hide-on-med-and-down.transaction-row-top")); + assertEquals(25, transactionsRows.size()); + assertTrue(transactionsRows.get(0).getAttribute("class").contains("budgetmaster-blue-light")); + for(int i = 1; i < transactionsRows.size(); i++) + { + assertFalse(transactionsRows.get(i).getAttribute("class").contains("budgetmaster-blue-light")); + } + } } \ No newline at end of file