Skip to content

Commit

Permalink
looks like correct use of 'act' should entirely eliminate the need to…
Browse files Browse the repository at this point in the history
… use 'waitFor', so we're removing it and things work happy
  • Loading branch information
robertfmurdock committed Jul 24, 2023
1 parent 0bf23fa commit b0ce2ec
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.zegreatrob.testmints.async.asyncTestTemplate
import com.zegreatrob.testmints.setup
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.render
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.waitFor
import com.zegreatrob.wrapper.testinglibrary.userevent.UserEvent
import js.core.jso
import kotlinx.datetime.Clock
Expand Down Expand Up @@ -67,14 +66,12 @@ class PrepareSpinTest {
?.firstOrNull(),
)
} verify {
waitFor {
wrapper.container.querySelector(".$deselectedPinsClass")
?.querySelectorAll("[data-pin-button='${firstPin.id}']")
?.asList()
?.map { it as? HTMLElement }
?.firstOrNull()
.assertIsNotEqualTo(null)
}
wrapper.container.querySelector(".$deselectedPinsClass")
?.querySelectorAll("[data-pin-button='${firstPin.id}']")
?.asList()
?.map { it as? HTMLElement }
?.firstOrNull()
.assertIsNotEqualTo(null)
}

@Test
Expand Down Expand Up @@ -104,14 +101,12 @@ class PrepareSpinTest {
?.first(),
)
} verify {
waitFor {
render.container.querySelector(".$selectedPinsClass")
?.querySelectorAll("[data-pin-button='${firstPin.id}']")
?.asList()
?.map { it as? HTMLElement }
?.firstOrNull()
.assertIsNotEqualTo(null)
}
render.container.querySelector(".$selectedPinsClass")
?.querySelectorAll("[data-pin-button='${firstPin.id}']")
?.asList()
?.map { it as? HTMLElement }
?.firstOrNull()
.assertIsNotEqualTo(null)
}

@Test
Expand Down Expand Up @@ -162,11 +157,9 @@ class PrepareSpinTest {
}
}
} verify {
waitFor {
screen.getByText("Spin!")
.attributes["disabled"]
.assertIsNotEqualTo(null)
}
screen.getByText("Spin!")
.attributes["disabled"]
.assertIsNotEqualTo(null)
}

@Test
Expand All @@ -181,13 +174,11 @@ class PrepareSpinTest {
}) exercise {
user.click(screen.getByText("All in!"))
} verify {
waitFor {
context.baseElement.querySelectorAll("[data-player-id]")
.asList()
.mapNotNull { it as? HTMLElement }
.map { it.getAttribute("data-selected") }
.assertIsEqualTo(listOf("true", "true", "true"))
}
context.baseElement.querySelectorAll("[data-player-id]")
.asList()
.mapNotNull { it as? HTMLElement }
.map { it.getAttribute("data-selected") }
.assertIsEqualTo(listOf("true", "true", "true"))
}

