From 528ef6e1f7c2f716ed55b6474ff3146aef84e3de Mon Sep 17 00:00:00 2001 From: Viktor Podzigun Date: Fri, 20 Aug 2021 13:21:34 +0200 Subject: [PATCH] Use TestRenderer instead of ShallowRenderer --- project/src/main/scala/common/Libs.scala | 2 +- .../showcase/table/TablePanelDemo.scala | 7 +- .../showcase/table/CustomTablePanelSpec.scala | 16 ++- .../showcase/table/SimpleTablePanelSpec.scala | 16 ++- .../showcase/table/TablePanelDemoSpec.scala | 32 ++--- .../scommons/client/app/AppMainPanel.scala | 7 +- .../client/app/AppTaskManagerUi.scala | 10 +- .../scommons/client/ui/popup/ErrorPopup.scala | 7 +- .../scommons/client/ui/popup/InputPopup.scala | 7 +- .../client/ui/popup/LoadingPopup.scala | 4 +- .../scommons/client/ui/popup/Modal.scala | 13 +- .../scommons/client/ui/popup/OkPopup.scala | 4 +- .../client/ui/popup/SaveCancelPopup.scala | 4 +- .../client/ui/popup/StatusPopup.scala | 7 +- .../client/ui/popup/YesNoCancelPopup.scala | 4 +- .../scommons/client/ui/popup/YesNoPopup.scala | 4 +- .../client/ui/select/SearchSelect.scala | 3 +- .../client/app/AppBrowsePanelSpec.scala | 11 +- .../client/app/AppMainPanelSpec.scala | 42 ++++--- .../client/app/AppTaskManagerUiSpec.scala | 88 +++++++------- .../scommons/client/ui/ButtonsPanelSpec.scala | 20 ++-- .../client/ui/ImageLabelWrapperSpec.scala | 23 ++-- .../client/ui/list/PickListSpec.scala | 113 ++++++++---------- .../client/ui/popup/ErrorPopupSpec.scala | 79 ++++++------ .../client/ui/popup/InputPopupSpec.scala | 94 +++++++-------- .../client/ui/popup/LoadingPopupSpec.scala | 19 +-- .../client/ui/popup/ModalBodySpec.scala | 7 +- .../client/ui/popup/ModalFooterSpec.scala | 9 +- .../scommons/client/ui/popup/ModalSpec.scala | 39 +++--- .../client/ui/popup/OkPopupSpec.scala | 37 +++--- .../client/ui/popup/SaveCancelPopupSpec.scala | 65 +++++----- .../client/ui/popup/StatusPopupSpec.scala | 24 ++-- .../ui/popup/YesNoCancelPopupSpec.scala | 49 ++++---- .../client/ui/popup/YesNoPopupSpec.scala | 41 +++---- .../client/ui/select/SearchSelectSpec.scala | 74 ++++++------ 35 files changed, 504 insertions(+), 477 deletions(-) diff --git a/project/src/main/scala/common/Libs.scala b/project/src/main/scala/common/Libs.scala index 32eb3d7..a32170e 100644 --- a/project/src/main/scala/common/Libs.scala +++ b/project/src/main/scala/common/Libs.scala @@ -7,7 +7,7 @@ import scommons.sbtplugin.project.CommonLibs object Libs extends CommonLibs { val scommonsNodejsVersion = "0.5.0" - val scommonsReactVersion = "0.5.0" + val scommonsReactVersion = "1.0.0-SNAPSHOT" private val scommonsApiVersion = "0.5.0" private val sjsReactJsVer = "0.15.0" diff --git a/showcase/src/main/scala/scommons/client/showcase/table/TablePanelDemo.scala b/showcase/src/main/scala/scommons/client/showcase/table/TablePanelDemo.scala index 541aa96..6f8cea5 100644 --- a/showcase/src/main/scala/scommons/client/showcase/table/TablePanelDemo.scala +++ b/showcase/src/main/scala/scommons/client/showcase/table/TablePanelDemo.scala @@ -4,16 +4,19 @@ import scommons.react._ object TablePanelDemo extends FunctionComponent[Unit] { + private[table] var simpleTablePanel: UiComponent[Unit] = SimpleTablePanel + private[table] var customTablePanel: UiComponent[Unit] = CustomTablePanel + protected def render(props: Props): ReactElement = { <.>()( <.h2()("TablePanel"), <.p()("Demonstrates table functionality"), <.h3()("Simple TablePanel"), - <(SimpleTablePanel()).empty, + <(simpleTablePanel()).empty, <.h3()("TablePanel with custom cell renderer"), - <(CustomTablePanel()).empty + <(customTablePanel()).empty ) } } diff --git a/showcase/src/test/scala/scommons/client/showcase/table/CustomTablePanelSpec.scala b/showcase/src/test/scala/scommons/client/showcase/table/CustomTablePanelSpec.scala index 6eef004..14003e7 100644 --- a/showcase/src/test/scala/scommons/client/showcase/table/CustomTablePanelSpec.scala +++ b/showcase/src/test/scala/scommons/client/showcase/table/CustomTablePanelSpec.scala @@ -3,23 +3,21 @@ package scommons.client.showcase.table import scommons.client.showcase.table.CustomTablePanel._ import scommons.client.ui.table.TablePanelCss._ import scommons.client.ui.table._ -import scommons.react.test.TestSpec -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ -class CustomTablePanelSpec extends TestSpec with ShallowRendererUtils { +class CustomTablePanelSpec extends TestSpec with TestRendererUtils { it should "select row when onSelect" in { //given - val renderer = createRenderer() - renderer.render(<(CustomTablePanel())()()) - val tableProps = findComponentProps(renderer.getRenderOutput(), tableComp) + val renderer = createTestRenderer(<(CustomTablePanel())()()) + val tableProps = findComponentProps(renderer.root, tableComp) tableProps.selectedIds shouldBe Set.empty //when tableProps.onSelect(tableProps.rows(1)) //then - val updatedProps = findComponentProps(renderer.getRenderOutput(), tableComp) + val updatedProps = findComponentProps(renderer.root, tableComp) updatedProps.selectedIds shouldBe Set(2) } @@ -28,10 +26,10 @@ class CustomTablePanelSpec extends TestSpec with ShallowRendererUtils { val component = <(CustomTablePanel())()() //when - val result = shallowRender(component) + val result = testRender(component) //then - assertComponent(result, tableComp) { + assertTestComponent(result, tableComp) { case TablePanelProps(header, rows, keyExtractor, rowClassExtractor, cellRenderer, selectedIds, _) => header shouldBe List( TableColumnData("Id"), diff --git a/showcase/src/test/scala/scommons/client/showcase/table/SimpleTablePanelSpec.scala b/showcase/src/test/scala/scommons/client/showcase/table/SimpleTablePanelSpec.scala index bf9555d..0c79ec2 100644 --- a/showcase/src/test/scala/scommons/client/showcase/table/SimpleTablePanelSpec.scala +++ b/showcase/src/test/scala/scommons/client/showcase/table/SimpleTablePanelSpec.scala @@ -1,23 +1,21 @@ package scommons.client.showcase.table import scommons.client.ui.table._ -import scommons.react.test.TestSpec -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ -class SimpleTablePanelSpec extends TestSpec with ShallowRendererUtils { +class SimpleTablePanelSpec extends TestSpec with TestRendererUtils { it should "select row when onSelect" in { //given - val renderer = createRenderer() - renderer.render(<(SimpleTablePanel())()()) - val tableProps = findComponentProps(renderer.getRenderOutput(), TablePanel) + val renderer = createTestRenderer(<(SimpleTablePanel())()()) + val tableProps = findComponentProps(renderer.root, TablePanel) tableProps.selectedIds shouldBe Set.empty //when tableProps.onSelect(tableProps.rows(1)) //then - val updatedProps = findComponentProps(renderer.getRenderOutput(), TablePanel) + val updatedProps = findComponentProps(renderer.root, TablePanel) updatedProps.selectedIds shouldBe Set("2") } @@ -26,10 +24,10 @@ class SimpleTablePanelSpec extends TestSpec with ShallowRendererUtils { val component = <(SimpleTablePanel())()() //when - val result = shallowRender(component) + val result = testRender(component) //then - assertComponent(result, TablePanel) { + assertTestComponent(result, TablePanel) { case TablePanelProps(header, rows, keyExtractor, rowClassExtractor, cellRenderer, selectedIds, _) => header shouldBe List( TableColumnData("Id"), diff --git a/showcase/src/test/scala/scommons/client/showcase/table/TablePanelDemoSpec.scala b/showcase/src/test/scala/scommons/client/showcase/table/TablePanelDemoSpec.scala index 265ca4d..75104ab 100644 --- a/showcase/src/test/scala/scommons/client/showcase/table/TablePanelDemoSpec.scala +++ b/showcase/src/test/scala/scommons/client/showcase/table/TablePanelDemoSpec.scala @@ -1,30 +1,30 @@ package scommons.client.showcase.table +import scommons.client.showcase.table.TablePanelDemo._ import scommons.react._ -import scommons.react.test.TestSpec -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ -class TablePanelDemoSpec extends TestSpec with ShallowRendererUtils { +class TablePanelDemoSpec extends TestSpec with TestRendererUtils { + + TablePanelDemo.simpleTablePanel = () => "SimpleTablePanel".asInstanceOf[ReactClass] + TablePanelDemo.customTablePanel = () => "CustomTablePanel".asInstanceOf[ReactClass] it should "render component" in { //given val component = <(TablePanelDemo())()() //when - val result = shallowRender(component) + val result = createTestRenderer(component).root //then - assertNativeComponent(result, - <.>()( - <.h2()("TablePanel"), - <.p()("Demonstrates table functionality"), - - <.h3()("Simple TablePanel"), - <(SimpleTablePanel()).empty, - - <.h3()("TablePanel with custom cell renderer"), - <(CustomTablePanel()).empty - ) - ) + inside(result.children.toList) { + case List(header1, p, header2, simpleTable, header3, customTable) => + assertNativeComponent(header1, <.h2()("TablePanel")) + assertNativeComponent(p, <.p()("Demonstrates table functionality")) + assertNativeComponent(header2, <.h3()("Simple TablePanel")) + assertNativeComponent(simpleTable, <(simpleTablePanel()).empty) + assertNativeComponent(header3, <.h3()("TablePanel with custom cell renderer")) + assertNativeComponent(customTable, <(customTablePanel()).empty) + } } } diff --git a/ui/src/main/scala/scommons/client/app/AppMainPanel.scala b/ui/src/main/scala/scommons/client/app/AppMainPanel.scala index a6f308e..dbc0eae 100644 --- a/ui/src/main/scala/scommons/client/app/AppMainPanel.scala +++ b/ui/src/main/scala/scommons/client/app/AppMainPanel.scala @@ -9,15 +9,18 @@ case class AppMainPanelProps(name: String = "App", object AppMainPanel extends FunctionComponent[AppMainPanelProps] { + private[app] var appHeaderComp: UiComponent[AppHeaderProps] = AppHeader + private[app] var appFooterComp: UiComponent[AppFooterProps] = AppFooter + protected def render(compProps: Props): ReactElement = { val props = compProps.wrapped <.>()( - <(AppHeader())(^.wrapped := AppHeaderProps(props.name, props.user))(), + <(appHeaderComp())(^.wrapped := AppHeaderProps(props.name, props.user))(), <.div(^.className := "container-fluid")( compProps.children ), - <(AppFooter())(^.wrapped := AppFooterProps(props.copyright, props.version))() + <(appFooterComp())(^.wrapped := AppFooterProps(props.copyright, props.version))() ) } } diff --git a/ui/src/main/scala/scommons/client/app/AppTaskManagerUi.scala b/ui/src/main/scala/scommons/client/app/AppTaskManagerUi.scala index 04979f0..cdd45fb 100644 --- a/ui/src/main/scala/scommons/client/app/AppTaskManagerUi.scala +++ b/ui/src/main/scala/scommons/client/app/AppTaskManagerUi.scala @@ -21,6 +21,10 @@ object AppTaskManagerUi extends FunctionComponent[TaskManagerUiProps] { } } + private[app] var statusPopup: UiComponent[StatusPopupProps] = StatusPopup + private[app] var loadingPopup: UiComponent[Unit] = LoadingPopup + private[app] var errorPopup: UiComponent[ErrorPopupProps] = ErrorPopup + protected def render(compProps: Props): ReactElement = { val props = compProps.wrapped val showStatus = props.status.isDefined @@ -30,18 +34,18 @@ object AppTaskManagerUi extends FunctionComponent[TaskManagerUiProps] { <.>()( if (showStatus) Some( - <(StatusPopup())(^.wrapped := StatusPopupProps( + <(statusPopup())(^.wrapped := StatusPopupProps( statusMessage, onHide = props.onHideStatus ))() ) else None, if (props.showLoading) Some( - <(LoadingPopup())()() + <(loadingPopup())()() ) else None, if (showError) Some( - <(ErrorPopup())(^.wrapped := ErrorPopupProps( + <(errorPopup())(^.wrapped := ErrorPopupProps( errorMessage, details = props.errorDetails, onClose = props.onCloseErrorPopup diff --git a/ui/src/main/scala/scommons/client/ui/popup/ErrorPopup.scala b/ui/src/main/scala/scommons/client/ui/popup/ErrorPopup.scala index c8f00c0..1619083 100644 --- a/ui/src/main/scala/scommons/client/ui/popup/ErrorPopup.scala +++ b/ui/src/main/scala/scommons/client/ui/popup/ErrorPopup.scala @@ -15,6 +15,9 @@ object ErrorPopup extends FunctionComponent[ErrorPopupProps] { private case class ErrorPopupState(showDetails: Boolean = false, opened: Boolean = false) + private[popup] var modalComp: UiComponent[ModalProps] = Modal + private[popup] var htmlComp: UiComponent[HTMLProps] = HTML + protected def render(compProps: Props): ReactElement = { val (state, setState) = useStateUpdater(() => ErrorPopupState()) @@ -25,7 +28,7 @@ object ErrorPopup extends FunctionComponent[ErrorPopupProps] { ) val closeBtn = SimpleButtonData("close", "Close", primary = true) - <(Modal())(^.wrapped := ModalProps( + <(modalComp())(^.wrapped := ModalProps( header = None, buttons = if (props.details.isDefined) List(detailsBtn, closeBtn) else List(closeBtn), actions = ActionsData(Set(detailsBtn.command, closeBtn.command), _ => { @@ -42,7 +45,7 @@ object ErrorPopup extends FunctionComponent[ErrorPopupProps] { ))( <.div(^.className := "row-fluid")( <.img(^.className := IconCss.dialogError, ^.src := UiSettings.imgClearCacheUrl)(), - <(HTML())(^.wrapped := HTMLProps( + <(htmlComp())(^.wrapped := HTMLProps( if (state.showDetails) getFullText(props) else props.error , diff --git a/ui/src/main/scala/scommons/client/ui/popup/InputPopup.scala b/ui/src/main/scala/scommons/client/ui/popup/InputPopup.scala index f56491a..87f4803 100644 --- a/ui/src/main/scala/scommons/client/ui/popup/InputPopup.scala +++ b/ui/src/main/scala/scommons/client/ui/popup/InputPopup.scala @@ -17,6 +17,9 @@ object InputPopup extends FunctionComponent[InputPopupProps] { actionCommands: Set[String], opened: Boolean = false) + private[popup] var modalComp: UiComponent[ModalProps] = Modal + private[popup] var textFieldComp: UiComponent[TextFieldProps] = TextField + protected def render(compProps: Props): ReactElement = { val props = compProps.wrapped val (state, setState) = useStateUpdater { () => @@ -25,7 +28,7 @@ object InputPopup extends FunctionComponent[InputPopupProps] { val onOk = () => props.onOk(state.value) - <(Modal())(^.wrapped := ModalProps( + <(modalComp())(^.wrapped := ModalProps( header = None, buttons = List(Buttons.OK, Buttons.CANCEL), actions = ActionsData(state.actionCommands, _ => { @@ -40,7 +43,7 @@ object InputPopup extends FunctionComponent[InputPopupProps] { <.div(^.className := "row-fluid")( <.p()(props.message), <.div(^.className := "control-group")( - <(TextField())(^.wrapped := TextFieldProps( + <(textFieldComp())(^.wrapped := TextFieldProps( state.value, onChange = { value => setState(_.copy(value = value, actionCommands = getActionCommands(value))) diff --git a/ui/src/main/scala/scommons/client/ui/popup/LoadingPopup.scala b/ui/src/main/scala/scommons/client/ui/popup/LoadingPopup.scala index 29db733..7d6892b 100644 --- a/ui/src/main/scala/scommons/client/ui/popup/LoadingPopup.scala +++ b/ui/src/main/scala/scommons/client/ui/popup/LoadingPopup.scala @@ -5,8 +5,10 @@ import scommons.react._ object LoadingPopup extends FunctionComponent[Unit] { + private[popup] var popupComp: UiComponent[PopupProps] = Popup + protected def render(compProps: Props): ReactElement = { - <(Popup())(^.wrapped := PopupProps( + <(popupComp())(^.wrapped := PopupProps( onClose = () => (), closable = false, focusable = false, diff --git a/ui/src/main/scala/scommons/client/ui/popup/Modal.scala b/ui/src/main/scala/scommons/client/ui/popup/Modal.scala index d8da0fe..9d795f4 100644 --- a/ui/src/main/scala/scommons/client/ui/popup/Modal.scala +++ b/ui/src/main/scala/scommons/client/ui/popup/Modal.scala @@ -15,21 +15,26 @@ case class ModalProps(header: Option[String], object Modal extends FunctionComponent[ModalProps] { + private[popup] var popupComp: UiComponent[PopupProps] = Popup + private[popup] var modalHeaderComp: UiComponent[ModalHeaderProps] = ModalHeader + private[popup] var modalBodyComp: UiComponent[Unit] = ModalBody + private[popup] var modalFooterComp: UiComponent[ModalFooterProps] = ModalFooter + protected def render(compProps: Props): ReactElement = { val props = compProps.wrapped - <(Popup())(^.wrapped := PopupProps( + <(popupComp())(^.wrapped := PopupProps( onClose = props.onClose, closable = props.closable, onOpen = props.onOpen ))( props.header.map { header => - <(ModalHeader())(^.wrapped := ModalHeaderProps(header, props.onClose, closable = props.closable))() + <(modalHeaderComp())(^.wrapped := ModalHeaderProps(header, props.onClose, closable = props.closable))() }, - <(ModalBody())()( + <(modalBodyComp())()( compProps.children ), - <(ModalFooter())(^.wrapped := ModalFooterProps(props.buttons, props.actions, props.dispatch))() + <(modalFooterComp())(^.wrapped := ModalFooterProps(props.buttons, props.actions, props.dispatch))() ) } } diff --git a/ui/src/main/scala/scommons/client/ui/popup/OkPopup.scala b/ui/src/main/scala/scommons/client/ui/popup/OkPopup.scala index c3e2ee3..ddb59b0 100644 --- a/ui/src/main/scala/scommons/client/ui/popup/OkPopup.scala +++ b/ui/src/main/scala/scommons/client/ui/popup/OkPopup.scala @@ -13,12 +13,14 @@ object OkPopup extends FunctionComponent[OkPopupProps] { private case class OkPopupState(opened: Boolean = false) + private[popup] var modalComp: UiComponent[ModalProps] = Modal + protected def render(compProps: Props): ReactElement = { val (state, setState) = useStateUpdater(() => OkPopupState()) val props = compProps.wrapped - <(Modal())(^.wrapped := ModalProps( + <(modalComp())(^.wrapped := ModalProps( header = None, buttons = List(Buttons.OK), actions = ActionsData(Set(Buttons.OK.command), _ => { diff --git a/ui/src/main/scala/scommons/client/ui/popup/SaveCancelPopup.scala b/ui/src/main/scala/scommons/client/ui/popup/SaveCancelPopup.scala index 2dbd70a..6979802 100644 --- a/ui/src/main/scala/scommons/client/ui/popup/SaveCancelPopup.scala +++ b/ui/src/main/scala/scommons/client/ui/popup/SaveCancelPopup.scala @@ -29,6 +29,8 @@ private object SaveCancelPopup extends FunctionComponent[SaveCancelPopupProps] { private case class SaveCancelPopupState(data: Any, opened: Boolean = false) + private[popup] var modalComp: UiComponent[ModalProps] = Modal + protected def render(compProps: Props): ReactElement = { val props = compProps.wrapped val (state, setState) = useStateUpdater(() => SaveCancelPopupState(props.initialData)) @@ -46,7 +48,7 @@ private object SaveCancelPopup extends FunctionComponent[SaveCancelPopupProps] { val data = state.data.asInstanceOf[props.DataType] val actionCommands = if (props.isSaveEnabled(data)) enabledActions else disabledActions - <(Modal())(^.wrapped := ModalProps( + <(modalComp())(^.wrapped := ModalProps( header = Some(props.title), buttons = List(Buttons.SAVE.copy( image = ButtonImagesCss.dbSave, diff --git a/ui/src/main/scala/scommons/client/ui/popup/StatusPopup.scala b/ui/src/main/scala/scommons/client/ui/popup/StatusPopup.scala index e1769ed..66be5cd 100644 --- a/ui/src/main/scala/scommons/client/ui/popup/StatusPopup.scala +++ b/ui/src/main/scala/scommons/client/ui/popup/StatusPopup.scala @@ -7,16 +7,19 @@ case class StatusPopupProps(text: String, object StatusPopup extends FunctionComponent[StatusPopupProps] { + private[popup] var popupComp: UiComponent[PopupProps] = Popup + private[popup] var withAutoHideComp: UiComponent[WithAutoHideProps] = WithAutoHide + protected def render(compProps: Props): ReactElement = { val props = compProps.wrapped - <(Popup())(^.wrapped := PopupProps( + <(popupComp())(^.wrapped := PopupProps( onClose = () => (), focusable = false, overlayClass = "scommons-modal-no-overlay", popupClass = PopupCss.statusContent ))( - <(WithAutoHide())(^.wrapped := WithAutoHideProps(props.onHide))(props.text) + <(withAutoHideComp())(^.wrapped := WithAutoHideProps(props.onHide))(props.text) ) } } diff --git a/ui/src/main/scala/scommons/client/ui/popup/YesNoCancelPopup.scala b/ui/src/main/scala/scommons/client/ui/popup/YesNoCancelPopup.scala index 3996e11..ae2cb19 100644 --- a/ui/src/main/scala/scommons/client/ui/popup/YesNoCancelPopup.scala +++ b/ui/src/main/scala/scommons/client/ui/popup/YesNoCancelPopup.scala @@ -13,12 +13,14 @@ case class YesNoCancelPopupProps(message: String, object YesNoCancelPopup extends FunctionComponent[YesNoCancelPopupProps] { + private[popup] var modalComp: UiComponent[ModalProps] = Modal + protected def render(compProps: Props): ReactElement = { val (opened, setOpened) = useState(false) val props = compProps.wrapped - <(Modal())(^.wrapped := ModalProps( + <(modalComp())(^.wrapped := ModalProps( header = None, buttons = List( SimpleButtonData(Yes.command, "Yes", props.selected == Yes), diff --git a/ui/src/main/scala/scommons/client/ui/popup/YesNoPopup.scala b/ui/src/main/scala/scommons/client/ui/popup/YesNoPopup.scala index baf3a12..df658fd 100644 --- a/ui/src/main/scala/scommons/client/ui/popup/YesNoPopup.scala +++ b/ui/src/main/scala/scommons/client/ui/popup/YesNoPopup.scala @@ -13,12 +13,14 @@ case class YesNoPopupProps(message: String, object YesNoPopup extends FunctionComponent[YesNoPopupProps] { + private[popup] var modalComp: UiComponent[ModalProps] = Modal + protected def render(compProps: Props): ReactElement = { val (opened, setOpened) = useState(false) val props = compProps.wrapped - <(Modal())(^.wrapped := ModalProps( + <(modalComp())(^.wrapped := ModalProps( header = None, buttons = List( SimpleButtonData(Yes.command, "Yes", props.selected == Yes), diff --git a/ui/src/main/scala/scommons/client/ui/select/SearchSelect.scala b/ui/src/main/scala/scommons/client/ui/select/SearchSelect.scala index 0139474..2e9f3b8 100644 --- a/ui/src/main/scala/scommons/client/ui/select/SearchSelect.scala +++ b/ui/src/main/scala/scommons/client/ui/select/SearchSelect.scala @@ -18,6 +18,7 @@ case class SearchSelectProps(selected: Option[SelectData], object SearchSelect extends ClassComponent[SearchSelectProps] { private[select] var global: js.Dynamic = window.asInstanceOf[js.Dynamic] + private[select] var singleSelectComp: UiComponent[SingleSelectProps] = SingleSelect private case class SearchSelectState(isLoading: Boolean = false, value: String = "", @@ -31,7 +32,7 @@ object SearchSelect extends ClassComponent[SearchSelectProps] { render = { self => val props = self.props.wrapped - <(SingleSelect())(^.wrapped := SingleSelectProps( + <(singleSelectComp())(^.wrapped := SingleSelectProps( selected = props.selected, options = self.state.options, onSelectChange = props.onChange, diff --git a/ui/src/test/scala/scommons/client/app/AppBrowsePanelSpec.scala b/ui/src/test/scala/scommons/client/app/AppBrowsePanelSpec.scala index a6d3a23..235d420 100644 --- a/ui/src/test/scala/scommons/client/app/AppBrowsePanelSpec.scala +++ b/ui/src/test/scala/scommons/client/app/AppBrowsePanelSpec.scala @@ -3,10 +3,9 @@ package scommons.client.app import scommons.client.ui.tree._ import scommons.client.ui.{Buttons, ButtonsPanel, ButtonsPanelProps} import scommons.client.util.{ActionsData, BrowsePath} -import scommons.react.test.TestSpec -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ -class AppBrowsePanelSpec extends TestSpec with ShallowRendererUtils { +class AppBrowsePanelSpec extends TestSpec with TestRendererUtils { it should "render the component" in { //given @@ -24,18 +23,18 @@ class AppBrowsePanelSpec extends TestSpec with ShallowRendererUtils { ) //when - val result = shallowRender(component) + val result = testRender(component) //then assertNativeComponent(result, <.div(^.className := "row-fluid")(), { case List(span4, span8) => assertNativeComponent(span4, <.div(^.className := "span4")(), { case List(sidebar) => assertNativeComponent(sidebar, <.div(^.className := "well sidebar-nav")(), { case List(sidebarBp, tree) => assertNativeComponent(sidebarBp, <.div(^.className := AppBrowsePanelCss.sidebarBp)(), { case List(bp) => - assertComponent(bp, ButtonsPanel) { bpProps => + assertTestComponent(bp, ButtonsPanel) { bpProps => bpProps shouldBe buttonsPanelProps } }) - assertComponent(tree, BrowseTree) { treeProps => + assertTestComponent(tree, BrowseTree) { treeProps => treeProps shouldBe browseTreeProps } }) diff --git a/ui/src/test/scala/scommons/client/app/AppMainPanelSpec.scala b/ui/src/test/scala/scommons/client/app/AppMainPanelSpec.scala index b5639c5..b675fec 100644 --- a/ui/src/test/scala/scommons/client/app/AppMainPanelSpec.scala +++ b/ui/src/test/scala/scommons/client/app/AppMainPanelSpec.scala @@ -1,10 +1,13 @@ package scommons.client.app +import scommons.client.app.AppMainPanel._ import scommons.react._ -import scommons.react.test.TestSpec -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ -class AppMainPanelSpec extends TestSpec with ShallowRendererUtils { +class AppMainPanelSpec extends TestSpec with TestRendererUtils { + + AppMainPanel.appHeaderComp = () => "AppHeader".asInstanceOf[ReactClass] + AppMainPanel.appFooterComp = () => "AppFooter".asInstanceOf[ReactClass] it should "render the component" in { //given @@ -16,25 +19,26 @@ class AppMainPanelSpec extends TestSpec with ShallowRendererUtils { ) //when - val result = shallowRender(<(AppMainPanel())(^.wrapped := props)( + val result = createTestRenderer(<(AppMainPanel())(^.wrapped := props)( <.div()("Some child element 1"), <.div()("Some child element 2") - )) + )).root //then - assertNativeComponent(result, <.>()(), { case List(header, cont, footer) => - assertComponent(header, AppHeader) { case AppHeaderProps(name, user) => - name shouldBe props.name - user shouldBe props.user - } - assertNativeComponent(cont, <.div(^.className := "container-fluid")( - <.div()("Some child element 1"), - <.div()("Some child element 2") - )) - assertComponent(footer, AppFooter) { case AppFooterProps(copyright, version) => - copyright shouldBe props.copyright - version shouldBe props.version - } - }) + inside(result.children.toList) { + case List(header, cont, footer) => + assertTestComponent(header, appHeaderComp) { case AppHeaderProps(name, user) => + name shouldBe props.name + user shouldBe props.user + } + assertNativeComponent(cont, <.div(^.className := "container-fluid")( + <.div()("Some child element 1"), + <.div()("Some child element 2") + )) + assertTestComponent(footer, appFooterComp) { case AppFooterProps(copyright, version) => + copyright shouldBe props.copyright + version shouldBe props.version + } + } } } diff --git a/ui/src/test/scala/scommons/client/app/AppTaskManagerUiSpec.scala b/ui/src/test/scala/scommons/client/app/AppTaskManagerUiSpec.scala index 610d728..68b58be 100644 --- a/ui/src/test/scala/scommons/client/app/AppTaskManagerUiSpec.scala +++ b/ui/src/test/scala/scommons/client/app/AppTaskManagerUiSpec.scala @@ -2,16 +2,19 @@ package scommons.client.app 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.TestSpec -import scommons.react.test.raw.ShallowInstance -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ import scala.util.Success -class AppTaskManagerUiSpec extends TestSpec with ShallowRendererUtils { +class AppTaskManagerUiSpec extends TestSpec with TestRendererUtils { + + AppTaskManagerUi.statusPopup = () => "StatusPopup".asInstanceOf[ReactClass] + AppTaskManagerUi.loadingPopup = () => "LoadingPopup".asInstanceOf[ReactClass] + AppTaskManagerUi.errorPopup = () => "ErrorPopup".asInstanceOf[ReactClass] it should "return error if unsuccessful response in errorHandler" in { //given @@ -46,8 +49,8 @@ class AppTaskManagerUiSpec extends TestSpec with ShallowRendererUtils { status = Some("Fetching data"), onHideStatus = onHideStatus ) - val comp = shallowRender(<(AppTaskManagerUi())(^.wrapped := props)()) - val statusProps = findComponentProps(comp, StatusPopup) + val comp = createTestRenderer(<(AppTaskManagerUi())(^.wrapped := props)()).root + val statusProps = findComponentProps(comp, statusPopup) //then onHideStatus.expects() @@ -63,8 +66,8 @@ class AppTaskManagerUiSpec extends TestSpec with ShallowRendererUtils { error = Some("Some error"), onCloseErrorPopup = onCloseErrorPopup ) - val comp = shallowRender(<(AppTaskManagerUi())(^.wrapped := props)()) - val errorProps = findComponentProps(comp, ErrorPopup) + val comp = createTestRenderer(<(AppTaskManagerUi())(^.wrapped := props)()).root + val errorProps = findComponentProps(comp, errorPopup) //then onCloseErrorPopup.expects() @@ -82,7 +85,7 @@ class AppTaskManagerUiSpec extends TestSpec with ShallowRendererUtils { val component = <(AppTaskManagerUi())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = createTestRenderer(component).root //then assertRenderingResult(result, props) @@ -96,7 +99,7 @@ class AppTaskManagerUiSpec extends TestSpec with ShallowRendererUtils { val component = <(AppTaskManagerUi())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = createTestRenderer(component).root //then assertRenderingResult(result, props) @@ -111,7 +114,7 @@ class AppTaskManagerUiSpec extends TestSpec with ShallowRendererUtils { val component = <(AppTaskManagerUi())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = createTestRenderer(component).root //then assertRenderingResult(result, props) @@ -126,7 +129,7 @@ class AppTaskManagerUiSpec extends TestSpec with ShallowRendererUtils { val component = <(AppTaskManagerUi())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = createTestRenderer(component).root //then assertRenderingResult(result, props) @@ -149,42 +152,39 @@ class AppTaskManagerUiSpec extends TestSpec with ShallowRendererUtils { ) } - private def assertRenderingResult(result: ShallowInstance, props: TaskManagerUiProps): Unit = { + private def assertRenderingResult(result: TestInstance, props: TaskManagerUiProps): Unit = { val showStatus = props.status.isDefined val showError = props.error.isDefined - assertNativeComponent(result, <.>()(), { children => - val (statusPopup, loadingPopup, errorPopup) = children match { - case List(sp) if showStatus => (Some(sp), None, None) - case List(lp) if props.showLoading => (None, Some(lp), None) - case List(sp, lp) if showStatus && props.showLoading => (Some(sp), Some(lp), None) - case List(sp, ep) if showStatus && showError => (Some(sp), None, Some(ep)) - case List(ep) if showError => (None, None, Some(ep)) - } - - if (showStatus) { - statusPopup should not be None - assertComponent(statusPopup.get, StatusPopup) { case StatusPopupProps(text, onHide) => - text shouldBe props.status.getOrElse("") - onHide shouldBe props.onHideStatus - } + val children = result.children.toList + val (resStatusPopup, resLoadingPopup, resErrorPopup) = inside(children) { + case List(sp) if showStatus => (Some(sp), None, None) + case List(lp) if props.showLoading => (None, Some(lp), None) + case List(sp, lp) if showStatus && props.showLoading => (Some(sp), Some(lp), None) + case List(sp, ep) if showStatus && showError => (Some(sp), None, Some(ep)) + case List(ep) if showError => (None, None, Some(ep)) + } + + if (showStatus) { + resStatusPopup should not be None + assertTestComponent(resStatusPopup.get, statusPopup) { case StatusPopupProps(text, onHide) => + text shouldBe props.status.getOrElse("") + onHide shouldBe props.onHideStatus } - - if (props.showLoading) { - loadingPopup should not be None - assertComponent(loadingPopup.get, LoadingPopup)(_ => Succeeded) - } - - if (showError) { - errorPopup should not be None - assertComponent(errorPopup.get, ErrorPopup) { case ErrorPopupProps(error, onClose, details) => - error shouldBe props.error.getOrElse("") - details shouldBe props.errorDetails - onClose shouldBe props.onCloseErrorPopup - } + } + + if (props.showLoading) { + resLoadingPopup should not be None + assertTestComponent(resLoadingPopup.get, loadingPopup)(_ => Succeeded) + } + + if (showError) { + resErrorPopup should not be None + assertTestComponent(resErrorPopup.get, errorPopup) { case ErrorPopupProps(error, onClose, details) => + error shouldBe props.error.getOrElse("") + details shouldBe props.errorDetails + onClose shouldBe props.onCloseErrorPopup } - - Succeeded - }) + } } } diff --git a/ui/src/test/scala/scommons/client/ui/ButtonsPanelSpec.scala b/ui/src/test/scala/scommons/client/ui/ButtonsPanelSpec.scala index ee4953b..cc9a568 100644 --- a/ui/src/test/scala/scommons/client/ui/ButtonsPanelSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/ButtonsPanelSpec.scala @@ -2,11 +2,9 @@ package scommons.client.ui import scommons.client.ui.ButtonImagesCss._ import scommons.client.util.ActionsData -import scommons.react.test.TestSpec -import scommons.react.test.raw.ShallowInstance -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ -class ButtonsPanelSpec extends TestSpec with ShallowRendererUtils { +class ButtonsPanelSpec extends TestSpec with TestRendererUtils { it should "call onCommand when click on button" in { //given @@ -21,7 +19,7 @@ class ButtonsPanelSpec extends TestSpec with ShallowRendererUtils { SimpleButtonData("accept", "test button 1"), ImageButtonData("add", add, addDisabled, "test button 2") ) - val comp = shallowRender(<(ButtonsPanel())(^.wrapped := ButtonsPanelProps( + val comp = testRender(<(ButtonsPanel())(^.wrapped := ButtonsPanelProps( buttons, ActionsData(buttons.map(_.command).toSet, onCommand), dispatch ))()) val btn1 = findComponentProps(comp, SimpleButton) @@ -49,7 +47,7 @@ class ButtonsPanelSpec extends TestSpec with ShallowRendererUtils { ) //when - val result = shallowRender(<(ButtonsPanel())(^.wrapped := props)()) + val result = testRender(<(ButtonsPanel())(^.wrapped := props)()) //then assertButtonsPanel(result, props.className.get, group = false, b1, b2) @@ -65,7 +63,7 @@ class ButtonsPanelSpec extends TestSpec with ShallowRendererUtils { ) //when - val result = shallowRender(<(ButtonsPanel())(^.wrapped := props)()) + val result = testRender(<(ButtonsPanel())(^.wrapped := props)()) //then assertButtonsPanel(result, "btn-toolbar", group = false, b1, b2) @@ -82,26 +80,26 @@ class ButtonsPanelSpec extends TestSpec with ShallowRendererUtils { ) //when - val result = shallowRender(<(ButtonsPanel())(^.wrapped := props)()) + val result = testRender(<(ButtonsPanel())(^.wrapped := props)()) //then assertButtonsPanel(result, "btn-group", group = true, b1, b2) } - private def assertButtonsPanel(result: ShallowInstance, + private def assertButtonsPanel(result: TestInstance, className: String, group: Boolean, b1: SimpleButtonData, b2: ImageButtonData): Unit = { assertNativeComponent(result, <.div(^.className := className)(), { case List(simpleBtn, imageBtn) => - assertComponent(simpleBtn, SimpleButton) { + assertTestComponent(simpleBtn, SimpleButton) { case SimpleButtonProps(data, _, disabled, requestFocus) => data shouldBe b1 disabled shouldBe false requestFocus shouldBe true } - assertComponent(imageBtn, ImageButton) { + assertTestComponent(imageBtn, ImageButton) { case ImageButtonProps(data, _, disabled, showTextAsTitle, requestFocus) => data shouldBe b2 disabled shouldBe true diff --git a/ui/src/test/scala/scommons/client/ui/ImageLabelWrapperSpec.scala b/ui/src/test/scala/scommons/client/ui/ImageLabelWrapperSpec.scala index 655c5e3..2b686a8 100644 --- a/ui/src/test/scala/scommons/client/ui/ImageLabelWrapperSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/ImageLabelWrapperSpec.scala @@ -1,27 +1,26 @@ package scommons.client.ui import scommons.react._ -import scommons.react.test.TestSpec -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ -class ImageLabelWrapperSpec extends TestSpec with ShallowRendererUtils { +class ImageLabelWrapperSpec extends TestSpec with TestRendererUtils { it should "render only image" in { //given val image = ButtonImagesCss.folder val wrapper = new FunctionComponent[Unit] { protected def render(props: Props): ReactElement = { - <.>()( + <.div()( ImageLabelWrapper(image, None) ) } } //when - val result = shallowRender(<(wrapper()).empty) + val result = testRender(<(wrapper()).empty) //then - assertNativeComponent(result, <.>()( + assertNativeComponent(result, <.div()( <.img(^.className := image, ^.src := "")() )) } @@ -32,17 +31,17 @@ class ImageLabelWrapperSpec extends TestSpec with ShallowRendererUtils { val text = "some text" val wrapper = new FunctionComponent[Unit] { protected def render(props: Props): ReactElement = { - <.>()( + <.div()( ImageLabelWrapper(image, Some(text)) ) } } //when - val result = shallowRender(<(wrapper()).empty) + val result = testRender(<(wrapper()).empty) //then - assertNativeComponent(result, <.>()( + assertNativeComponent(result, <.div()( <.img(^.className := image, ^.src := "")(), <.span(^.style := Map( "paddingLeft" -> "3px", @@ -57,17 +56,17 @@ class ImageLabelWrapperSpec extends TestSpec with ShallowRendererUtils { val text = "some text" val wrapper = new FunctionComponent[Unit] { protected def render(props: Props): ReactElement = { - <.>()( + <.div()( ImageLabelWrapper(image, Some(text), alignText = false) ) } } //when - val result = shallowRender(<(wrapper()).empty) + val result = testRender(<(wrapper()).empty) //then - assertNativeComponent(result, <.>()( + assertNativeComponent(result, <.div()( <.img(^.className := image, ^.src := "")(), <.span(^.style := Map( "paddingLeft" -> "3px" diff --git a/ui/src/test/scala/scommons/client/ui/list/PickListSpec.scala b/ui/src/test/scala/scommons/client/ui/list/PickListSpec.scala index d14a632..eca2979 100644 --- a/ui/src/test/scala/scommons/client/ui/list/PickListSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/list/PickListSpec.scala @@ -1,21 +1,16 @@ package scommons.client.ui.list import scommons.client.ui.ButtonImagesCss -import scommons.react.test.TestSpec -import scommons.react.test.raw.ShallowInstance -import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils} +import scommons.react.test._ -class PickListSpec extends TestSpec - with TestRendererUtils - with ShallowRendererUtils { +class PickListSpec extends TestSpec with TestRendererUtils { it should "call onSelectChange when onAdd" in { //given val onSelectChange = mockFunction[Set[String], Boolean, Unit] val props = PickListProps(List(ListBoxData("1", "Test")), onSelectChange = onSelectChange) - val renderer = createRenderer() - renderer.render(<(PickList())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() + val renderer = createTestRenderer(<(PickList())(^.wrapped := props)()) + val comp = renderer.root val lists = findProps(comp, ListBox) lists.size shouldBe 2 val srcList = lists.head @@ -26,12 +21,12 @@ class PickListSpec extends TestSpec //when & then srcList.onSelect(ids) - val compV2 = renderer.getRenderOutput() + val compV2 = renderer.root assertPickList(compV2, props, selectedSourceIds = ids, addEnabled = true) //when & then findComponentProps(compV2, PickButtons).onAdd() - val compV3 = renderer.getRenderOutput() + val compV3 = renderer.root assertPickList(compV3, props.copy(selectedIds = ids), addAllEnabled = false, removeAllEnabled = true) } @@ -39,9 +34,8 @@ class PickListSpec extends TestSpec //given val onSelectChange = mockFunction[Set[String], Boolean, Unit] val props = PickListProps(List(ListBoxData("1", "Test")), selectedIds = Set("1"), onSelectChange = onSelectChange) - val renderer = createRenderer() - renderer.render(<(PickList())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() + val renderer = createTestRenderer(<(PickList())(^.wrapped := props)()) + val comp = renderer.root val lists = findProps(comp, ListBox) lists.size shouldBe 2 val dstList = lists(1) @@ -52,13 +46,13 @@ class PickListSpec extends TestSpec //when & then dstList.onSelect(ids) - val compV2 = renderer.getRenderOutput() + val compV2 = renderer.root assertPickList(compV2, props, selectedDestIds = ids, removeEnabled = true, addAllEnabled = false, removeAllEnabled = true) //when & then findComponentProps(compV2, PickButtons).onRemove() - val compV3 = renderer.getRenderOutput() + val compV3 = renderer.root assertPickList(compV3, props.copy(selectedIds = Set.empty[String])) } @@ -66,9 +60,8 @@ class PickListSpec extends TestSpec //given val onSelectChange = mockFunction[Set[String], Boolean, Unit] val props = PickListProps(List(ListBoxData("1", "Test")), onSelectChange = onSelectChange) - val renderer = createRenderer() - renderer.render(<(PickList())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() + val renderer = createTestRenderer(<(PickList())(^.wrapped := props)()) + val comp = renderer.root val ids = Set("1") //then @@ -78,7 +71,7 @@ class PickListSpec extends TestSpec findComponentProps(comp, PickButtons).onAddAll() //then - val compV2 = renderer.getRenderOutput() + val compV2 = renderer.root assertPickList(compV2, props.copy(selectedIds = ids), addAllEnabled = false, removeAllEnabled = true) } @@ -86,9 +79,8 @@ class PickListSpec extends TestSpec //given val onSelectChange = mockFunction[Set[String], Boolean, Unit] val props = PickListProps(List(ListBoxData("1", "Test")), selectedIds = Set("1"), onSelectChange = onSelectChange) - val renderer = createRenderer() - renderer.render(<(PickList())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() + val renderer = createTestRenderer(<(PickList())(^.wrapped := props)()) + val comp = renderer.root val ids = Set("1") //then @@ -98,7 +90,7 @@ class PickListSpec extends TestSpec findComponentProps(comp, PickButtons).onRemoveAll() //then - val compV2 = renderer.getRenderOutput() + val compV2 = renderer.root assertPickList(compV2, props.copy(selectedIds = Set.empty[String])) } @@ -159,7 +151,7 @@ class PickListSpec extends TestSpec val comp = <(PickList())(^.wrapped := props)() //when - val result = shallowRender(comp) + val result = createTestRenderer(comp).root //then assertPickList(result, props) @@ -171,9 +163,8 @@ class PickListSpec extends TestSpec ListBoxData("1", "Test"), ListBoxData("2", "Test2") ), preSelectedIds = Set("2")) - val renderer = createRenderer() - renderer.render(<(PickList())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() + val renderer = createTestRenderer(<(PickList())(^.wrapped := props)()) + val comp = renderer.root val lists = findProps(comp, ListBox) lists.size shouldBe 2 val dstList = lists(1) @@ -182,7 +173,7 @@ class PickListSpec extends TestSpec dstList.onSelect(Set("2")) //then - assertPickList(renderer.getRenderOutput(), props, + assertPickList(renderer.root, props, selectedDestIds = Set("2") ) } @@ -193,9 +184,8 @@ class PickListSpec extends TestSpec ListBoxData("1", "Test"), ListBoxData("2", "Test2") ), selectedIds = Set("2")) - val renderer = createRenderer() - renderer.render(<(PickList())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() + val renderer = createTestRenderer(<(PickList())(^.wrapped := props)()) + val comp = renderer.root val lists = findProps(comp, ListBox) lists.size shouldBe 2 val srcList = lists.head @@ -206,7 +196,7 @@ class PickListSpec extends TestSpec dstList.onSelect(Set("2")) //then - assertPickList(renderer.getRenderOutput(), props, + assertPickList(renderer.root, props, selectedSourceIds = Set("1"), selectedDestIds = Set("2"), addEnabled = true, @@ -215,7 +205,7 @@ class PickListSpec extends TestSpec ) } - private def assertPickList(result: ShallowInstance, + private def assertPickList(result: TestInstance, props: PickListProps, selectedSourceIds: Set[String] = Set.empty, selectedDestIds: Set[String] = Set.empty, @@ -228,35 +218,34 @@ class PickListSpec extends TestSpec val sourceItems = props.items.filterNot(i => selectedIds.contains(i.id)) val destItems = props.items.filter(i => selectedIds.contains(i.id)) - assertNativeComponent(result, <.div(^.className := "row-fluid")(), { children: List[ShallowInstance] => - val List(src, btns, dst) = children - - assertNativeComponent(src, <.div(^.className := "span5")(), { children: List[ShallowInstance] => - val List(title, hr, list) = children - assertNativeComponent(title, <.strong()(props.sourceTitle)) - assertNativeComponent(hr, <.hr(^.style := Map("margin" -> "7px 0"))()) - assertComponent(list, ListBox) { case ListBoxProps(items, srcSelectedIds, _) => - items shouldBe sourceItems - srcSelectedIds shouldBe selectedSourceIds - } - }) - assertComponent(btns, PickButtons) { - case PickButtonsProps(add, remove, addAll, removeAll, _, _, _, _, className) => - className shouldBe Some("span2") - add shouldBe addEnabled - remove shouldBe removeEnabled - addAll shouldBe addAllEnabled - removeAll shouldBe removeAllEnabled - } - assertNativeComponent(dst, <.div(^.className := "span5")(), { children: List[ShallowInstance] => - val List(title, hr, list) = children - assertNativeComponent(title, <.strong()(props.destTitle)) - assertNativeComponent(hr, <.hr(^.style := Map("margin" -> "7px 0"))()) - assertComponent(list, ListBox) { case ListBoxProps(items, dstSelectedIds, _) => - items shouldBe destItems - dstSelectedIds shouldBe selectedDestIds + assertNativeComponent(result.children(0), <.div(^.className := "row-fluid")(), inside(_) { + case List(src, btns, dst) => + assertNativeComponent(src, <.div(^.className := "span5")(), inside(_) { + case List(title, hr, list) => + assertNativeComponent(title, <.strong()(props.sourceTitle)) + assertNativeComponent(hr, <.hr(^.style := Map("margin" -> "7px 0"))()) + assertTestComponent(list, ListBox) { case ListBoxProps(items, srcSelectedIds, _) => + items shouldBe sourceItems + srcSelectedIds shouldBe selectedSourceIds + } + }) + assertTestComponent(btns, PickButtons) { + case PickButtonsProps(add, remove, addAll, removeAll, _, _, _, _, className) => + className shouldBe Some("span2") + add shouldBe addEnabled + remove shouldBe removeEnabled + addAll shouldBe addAllEnabled + removeAll shouldBe removeAllEnabled } - }) + assertNativeComponent(dst, <.div(^.className := "span5")(), inside(_) { + case List(title, hr, list) => + assertNativeComponent(title, <.strong()(props.destTitle)) + assertNativeComponent(hr, <.hr(^.style := Map("margin" -> "7px 0"))()) + assertTestComponent(list, ListBox) { case ListBoxProps(items, dstSelectedIds, _) => + items shouldBe destItems + dstSelectedIds shouldBe selectedDestIds + } + }) }) } } diff --git a/ui/src/test/scala/scommons/client/ui/popup/ErrorPopupSpec.scala b/ui/src/test/scala/scommons/client/ui/popup/ErrorPopupSpec.scala index 34e132c..67a37a8 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/ErrorPopupSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/ErrorPopupSpec.scala @@ -1,19 +1,22 @@ 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.test.TestSpec -import scommons.react.test.raw.ShallowInstance -import scommons.react.test.util.ShallowRendererUtils +import scommons.react._ +import scommons.react.test._ -class ErrorPopupSpec extends TestSpec with ShallowRendererUtils { +class ErrorPopupSpec extends TestSpec with TestRendererUtils { + + ErrorPopup.modalComp = () => "Modal".asInstanceOf[ReactClass] + ErrorPopup.htmlComp = () => "HTML".asInstanceOf[ReactClass] it should "call onClose function when on close command" in { //given val onClose = mockFunction[Unit] val props = ErrorPopupProps("Some error text", onClose = onClose) - val component = shallowRender(<(ErrorPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(ErrorPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onClose.expects() @@ -25,33 +28,31 @@ class ErrorPopupSpec extends TestSpec with ShallowRendererUtils { it should "show details when on details command" in { //given val props = ErrorPopupProps("Some error text", () => (), details = Some("Error details")) - val renderer = createRenderer() - renderer.render(<(ErrorPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val modalProps = findComponentProps(comp, Modal) + val renderer = createTestRenderer(<(ErrorPopup())(^.wrapped := props)()) + val comp = renderer.root + val modalProps = findComponentProps(comp, modalComp) //when modalProps.actions.onCommand(_ => ())("details") //then - assertErrorPopup(renderer.getRenderOutput(), props, showDetails = true) + assertErrorPopup(renderer.root, props, showDetails = true) } it should "hide details when on details command 2nd time" in { //given val props = ErrorPopupProps("Some error text", () => (), details = Some("Error details")) - val renderer = createRenderer() - renderer.render(<(ErrorPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val modalProps = findComponentProps(comp, Modal) + val renderer = createTestRenderer(<(ErrorPopup())(^.wrapped := props)()) + val comp = renderer.root + val modalProps = findComponentProps(comp, modalComp) modalProps.actions.onCommand(_ => ())("details") - assertErrorPopup(renderer.getRenderOutput(), props, showDetails = true) + assertErrorPopup(renderer.root, props, showDetails = true) //when modalProps.actions.onCommand(_ => ())("details") //then - assertErrorPopup(renderer.getRenderOutput(), props, showDetails = false) + assertErrorPopup(renderer.root, props, showDetails = false) } it should "render component without details" in { @@ -60,7 +61,7 @@ class ErrorPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(ErrorPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = createTestRenderer(component).root //then assertErrorPopup(result, props, showDetails = false) @@ -72,7 +73,7 @@ class ErrorPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(ErrorPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = createTestRenderer(component).root //then assertErrorPopup(result, props, showDetails = false) @@ -81,29 +82,28 @@ class ErrorPopupSpec extends TestSpec with ShallowRendererUtils { it should "set focusedCommand when onOpen" in { //given val props = ErrorPopupProps("Some error text", () => ()) - val renderer = createRenderer() - renderer.render(<(ErrorPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val modalProps = findComponentProps(comp, Modal) + val renderer = createTestRenderer(<(ErrorPopup())(^.wrapped := props)()) + val comp = renderer.root + val modalProps = findComponentProps(comp, modalComp) modalProps.actions.focusedCommand shouldBe None //when modalProps.onOpen() //then - val updatedComp = renderer.getRenderOutput() - val updatedModalProps = findComponentProps(updatedComp, Modal) + val updatedComp = renderer.root + val updatedModalProps = findComponentProps(updatedComp, modalComp) updatedModalProps.actions.focusedCommand shouldBe Some("close") } - private def assertErrorPopup(result: ShallowInstance, props: ErrorPopupProps, showDetails: Boolean): Unit = { + private def assertErrorPopup(result: TestInstance, props: ErrorPopupProps, showDetails: Boolean): Unit = { val detailsButton = SimpleButtonData("details", if (showDetails) "Details <<" else "Details >>") val closeButton = SimpleButtonData("close", "Close", primary = true) val buttonsList = if (props.details.isDefined) List(detailsButton, closeButton) else List(closeButton) - assertComponent(result, Modal)({ + assertTestComponent(result.children(0), modalComp)({ case ModalProps(header, buttons, actions, _, onClose, closable, _) => header shouldBe None buttons shouldBe buttonsList @@ -111,18 +111,19 @@ class ErrorPopupSpec extends TestSpec with ShallowRendererUtils { actions.focusedCommand shouldBe None onClose shouldBe props.onClose closable shouldBe true - }, { case List(modalChild) => - assertNativeComponent(modalChild, <.div(^.className := "row-fluid")(), { case List(img, html) => - assertNativeComponent(img, <.img(^.className := IconCss.dialogError, ^.src := "")()) - assertComponent(html, HTML) { - case HTMLProps(htmlText, wordWrap) => - if (showDetails) - htmlText shouldBe HTML.makeHtmlText(s"${props.error}\n\n${props.details.getOrElse("")}") - else - htmlText shouldBe props.error - - wordWrap shouldBe false - } + }, inside(_) { case List(modalChild) => + assertNativeComponent(modalChild, <.div(^.className := "row-fluid")(), inside(_) { + case List(img, html) => + assertNativeComponent(img, <.img(^.className := IconCss.dialogError, ^.src := "")()) + assertTestComponent(html, htmlComp) { + case HTMLProps(htmlText, wordWrap) => + if (showDetails) + htmlText shouldBe HTML.makeHtmlText(s"${props.error}\n\n${props.details.getOrElse("")}") + else + htmlText shouldBe props.error + + wordWrap shouldBe false + } }) }) } diff --git a/ui/src/test/scala/scommons/client/ui/popup/InputPopupSpec.scala b/ui/src/test/scala/scommons/client/ui/popup/InputPopupSpec.scala index 9c1e1a6..1e708b4 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/InputPopupSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/InputPopupSpec.scala @@ -1,18 +1,21 @@ package scommons.client.ui.popup -import scommons.client.ui.{Buttons, TextField, TextFieldProps} -import scommons.react.test.TestSpec -import scommons.react.test.raw.ShallowInstance -import scommons.react.test.util.ShallowRendererUtils +import scommons.client.ui.popup.InputPopup._ +import scommons.client.ui.{Buttons, TextFieldProps} +import scommons.react._ +import scommons.react.test._ -class InputPopupSpec extends TestSpec with ShallowRendererUtils { +class InputPopupSpec extends TestSpec with TestRendererUtils { + + InputPopup.modalComp = () => "Modal".asInstanceOf[ReactClass] + InputPopup.textFieldComp = () => "TextField".asInstanceOf[ReactClass] it should "call onCancel when cancel command" in { //given val onCancel = mockFunction[Unit] val props = getInputPopupProps("Test message", onCancel = onCancel) - val component = shallowRender(<(InputPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(InputPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onCancel.expects() @@ -25,8 +28,8 @@ class InputPopupSpec extends TestSpec with ShallowRendererUtils { //given val onOk = mockFunction[String, Unit] val props = getInputPopupProps("Test message", initialValue = "initial value", onOk = onOk) - val component = shallowRender(<(InputPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(InputPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onOk.expects(props.initialValue) @@ -39,85 +42,81 @@ class InputPopupSpec extends TestSpec with ShallowRendererUtils { //given val onOk = mockFunction[String, Unit] val props = getInputPopupProps("Test message", initialValue = "initial value", onOk = onOk) - val renderer = createRenderer() - renderer.render(<(InputPopup())(^.wrapped := props)()) + val renderer = createTestRenderer(<(InputPopup())(^.wrapped := props)()) val newValue = "new value" - findComponentProps(renderer.getRenderOutput(), TextField).onChange(newValue) + findComponentProps(renderer.root, textFieldComp).onChange(newValue) //then onOk.expects(newValue) //when - findComponentProps(renderer.getRenderOutput(), Modal).actions.onCommand(_ => ())(Buttons.OK.command) + findComponentProps(renderer.root, modalComp).actions.onCommand(_ => ())(Buttons.OK.command) } it should "call onOk with initial value when onEnter" in { //given val onOk = mockFunction[String, Unit] val props = getInputPopupProps("Test message", initialValue = "initial value", onOk = onOk) - val comp = shallowRender(<(InputPopup())(^.wrapped := props)()) + val comp = testRender(<(InputPopup())(^.wrapped := props)()) //then onOk.expects(props.initialValue) //when - findComponentProps(comp, TextField).onEnter() + findComponentProps(comp, textFieldComp).onEnter() } it should "call onOk with new value when onEnter" in { //given val onOk = mockFunction[String, Unit] val props = getInputPopupProps("Test message", initialValue = "initial value", onOk = onOk) - val renderer = createRenderer() - renderer.render(<(InputPopup())(^.wrapped := props)()) + val renderer = createTestRenderer(<(InputPopup())(^.wrapped := props)()) val newValue = "new value" - findComponentProps(renderer.getRenderOutput(), TextField).onChange(newValue) + findComponentProps(renderer.root, textFieldComp).onChange(newValue) //then onOk.expects(newValue) //when - findComponentProps(renderer.getRenderOutput(), TextField).onEnter() + findComponentProps(renderer.root, textFieldComp).onEnter() } it should "enable OK command when new value is non-emtpy" in { //given val props = getInputPopupProps("Test message") - val renderer = createRenderer() - renderer.render(<(InputPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() + val renderer = createTestRenderer(<(InputPopup())(^.wrapped := props)()) + val comp = renderer.root val newValue = "new value" //when - findComponentProps(comp, TextField).onChange(newValue) + findComponentProps(comp, textFieldComp).onChange(newValue) //then - val updatedComp = renderer.getRenderOutput() - val textProps = findComponentProps(updatedComp, TextField) + val updatedComp = renderer.root + val textProps = findComponentProps(updatedComp, textFieldComp) textProps.text shouldBe newValue - val modalProps = findComponentProps(updatedComp, Modal) + val modalProps = findComponentProps(updatedComp, modalComp) modalProps.actions.enabledCommands shouldBe Set(Buttons.OK.command, Buttons.CANCEL.command) } it should "disable OK command when new value is emtpy" in { //given val props = getInputPopupProps("Test message", initialValue = "initial value") - val renderer = createRenderer() - renderer.render(<(InputPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val prevTextProps = findComponentProps(comp, TextField) + val renderer = createTestRenderer(<(InputPopup())(^.wrapped := props)()) + val comp = renderer.root + val prevTextProps = findComponentProps(comp, textFieldComp) val newValue = "" //when prevTextProps.onChange(newValue) //then - val updatedComp = renderer.getRenderOutput() - val textProps = findComponentProps(updatedComp, TextField) + val updatedComp = renderer.root + val textProps = findComponentProps(updatedComp, textFieldComp) textProps.text shouldBe newValue - val modalProps = findComponentProps(updatedComp, Modal) + val modalProps = findComponentProps(updatedComp, modalComp) modalProps.actions.enabledCommands shouldBe Set(Buttons.CANCEL.command) } @@ -127,7 +126,7 @@ class InputPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(InputPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertInputPopup(result, props) @@ -142,7 +141,7 @@ class InputPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(InputPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertInputPopup(result, props) @@ -151,11 +150,10 @@ class InputPopupSpec extends TestSpec with ShallowRendererUtils { it should "set requestFocus when onOpen" in { //given val props = getInputPopupProps("Test message") - val renderer = createRenderer() - renderer.render(<(InputPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val modalProps = findComponentProps(comp, Modal) - val textProps = findComponentProps(comp, TextField) + val renderer = createTestRenderer(<(InputPopup())(^.wrapped := props)()) + val comp = renderer.root + val modalProps = findComponentProps(comp, modalComp) + val textProps = findComponentProps(comp, textFieldComp) textProps.requestFocus shouldBe false textProps.requestSelect shouldBe false @@ -163,8 +161,8 @@ class InputPopupSpec extends TestSpec with ShallowRendererUtils { modalProps.onOpen() //then - val updatedComp = renderer.getRenderOutput() - val updatedTextProps = findComponentProps(updatedComp, TextField) + val updatedComp = renderer.root + val updatedTextProps = findComponentProps(updatedComp, textFieldComp) updatedTextProps.requestFocus shouldBe true updatedTextProps.requestSelect shouldBe true } @@ -181,23 +179,23 @@ class InputPopupSpec extends TestSpec with ShallowRendererUtils { initialValue = initialValue ) - private def assertInputPopup(result: ShallowInstance, props: InputPopupProps): Unit = { + private def assertInputPopup(result: TestInstance, props: InputPopupProps): Unit = { val actionCommands = if (props.initialValue.nonEmpty) Set(Buttons.OK.command, Buttons.CANCEL.command) else Set(Buttons.CANCEL.command) - assertComponent(result, Modal)({ + assertTestComponent(result, modalComp)({ case ModalProps(header, buttons, actions, _, onClose, closable, _) => header shouldBe None buttons shouldBe List(Buttons.OK, Buttons.CANCEL) actions.enabledCommands shouldBe actionCommands onClose shouldBe props.onCancel closable shouldBe true - }, { case List(modalChild) => - assertNativeComponent(modalChild, <.div(^.className := "row-fluid")(), { case List(p, div) => + }, inside(_) { case List(modalChild) => + assertNativeComponent(modalChild, <.div(^.className := "row-fluid")(), inside(_) { case List(p, div) => assertNativeComponent(p, <.p()(props.message)) - assertNativeComponent(div, <.div(^.className := "control-group")(), { case List(textField) => - assertComponent(textField, TextField) { + assertNativeComponent(div, <.div(^.className := "control-group")(), inside(_) { case List(textField) => + assertTestComponent(textField, textFieldComp) { case TextFieldProps(text, _, requestFocus, requestSelect, className, placeholder, _, readOnly) => text shouldBe props.initialValue requestFocus shouldBe false diff --git a/ui/src/test/scala/scommons/client/ui/popup/LoadingPopupSpec.scala b/ui/src/test/scala/scommons/client/ui/popup/LoadingPopupSpec.scala index 91439ee..1a911af 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/LoadingPopupSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/LoadingPopupSpec.scala @@ -1,15 +1,18 @@ package scommons.client.ui.popup +import scommons.client.ui.popup.LoadingPopup.popupComp import scommons.client.ui.popup.PopupCss._ -import scommons.react.test.TestSpec -import scommons.react.test.util.ShallowRendererUtils +import scommons.react._ +import scommons.react.test._ -class LoadingPopupSpec extends TestSpec with ShallowRendererUtils { +class LoadingPopupSpec extends TestSpec with TestRendererUtils { + + LoadingPopup.popupComp = () => "Popup".asInstanceOf[ReactClass] it should "do nothing when onClose/onOpen" in { //given - val comp = shallowRender(<(LoadingPopup())()()) - val popupProps = findComponentProps(comp, Popup) + val comp = testRender(<(LoadingPopup())()()) + val popupProps = findComponentProps(comp, popupComp) //when popupProps.onClose() @@ -18,16 +21,16 @@ class LoadingPopupSpec extends TestSpec with ShallowRendererUtils { it should "render component" in { //when - val result = shallowRender(<(LoadingPopup())()()) + val result = testRender(<(LoadingPopup())()()) //then - assertComponent(result, Popup)({ + assertTestComponent(result, popupComp)({ case PopupProps(_, closable, focusable, _, overlayClass, popupClass) => closable shouldBe false focusable shouldBe false overlayClass shouldBe loadingOverlay popupClass shouldBe loadingContent - }, { case List(img) => + }, inside(_) { case List(img) => assertNativeComponent(img, <.img(^.className := loadingImg, ^.src := "")()) }) } diff --git a/ui/src/test/scala/scommons/client/ui/popup/ModalBodySpec.scala b/ui/src/test/scala/scommons/client/ui/popup/ModalBodySpec.scala index 964bda8..5c19650 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/ModalBodySpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/ModalBodySpec.scala @@ -1,9 +1,8 @@ package scommons.client.ui.popup -import scommons.react.test.TestSpec -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ -class ModalBodySpec extends TestSpec with ShallowRendererUtils { +class ModalBodySpec extends TestSpec with TestRendererUtils { it should "render component with provided children" in { //given @@ -12,7 +11,7 @@ class ModalBodySpec extends TestSpec with ShallowRendererUtils { ) //when - val result = shallowRender(component) + val result = testRender(component) //then assertNativeComponent(result, <.div(^.className := "modal-body")(), { case List(child) => diff --git a/ui/src/test/scala/scommons/client/ui/popup/ModalFooterSpec.scala b/ui/src/test/scala/scommons/client/ui/popup/ModalFooterSpec.scala index d2e5291..35f21e6 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/ModalFooterSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/ModalFooterSpec.scala @@ -2,10 +2,9 @@ package scommons.client.ui.popup import scommons.client.ui.{Buttons, ButtonsPanel, ButtonsPanelProps} import scommons.client.util.ActionsData -import scommons.react.test.TestSpec -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ -class ModalFooterSpec extends TestSpec with ShallowRendererUtils { +class ModalFooterSpec extends TestSpec with TestRendererUtils { it should "render component with correct props" in { //given @@ -16,10 +15,10 @@ class ModalFooterSpec extends TestSpec with ShallowRendererUtils { val component = <(ModalFooter())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then - assertComponent(result, ButtonsPanel) { + assertTestComponent(result, ButtonsPanel) { case ButtonsPanelProps(buttons, actions, dispatch, group, className) => buttons shouldBe props.buttons actions shouldBe props.actions diff --git a/ui/src/test/scala/scommons/client/ui/popup/ModalSpec.scala b/ui/src/test/scala/scommons/client/ui/popup/ModalSpec.scala index ce6867c..c73eb4d 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/ModalSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/ModalSpec.scala @@ -2,12 +2,17 @@ package scommons.client.ui.popup import org.scalatest.{Assertion, Succeeded} import scommons.client.ui.Buttons +import scommons.client.ui.popup.Modal._ import scommons.client.util.ActionsData -import scommons.react.test.TestSpec -import scommons.react.test.raw.ShallowInstance -import scommons.react.test.util.ShallowRendererUtils +import scommons.react._ +import scommons.react.test._ -class ModalSpec extends TestSpec with ShallowRendererUtils { +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] it should "render closable modal with header" in { //given @@ -17,7 +22,7 @@ class ModalSpec extends TestSpec with ShallowRendererUtils { ) //when - val result = shallowRender(component) + val result = testRender(component) //then assertModal(result, props) @@ -31,7 +36,7 @@ class ModalSpec extends TestSpec with ShallowRendererUtils { ) //when - val result = shallowRender(component) + val result = testRender(component) //then assertModal(result, props) @@ -45,40 +50,40 @@ class ModalSpec extends TestSpec with ShallowRendererUtils { ) //when - val result = shallowRender(component) + val result = testRender(component) //then - assertComponent(result, Popup)({ popupProps => + assertTestComponent(result, popupComp)({ popupProps => popupProps shouldBe PopupProps( onClose = props.onClose, closable = props.closable, onOpen = props.onOpen ) - }, { case List(body, footer) => - assertComponent(body, ModalBody)({ _ => Succeeded }, { case List(child) => + }, inside(_) { case List(body, footer) => + assertTestComponent(body, modalBodyComp)({ _ => Succeeded }, inside(_) { case List(child) => assertNativeComponent(child, <.p()("some children")) }) - assertComponent(footer, ModalFooter) { footerProps => + assertTestComponent(footer, modalFooterComp) { footerProps => footerProps shouldBe ModalFooterProps(props.buttons, props.actions, props.dispatch) } }) } - private def assertModal(result: ShallowInstance, props: ModalProps): Assertion = { - assertComponent(result, Popup)({ popupProps => + private def assertModal(result: TestInstance, props: ModalProps): Assertion = { + assertTestComponent(result, popupComp)({ popupProps => popupProps shouldBe PopupProps( onClose = props.onClose, closable = props.closable, onOpen = props.onOpen ) - }, { case List(header, body, footer) => - assertComponent(header, ModalHeader) { headerProps: ModalHeaderProps => + }, inside(_) { case List(header, body, footer) => + assertTestComponent(header, modalHeaderComp) { headerProps: ModalHeaderProps => headerProps shouldBe ModalHeaderProps(props.header.get, props.onClose, closable = props.closable) } - assertComponent(body, ModalBody)({ _ => Succeeded }, { case List(child) => + assertTestComponent(body, modalBodyComp)({ _ => Succeeded }, inside(_) { case List(child) => assertNativeComponent(child, <.p()("some children")) }) - assertComponent(footer, ModalFooter) { footerProps => + assertTestComponent(footer, modalFooterComp) { footerProps => footerProps shouldBe ModalFooterProps(props.buttons, props.actions, props.dispatch) } }) diff --git a/ui/src/test/scala/scommons/client/ui/popup/OkPopupSpec.scala b/ui/src/test/scala/scommons/client/ui/popup/OkPopupSpec.scala index 0118ee1..112e5a9 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/OkPopupSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/OkPopupSpec.scala @@ -2,18 +2,20 @@ package scommons.client.ui.popup import scommons.client.ui.Buttons import scommons.client.ui.icon.IconCss -import scommons.react.test.TestSpec -import scommons.react.test.raw.ShallowInstance -import scommons.react.test.util.ShallowRendererUtils +import scommons.client.ui.popup.OkPopup._ +import scommons.react._ +import scommons.react.test._ -class OkPopupSpec extends TestSpec with ShallowRendererUtils { +class OkPopupSpec extends TestSpec with TestRendererUtils { + + OkPopup.modalComp = () => "Modal".asInstanceOf[ReactClass] it should "call onClose function when onOkCommand" in { //given val onClose = mockFunction[Unit] val props = getOkPopupProps("Test message", onClose = onClose) - val component = shallowRender(<(OkPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(OkPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onClose.expects() @@ -28,7 +30,7 @@ class OkPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(OkPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertOkPopup(result, props) @@ -40,7 +42,7 @@ class OkPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(OkPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertOkPopup(result, props) @@ -49,18 +51,17 @@ class OkPopupSpec extends TestSpec with ShallowRendererUtils { it should "set focusedCommand when onOpen" in { //given val props = getOkPopupProps("Test message") - val renderer = createRenderer() - renderer.render(<(OkPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val modalProps = findComponentProps(comp, Modal) + val renderer = createTestRenderer(<(OkPopup())(^.wrapped := props)()) + val comp = renderer.root + val modalProps = findComponentProps(comp, modalComp) modalProps.actions.focusedCommand shouldBe None //when modalProps.onOpen() //then - val updatedComp = renderer.getRenderOutput() - val updatedModalProps = findComponentProps(updatedComp, Modal) + val updatedComp = renderer.root + val updatedModalProps = findComponentProps(updatedComp, modalComp) updatedModalProps.actions.focusedCommand shouldBe Some(Buttons.OK.command) } @@ -72,10 +73,10 @@ class OkPopupSpec extends TestSpec with ShallowRendererUtils { image = image ) - private def assertOkPopup(result: ShallowInstance, props: OkPopupProps): Unit = { + private def assertOkPopup(result: TestInstance, props: OkPopupProps): Unit = { val actionCommands = Set(Buttons.OK.command) - assertComponent(result, Modal)({ + assertTestComponent(result, modalComp)({ case ModalProps(header, buttons, actions, _, onClose, closable, _) => header shouldBe None buttons shouldBe List(Buttons.OK) @@ -83,9 +84,9 @@ class OkPopupSpec extends TestSpec with ShallowRendererUtils { actions.focusedCommand shouldBe None onClose shouldBe props.onClose closable shouldBe true - }, { case List(modalChild) => + }, inside(_) { case List(modalChild) => assertNativeComponent(modalChild, <.div(^.className := "row-fluid")(), { children => - val (img, p) = children match { + val (img, p) = inside(children) { case List(pElem) => (None, pElem) case List(imgElem, pElem) => (Some(imgElem), pElem) } diff --git a/ui/src/test/scala/scommons/client/ui/popup/SaveCancelPopupSpec.scala b/ui/src/test/scala/scommons/client/ui/popup/SaveCancelPopupSpec.scala index 8426987..3a431be 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/SaveCancelPopupSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/SaveCancelPopupSpec.scala @@ -1,20 +1,21 @@ package scommons.client.ui.popup +import scommons.client.ui.popup.SaveCancelPopup._ import scommons.client.ui.popup.SaveCancelPopupSpec._ import scommons.client.ui.{ButtonImagesCss, Buttons} import scommons.react._ -import scommons.react.test.TestSpec -import scommons.react.test.raw.ShallowInstance -import scommons.react.test.util.ShallowRendererUtils +import scommons.react.test._ -class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { +class SaveCancelPopupSpec extends TestSpec with TestRendererUtils { + + SaveCancelPopup.modalComp = () => "Modal".asInstanceOf[ReactClass] it should "call onCancel function when cancel command" in { //given val onCancel = mockFunction[Unit] val props = TestPopupProps(title = "Test message", onCancel = onCancel) - val component = shallowRender(<(SaveCancelPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(SaveCancelPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onCancel.expects() @@ -27,8 +28,8 @@ class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { //given val onSave = mockFunction[TestData, Unit] val props = TestPopupProps(onSave = onSave) - val component = shallowRender(<(SaveCancelPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(SaveCancelPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onSave.expects(props.initialData) @@ -41,24 +42,22 @@ class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { //given val onSave = mockFunction[TestData, Unit] val props = TestPopupProps(onSave = onSave) - val renderer = createRenderer() - renderer.render(<(SaveCancelPopup())(^.wrapped := props)()) + val renderer = createTestRenderer(<(SaveCancelPopup())(^.wrapped := props)()) val newData = props.initialData.copy(name = "updated") - findComponentProps(renderer.getRenderOutput(), TestEditPanel).onChange(newData) + findComponentProps(renderer.root, TestEditPanel).onChange(newData) //then onSave.expects(newData) //when - findComponentProps(renderer.getRenderOutput(), TestEditPanel).onEnter() + findComponentProps(renderer.root, TestEditPanel).onEnter() } it should "enable SAVE command when all the fields are filled" in { //given val props = TestPopupProps() - val renderer = createRenderer() - renderer.render(<(SaveCancelPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() + val renderer = createTestRenderer(<(SaveCancelPopup())(^.wrapped := props)()) + val comp = renderer.root val prevEditProps = findComponentProps(comp, TestEditPanel) val newData = props.initialData.copy(name = "updated") @@ -66,20 +65,19 @@ class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { prevEditProps.onChange(newData) //then - val updatedComp = renderer.getRenderOutput() + val updatedComp = renderer.root val editProps = findComponentProps(updatedComp, TestEditPanel) editProps.initialData shouldBe newData - val modalProps = findComponentProps(updatedComp, Modal) + val modalProps = findComponentProps(updatedComp, modalComp) modalProps.actions.enabledCommands shouldBe Set(Buttons.SAVE.command, Buttons.CANCEL.command) } it should "disable SAVE command when one of the fields is emtpy" in { //given val props = TestPopupProps() - val renderer = createRenderer() - renderer.render(<(SaveCancelPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() + val renderer = createTestRenderer(<(SaveCancelPopup())(^.wrapped := props)()) + val comp = renderer.root val prevEditProps = findComponentProps(comp, TestEditPanel) val newData = props.initialData.copy(name = "") @@ -87,11 +85,11 @@ class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { prevEditProps.onChange(newData) //then - val updatedComp = renderer.getRenderOutput() + val updatedComp = renderer.root val editProps = findComponentProps(updatedComp, TestEditPanel) editProps.initialData shouldBe newData - val modalProps = findComponentProps(updatedComp, Modal) + val modalProps = findComponentProps(updatedComp, modalComp) modalProps.actions.enabledCommands shouldBe Set(Buttons.CANCEL.command) } @@ -101,10 +99,10 @@ class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(TestPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then - assertComponent(result, SaveCancelPopup) { pProps => + assertTestComponent(result, SaveCancelPopup) { pProps => pProps shouldBe props } } @@ -115,7 +113,7 @@ class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(SaveCancelPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertSaveCancelPopup(result, props) @@ -124,10 +122,9 @@ class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { it should "set requestFocus when onOpen" in { //given val props = TestPopupProps(title = "Test message") - val renderer = createRenderer() - renderer.render(<(SaveCancelPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val modalProps = findComponentProps(comp, Modal) + val renderer = createTestRenderer(<(SaveCancelPopup())(^.wrapped := props)()) + val comp = renderer.root + val modalProps = findComponentProps(comp, modalComp) val editProps = findComponentProps(comp, TestEditPanel) editProps.requestFocus shouldBe false @@ -135,12 +132,12 @@ class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { modalProps.onOpen() //then - val updatedComp = renderer.getRenderOutput() + val updatedComp = renderer.root val updatedTextProps = findComponentProps(updatedComp, TestEditPanel) updatedTextProps.requestFocus shouldBe true } - private def assertSaveCancelPopup(result: ShallowInstance, props: SaveCancelPopupProps): Unit = { + private def assertSaveCancelPopup(result: TestInstance, props: SaveCancelPopupProps): Unit = { val data = props.initialData val actionCommands = if (props.isSaveEnabled(data)) { @@ -148,7 +145,7 @@ class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { } else Set(Buttons.CANCEL.command) - assertComponent(result, Modal)({ + assertTestComponent(result, modalComp)({ case ModalProps(header, buttons, actions, _, onClose, closable, _) => header shouldBe Some(props.title) buttons shouldBe List(Buttons.SAVE.copy( @@ -159,8 +156,8 @@ class SaveCancelPopupSpec extends TestSpec with ShallowRendererUtils { actions.enabledCommands shouldBe actionCommands onClose shouldBe props.onCancel closable shouldBe true - }, { case List(editPanel) => - assertComponent(editPanel, TestEditPanel) { + }, inside(_) { case List(editPanel) => + assertTestComponent(editPanel, TestEditPanel) { case TestEditPanelProps(initialData, requestFocus, _, _) => initialData shouldBe props.initialData requestFocus shouldBe false diff --git a/ui/src/test/scala/scommons/client/ui/popup/StatusPopupSpec.scala b/ui/src/test/scala/scommons/client/ui/popup/StatusPopupSpec.scala index 3a51503..56e4ab8 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/StatusPopupSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/StatusPopupSpec.scala @@ -1,16 +1,20 @@ package scommons.client.ui.popup import scommons.client.ui.popup.PopupCss._ -import scommons.react.test.TestSpec -import scommons.react.test.util.ShallowRendererUtils +import scommons.client.ui.popup.StatusPopup._ +import scommons.react._ +import scommons.react.test._ -class StatusPopupSpec extends TestSpec with ShallowRendererUtils { +class StatusPopupSpec extends TestSpec with TestRendererUtils { + + StatusPopup.popupComp = () => "Popup".asInstanceOf[ReactClass] + StatusPopup.withAutoHideComp = () => "WithAutoHide".asInstanceOf[ReactClass] it should "do nothing when onClose/onOpen" in { //given val props = StatusPopupProps("test text", () => ()) - val comp = shallowRender(<(StatusPopup())(^.wrapped := props)()) - val popupProps = findComponentProps(comp, Popup) + val comp = testRender(<(StatusPopup())(^.wrapped := props)()) + val popupProps = findComponentProps(comp, popupComp) //when popupProps.onClose() @@ -23,19 +27,19 @@ class StatusPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(StatusPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then - assertComponent(result, Popup)({ + assertTestComponent(result, popupComp)({ case PopupProps(_, closable, focusable, _, overlayClass, popupClass) => closable shouldBe true focusable shouldBe false overlayClass shouldBe "scommons-modal-no-overlay" popupClass shouldBe statusContent - }, { case List(autoHide) => - assertComponent(autoHide, WithAutoHide)({ autoHideProps => + }, inside(_) { case List(autoHide) => + assertTestComponent(autoHide, withAutoHideComp)({ autoHideProps => autoHideProps shouldBe WithAutoHideProps(props.onHide) - }, { case List(child) => + }, inside(_) { case List(child) => child shouldBe props.text }) }) diff --git a/ui/src/test/scala/scommons/client/ui/popup/YesNoCancelPopupSpec.scala b/ui/src/test/scala/scommons/client/ui/popup/YesNoCancelPopupSpec.scala index 2a6d421..0ac30b7 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/YesNoCancelPopupSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/YesNoCancelPopupSpec.scala @@ -2,19 +2,21 @@ package scommons.client.ui.popup 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.test.TestSpec -import scommons.react.test.raw.ShallowInstance -import scommons.react.test.util.ShallowRendererUtils +import scommons.react._ +import scommons.react.test._ -class YesNoCancelPopupSpec extends TestSpec with ShallowRendererUtils { +class YesNoCancelPopupSpec extends TestSpec with TestRendererUtils { + + YesNoCancelPopup.modalComp = () => "Modal".asInstanceOf[ReactClass] it should "call onSelect(Yes) function when Yes selected" in { //given val onSelect = mockFunction[YesNoCancelOption, Unit] val props = getYesNoCancelPopupProps("Test message", onSelect = onSelect) - val component = shallowRender(<(YesNoCancelPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(YesNoCancelPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onSelect.expects(Yes) @@ -27,8 +29,8 @@ class YesNoCancelPopupSpec extends TestSpec with ShallowRendererUtils { //given val onSelect = mockFunction[YesNoCancelOption, Unit] val props = getYesNoCancelPopupProps("Test message", onSelect = onSelect) - val component = shallowRender(<(YesNoCancelPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(YesNoCancelPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onSelect.expects(No) @@ -41,8 +43,8 @@ class YesNoCancelPopupSpec extends TestSpec with ShallowRendererUtils { //given val onSelect = mockFunction[YesNoCancelOption, Unit] val props = getYesNoCancelPopupProps("Test message", onSelect = onSelect) - val component = shallowRender(<(YesNoCancelPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(YesNoCancelPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onSelect.expects(Cancel) @@ -55,8 +57,8 @@ class YesNoCancelPopupSpec extends TestSpec with ShallowRendererUtils { //given val onSelect = mockFunction[YesNoCancelOption, Unit] val props = getYesNoCancelPopupProps("Test message", onSelect = onSelect) - val component = shallowRender(<(YesNoCancelPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(YesNoCancelPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onSelect.expects(Cancel) @@ -71,7 +73,7 @@ class YesNoCancelPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(YesNoCancelPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertYesNoCancelPopup(result, props) @@ -83,7 +85,7 @@ class YesNoCancelPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(YesNoCancelPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertYesNoCancelPopup(result, props) @@ -92,18 +94,17 @@ class YesNoCancelPopupSpec extends TestSpec with ShallowRendererUtils { it should "set focusedCommand when onOpen" in { //given val props = getYesNoCancelPopupProps("Test message") - val renderer = createRenderer() - renderer.render(<(YesNoCancelPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val modalProps = findComponentProps(comp, Modal) + val renderer = createTestRenderer(<(YesNoCancelPopup())(^.wrapped := props)()) + val comp = renderer.root + val modalProps = findComponentProps(comp, modalComp) modalProps.actions.focusedCommand shouldBe None //when modalProps.onOpen() //then - val updatedComp = renderer.getRenderOutput() - val updatedModalProps = findComponentProps(updatedComp, Modal) + val updatedComp = renderer.root + val updatedModalProps = findComponentProps(updatedComp, modalComp) updatedModalProps.actions.focusedCommand shouldBe Some(props.selected.command) } @@ -117,7 +118,7 @@ class YesNoCancelPopupSpec extends TestSpec with ShallowRendererUtils { image = image ) - private def assertYesNoCancelPopup(result: ShallowInstance, props: YesNoCancelPopupProps): Unit = { + private def assertYesNoCancelPopup(result: TestInstance, props: YesNoCancelPopupProps): Unit = { val expectedButtons = List( SimpleButtonData(Yes.command, "Yes", props.selected == Yes), SimpleButtonData(No.command, "No", props.selected == No), @@ -125,16 +126,16 @@ class YesNoCancelPopupSpec extends TestSpec with ShallowRendererUtils { ) val enabledCommands = Set(Yes.command, No.command, Cancel.command) - assertComponent(result, Modal)({ + assertTestComponent(result, modalComp)({ case ModalProps(header, buttons, actions, _, _, closable, _) => header shouldBe None buttons shouldBe expectedButtons actions.enabledCommands shouldBe enabledCommands actions.focusedCommand shouldBe None closable shouldBe true - }, { case List(modalChild) => + }, inside(_) { case List(modalChild) => assertNativeComponent(modalChild, <.div(^.className := "row-fluid")(), { children => - val (img, p) = children match { + val (img, p) = inside(children) { case List(pElem) => (None, pElem) case List(imgElem, pElem) => (Some(imgElem), pElem) } diff --git a/ui/src/test/scala/scommons/client/ui/popup/YesNoPopupSpec.scala b/ui/src/test/scala/scommons/client/ui/popup/YesNoPopupSpec.scala index f7fd1bc..9cdc8be 100644 --- a/ui/src/test/scala/scommons/client/ui/popup/YesNoPopupSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/popup/YesNoPopupSpec.scala @@ -3,18 +3,20 @@ package scommons.client.ui.popup import scommons.client.ui.SimpleButtonData import scommons.client.ui.icon.IconCss import scommons.client.ui.popup.YesNoCancelOption._ -import scommons.react.test.TestSpec -import scommons.react.test.raw.ShallowInstance -import scommons.react.test.util.ShallowRendererUtils +import scommons.client.ui.popup.YesNoPopup._ +import scommons.react._ +import scommons.react.test._ -class YesNoPopupSpec extends TestSpec with ShallowRendererUtils { +class YesNoPopupSpec extends TestSpec with TestRendererUtils { + + YesNoPopup.modalComp = () => "Modal".asInstanceOf[ReactClass] it should "call onSelect(Yes) function when Yes selected" in { //given val onSelect = mockFunction[YesNoCancelOption, Unit] val props = getYesNoPopupProps("Test message", onSelect = onSelect) - val component = shallowRender(<(YesNoPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(YesNoPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onSelect.expects(Yes) @@ -27,8 +29,8 @@ class YesNoPopupSpec extends TestSpec with ShallowRendererUtils { //given val onSelect = mockFunction[YesNoCancelOption, Unit] val props = getYesNoPopupProps("Test message", onSelect = onSelect) - val component = shallowRender(<(YesNoPopup())(^.wrapped := props)()) - val modalProps = findComponentProps(component, Modal) + val component = testRender(<(YesNoPopup())(^.wrapped := props)()) + val modalProps = findComponentProps(component, modalComp) //then onSelect.expects(No) @@ -43,7 +45,7 @@ class YesNoPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(YesNoPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertYesNoPopup(result, props) @@ -55,7 +57,7 @@ class YesNoPopupSpec extends TestSpec with ShallowRendererUtils { val component = <(YesNoPopup())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertYesNoPopup(result, props) @@ -64,18 +66,17 @@ class YesNoPopupSpec extends TestSpec with ShallowRendererUtils { it should "set focusedCommand when onOpen" in { //given val props = getYesNoPopupProps("Test message") - val renderer = createRenderer() - renderer.render(<(YesNoPopup())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val modalProps = findComponentProps(comp, Modal) + val renderer = createTestRenderer(<(YesNoPopup())(^.wrapped := props)()) + val comp = renderer.root + val modalProps = findComponentProps(comp, modalComp) modalProps.actions.focusedCommand shouldBe None //when modalProps.onOpen() //then - val updatedComp = renderer.getRenderOutput() - val updatedModalProps = findComponentProps(updatedComp, Modal) + val updatedComp = renderer.root + val updatedModalProps = findComponentProps(updatedComp, modalComp) updatedModalProps.actions.focusedCommand shouldBe Some(props.selected.command) } @@ -89,23 +90,23 @@ class YesNoPopupSpec extends TestSpec with ShallowRendererUtils { image = image ) - private def assertYesNoPopup(result: ShallowInstance, props: YesNoPopupProps): Unit = { + private def assertYesNoPopup(result: TestInstance, props: YesNoPopupProps): Unit = { val expectedButtons = List( SimpleButtonData(Yes.command, "Yes", props.selected == Yes), SimpleButtonData(No.command, "No", props.selected == No) ) val enabledCommands = Set(Yes.command, No.command) - assertComponent(result, Modal)({ + assertTestComponent(result, modalComp)({ case ModalProps(header, buttons, actions, _, _, closable, _) => header shouldBe None buttons shouldBe expectedButtons actions.enabledCommands shouldBe enabledCommands actions.focusedCommand shouldBe None closable shouldBe false - }, { case List(modalChild) => + }, inside(_) { case List(modalChild) => assertNativeComponent(modalChild, <.div(^.className := "row-fluid")(), { children => - val (img, p) = children match { + val (img, p) = inside(children) { case List(pElem) => (None, pElem) case List(imgElem, pElem) => (Some(imgElem), pElem) } diff --git a/ui/src/test/scala/scommons/client/ui/select/SearchSelectSpec.scala b/ui/src/test/scala/scommons/client/ui/select/SearchSelectSpec.scala index 359a160..8432bcd 100644 --- a/ui/src/test/scala/scommons/client/ui/select/SearchSelectSpec.scala +++ b/ui/src/test/scala/scommons/client/ui/select/SearchSelectSpec.scala @@ -1,23 +1,26 @@ package scommons.client.ui.select 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} import scala.scalajs.js -class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRendererUtils { +class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with TestRendererUtils { SearchSelect.global = nodejs.global.asInstanceOf[js.Dynamic] + SearchSelect.singleSelectComp = () => "SingleSelect".asInstanceOf[ReactClass] it should "call onChange function when onSelectChange" in { //given val onChange = mockFunction[Option[SelectData], Unit] val props = SearchSelectProps(None, onChange = onChange) - val component = shallowRender(<(SearchSelect())(^.wrapped := props)()) - val selectProps = findComponentProps(component, SingleSelect) + val component = testRender(<(SearchSelect())(^.wrapped := props)()) + val selectProps = findComponentProps(component, singleSelectComp) val data = SelectData("test", "Test") //then @@ -33,10 +36,9 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende //given val onLoad = mockFunction[String, Future[List[SelectData]]] val props = SearchSelectProps(None, onLoad = onLoad) - val renderer = createRenderer() - renderer.render(<(SearchSelect())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val selectProps = findComponentProps(comp, SingleSelect) + val renderer = createTestRenderer(<(SearchSelect())(^.wrapped := props)()) + val comp = renderer.root + val selectProps = findComponentProps(comp, singleSelectComp) selectProps.isLoading shouldBe false val inputValue = "some input" val promise = Promise[List[SelectData]]() @@ -48,8 +50,8 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende //then eventually { - val updatedComp = renderer.getRenderOutput() - val updatedSelectProps = findComponentProps(updatedComp, SingleSelect) + val updatedComp = renderer.root + val updatedSelectProps = findComponentProps(updatedComp, singleSelectComp) updatedSelectProps.isLoading shouldBe true } } @@ -58,10 +60,9 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende //given val onLoad = mockFunction[String, Future[List[SelectData]]] val props = SearchSelectProps(None, onLoad = onLoad) - val renderer = createRenderer() - renderer.render(<(SearchSelect())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val selectProps = findComponentProps(comp, SingleSelect) + val renderer = createTestRenderer(<(SearchSelect())(^.wrapped := props)()) + val comp = renderer.root + val selectProps = findComponentProps(comp, singleSelectComp) selectProps.isLoading shouldBe false val inputValue = "some input" val options = List( @@ -76,8 +77,8 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende //then eventually { - val updatedComp = renderer.getRenderOutput() - val updatedSelectProps = findComponentProps(updatedComp, SingleSelect) + val updatedComp = renderer.root + val updatedSelectProps = findComponentProps(updatedComp, singleSelectComp) updatedSelectProps.isLoading shouldBe false updatedSelectProps.options shouldBe options } @@ -87,10 +88,9 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende //given val onLoad = mockFunction[String, Future[List[SelectData]]] val props = SearchSelectProps(None, onLoad = onLoad) - val renderer = createRenderer() - renderer.render(<(SearchSelect())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val selectProps = findComponentProps(comp, SingleSelect) + val renderer = createTestRenderer(<(SearchSelect())(^.wrapped := props)()) + val comp = renderer.root + val selectProps = findComponentProps(comp, singleSelectComp) selectProps.isLoading shouldBe false val inputValue = "some input" val promise = Promise[List[SelectData]]() @@ -103,8 +103,8 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende //then var loaded = false eventually { - val updatedComp = renderer.getRenderOutput() - val updatedSelectProps = findComponentProps(updatedComp, SingleSelect) + val updatedComp = renderer.root + val updatedSelectProps = findComponentProps(updatedComp, singleSelectComp) if (!loaded) { updatedSelectProps.isLoading shouldBe true @@ -126,10 +126,9 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende //given val onLoad = mockFunction[String, Future[List[SelectData]]] val props = SearchSelectProps(None, onLoad = onLoad) - val renderer = createRenderer() - renderer.render(<(SearchSelect())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val selectProps = findComponentProps(comp, SingleSelect) + val renderer = createTestRenderer(<(SearchSelect())(^.wrapped := props)()) + val comp = renderer.root + val selectProps = findComponentProps(comp, singleSelectComp) selectProps.isLoading shouldBe false val inputValue1 = "some input 1" val inputValue2 = "some input 2" @@ -145,8 +144,8 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende //then var loaded = false eventually { - val updatedComp = renderer.getRenderOutput() - val updatedSelectProps = findComponentProps(updatedComp, SingleSelect) + val updatedComp = renderer.root + val updatedSelectProps = findComponentProps(updatedComp, singleSelectComp) if (!loaded) { updatedSelectProps.isLoading shouldBe true @@ -170,10 +169,9 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende //given val onLoad = mockFunction[String, Future[List[SelectData]]] val props = SearchSelectProps(None, onLoad = onLoad) - val renderer = createRenderer() - renderer.render(<(SearchSelect())(^.wrapped := props)()) - val comp = renderer.getRenderOutput() - val selectProps = findComponentProps(comp, SingleSelect) + val renderer = createTestRenderer(<(SearchSelect())(^.wrapped := props)()) + val comp = renderer.root + val selectProps = findComponentProps(comp, singleSelectComp) selectProps.isLoading shouldBe false val inputValue1 = "some input 1" val inputValue2 = "some input 2" @@ -188,8 +186,8 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende //then eventually { - val updatedComp = renderer.getRenderOutput() - val updatedSelectProps = findComponentProps(updatedComp, SingleSelect) + val updatedComp = renderer.root + val updatedSelectProps = findComponentProps(updatedComp, singleSelectComp) updatedSelectProps.isLoading shouldBe false updatedSelectProps.options shouldBe options } @@ -201,7 +199,7 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende val component = <(SearchSelect())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertSearchSelect(result, props) @@ -213,7 +211,7 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende val component = <(SearchSelect())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertSearchSelect(result, props) @@ -225,14 +223,14 @@ class SearchSelectSpec extends AsyncTestSpec with BaseTestSpec with ShallowRende val component = <(SearchSelect())(^.wrapped := props)() //when - val result = shallowRender(component) + val result = testRender(component) //then assertSearchSelect(result, props) } - private def assertSearchSelect(result: ShallowInstance, props: SearchSelectProps): Assertion = { - assertComponent(result, SingleSelect) { + private def assertSearchSelect(result: TestInstance, props: SearchSelectProps): Assertion = { + assertTestComponent(result, singleSelectComp) { case SingleSelectProps( selected, options,