From b0ce2ec22790632fc13405b310d46c460abbae81 Mon Sep 17 00:00:00 2001 From: RoB Murdock Date: Mon, 24 Jul 2023 18:05:56 -0400 Subject: [PATCH] looks like correct use of 'act' should entirely eliminate the need to use 'waitFor', so we're removing it and things work happy --- .../client/components/PrepareSpinTest.kt | 61 ++++++++----------- .../client/components/StubDispatcher.kt | 11 +++- .../CurrentPairAssignmentsPanelTest.kt | 15 ++--- .../pairassignments/PairAssignmentRowTest.kt | 2 +- .../components/party/PartyConfigTest.kt | 30 ++++----- .../components/pin/PinConfigEditorTest.kt | 12 ++-- .../components/player/PlayerConfigTest.kt | 21 +++---- .../slack/SlackConnectPageContentTest.kt | 3 +- 8 files changed, 67 insertions(+), 88 deletions(-) diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/PrepareSpinTest.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/PrepareSpinTest.kt index 1abf021670..daeccc5275 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/PrepareSpinTest.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/PrepareSpinTest.kt @@ -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 @@ -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 @@ -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 @@ -162,11 +157,9 @@ class PrepareSpinTest { } } } verify { - waitFor { - screen.getByText("Spin!") - .attributes["disabled"] - .assertIsNotEqualTo(null) - } + screen.getByText("Spin!") + .attributes["disabled"] + .assertIsNotEqualTo(null) } @Test @@ -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 @@ -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")) } } diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/StubDispatcher.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/StubDispatcher.kt index 46a387db9b..ce66aac6d1 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/StubDispatcher.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/StubDispatcher.kt @@ -7,9 +7,14 @@ import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.receiveAsFlow -class StubDispatcher { - val receivedActions = mutableListOf() - fun synchFunc() = stubDispatchFunc(StubCannon.Synchronous(receivedActions)) +object StubDispatcher { + + operator fun invoke() = SynchronousStubDispatcher() + + class SynchronousStubDispatcher { + val receivedActions = mutableListOf() + fun func() = stubDispatchFunc(StubCannon.Synchronous(receivedActions)) + } class Channel { val resultChannel = Channel() diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanelTest.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanelTest.kt index 4dff01eaf3..e5c11b36a4 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanelTest.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/CurrentPairAssignmentsPanelTest.kt @@ -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 @@ -54,7 +53,7 @@ class CurrentPairAssignmentsPanelTest { pairAssignments, setPairAssignments = { }, allowSave = true, - dispatchFunc = stubDispatcher.synchFunc(), + dispatchFunc = stubDispatcher.func(), ) }, ), @@ -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 @@ -108,9 +105,7 @@ class CurrentPairAssignmentsPanelTest { } verify { receivedAction -> receivedAction .assertIsEqualTo(DeletePairAssignmentsCommand(party.id, pairAssignments.id)) - waitFor { - screen.getByText("current pairs") - } + screen.getByText("current pairs") } } diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRowTest.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRowTest.kt index e8f0dcc985..10cfee271b 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRowTest.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pairassignments/PairAssignmentRowTest.kt @@ -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 }, diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/party/PartyConfigTest.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/party/PartyConfigTest.kt index ccf668fe86..c4d7762f3c 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/party/PartyConfigTest.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/party/PartyConfigTest.kt @@ -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 @@ -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 @@ -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() - .first() - .party.id.value.run { - assertIsNotEqualTo("") - assertIsEqualTo(automatedPartyId) - } - } + stubDispatcher.receivedActions + .filterIsInstance() + .first() + .party.id.value.run { + assertIsNotEqualTo("") + assertIsEqualTo(automatedPartyId) + } screen.getByLabelText("Unique Id").let { it as? HTMLInputElement }?.value .assertIsEqualTo(automatedPartyId) } diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pin/PinConfigEditorTest.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pin/PinConfigEditorTest.kt index 897ffe4e3c..62a5d27e10 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pin/PinConfigEditorTest.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/pin/PinConfigEditorTest.kt @@ -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 @@ -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)))) } } diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/player/PlayerConfigTest.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/player/PlayerConfigTest.kt index 6496b88895..ef9e12de3d 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/player/PlayerConfigTest.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/player/PlayerConfigTest.kt @@ -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 @@ -54,7 +53,7 @@ class PlayerConfigTest { player = player, players = emptyList(), reload = {}, - dispatchFunc = stubDispatcher.synchFunc(), + dispatchFunc = stubDispatcher.func(), ) } }, @@ -87,7 +86,7 @@ class PlayerConfigTest { player = player, players = emptyList(), reload = {}, - dispatchFunc = altStubDispatcher.synchFunc(), + dispatchFunc = altStubDispatcher.func(), ) } }, @@ -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 @@ -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 @@ -235,7 +232,7 @@ class PlayerConfigTest { player = player, players = emptyList(), reload = { }, - dispatchFunc = stubDispatcher.synchFunc(), + dispatchFunc = stubDispatcher.func(), windowFuncs = windowFunctions, ) } diff --git a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt index d16413e348..ff5233f7a5 100644 --- a/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt +++ b/client/components/src/jsTest/kotlin/com/zegreatrob/coupling/client/components/slack/SlackConnectPageContentTest.kt @@ -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 @@ -61,7 +60,7 @@ class SlackConnectPageContentTest { channel = slackChannel, ), ) - waitFor { returnButton.assertIsNotEqualTo(null) } + returnButton.assertIsNotEqualTo(null) } @Test