Skip to content

Commit

Permalink
Use mockUiComponent test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Nov 11, 2021
1 parent 5dfb08d commit ad3f803
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package scommons.client.showcase

import io.github.shogowada.scalajs.reactjs.React.Props
import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import scommons.client.app.{AppBrowseController, AppBrowseControllerProps}
import scommons.client.ui.Buttons
import scommons.react.UiComponent
import scommons.react.redux.BaseStateController
import scommons.react.redux._

object ShowcaseRouteController extends BaseStateController[ShowcaseState, AppBrowseControllerProps] {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package scommons.client.showcase

import io.github.shogowada.scalajs.reactjs.React.Props
import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import scommons.client.app.AppTaskManagerUi
import scommons.react.UiComponent
import scommons.react.redux.BaseStateController
import scommons.react.redux._
import scommons.react.redux.task.{TaskManager, TaskManagerProps}

object ShowcaseTaskController extends BaseStateController[ShowcaseState, TaskManagerProps] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package scommons.client.showcase.action.api

import io.github.shogowada.scalajs.reactjs.redux.Action
import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import scommons.api.{ApiStatus, StatusResponse}
import scommons.react.redux._
import scommons.react.redux.task.{FutureTask, TaskAction}

import scala.concurrent.ExecutionContext.Implicits.global
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package scommons.client.showcase.demo

import io.github.shogowada.scalajs.reactjs.React.Props
import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import play.api.libs.json.Json
import scommons.client.showcase.ShowcaseState
import scommons.client.showcase.action.api.ApiActions
Expand All @@ -11,7 +10,7 @@ import scommons.client.ui.popup._
import scommons.client.util.ActionsData
import scommons.react._
import scommons.react.hooks._
import scommons.react.redux.BaseStateController
import scommons.react.redux._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Success
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package scommons.client.showcase.table

import scommons.client.showcase.table.TablePanelDemo._
import scommons.react._
import scommons.react.test._

class TablePanelDemoSpec extends TestSpec with TestRendererUtils {

TablePanelDemo.simpleTablePanel = () => "SimpleTablePanel".asInstanceOf[ReactClass]
TablePanelDemo.customTablePanel = () => "CustomTablePanel".asInstanceOf[ReactClass]
TablePanelDemo.simpleTablePanel = mockUiComponent("SimpleTablePanel")
TablePanelDemo.customTablePanel = mockUiComponent("CustomTablePanel")

it should "render component" in {
//given
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package scommons.client.app

import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import io.github.shogowada.scalajs.reactjs.router.dom.RouterDOM._
import io.github.shogowada.scalajs.reactjs.router.{RouterProps, WithRouter}
import scommons.client.ui._
import scommons.client.ui.tree._
import scommons.client.util.{ActionsData, BrowsePath}
import scommons.react._
import scommons.react.redux.Dispatch

case class AppBrowseControllerProps(buttons: List[ButtonData],
treeRoots: List[BrowseTreeData],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package scommons.client.controller

import io.github.shogowada.scalajs.reactjs.React.Props
import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import io.github.shogowada.scalajs.reactjs.router.RouterProps._
import scommons.react.redux.BaseStateController
import scommons.react.redux._

trait BaseStateAndRouteController[S, P] extends BaseStateController[S, P] {

Expand Down
2 changes: 1 addition & 1 deletion ui/src/main/scala/scommons/client/ui/ButtonsPanel.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package scommons.client.ui

import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import scommons.client.util.ActionsData
import scommons.react._
import scommons.react.redux.Dispatch

case class ButtonsPanelProps(buttons: List[ButtonData],
actions: ActionsData,
Expand Down
2 changes: 1 addition & 1 deletion ui/src/main/scala/scommons/client/ui/popup/Modal.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package scommons.client.ui.popup

import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import scommons.client.ui.ButtonData
import scommons.client.util.ActionsData
import scommons.react._
import scommons.react.redux.Dispatch

case class ModalProps(header: Option[String],
buttons: List[ButtonData],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package scommons.client.ui.popup

import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import scommons.client.ui.{ButtonData, ButtonsPanel, ButtonsPanelProps}
import scommons.client.util.ActionsData
import scommons.react._
import scommons.react.redux.Dispatch

case class ModalFooterProps(buttons: List[ButtonData],
actions: ActionsData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package scommons.client.app

import io.github.shogowada.scalajs.reactjs.redux.Redux.Dispatch
import scommons.client.app.AppBrowseController.findItemAndPath
import scommons.client.app.AppBrowseControllerSpec._
import scommons.client.test.raw.MemoryRouter._
import scommons.client.ui.Buttons
import scommons.client.ui.tree.{BrowseTreeItemData, BrowseTreeNodeData}
import scommons.client.util.{ActionsData, BrowsePath}
import scommons.react._
import scommons.react.test.TestSpec
import scommons.react.test.raw.TestInstance
import scommons.react.test.util.TestRendererUtils
import scommons.react.redux.Dispatch
import scommons.react.test._

class AppBrowseControllerSpec extends TestSpec with TestRendererUtils {

Expand Down
5 changes: 2 additions & 3 deletions ui/src/test/scala/scommons/client/app/AppMainPanelSpec.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package scommons.client.app

import scommons.client.app.AppMainPanel._
import scommons.react._
import scommons.react.test._

class AppMainPanelSpec extends TestSpec with TestRendererUtils {

AppMainPanel.appHeaderComp = () => "AppHeader".asInstanceOf[ReactClass]
AppMainPanel.appFooterComp = () => "AppFooter".asInstanceOf[ReactClass]
AppMainPanel.appHeaderComp = mockUiComponent("AppHeader")
AppMainPanel.appFooterComp = mockUiComponent("AppFooter")

it should "render the component" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import org.scalatest.Succeeded
import scommons.api.{ApiStatus, StatusResponse}
import scommons.client.app.AppTaskManagerUi._
import scommons.client.ui.popup._
import scommons.react._
import scommons.react.redux.task.TaskManagerUiProps
import scommons.react.test._

import scala.util.Success

class AppTaskManagerUiSpec extends TestSpec with TestRendererUtils {

AppTaskManagerUi.statusPopup = () => "StatusPopup".asInstanceOf[ReactClass]
AppTaskManagerUi.loadingPopup = () => "LoadingPopup".asInstanceOf[ReactClass]
AppTaskManagerUi.errorPopup = () => "ErrorPopup".asInstanceOf[ReactClass]
AppTaskManagerUi.statusPopup = mockUiComponent("StatusPopup")
AppTaskManagerUi.loadingPopup = mockUiComponent("LoadingPopup")
AppTaskManagerUi.errorPopup = mockUiComponent("ErrorPopup")

it should "return error if unsuccessful response in errorHandler" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package scommons.client.ui.popup
import scommons.client.ui.icon.IconCss
import scommons.client.ui.popup.ErrorPopup._
import scommons.client.ui.{HTML, HTMLProps, SimpleButtonData}
import scommons.react._
import scommons.react.test._

class ErrorPopupSpec extends TestSpec with TestRendererUtils {

ErrorPopup.modalComp = () => "Modal".asInstanceOf[ReactClass]
ErrorPopup.htmlComp = () => "HTML".asInstanceOf[ReactClass]
ErrorPopup.modalComp = mockUiComponent("Modal")
ErrorPopup.htmlComp = mockUiComponent("HTML")

it should "call onClose function when on close command" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package scommons.client.ui.popup

import scommons.client.ui.popup.InputPopup._
import scommons.client.ui.{Buttons, TextFieldProps}
import scommons.react._
import scommons.react.test._

class InputPopupSpec extends TestSpec with TestRendererUtils {

InputPopup.modalComp = () => "Modal".asInstanceOf[ReactClass]
InputPopup.textFieldComp = () => "TextField".asInstanceOf[ReactClass]
InputPopup.modalComp = mockUiComponent("Modal")
InputPopup.textFieldComp = mockUiComponent("TextField")

it should "call onCancel when cancel command" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package scommons.client.ui.popup

import scommons.client.ui.popup.LoadingPopup.popupComp
import scommons.client.ui.popup.PopupCss._
import scommons.react._
import scommons.react.test._

class LoadingPopupSpec extends TestSpec with TestRendererUtils {

LoadingPopup.popupComp = () => "Popup".asInstanceOf[ReactClass]
LoadingPopup.popupComp = mockUiComponent("Popup")

it should "do nothing when onClose/onOpen" in {
//given
Expand Down
9 changes: 4 additions & 5 deletions ui/src/test/scala/scommons/client/ui/popup/ModalSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import org.scalatest.{Assertion, Succeeded}
import scommons.client.ui.Buttons
import scommons.client.ui.popup.Modal._
import scommons.client.util.ActionsData
import scommons.react._
import scommons.react.test._

class ModalSpec extends TestSpec with TestRendererUtils {

Modal.popupComp = () => "Popup".asInstanceOf[ReactClass]
Modal.modalHeaderComp = () => "ModalHeader".asInstanceOf[ReactClass]
Modal.modalBodyComp = () => "ModalBody".asInstanceOf[ReactClass]
Modal.modalFooterComp = () => "ModalFooter".asInstanceOf[ReactClass]
Modal.popupComp = mockUiComponent("Popup")
Modal.modalHeaderComp = mockUiComponent("ModalHeader")
Modal.modalBodyComp = mockUiComponent("ModalBody")
Modal.modalFooterComp = mockUiComponent("ModalFooter")

it should "render closable modal with header" in {
//given
Expand Down
3 changes: 1 addition & 2 deletions ui/src/test/scala/scommons/client/ui/popup/OkPopupSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package scommons.client.ui.popup
import scommons.client.ui.Buttons
import scommons.client.ui.icon.IconCss
import scommons.client.ui.popup.OkPopup._
import scommons.react._
import scommons.react.test._

class OkPopupSpec extends TestSpec with TestRendererUtils {

OkPopup.modalComp = () => "Modal".asInstanceOf[ReactClass]
OkPopup.modalComp = mockUiComponent("Modal")

it should "call onClose function when onOkCommand" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scommons.react.test._

class SaveCancelPopupSpec extends TestSpec with TestRendererUtils {

SaveCancelPopup.modalComp = () => "Modal".asInstanceOf[ReactClass]
SaveCancelPopup.modalComp = mockUiComponent("Modal")

it should "call onCancel function when cancel command" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package scommons.client.ui.popup

import scommons.client.ui.popup.PopupCss._
import scommons.client.ui.popup.StatusPopup._
import scommons.react._
import scommons.react.test._

class StatusPopupSpec extends TestSpec with TestRendererUtils {

StatusPopup.popupComp = () => "Popup".asInstanceOf[ReactClass]
StatusPopup.withAutoHideComp = () => "WithAutoHide".asInstanceOf[ReactClass]
StatusPopup.popupComp = mockUiComponent("Popup")
StatusPopup.withAutoHideComp = mockUiComponent("WithAutoHide")

it should "do nothing when onClose/onOpen" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import scommons.client.ui.icon.IconCss
import scommons.client.ui.popup.YesNoCancelOption._
import scommons.client.ui.popup.YesNoCancelPopup._
import scommons.client.ui.{Buttons, SimpleButtonData}
import scommons.react._
import scommons.react.test._

class YesNoCancelPopupSpec extends TestSpec with TestRendererUtils {

YesNoCancelPopup.modalComp = () => "Modal".asInstanceOf[ReactClass]
YesNoCancelPopup.modalComp = mockUiComponent("Modal")

it should "call onSelect(Yes) function when Yes selected" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import scommons.client.ui.SimpleButtonData
import scommons.client.ui.icon.IconCss
import scommons.client.ui.popup.YesNoCancelOption._
import scommons.client.ui.popup.YesNoPopup._
import scommons.react._
import scommons.react.test._

class YesNoPopupSpec extends TestSpec with TestRendererUtils {

YesNoPopup.modalComp = () => "Modal".asInstanceOf[ReactClass]
YesNoPopup.modalComp = mockUiComponent("Modal")

it should "call onSelect(Yes) function when Yes selected" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.scalatest.{Assertion, Succeeded}
import scommons.client.ui.select.SearchSelect._
import scommons.nodejs
import scommons.nodejs.test.AsyncTestSpec
import scommons.react._
import scommons.react.test._

import scala.concurrent.{Future, Promise}
Expand All @@ -13,7 +12,7 @@ import scala.scalajs.js
class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with TestRendererUtils {

SearchSelect.global = nodejs.global.asInstanceOf[js.Dynamic]
SearchSelect.singleSelectComp = () => "SingleSelect".asInstanceOf[ReactClass]
SearchSelect.singleSelectComp = mockUiComponent("SingleSelect")

it should "call onChange function when onSelectChange" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scommons.react.test._

class BrowseTreeSpec extends TestSpec with TestRendererUtils {

BrowseTree.treeNodeComp = () => "TreeNode".asInstanceOf[ReactClass]
BrowseTree.treeNodeComp = mockUiComponent("TreeNode")

it should "call onSelect function when select new item" in {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scommons.react.test._

class CheckBoxTreeSpec extends TestSpec with TestRendererUtils {

CheckBoxTree.treeNodeComp = () => "TreeNode".asInstanceOf[ReactClass]
CheckBoxTree.treeNodeComp = mockUiComponent("TreeNode")

it should "expand node when onExpand" in {
//given
Expand Down

0 comments on commit ad3f803

Please sign in to comment.