@Test
Expand All @@ -207,12 +198,10 @@ class PrepareSpinTest {
} exercise {
user.click(screen.getByText("All out!"))
} verify {
waitFor {
context.baseElement.querySelectorAll("[data-player-id]")
.asList()
.mapNotNull { it as? HTMLElement }
.map { it.getAttribute("data-selected") }
.assertIsEqualTo(listOf("false", "false", "false"))
}
context.baseElement.querySelectorAll("[data-player-id]")
.asList()
.mapNotNull { it as? HTMLElement }
.map { it.getAttribute("data-selected") }
.assertIsEqualTo(listOf("false", "false", "false"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.receiveAsFlow

class StubDispatcher {
val receivedActions = mutableListOf<Any?>()
fun <T> synchFunc() = stubDispatchFunc<T>(StubCannon.Synchronous(receivedActions))
object StubDispatcher {

operator fun invoke() = SynchronousStubDispatcher()

class SynchronousStubDispatcher {
val receivedActions = mutableListOf<Any?>()
fun <T> func() = stubDispatchFunc<T>(StubCannon.Synchronous(receivedActions))
}

class Channel {
val resultChannel = Channel<Any?>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.zegreatrob.testmints.async.asyncSetup
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.act
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.render
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.waitFor
import com.zegreatrob.wrapper.testinglibrary.userevent.UserEvent
import js.core.jso
import kotlinx.datetime.Clock
Expand Down Expand Up @@ -54,7 +53,7 @@ class CurrentPairAssignmentsPanelTest {
pairAssignments,
setPairAssignments = { },
allowSave = true,
dispatchFunc = stubDispatcher.synchFunc(),
dispatchFunc = stubDispatcher.func(),
)
},
),
Expand All @@ -64,11 +63,9 @@ class CurrentPairAssignmentsPanelTest {
} exercise {
actor.click(screen.getByText("Save!"))
} verify {
waitFor {
stubDispatcher.receivedActions.size
.assertIsEqualTo(0)
screen.getByText("current pairs")
}
stubDispatcher.receivedActions.size
.assertIsEqualTo(0)
screen.getByText("current pairs")
}

@Test
Expand Down Expand Up @@ -108,9 +105,7 @@ class CurrentPairAssignmentsPanelTest {
} verify { receivedAction ->
receivedAction
.assertIsEqualTo(DeletePairAssignmentsCommand(party.id, pairAssignments.id))
waitFor {
screen.getByText("current pairs")
}
screen.getByText("current pairs")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PairAssignmentRowTest {
PairAssignmentRow.create(
party = party,
document = document,
controls = Controls(stubDispatcher.synchFunc(), reloadSpy::spyFunction),
controls = Controls(stubDispatcher.func(), reloadSpy::spyFunction),
windowFunctions = this,
),
jso { wrapper = MemoryRouter },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import com.zegreatrob.minassert.assertIsEqualTo
import com.zegreatrob.minassert.assertIsNotEqualTo
import com.zegreatrob.testmints.async.asyncSetup
import com.zegreatrob.wrapper.testinglibrary.react.RoleOptions
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.act
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.fireEvent
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.render
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.waitFor
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.within
import js.core.jso
import org.w3c.dom.HTMLInputElement
Expand Down Expand Up @@ -81,14 +81,12 @@ class PartyConfigTest {
)
} exercise {
fireEvent.submit(screen.getByRole("form"))
stubDispatcher.onActionReturn(VoidResult.Accepted)
act { stubDispatcher.onActionReturn(VoidResult.Accepted) }
} verify { action ->
action.assertIsEqualTo(SavePartyCommand(party))

waitFor {
screen.getByText("Parties!")
.assertNotNull()
}
screen.getByText("Parties!")
.assertNotNull()
}

@Test
Expand All @@ -97,21 +95,19 @@ class PartyConfigTest {
val stubDispatcher = StubDispatcher()
}) {
render(jso { wrapper = MemoryRouter }) {
PartyConfig(party, stubDispatcher.synchFunc())
PartyConfig(party, stubDispatcher.func())
}
} exercise {
screen.getByLabelText("Unique Id").let { it as? HTMLInputElement }?.value
.also { fireEvent.submit(screen.getByRole("form")) }
.also { act { fireEvent.submit(screen.getByRole("form")) } }
} verify { automatedPartyId ->
waitFor {
stubDispatcher.receivedActions
.filterIsInstance<SavePartyCommand>()
.first()
.party.id.value.run {
assertIsNotEqualTo("")
assertIsEqualTo(automatedPartyId)
}
}
stubDispatcher.receivedActions
.filterIsInstance<SavePartyCommand>()
.first()
.party.id.value.run {
assertIsNotEqualTo("")
assertIsEqualTo(automatedPartyId)
}
screen.getByLabelText("Unique Id").let { it as? HTMLInputElement }?.value
.assertIsEqualTo(automatedPartyId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import com.zegreatrob.coupling.model.pin.Pin
import com.zegreatrob.minassert.assertIsEqualTo
import com.zegreatrob.testmints.async.asyncSetup
import com.zegreatrob.testmints.setup
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.act
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.fireEvent
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.render
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.waitFor
import com.zegreatrob.wrapper.testinglibrary.userevent.UserEvent
import react.create
import react.router.RouterProvider
Expand Down Expand Up @@ -72,17 +72,15 @@ class PinConfigEditorTest {
}) {
render(
RouterProvider.create {
router = singleRouteRouter { PinConfig(party, pin, emptyList(), {}, stubDispatcher.synchFunc()) }
router = singleRouteRouter { PinConfig(party, pin, emptyList(), {}, stubDispatcher.func()) }
},
)
actor.type(screen.getByLabelText("Name"), newName)
actor.type(screen.getByLabelText("Icon"), newIcon)
} exercise {
fireEvent.submit(screen.getByRole("form"))
act { fireEvent.submit(screen.getByRole("form")) }
} verify {
waitFor {
stubDispatcher.receivedActions
.assertIsEqualTo(listOf(SavePinCommand(party.id, Pin(name = newName, icon = newIcon))))
}
stubDispatcher.receivedActions
.assertIsEqualTo(listOf(SavePinCommand(party.id, Pin(name = newName, icon = newIcon))))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.act
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.fireEvent
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.render
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.waitFor
import com.zegreatrob.wrapper.testinglibrary.userevent.UserEvent
import js.core.jso
import kotlinx.browser.window
Expand Down Expand Up @@ -54,7 +53,7 @@ class PlayerConfigTest {
player = player,
players = emptyList(),
reload = {},
dispatchFunc = stubDispatcher.synchFunc(),
dispatchFunc = stubDispatcher.func(),
)
}
},
Expand Down Expand Up @@ -87,7 +86,7 @@ class PlayerConfigTest {
player = player,
players = emptyList(),
reload = {},
dispatchFunc = altStubDispatcher.synchFunc(),
dispatchFunc = altStubDispatcher.func(),
)
}
},
Expand Down Expand Up @@ -163,10 +162,10 @@ class PlayerConfigTest {
actor.type(screen.getByLabelText("Name"), "nonsense")

fireEvent.submit(screen.getByRole("form"))
altStubDispatcher.onActionReturn(VoidResult.Accepted)
act { altStubDispatcher.onActionReturn(VoidResult.Accepted) }
} verify { action ->
action.assertIsEqualTo(SavePlayerCommand(party.id, player.copy(name = "nonsense")))
waitFor { reloaderSpy.callCount.assertIsEqualTo(1) }
reloaderSpy.callCount.assertIsEqualTo(1)
}

@Test
Expand Down Expand Up @@ -209,12 +208,10 @@ class PlayerConfigTest {
actor.click(screen.getByText("Retire"))
act { altStubDispatcher.onActionReturn(VoidResult.Accepted) }
} verify { action ->
waitFor {
action.assertIsEqualTo(DeletePlayerCommand(party.id, player.id))
pathSetterSpy.spyReceivedValues.contains(
"/${party.id.value}/pairAssignments/current/",
)
}
action.assertIsEqualTo(DeletePlayerCommand(party.id, player.id))
pathSetterSpy.spyReceivedValues.contains(
"/${party.id.value}/pairAssignments/current/",
)
}

@Test
Expand All @@ -235,7 +232,7 @@ class PlayerConfigTest {
player = player,
players = emptyList(),
reload = { },
dispatchFunc = stubDispatcher.synchFunc(),
dispatchFunc = stubDispatcher.func(),
windowFuncs = windowFunctions,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.zegreatrob.wrapper.testinglibrary.react.RoleOptions
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.act
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.render
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.screen
import com.zegreatrob.wrapper.testinglibrary.react.TestingLibraryReact.waitFor
import com.zegreatrob.wrapper.testinglibrary.userevent.UserEvent
import js.core.jso
import react.ReactNode
Expand Down Expand Up @@ -61,7 +60,7 @@ class SlackConnectPageContentTest {
channel = slackChannel,
),
)
waitFor { returnButton.assertIsNotEqualTo(null) }
returnButton.assertIsNotEqualTo(null)
}

@Test
Expand Down

0 comments on commit b0ce2ec

Please sign in to comment.