Skip to content

Commit

Permalink
#236: simplifies file handling for end2end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rladstaetter committed Jul 23, 2024
1 parent b918d2a commit bac1103
Show file tree
Hide file tree
Showing 51 changed files with 184 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .run/LogoRRRApp.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<configuration default="false" name="LogoRRRApp" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="app.logorrr.LogoRRRApp" />
<module name="app" />
<option name="VM_PARAMETERS" value="-Xmx4g -Djava.util.logging.config.file=develop-logging.properties -Djava.library.path=$PROJECT_DIR$/native/native-osx/target -Duser.language=en --module-path $PROJECT_DIR$/env/target/javafx-sdk-22.0.1/lib --add-modules javafx.controls,javafx.fxml --add-exports javafx.base/com.sun.javafx.binding=ALL-UNNAMED" />
<option name="VM_PARAMETERS" value="-Xmx8g -Djava.util.logging.config.file=develop-logging.properties -Djava.library.path=$PROJECT_DIR$/native/native-osx/target -Duser.language=en --module-path $PROJECT_DIR$/env/target/javafx-sdk-22.0.1/lib --add-modules javafx.controls,javafx.fxml --add-exports javafx.base/com.sun.javafx.binding=ALL-UNNAMED" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="app.logorrr.*" />
Expand Down
18 changes: 10 additions & 8 deletions app-tests/src/test/scala/app/logorrr/TestFiles.scala
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package app.logorrr

import app.logorrr.io.FileId

import java.nio.file.{Path, Paths}

