Skip to content

Commit

Permalink
Check if Test was successful
Browse files Browse the repository at this point in the history
  • Loading branch information
firefrorefiddle committed Jun 27, 2022
1 parent 95f4a6e commit 520592e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
3 changes: 3 additions & 0 deletions examples/Pkh2Pkh.purs
Expand Up @@ -33,6 +33,7 @@ import Contract.TxConstraints as Constraints
import Contract.Value as Value
import Contract.Wallet (mkNamiWalletAff)
import Data.BigInt as BigInt
import Examples.TestFeedback

main :: Effect Unit
main = launchAff_ $ do
Expand Down Expand Up @@ -66,3 +67,5 @@ main = launchAff_ $ do
liftedM "Failed to balance/sign tx" $ balanceAndSignTx ubTx
txId <- submit bsTx.signedTxCbor
logInfo' $ "Tx ID: " <> show txId

liftAff $ publishTestFeedback true
13 changes: 13 additions & 0 deletions examples/TestFeedback.js
@@ -0,0 +1,13 @@
exports._publishTestFeedback = value => () => window.ctlTestFeedback = value;

exports._retrieveTestFeedback = nothing => mkJust => () => {
console.log("test");
if(typeof(window.ctlTestFeedback) === 'undefined') {
console.log("1");
return nothing;
}
else {
console.log("2");
return mkJust(ctlTestFeedback);
}
}
18 changes: 12 additions & 6 deletions test/E2E/Helpers.purs
Expand Up @@ -18,22 +18,25 @@ module Test.E2E.Helpers
, testPassword
, reactSetValue
, retrieveJQuery
, testFeedbackIsTrue
, Selector(..)
, Action(..)
, NoShowPage(..)
) where

import Toppokki as Toki
import Prelude

import Control.Promise (Promise, toAffE, toAff)
import Control.Monad (join)
import Data.Array (head, filterA)
import Data.Maybe (Maybe)
import Data.Newtype (class Newtype, wrap, unwrap)
import Data.Traversable (for, fold)
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class.Console (log)
import Effect (Effect)
import Data.Maybe (Maybe)
import Foreign (Foreign, unsafeFromForeign)
import Prelude
import Control.Promise (Promise, toAffE)
import Data.Traversable (for, fold)
import Toppokki as Toki

foreign import _retrieveJQuery :: Toki.Page -> Effect (Promise String)

Expand All @@ -55,6 +58,9 @@ findNamiPage browser = do
pages' <- filterA (hasSelector button) pages
pure $ head $ pages'

testFeedbackIsTrue :: Toki.Page -> Aff Boolean
testFeedbackIsTrue page = unsafeFromForeign <$> Toki.unsafeEvaluateStringFunction "window.ctlTestFeedback" page

-- | Wrapper for Page so it can be used in `shouldSatisfy`, which needs 'Show'
-- | Doesn't show anything, thus 'NoShow'
newtype NoShowPage = NoShowPage Toki.Page
Expand Down
29 changes: 13 additions & 16 deletions test/Examples/Pkh2Pkh.purs
@@ -1,27 +1,20 @@
module Test.Examples.Pkh2Pkh where

import Effect.Aff (delay)
import Mote (test)
import Examples.TestFeedback
import Prelude
import Test.E2E.Wallet (Mode(..), launchWithNami)
import TestM (TestPlanM)

import Effect.Class (liftEffect)
import Effect.Exception (throw)
import Data.Maybe (isJust, Maybe(..))
import Data.Newtype (wrap)
import Test.E2E.Helpers
( clickButton
, findNamiPage
, injectJQueryAll
, password
, testPassword
, reactSetValue
, retrieveJQuery
, NoShowPage(NoShowPage)
)
import Effect.Aff (delay)
import Effect.Class (liftEffect)
import Effect.Exception (throw)
import Foreign (unsafeFromForeign)
import Mote (test)
import Test.E2E.Helpers (NoShowPage(NoShowPage), clickButton, findNamiPage, injectJQueryAll, password, reactSetValue, retrieveJQuery, testFeedbackIsTrue, testPassword)
import Test.E2E.Wallet (Mode(..), launchWithNami)
import Test.Spec.Assertions (shouldSatisfy)
import Test.Toppoki (example)
import TestM (TestPlanM)
import Toppokki as Toki

testPkh2Pkh :: TestPlanM Unit
Expand All @@ -43,4 +36,8 @@ testPkh2Pkh = test "Pkh2Pkh" do
clickButton "Sign" np
reactSetValue password testPassword np
clickButton "Confirm" np
delay (wrap 1000.0)
delay (wrap 500.0)
feedback <- testFeedbackIsTrue page
shouldSatisfy feedback (_ == true)

0 comments on commit 520592e

Please sign in to comment.