Skip to content

Commit 65321b9

Browse files
Removed unused react test utils methods
1 parent 0cc90ab commit 65321b9

File tree

5 files changed

+17
-41
lines changed

5 files changed

+17
-41
lines changed

test/src/main/scala/scommons/react/test/util/RendererUtils.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package scommons.react.test.util
22

3-
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
43
import io.github.shogowada.scalajs.reactjs.elements.ReactElement
54
import org.scalactic.source.Position
65
import org.scalatest.{Assertion, Matchers, Succeeded}
@@ -32,20 +31,21 @@ sealed trait RendererUtils[Instance <: RenderedInstance] extends Matchers {
3231
}
3332

3433
def findProps[T](renderedComp: Instance, searchComp: UiComponent[T]): List[T] = {
35-
findComponents(renderedComp, searchComp.apply()).map(getComponentProps[T])
34+
def getComponentProps(component: Instance): T = {
35+
component.props.wrapped.asInstanceOf[T]
36+
}
37+
38+
findComponents(renderedComp, searchComp.apply()).map(getComponentProps)
3639
}
3740

38-
def getComponentProps[T](component: Instance): T = component.props.wrapped.asInstanceOf[T]
39-
40-
def findComponents(component: Instance,
41-
componentClass: ReactClass): List[Instance] = {
41+
def findComponents(component: Instance, componentType: Any): List[Instance] = {
4242

4343
def search(components: List[Instance],
4444
result: ListBuffer[Instance]): Unit = components match {
4545

4646
case Nil =>
4747
case head :: tail =>
48-
if (head.`type` == componentClass) {
48+
if (head.`type` == componentType) {
4949
result += head
5050
}
5151

test/src/main/scala/scommons/react/test/util/ShallowRendererUtils.scala

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package scommons.react.test.util
22

3-
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
43
import io.github.shogowada.scalajs.reactjs.elements.ReactElement
54
import org.scalactic.source.Position
65
import org.scalatest.Assertion
@@ -13,14 +12,11 @@ trait ShallowRendererUtils {
1312
def createRenderer(): ShallowRenderer = new ShallowRenderer
1413

1514
def shallowRender(element: ReactElement): ShallowInstance = {
16-
shallowRender(createRenderer(), element)
17-
}
18-
19-
def shallowRender(renderer: ShallowRenderer, element: ReactElement): ShallowInstance = {
15+
val renderer = createRenderer()
2016
renderer.render(element)
2117
renderer.getRenderOutput()
2218
}
23-
19+
2420
def findComponentProps[T](renderedComp: ShallowInstance,
2521
searchComp: UiComponent[T])(implicit pos: Position): T = {
2622

@@ -31,12 +27,8 @@ trait ShallowRendererUtils {
3127
utils.findProps(renderedComp, searchComp)
3228
}
3329

34-
def getComponentProps[T](component: ShallowInstance): T = {
35-
utils.getComponentProps(component)
36-
}
37-
38-
def findComponents(component: ShallowInstance, componentClass: ReactClass): List[ShallowInstance] = {
39-
utils.findComponents(component, componentClass)
30+
def findComponents(component: ShallowInstance, componentType: Any): List[ShallowInstance] = {
31+
utils.findComponents(component, componentType)
4032
}
4133

4234
def assertComponent[T](result: ShallowInstance, expectedComp: UiComponent[T])

test/src/main/scala/scommons/react/test/util/TestRendererUtils.scala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package scommons.react.test.util
22

3-
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
43
import io.github.shogowada.scalajs.reactjs.elements.ReactElement
54
import org.scalactic.source.Position
65
import org.scalatest.{Assertion, Succeeded}
@@ -47,12 +46,8 @@ trait TestRendererUtils {
4746
utils.findProps(renderedComp, searchComp)
4847
}
4948

50-
def getComponentProps[T](component: TestInstance): T = {
51-
utils.getComponentProps(component)
52-
}
53-
54-
def findComponents(component: TestInstance, componentClass: ReactClass): List[TestInstance] = {
55-
utils.findComponents(component, componentClass)
49+
def findComponents(component: TestInstance, componentType: Any): List[TestInstance] = {
50+
utils.findComponents(component, componentType)
5651
}
5752

5853
def assertTestComponent[T](result: TestInstance, expectedComp: UiComponent[T])

test/src/test/scala/scommons/react/test/util/RendererUtilsSpec.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ abstract class RendererUtilsSpec[Instance <: RenderedInstance] extends TestSpec
1818

1919
def findComponentProps[T](renderedComp: Instance, searchComp: UiComponent[T])(implicit pos: Position): T
2020
def findProps[T](renderedComp: Instance, searchComp: UiComponent[T]): List[T]
21-
def getComponentProps[T](component: Instance): T
22-
def findComponents(component: Instance, componentClass: ReactClass): List[Instance]
21+
def findComponents(component: Instance, componentType: Any): List[Instance]
2322
def assertNativeComponent(result: Instance, expectedElement: ReactElement)(implicit pos: Position): Assertion
2423

2524
it should "fail if comp not found when findComponentProps" in {
@@ -78,7 +77,9 @@ abstract class RendererUtilsSpec[Instance <: RenderedInstance] extends TestSpec
7877
val results = findComponents(comp, TestComp())
7978

8079
//then
81-
results.map(getComponentProps[Comp1Props]) shouldBe List(Comp1Props(1), Comp1Props(2))
80+
results.map(p => p.props.wrapped.asInstanceOf[Comp1Props]) shouldBe {
81+
List(Comp1Props(1), Comp1Props(2))
82+
}
8283
}
8384

8485
it should "fail if array attribute doesn't match when assertNativeComponent" in {

test/src/test/scala/scommons/react/test/util/TestRendererUtilsSpec.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,6 @@ class TestRendererUtilsSpec extends RendererUtilsSpec[TestInstance]
5656
})
5757
}
5858

59-
it should "return wrapped props when getComponentProps" in {
60-
//given
61-
val props = Comp1Props(1)
62-
val root = createTestRenderer(<(TestComp())(^.wrapped := props)("test1 child")).root
63-
64-
//when
65-
val result = getComponentProps[Comp1Props](root)
66-
67-
//then
68-
result shouldBe props
69-
}
70-
7159
it should "not fail if non-empty when assertTestComponent" in {
7260
//given
7361
val comp = testRender(<(comp2Class)(^.wrapped := Comp2Props(true))())

0 commit comments

Comments
 (0)