Skip to content

Commit

Permalink
Added scommons.react.test and test.dom package objects, fixed #1
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Apr 16, 2020
1 parent a426e6f commit 297ada5
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package scommons.react.showcase

import scommons.react._
import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

import scala.scalajs.js

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package scommons.react.showcase

import org.scalajs.dom.{Event, window}
import scommons.react._
import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

import scala.scalajs.js

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

import scommons.react._
import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

import scala.scalajs.js

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

import scommons.react._
import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.raw.React.{Fragment => ReactFragment}
import scommons.react.test._
import scommons.react.test.dom._

class ReactFragmentDemoSpec extends TestSpec
with TestDOMUtils
Expand Down Expand Up @@ -38,7 +38,7 @@ class ReactFragmentDemoSpec extends TestSpec
val result = shallowRender(comp)

//then
result.`type` shouldBe raw.React.Fragment
result.`type` shouldBe ReactFragment

assertNativeComponent(result,
<.>()(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package scommons.react.showcase

import scommons.react.test.TestSpec
import scommons.react.test.raw.TestRenderer
import scommons.react.test.util.TestRendererUtils
import scommons.react.test._

class ReactMemoDemoSpec extends TestSpec with TestRendererUtils {

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

import org.scalajs.dom.document
import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

class ReactRefDemoSpec extends TestSpec
with TestDOMUtils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package scommons.react.showcase.app

import org.scalajs.dom
import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test._
import scommons.react.test.dom._

class ShowcaseReactAppSpec extends TestSpec with TestDOMUtils {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package scommons.react.showcase.app.counter

import org.scalajs.dom
import org.scalajs.dom.document
import scommons.react._
import scommons.react.redux.task.FutureTask
import scommons.react.showcase.app.counter.CounterActions._
import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.util.ShallowRendererUtils
import scommons.react.test._
import scommons.react.test.dom._

import scala.concurrent.Future

Expand All @@ -21,7 +20,7 @@ class CounterPanelSpec extends TestSpec
val state = CounterState(123)
val props = CounterPanelProps(dispatch, actions, state)
domRender(<(CounterPanel())(^.wrapped := props)())
val button = dom.document.body.querySelectorAll("button").item(0)
val button = document.body.querySelectorAll("button").item(0)
val action = CounterChangeAction(
FutureTask("Changing Counter", Future.successful(0))
)
Expand All @@ -41,7 +40,7 @@ class CounterPanelSpec extends TestSpec
val state = CounterState(123)
val props = CounterPanelProps(dispatch, actions, state)
domRender(<(CounterPanel())(^.wrapped := props)())
val button = dom.document.body.querySelectorAll("button").item(1)
val button = document.body.querySelectorAll("button").item(1)
val action = CounterChangeAction(
FutureTask("Changing Counter", Future.successful(0))
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package scommons.react.showcase.dom

import org.scalajs.dom
import org.scalajs.dom.{Element, document}
import scommons.react._
import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test._
import scommons.react.test.dom._

class ReactPortalDemoSpec extends TestSpec with TestDOMUtils {

Expand All @@ -14,7 +14,7 @@ class ReactPortalDemoSpec extends TestSpec with TestDOMUtils {
))

assertDOMElement(domContainer, <.div()())
assertDOMElement(dom.document.body.querySelector(".portal-content"),
assertDOMElement(document.body.querySelector(".portal-content"),
<.div(^("class") := "portal-content")(
"Portal Child"
)
Expand All @@ -23,7 +23,7 @@ class ReactPortalDemoSpec extends TestSpec with TestDOMUtils {
//when & then
domRender(<(ReactPortalDemo())(^.wrapped := ReactPortalDemoProps(show = false))())

dom.document.body.querySelectorAll(".portal-content").length shouldBe 0
document.body.querySelectorAll(".portal-content").length shouldBe 0
}

it should "re-render portal content" in {
Expand All @@ -32,7 +32,7 @@ class ReactPortalDemoSpec extends TestSpec with TestDOMUtils {
"Portal Child"
))
assertDOMElement(domContainer, <.div()())
assertDOMElement(dom.document.body.querySelector(".portal-content"),
assertDOMElement(document.body.querySelector(".portal-content"),
<.div(^("class") := "portal-content")(
"Portal Child"
)
Expand All @@ -42,15 +42,15 @@ class ReactPortalDemoSpec extends TestSpec with TestDOMUtils {
domRender(<(ReactPortalDemo())(^.wrapped := ReactPortalDemoProps(show = true))(
"Portal Updated"
))
assertDOMElement(dom.document.body.querySelector(".portal-content"),
assertDOMElement(document.body.querySelector(".portal-content"),
<.div(^("class") := "portal-content")(
"Portal Updated"
)
)

//when & then
domRender(<(ReactPortalDemo())(^.wrapped := ReactPortalDemoProps(show = false))())
dom.document.body.querySelectorAll(".portal-content").length shouldBe 0
document.body.querySelectorAll(".portal-content").length shouldBe 0
}

it should "render several portals" in {
Expand Down Expand Up @@ -81,20 +81,20 @@ class ReactPortalDemoSpec extends TestSpec with TestDOMUtils {

assertDOMElement(domContainer, <.div()())

val portals = dom.document.body.querySelectorAll(".portal-content")
assertDOMElement(portals.item(0).asInstanceOf[dom.Element],
val portals = document.body.querySelectorAll(".portal-content")
assertDOMElement(portals.item(0).asInstanceOf[Element],
<.div(^("class") := "portal-content")(
"Portal 1"
)
)
assertDOMElement(portals.item(1).asInstanceOf[dom.Element],
assertDOMElement(portals.item(1).asInstanceOf[Element],
<.div(^("class") := "portal-content")(
"Portal 2"
)
)

//when & then
domRender(<(comp())(^.wrapped := Tuple2(false, false))())
dom.document.body.querySelectorAll(".portal-content").length shouldBe 0
document.body.querySelectorAll(".portal-content").length shouldBe 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package scommons.react.showcase.hooks

import scommons.react._
import scommons.react.showcase.hooks.UseContextDemoApp._
import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.raw.{ShallowInstance, TestRenderer}
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

class UseContextDemoSpec extends TestSpec
with TestDOMUtils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package scommons.react.showcase.hooks

import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.raw.TestRenderer
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

class UseEffectDemoSpec extends TestSpec
with TestDOMUtils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package scommons.react.showcase.hooks

import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.raw.TestRenderer
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

class UseLayoutEffectDemoSpec extends TestSpec
with TestDOMUtils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package scommons.react.showcase.hooks

import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

class UseMemoDemoSpec extends TestSpec
with TestDOMUtils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package scommons.react.showcase.hooks

import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

class UseReducerDemoSpec extends TestSpec
with TestDOMUtils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package scommons.react.showcase.hooks

import org.scalajs.dom
import org.scalajs.dom.document
import scommons.react._
import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

class UseRefDemoSpec extends TestSpec
with TestDOMUtils
Expand All @@ -30,14 +29,14 @@ class UseRefDemoSpec extends TestSpec
domRender(<(UseRefDemo())()())

val button = domContainer.querySelector("button")
dom.document.hasFocus() shouldBe false
document.hasFocus() shouldBe false

//when
fireDomEvent(Simulate.click(button))

//then
domContainer.querySelector("input") shouldBe dom.document.activeElement
dom.document.hasFocus() shouldBe true
domContainer.querySelector("input") shouldBe document.activeElement
document.hasFocus() shouldBe true
}

it should "shallow render component" in {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package scommons.react.showcase.hooks

import scommons.react.test.TestSpec
import scommons.react.test.dom.util.TestDOMUtils
import scommons.react.test.util.{ShallowRendererUtils, TestRendererUtils}
import scommons.react.test._
import scommons.react.test.dom._

class UseStateDemoSpec extends TestSpec
with TestDOMUtils
Expand Down
8 changes: 8 additions & 0 deletions test-dom/src/main/scala/scommons/react/test/dom/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package scommons.react.test

package object dom {

lazy val ReactTestUtils = dom.raw.ReactTestUtils
lazy val TestReactDOM = dom.raw.TestReactDOM
type TestDOMUtils = dom.util.TestDOMUtils
}
11 changes: 11 additions & 0 deletions test/src/main/scala/scommons/react/test/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package scommons.react

package object test {

type ShallowInstance = test.raw.ShallowInstance
type ShallowRendererUtils = test.util.ShallowRendererUtils

lazy val TestRenderer = test.raw.TestRenderer
type TestInstance = test.raw.TestInstance
type TestRendererUtils = test.util.TestRendererUtils
}

0 comments on commit 297ada5

Please sign in to comment.