Skip to content

Commit

Permalink
#208: adds tests for tab context menu, makes test execution more resi…
Browse files Browse the repository at this point in the history
…lient
  • Loading branch information
rladstaetter committed Apr 12, 2024
1 parent 558cdb2 commit 7506729
Show file tree
Hide file tree
Showing 26 changed files with 236 additions and 96 deletions.
19 changes: 0 additions & 19 deletions app-tests/src/test/scala/app/logorrr/steps/CanCloseAllFiles.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package app.logorrr.steps

import app.logorrr.usecases.TestFxBaseApplicationTest
import app.logorrr.views.UiNodes
import javafx.scene.control.TabPane


trait CheckTabPaneActions {
self: TestFxBaseApplicationTest =>

def checkForEmptyTabPane(): Unit = {
waitForPredicate[TabPane](UiNodes.MainTabPane, classOf[TabPane], tabPane => {
tabPane.getTabs.isEmpty
})
}

def checkForNonEmptyTabPane(): Unit = {
waitForPredicate[TabPane](UiNodes.MainTabPane, classOf[TabPane], tabPane => {
!tabPane.getTabs.isEmpty
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,33 @@ import app.logorrr.io.FileId
import app.logorrr.usecases.TestFxBaseApplicationTest
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 CanOpenFile extends VisibleItemActions {
self: TestFxBaseApplicationTest =>
trait FileMenuActions extends VisibleItemActions {
self: TestFxBaseApplicationTest =>

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

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


def quitApplication(): Unit = {
waitAndClickVisibleItem(UiNodes.FileMenu)
waitAndClickVisibleItem(UiNodes.FileMenuQuitApplication)
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import app.logorrr.conf.Settings
import app.logorrr.services.LogoRRRServices
import app.logorrr.services.fileservices.OpenMultipleFilesService
import app.logorrr.services.hostservices.MockHostServices
import app.logorrr.steps.{CanOpenFile, CanStartApplication, VisibleItemActions}
import app.logorrr.steps.{CanStartApplication, VisibleItemActions}

import java.nio.file.Path

Expand All @@ -16,11 +16,10 @@ import java.nio.file.Path
class MultipleFileApplicationTest(val files: Seq[Path])
extends TestFxBaseApplicationTest
with CanStartApplication
with VisibleItemActions
with CanOpenFile {
with VisibleItemActions{

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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.hostservices.MockHostServices
import app.logorrr.steps.{CanOpenFile, CanStartApplication}
import app.logorrr.steps.CanStartApplication

import java.nio.file.Path

Expand All @@ -14,8 +15,9 @@ import java.nio.file.Path
*/
class SingleFileApplicationTest(val path: Path)
extends TestFxBaseApplicationTest
with CanStartApplication
with CanOpenFile {
with CanStartApplication {

protected val fileId = FileId(path)

final def services: LogoRRRServices = LogoRRRServices(Settings.Default
, new MockHostServices
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.logorrr.usecases

import app.logorrr.steps.FileMenuActions
import app.logorrr.views.UiNode
import javafx.scene.Node
import javafx.scene.input.{KeyCode, MouseButton}
Expand All @@ -15,13 +16,16 @@ import scala.concurrent.duration.{DurationInt, FiniteDuration}
/**
* provides helper methods to work with LogoRRR's UI components
*/
class TestFxBaseApplicationTest extends ApplicationTest {
class TestFxBaseApplicationTest
extends ApplicationTest
with FileMenuActions {

@AfterEach
@throws[Exception]
def tearDown(): Unit = {
quitApplication()
// exit application
push(KeyCode.COMMAND, KeyCode.Q)
//push(KeyCode.COMMAND, KeyCode.Q)
FxToolkit.hideStage()
release(Array[KeyCode](): _*)
release(Array[MouseButton](): _*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import app.logorrr.services.hostservices.MockHostServices
import app.logorrr.steps.{CanStartApplication, VisibleItemActions}
import app.logorrr.usecases.TestFxBaseApplicationTest
import app.logorrr.views.UiNodes
import app.logorrr.views.about.AboutScreen
import app.logorrr.views.about.AboutDialog
import org.junit.jupiter.api.Test


Expand All @@ -33,8 +33,9 @@ class ShowAboutDialogTest extends TestFxBaseApplicationTest
waitAndClickVisibleItem(UiNodes.AboutDialogOpenLogorrrMainSite)
waitAndClickVisibleItem(UiNodes.AboutDialogOpenDevelopmentBlog)
waitAndClickVisibleItem(UiNodes.AboutDialogOpenIssuePage)
waitAndClickVisibleItem(UiNodes.AboutDialogCloseButton)

assert(AboutScreen.links.map(_.url.toString).forall(u => mockHostServices.visitedUrls.contains(u)))
assert(AboutDialog.links.map(_.url.toString).forall(u => mockHostServices.visitedUrls.contains(u)))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package app.logorrr.usecases.contextmenu

import app.logorrr.TestFiles
import app.logorrr.steps.{CheckTabPaneActions, VisibleItemActions}
import app.logorrr.usecases.SingleFileApplicationTest
import app.logorrr.views.UiNodes
import app.logorrr.views.logfiletab.actions.CloseTabMenuItem
import javafx.scene.input.MouseButton
import javafx.scene.layout.StackPane
import org.junit.jupiter.api.Test

/**
* Checks if LogoRRR can open a file via the 'open file' menu
*/
class OpenSingleFileAndCloseViaContextMenuTest
extends SingleFileApplicationTest(TestFiles.simpleLog0)
with VisibleItemActions
with CheckTabPaneActions {

/**
* checks if an open file creates a new logfiletab with an id matching the file opened.
*/
@Test def openAndCloseTab(): Unit = {
checkForEmptyTabPane()
openFile(path)
checkForNonEmptyTabPane()
clickOn(lookup(UiNodes.LogFileHeaderTabs).query[StackPane](), MouseButton.SECONDARY)
waitAndClickVisibleItem(CloseTabMenuItem.uiNode(fileId))
checkForEmptyTabPane()
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package app.logorrr.usecases.contextmenu

import app.logorrr.TestFiles
import app.logorrr.steps.{CheckTabPaneActions, VisibleItemActions}
import app.logorrr.usecases.SingleFileApplicationTest
import app.logorrr.views.UiNodes
import app.logorrr.views.logfiletab.actions.OpenInFinderMenuItem
import javafx.scene.input.MouseButton
import javafx.scene.layout.StackPane
import org.junit.jupiter.api.Test

/**
* Checks if LogoRRR can open a file via the 'open file' menu
*/
class OpenSingleFileAndOpenInFinderTest
extends SingleFileApplicationTest(TestFiles.simpleLog0)
with VisibleItemActions
with CheckTabPaneActions {

/**
* checks if an open file creates a new logfiletab with an id matching the file opened.
*/
@Test def openSingleFileAndOpenInFinderTest(): Unit = {
checkForEmptyTabPane()
openFile(path)
checkForNonEmptyTabPane()
clickOn(lookup(UiNodes.LogFileHeaderTabs).query[StackPane](), MouseButton.SECONDARY)
waitAndClickVisibleItem(OpenInFinderMenuItem.uiNode(fileId))
checkForNonEmptyTabPane()
}

}

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

import app.logorrr.TestFiles
import app.logorrr.steps.CanCloseAllFiles
import app.logorrr.steps.CheckTabPaneActions
import app.logorrr.usecases.SingleFileApplicationTest
import app.logorrr.views.UiNodes
import javafx.scene.control.TabPane
import org.junit.jupiter.api.Test

import java.nio.file.Path
Expand All @@ -13,7 +11,7 @@ import java.nio.file.Path
* Checks if a file can be opened and closed
*/
class OpenAndCloseFileTestViaFileMenuCloseAllTest extends SingleFileApplicationTest(TestFiles.simpleLog0)
with CanCloseAllFiles {
with CheckTabPaneActions {

override val path: Path = TestFiles.simpleLog0

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

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

checkForEmptyTabPane()
}

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

import app.logorrr.TestFiles
import app.logorrr.steps.CheckTabPaneActions
import app.logorrr.usecases.SingleFileApplicationTest
import app.logorrr.views.UiNodes
import javafx.scene.control.TabPane
import javafx.scene.layout.StackPane
import org.junit.jupiter.api.Test

Expand All @@ -12,7 +12,9 @@ import java.nio.file.Path
/**
* Checks if a file can be opened and closed via it's closing button
*/
class OpenAndCloseFileTestViaTabCloseButtonTest extends SingleFileApplicationTest(TestFiles.simpleLog0) {
class OpenAndCloseFileTestViaTabCloseButtonTest
extends SingleFileApplicationTest(TestFiles.simpleLog0)
with CheckTabPaneActions {

override val path: Path = TestFiles.simpleLog0

Expand All @@ -31,10 +33,7 @@ class OpenAndCloseFileTestViaTabCloseButtonTest extends SingleFileApplicationTes

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

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

checkForEmptyTabPane()
}

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

import app.logorrr.views.UiNodes
import app.logorrr.TestFiles
import app.logorrr.steps.CheckTabPaneActions
import app.logorrr.usecases.MultipleFileApplicationTest
import javafx.scene.control.TabPane
import app.logorrr.views.UiNodes
import javafx.scene.layout.StackPane
import org.junit.jupiter.api.Test
import org.testfx.service.query.NodeQuery
Expand All @@ -13,7 +13,9 @@ import scala.jdk.CollectionConverters.CollectionHasAsScala
/**
* Check if multiple files can be opened and then closed again via file menu 'close all'
*/
class OpenAndCloseMultipleFilesViaCloseButtonTest extends MultipleFileApplicationTest(TestFiles.seq) {
class OpenAndCloseMultipleFilesViaCloseButtonTest
extends MultipleFileApplicationTest(TestFiles.seq)
with CheckTabPaneActions {

@Test def openFilesAndCloseOneByOneViaTabCloseButton(): Unit = {
TestFiles.seq.foreach {
Expand All @@ -28,10 +30,7 @@ class OpenAndCloseMultipleFilesViaCloseButtonTest extends MultipleFileApplicatio
clickOn(nodeQuery.queryAs[StackPane](classOf[StackPane]))
}

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

checkForEmptyTabPane()
}


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

import app.logorrr.views.UiNodes
import app.logorrr.TestFiles
import app.logorrr.steps.CheckTabPaneActions
import app.logorrr.usecases.MultipleFileApplicationTest
import javafx.scene.control.TabPane
import app.logorrr.views.UiNodes
import org.junit.jupiter.api.Test


/**
* Check if multiple files can be opened and then closed again via file menu 'close all'
*/
class OpenAndCloseMultipleFilesViaMenuTest extends MultipleFileApplicationTest(TestFiles.seq){
class OpenAndCloseMultipleFilesViaMenuTest
extends MultipleFileApplicationTest(TestFiles.seq)
with CheckTabPaneActions {

@Test def openFilesAndCloseAllViaMenu(): Unit = {
TestFiles.seq.foreach {
p => openFile(p)
}
// now close them all again
clickOn(UiNodes.FileMenu)
waitForVisibility(UiNodes.FileMenuCloseAll)

waitForVisibility(UiNodes.FileMenuCloseAll)
clickOn(UiNodes.FileMenuCloseAll)

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

}

Expand Down
Loading

0 comments on commit 7506729

Please sign in to comment.