Skip to content

Commit

Permalink
#208: adds simple text size test
Browse files Browse the repository at this point in the history
  • Loading branch information
rladstaetter committed Apr 4, 2024
1 parent 15a71a5 commit 98bb638
Show file tree
Hide file tree
Showing 32 changed files with 235 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.logorrr.steps

import app.logorrr.usecases.TestFxBaseApplicationTest
import app.logorrr.views.LogoRRRNodes
import app.logorrr.views.UiNodes
import org.testfx.api.FxRobotInterface

/**
Expand All @@ -11,9 +11,9 @@ trait CanCloseAllFiles {
self: TestFxBaseApplicationTest =>

protected def closeAllFiles(): FxRobotInterface = {
clickOnNode(LogoRRRNodes.FileMenu)
waitForVisibility(LogoRRRNodes.FileMenuCloseAll)
clickOnNode(LogoRRRNodes.FileMenuCloseAll)
clickOn(UiNodes.FileMenu)
waitForVisibility(UiNodes.FileMenuCloseAll)
clickOn(UiNodes.FileMenuCloseAll)
}

}
12 changes: 6 additions & 6 deletions app-tests/src/test/scala/app/logorrr/steps/CanOpenFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.logorrr.steps

import app.logorrr.io.FileId
import app.logorrr.usecases.TestFxBaseApplicationTest
import app.logorrr.views.LogoRRRNodes
import app.logorrr.views.UiNodes
import app.logorrr.views.logfiletab.LogFileTab

import java.nio.file.Path
Expand All @@ -14,11 +14,11 @@ trait CanOpenFile {
self: TestFxBaseApplicationTest =>

protected def openFile(path: Path): Unit = {
waitForVisibility(LogoRRRNodes.FileMenu)
clickOnNode(LogoRRRNodes.FileMenu)
waitForVisibility(LogoRRRNodes.FileMenuOpenFile)
clickOnNode(LogoRRRNodes.FileMenuOpenFile)
waitForVisibility(LogFileTab.idFor(FileId(path)))
waitForVisibility(UiNodes.FileMenu)
clickOn(UiNodes.FileMenu)
waitForVisibility(UiNodes.FileMenuOpenFile)
clickOn(UiNodes.FileMenuOpenFile)
waitForVisibility(LogFileTab.uiNode(FileId(path)))
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package app.logorrr.steps

import app.logorrr.conf.Settings
import app.logorrr.services.LogoRRRServices
import app.logorrr.LogoRRRApp
import app.logorrr.usecases.TestFxBaseApplicationTest
Expand All @@ -16,7 +15,7 @@ trait CanStartApplication {

@throws[Exception]
override def start(stage: Stage): Unit = {
LogoRRRApp.start(stage, Settings.Default, services)
LogoRRRApp.start(stage, services)
stage.toFront()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.logorrr.usecases

import app.logorrr.conf.Settings
import app.logorrr.services.LogoRRRServices
import app.logorrr.services.fileservices.OpenMultipleFilesService
import app.logorrr.services.hostservices.MockHostServices
Expand All @@ -17,7 +18,8 @@ class MultipleFileApplicationTest(val files: Seq[Path])
with CanStartApplication
with CanOpenFile {

val services = LogoRRRServices(new MockHostServices
val services = LogoRRRServices(Settings.Default
,new MockHostServices
, new OpenMultipleFilesService(files)
, isUnderTest = true)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.logorrr.usecases

import app.logorrr.conf.Settings
import app.logorrr.services.LogoRRRServices
import app.logorrr.services.fileservices.OpenSingleFileService
import app.logorrr.services.hostservices.MockHostServices
Expand All @@ -14,9 +15,10 @@ import java.nio.file.Path
class SingleFileApplicationTest(val path: Path)
extends TestFxBaseApplicationTest
with CanStartApplication
with CanOpenFile{
with CanOpenFile {

val services = LogoRRRServices(new MockHostServices
val services = LogoRRRServices(Settings.Default
, new MockHostServices
, new OpenSingleFileService(Option(path))
, isUnderTest = true)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.logorrr.usecases

import app.logorrr.views.LogoRRRNode
import app.logorrr.views.UiNode
import javafx.scene.Node
import javafx.scene.input.{KeyCode, MouseButton}
import org.junit.jupiter.api.AfterEach
Expand All @@ -27,9 +27,9 @@ class TestFxBaseApplicationTest extends ApplicationTest {
release(Array[MouseButton](): _*)
}

def clickOnNode(node: LogoRRRNode): FxRobotInterface = clickOn(node.ref)
def clickOn(node: UiNode): FxRobotInterface = clickOn(node.ref)

def waitForVisibility(id: LogoRRRNode): Unit = waitForVisibility(lookup(id.ref))
def waitForVisibility(id: UiNode): Unit = waitForVisibility(lookup(id.ref))

def waitForVisibility(query: String): Unit = waitForVisibility(lookup(query))

Expand All @@ -39,7 +39,7 @@ class TestFxBaseApplicationTest extends ApplicationTest {
})
}

def waitForPredicate[A <: Node](id: LogoRRRNode, clazz: Class[A], predicate: A => Boolean): Unit = {
def waitForPredicate[A <: Node](id: UiNode, clazz: Class[A], predicate: A => Boolean): Unit = {
WaitForAsyncUtils.waitFor(2, TimeUnit.SECONDS, new Callable[java.lang.Boolean] {
override def call(): java.lang.Boolean = {
predicate(lookup(id.ref).queryAs(clazz))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.logorrr.usecases.openclose
import app.logorrr.TestFiles
import app.logorrr.steps.CanCloseAllFiles
import app.logorrr.usecases.SingleFileApplicationTest
import app.logorrr.views.LogoRRRNodes
import app.logorrr.views.UiNodes
import javafx.scene.control.TabPane
import org.junit.jupiter.api.Test

Expand All @@ -26,7 +26,7 @@ class OpenAndCloseFileTestViaFileMenuCloseAllTest extends SingleFileApplicationT
// click on file menu and then close all button
closeAllFiles()

waitForPredicate[TabPane](LogoRRRNodes.MainTabPane, classOf[TabPane], tabPane => {
waitForPredicate[TabPane](UiNodes.MainTabPane, classOf[TabPane], tabPane => {
tabPane.getTabs.isEmpty
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.logorrr.usecases.openclose

import app.logorrr.TestFiles
import app.logorrr.usecases.SingleFileApplicationTest
import app.logorrr.views.LogoRRRNodes
import app.logorrr.views.UiNodes
import javafx.scene.control.TabPane
import javafx.scene.layout.StackPane
import org.junit.jupiter.api.Test
Expand All @@ -22,14 +22,14 @@ class OpenAndCloseFileTestViaTabCloseButtonTest extends SingleFileApplicationTes
openFile(path)

// yields only one tab since there is only one loaded
val tabsQuery = LogoRRRNodes.LogFileHeaderTabs
val tabsQuery = UiNodes.LogFileHeaderTabs

val closeButtonQuery = clickOn(lookup(tabsQuery).query[StackPane]()).lookup(LogoRRRNodes.LogFileHeaderTabCloseButton)
val closeButtonQuery = clickOn(lookup(tabsQuery).query[StackPane]()).lookup(UiNodes.LogFileHeaderTabCloseButton)
waitForVisibility(closeButtonQuery)

clickOn(closeButtonQuery.queryAs[StackPane](classOf[StackPane]))

waitForPredicate[TabPane](LogoRRRNodes.MainTabPane, classOf[TabPane], tabPane => {
waitForPredicate[TabPane](UiNodes.MainTabPane, classOf[TabPane], tabPane => {
tabPane.getTabs.isEmpty
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.logorrr.usecases.openclose

import app.logorrr.views.LogoRRRNodes
import app.logorrr.views.UiNodes
import app.logorrr.TestFiles
import app.logorrr.usecases.MultipleFileApplicationTest
import javafx.scene.control.TabPane
Expand All @@ -20,15 +20,15 @@ class OpenAndCloseMultipleFilesViaCloseButtonTest extends MultipleFileApplicatio
p => openFile(p)
}

val tabCards = lookup(LogoRRRNodes.LogFileHeaderTabs).queryAll[StackPane]().asScala
val tabCards = lookup(UiNodes.LogFileHeaderTabs).queryAll[StackPane]().asScala

for (n <- tabCards) {
val nodeQuery: NodeQuery = clickOn(n).lookup(LogoRRRNodes.LogFileHeaderTabCloseButton)
val nodeQuery: NodeQuery = clickOn(n).lookup(UiNodes.LogFileHeaderTabCloseButton)
waitForVisibility(nodeQuery)
clickOn(nodeQuery.queryAs[StackPane](classOf[StackPane]))
}

waitForPredicate[TabPane](LogoRRRNodes.MainTabPane, classOf[TabPane], tabPane => {
waitForPredicate[TabPane](UiNodes.MainTabPane, classOf[TabPane], tabPane => {
tabPane.getTabs.isEmpty
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.logorrr.usecases.openclose

import app.logorrr.views.LogoRRRNodes
import app.logorrr.views.UiNodes
import app.logorrr.TestFiles
import app.logorrr.usecases.MultipleFileApplicationTest
import javafx.scene.control.TabPane
Expand All @@ -17,12 +17,12 @@ class OpenAndCloseMultipleFilesViaMenuTest extends MultipleFileApplicationTest(T
p => openFile(p)
}
// now close them all again
clickOnNode(LogoRRRNodes.FileMenu)
waitForVisibility(LogoRRRNodes.FileMenuCloseAll)
clickOn(UiNodes.FileMenu)
waitForVisibility(UiNodes.FileMenuCloseAll)

clickOnNode(LogoRRRNodes.FileMenuCloseAll)
clickOn(UiNodes.FileMenuCloseAll)

waitForPredicate[TabPane](LogoRRRNodes.MainTabPane, classOf[TabPane], tabPane => {
waitForPredicate[TabPane](UiNodes.MainTabPane, classOf[TabPane], tabPane => {
tabPane.getTabs.isEmpty
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SimpleSearchTest extends SingleFileApplicationTest(TestFiles.simpleLog0) {
}

private def searchFor(needle: String) = {
clickOn(SearchTextField.id(FileId(path)).ref).write(needle)
clickOn(SearchTextField.uiNode(FileId(path)).ref).write(needle)
clickOn(SearchButton.id(FileId(path)).ref)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package app.logorrr.usecases.textview

import app.logorrr.TestFiles
import app.logorrr.conf.{LogoRRRGlobals, Settings, StageSettings}
import app.logorrr.io.FileId
import app.logorrr.services.LogoRRRServices
import app.logorrr.services.fileservices.OpenSingleFileService
import app.logorrr.services.hostservices.MockHostServices
import app.logorrr.usecases.SingleFileApplicationTest
import app.logorrr.views.text.toolbaractions.{DecreaseTextSizeButton, IncreaseTextSizeButton}
import org.junit.jupiter.api.Test

class SimpleTextSizeTest extends SingleFileApplicationTest(TestFiles.simpleLog0) {

override val services = LogoRRRServices(Settings.Default.copy(stageSettings = StageSettings(100, 100, 1200, 600))
, new MockHostServices
, new OpenSingleFileService(Option(path))
, isUnderTest = true)

@Test def search(): Unit = {
openFile(path)
val fileId = FileId(path)

val size = LogoRRRGlobals.getLogFileSettings(fileId).getFontSize
val count = 10

for (_ <- 1 to count) increaseTextSize(fileId)
assert(size + count == LogoRRRGlobals.getLogFileSettings(fileId).getFontSize)

// decrease again
for (_ <- 1 to 10) decreaseTextSize(fileId)
assert(size == LogoRRRGlobals.getLogFileSettings(fileId).getFontSize)
}


private def increaseTextSize(fileId: FileId): Unit = {
waitForVisibility(IncreaseTextSizeButton.uiNode(fileId))
clickOn(IncreaseTextSizeButton.uiNode(fileId))
}

private def decreaseTextSize(fileId: FileId): Unit = {
waitForVisibility(DecreaseTextSizeButton.uiNode(fileId))
clickOn(DecreaseTextSizeButton.uiNode(fileId))
}

}
11 changes: 6 additions & 5 deletions app/src/main/scala/app/logorrr/LogoRRRApp.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.logorrr

import app.logorrr
import app.logorrr.conf.{LogoRRRGlobals, Settings, SettingsIO}
import app.logorrr.conf.{LogoRRRGlobals, SettingsIO}
import app.logorrr.io.FilePaths
import app.logorrr.meta.AppMeta
import app.logorrr.services.LogoRRRServices
Expand All @@ -28,7 +28,6 @@ object LogoRRRApp extends CanLog {
}

def start(stage: Stage
, settings: Settings
, services: LogoRRRServices): LogoRRRMain = {
System.setProperty("user.language", "en")
System.setProperty("java.util.logging.SimpleFormatter.format", LogFormat)
Expand All @@ -37,7 +36,7 @@ object LogoRRRApp extends CanLog {
Application.setUserAgentStylesheet("/app/logorrr/LogoRRR.css")
logInfo(s"Started ${AppMeta.fullAppNameWithVersion} in '${Paths.get("").toAbsolutePath.toString}'")

LogoRRRGlobals.set(settings, services.hostServices)
LogoRRRGlobals.set(services.settings, services.hostServices)
val logoRRRMain = new LogoRRRMain(JfxUtils.closeStage(stage), services.fileOpenService, services.isUnderTest)
LogoRRRStage.init(stage, logoRRRMain)
logoRRRMain.initLogFilesFromConfig()
Expand All @@ -53,11 +52,13 @@ class LogoRRRApp extends javafx.application.Application with CanLog {
val hostServices = new NativeHostServices(getHostServices)


val services = logorrr.services.LogoRRRServices(hostServices
val services = logorrr.services.LogoRRRServices(
SettingsIO.fromFile(FilePaths.settingsFilePath)
, hostServices
, new NativeOpenFileService(() => stage.getScene.getWindow)
, isUnderTest = false)

LogoRRRApp.start(stage, SettingsIO.fromFile(FilePaths.settingsFilePath), services)
LogoRRRApp.start(stage, services)
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package app.logorrr.services

import app.logorrr.conf.Settings
import app.logorrr.services.fileservices.LogoRRRFileOpenService
import app.logorrr.services.hostservices.LogoRRRHostServices

case class LogoRRRServices(hostServices: LogoRRRHostServices
case class LogoRRRServices(settings: Settings
, hostServices: LogoRRRHostServices
, fileOpenService: LogoRRRFileOpenService
, isUnderTest: Boolean)
9 changes: 9 additions & 0 deletions app/src/main/scala/app/logorrr/views/UiNodeAware.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package app.logorrr.views

import app.logorrr.io.FileId

trait UiNodeAware {

def uiNode(id: FileId): UiNode

}
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package app.logorrr.views

case class LogoRRRNode(value: String) {
case class UiNode(value: String) {

lazy val ref: String = "#" + value

}

object LogoRRRNodes {
object UiNodes {

/** id for the file menu */
val FileMenu: LogoRRRNode = LogoRRRNode("file_menu")
val FileMenu: UiNode = UiNode("file_menu")

/** ID of menu item which opens a file */
val FileMenuOpenFile: LogoRRRNode = LogoRRRNode("file_menu_open_file")
val FileMenuOpenFile: UiNode = UiNode("file_menu_open_file")

/**
* close all files
*/
val FileMenuCloseAll: LogoRRRNode = LogoRRRNode("file_menu_close_all")
val FileMenuCloseAll: UiNode = UiNode("file_menu_close_all")

/**
* ID of main tab pane where all log files are placed
*/
val MainTabPane: LogoRRRNode = LogoRRRNode("main_tab_pane")
val MainTabPane: UiNode = UiNode("main_tab_pane")

/** yields all tab 'cards' which are available */
val LogFileHeaderTabs = s"${LogoRRRNodes.MainTabPane.ref} > .tab-header-area > .headers-region > .tab"
val LogFileHeaderTabs = s"${UiNodes.MainTabPane.ref} > .tab-header-area > .headers-region > .tab"

/** css rule to target the close button of a LogFileHeaderTab */
val LogFileHeaderTabCloseButton = ".tab-container > .tab-close-button"
Expand Down
Loading

0 comments on commit 98bb638

Please sign in to comment.