object TestFiles {

val baseDir = Paths.get("src/test/resources/app/logorrr/")
val baseDir: Path = Paths.get("src/test/resources/app/logorrr/")

val simpleLog0: Path = baseDir.resolve("SimpleLog-0.txt")
val simpleLog1: Path = baseDir.resolve("SimpleLog-1.txt")
val simpleLog2: Path = baseDir.resolve("SimpleLog-2.txt")
val simpleLog3: Path = baseDir.resolve("SimpleLog-3.txt")
val simpleLog4: Path = baseDir.resolve("SimpleLog-4.txt")
val simpleLog0: FileId = FileId(baseDir.resolve("SimpleLog-0.txt"))
val simpleLog1: FileId = FileId(baseDir.resolve("SimpleLog-1.txt"))
val simpleLog2: FileId = FileId(baseDir.resolve("SimpleLog-2.txt"))
val simpleLog3: FileId = FileId(baseDir.resolve("SimpleLog-3.txt"))
val simpleLog4: FileId = FileId(baseDir.resolve("SimpleLog-4.txt"))

val zipFileContaining10Files: Path = baseDir.resolve("zip-containing-10-files.zip")
val zipFileContaining10Files: FileId = FileId(baseDir.resolve("zip-containing-10-files.zip"))

val seq: Seq[Path] = Seq(
val seq: Seq[FileId] = Seq(
simpleLog0
, simpleLog1
, simpleLog2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package app.logorrr.services.file

class EmptyFileService extends MockFileService(Seq())
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app.logorrr.services.file

import app.logorrr.io.FileId

/**
* Given a list of files, it returns each file in order, and if the last file is reached, a
* `None`
*
* @param files which this service is returning
*/
class MockFileService(files: Seq[FileId]) extends FileService {

private val it = files.iterator

override def openFile: Option[FileId] = {
if (it.hasNext) {
Option(it.next())
} else None
}

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

import app.logorrr.io.FileId

/**
* Service which always opens given file
*
* @param fileId file reference to open
*/
class SingleFileService(fileId: FileId) extends MockFileService(Seq(fileId))
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ import app.logorrr.views.UiNodes
import app.logorrr.views.logfiletab.LogFileTab
import org.testfx.api.FxRobotInterface

import java.nio.file.Path

/**
* Mix in if you need to be able to open a file in your test
*/
trait FileMenuActions extends VisibleItemActions {
self: TestFxBaseApplicationTest =>

protected def openFile(path: Path): Unit = {
protected def openFile(fileId: FileId): Unit = {
waitAndClickVisibleItem(UiNodes.FileMenu)
waitAndClickVisibleItem(UiNodes.FileMenuOpenFile)
waitForVisibility(LogFileTab.uiNode(FileId(path)))
waitForVisibility(LogFileTab.uiNode(fileId))
}

protected def closeAllFiles(): FxRobotInterface = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import org.testfx.api.FxRobotInterface
trait VisibleItemActions {
self: TestFxBaseApplicationTest =>

def waitAndClickVisibleItem(menu: UiNode): FxRobotInterface = {
waitForVisibility(menu)
clickOn(menu)
def waitAndClickVisibleItem(node: UiNode): FxRobotInterface = {
waitForVisibility(node)
clickOn(node)
}

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package app.logorrr.usecases

import app.logorrr.conf.Settings
import app.logorrr.io.FileId
import app.logorrr.services.LogoRRRServices
import app.logorrr.services.fileservices.OpenMultipleFilesService
import app.logorrr.services.file.MockFileService
import app.logorrr.services.hostservices.MockHostServices
import app.logorrr.steps.{CanStartApplication, VisibleItemActions}

import java.nio.file.Path

/**
* Extend this class if you have tests which involve more than one file
*
* @param files files which are supported for this test
*/
class MultipleFileApplicationTest(val files: Seq[Path])
class MultipleFileApplicationTest(val files: Seq[FileId])
extends TestFxBaseApplicationTest
with CanStartApplication
with VisibleItemActions{
with VisibleItemActions {

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@ package app.logorrr.usecases
import app.logorrr.conf.Settings
import app.logorrr.io.FileId
import app.logorrr.services.LogoRRRServices
import app.logorrr.services.fileservices.OpenSingleFileService
import app.logorrr.services.file.SingleFileService
import app.logorrr.services.hostservices.MockHostServices
import app.logorrr.steps.CanStartApplication

import java.nio.file.Path


/**
* Test which work with a single file can extend this test
*/
class SingleFileApplicationTest(val path: Path)
class SingleFileApplicationTest(val fileId: FileId)
extends TestFxBaseApplicationTest
with CanStartApplication {

protected val fileId = FileId(path)

final def services: LogoRRRServices = LogoRRRServices(Settings.Default
, new MockHostServices
, new OpenSingleFileService(Option(path))
, new SingleFileService(fileId)
, isUnderTest = true)


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

import app.logorrr.conf.Settings
import app.logorrr.services.LogoRRRServices
import app.logorrr.services.fileservices.EmptyFileService
import app.logorrr.services.file.EmptyFileService
import app.logorrr.services.hostservices.MockHostServices
import app.logorrr.steps.CanStartApplication

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

import app.logorrr.conf.Settings
import app.logorrr.services.LogoRRRServices
import app.logorrr.services.fileservices.EmptyFileService
import app.logorrr.services.file.EmptyFileService
import app.logorrr.services.hostservices.MockHostServices
import app.logorrr.steps.{CanStartApplication, VisibleItemActions}
import app.logorrr.usecases.TestFxBaseApplicationTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app.logorrr.usecases.blockview

import app.logorrr.TestFiles
import app.logorrr.conf.LogoRRRGlobals
import app.logorrr.io.FileId
import app.logorrr.usecases.SingleFileApplicationTest
import app.logorrr.views.logfiletab.BlockSizeSlider
import javafx.scene.input.MouseButton
Expand All @@ -14,8 +13,7 @@ import org.junit.jupiter.api.Test
class BlockSizeWithSliderTest extends SingleFileApplicationTest(TestFiles.simpleLog0) {

@Test def search(): Unit = {
openFile(path)
val fileId = FileId(path)
openFile(fileId)
waitForVisibility(BlockSizeSlider.uiNode(fileId))

val slider0 = drag(BlockSizeSlider.uiNode(fileId).ref).moveBy(0,0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import org.junit.jupiter.api.Test
class SimpleBlockSizeTest extends SingleFileApplicationTest(TestFiles.simpleLog0) {

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

val size = LogoRRRGlobals.getLogFileSettings(fileId).getBlockSize
val count = 10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.logorrr.usecases.contextmenu

import app.logorrr.TestFiles
import app.logorrr.io.FileId
import app.logorrr.steps.CheckTabPaneActions
import app.logorrr.usecases.MultipleFileApplicationTest
import app.logorrr.views.UiNodes
Expand All @@ -18,7 +17,7 @@ class OpenMultipleFilesAndCloseAllViaContextMenu

@Test def openFilesAndCloseAllViaContextMenuItem(): Unit = {
TestFiles.seq.foreach {
p => openFile(p)
fileId => openFile(fileId)
}
expectCountOfOpenFiles(TestFiles.seq.size)
val selectedFile = Random.nextInt(TestFiles.seq.size)
Expand All @@ -28,7 +27,7 @@ class OpenMultipleFilesAndCloseAllViaContextMenu
val lastNodeQuery = looksi.nth(selectedFile)
clickOn(lastNodeQuery.query[StackPane]())
clickOn(lastNodeQuery.query[StackPane](), MouseButton.SECONDARY)
waitAndClickVisibleItem(CloseAllFilesMenuItem.uiNode(FileId(TestFiles.seq(selectedFile))))
waitAndClickVisibleItem(CloseAllFilesMenuItem.uiNode(TestFiles.seq(selectedFile)))

expectCountOfOpenFiles(0)

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

import app.logorrr.TestFiles
import app.logorrr.io.FileId
import app.logorrr.steps.CheckTabPaneActions
import app.logorrr.usecases.MultipleFileApplicationTest
import app.logorrr.views.UiNodes
Expand All @@ -28,7 +27,7 @@ class OpenMultipleFilesAndCloseOthersViaContextMenu
val lastNodeQuery = looksi.nth(selectedFile)
clickOn(lastNodeQuery.query[StackPane]())
clickOn(lastNodeQuery.query[StackPane](), MouseButton.SECONDARY)
waitAndClickVisibleItem(CloseOtherFilesMenuItem.uiNode(FileId(TestFiles.seq(selectedFile))))
waitAndClickVisibleItem(CloseOtherFilesMenuItem.uiNode(TestFiles.seq(selectedFile)))

expectCountOfOpenFiles(1)

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

import app.logorrr.TestFiles
import app.logorrr.io.FileId
import app.logorrr.steps.CheckTabPaneActions
import app.logorrr.usecases.MultipleFileApplicationTest
import app.logorrr.views.UiNodes
Expand All @@ -24,7 +23,7 @@ class OpenMultipleFilesAndCloseToTheLeft
val lastNodeQuery = looksi.nth(TestFiles.seq.size - 1)
clickOn(lastNodeQuery.query[StackPane]())
clickOn(lastNodeQuery.query[StackPane](), MouseButton.SECONDARY)
waitAndClickVisibleItem(CloseLeftFilesMenuItem.uiNode(FileId(TestFiles.seq.last)))
waitAndClickVisibleItem(CloseLeftFilesMenuItem.uiNode(TestFiles.seq.last))

expectCountOfOpenFiles(1)

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

import app.logorrr.TestFiles
import app.logorrr.io.FileId
import app.logorrr.steps.CheckTabPaneActions
import app.logorrr.usecases.MultipleFileApplicationTest
import app.logorrr.views.UiNodes
Expand All @@ -22,7 +21,7 @@ class OpenMultipleFilesAndCloseToTheRight
// activate first tab
clickOn(lookup(UiNodes.LogFileHeaderTabs).query[StackPane]())
clickOn(lookup(UiNodes.LogFileHeaderTabs).query[StackPane](), MouseButton.SECONDARY)
waitAndClickVisibleItem(CloseRightFilesMenuItem.uiNode(FileId(TestFiles.seq.head)))
waitAndClickVisibleItem(CloseRightFilesMenuItem.uiNode(TestFiles.seq.head))

expectCountOfOpenFiles(1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OpenSingleFileAndCloseViaContextMenuTest
*/
@Test def openAndCloseTab(): Unit = {
checkForEmptyTabPane()
openFile(path)
openFile(fileId)
checkForNonEmptyTabPane()
clickOn(lookup(UiNodes.LogFileHeaderTabs).query[StackPane](), MouseButton.SECONDARY)
waitAndClickVisibleItem(CloseTabMenuItem.uiNode(fileId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OpenSingleFileAndOpenInFinderTest
// basically skips this until https://github.com/rladstaetter/LogoRRR/issues/221#issuecomment-2083771649
if (false) {
checkForEmptyTabPane()
openFile(path)
openFile(fileId)
checkForNonEmptyTabPane()
clickOn(lookup(UiNodes.LogFileHeaderTabs).query[StackPane](), MouseButton.SECONDARY)
waitAndClickVisibleItem(OpenInFinderMenuItem.uiNode(fileId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DndDropDirectoryTest extends StartEmptyApplicationTest
LogoRRRApp.start(stage, services)

val dndStage = new Stage()
val dropBox = new ToolBar(Seq(new DragSourceButton(TestFiles.baseDir)): _*)
val dropBox = new ToolBar(Seq(new DragSourceButton(FileId(TestFiles.baseDir))): _*)
dndStage.setScene(new Scene(dropBox))
dndStage.show()

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

import app.logorrr.io.FileId
import app.logorrr.steps.{CheckTabPaneActions, VisibleItemActions}
import app.logorrr.usecases.StartEmptyApplicationTest
import app.logorrr.views.UiNodes
Expand Down Expand Up @@ -40,7 +39,7 @@ class DndDropFileTest extends StartEmptyApplicationTest
@Test def startupEmpty(): Unit = {
checkForEmptyTabPane()
TestFiles.seq.foreach {
f => drag(DragSourceButton.uiNode(FileId(f)).ref, MouseButton.PRIMARY).dropTo(UiNodes.MainTabPane.ref)
fileId => drag(DragSourceButton.uiNode(fileId).ref, MouseButton.PRIMARY).dropTo(UiNodes.MainTabPane.ref)
}
expectCountOfOpenFiles(TestFiles.seq.size)

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

import app.logorrr.io.FileId
import app.logorrr.steps.{CheckTabPaneActions, VisibleItemActions}
import app.logorrr.usecases.StartEmptyApplicationTest
import app.logorrr.views.UiNodes
Expand Down Expand Up @@ -39,7 +38,7 @@ class DndDropZipFileTest extends StartEmptyApplicationTest

@Test def testOpeningAZipFileWith10Files(): Unit = {
checkForEmptyTabPane()
drag(DragSourceButton.uiNode(FileId(TestFiles.zipFileContaining10Files)).ref, MouseButton.PRIMARY).dropTo(UiNodes.MainTabPane.ref)
drag(DragSourceButton.uiNode(TestFiles.zipFileContaining10Files).ref, MouseButton.PRIMARY).dropTo(UiNodes.MainTabPane.ref)
expectCountOfOpenFiles(10)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import app.logorrr.views.{UiNode, UiNodeFileIdAware}
import javafx.scene.control.Button
import javafx.scene.input.{ClipboardContent, TransferMode}

import java.nio.file.Path
import java.util.Collections

object DragSourceButton extends UiNodeFileIdAware {
Expand All @@ -14,12 +13,12 @@ object DragSourceButton extends UiNodeFileIdAware {

}

class DragSourceButton(p: Path) extends Button(p.getFileName.toString) {
setId(DragSourceButton.uiNode(FileId(p)).value)
class DragSourceButton(fileId: FileId) extends Button(fileId.fileName) {
setId(DragSourceButton.uiNode(fileId).value)

setOnDragDetected(_ => {
val content = new ClipboardContent()
content.putFiles(Collections.singletonList(p.toFile))
content.putFiles(Collections.singletonList(fileId.asPath.toFile))
startFullDrag()
startDragAndDrop(TransferMode.ANY: _*).setContent(content)
})
Expand Down
Loading

0 comments on commit bac1103

Please sign in to comment.