From 046b2ccaec11bcf7caf7d621d540e99ac472efed Mon Sep 17 00:00:00 2001 From: Larry Adames Date: Mon, 23 Oct 2023 14:53:42 -0400 Subject: [PATCH] PLT-7826 finish choice contract test --- e2e/config/mappings/page-elements/home.json | 3 +- e2e/src/features/apply-inputs.feature | 44 +++++++++--- e2e/src/step-definitions/generate-contract.ts | 71 ++++++++++++++++--- src/Component/ApplyInputs.purs | 3 +- .../StatlessFormSpecBuilders.purs | 9 +++ 5 files changed, 107 insertions(+), 23 deletions(-) diff --git a/e2e/config/mappings/page-elements/home.json b/e2e/config/mappings/page-elements/home.json index b9ddcd94..31fc5f37 100644 --- a/e2e/config/mappings/page-elements/home.json +++ b/e2e/config/mappings/page-elements/home.json @@ -1,3 +1,4 @@ { - "contract-input": {"role": "textbox", "name": "contract-input" } + "contract-input": {"role": "textbox", "name": "contract-input" }, + "choice-input": {"role": "spinbutton", "name": "choice-input" } } \ No newline at end of file diff --git a/e2e/src/features/apply-inputs.feature b/e2e/src/features/apply-inputs.feature index 27a1881c..d3de2ac0 100644 --- a/e2e/src/features/apply-inputs.feature +++ b/e2e/src/features/apply-inputs.feature @@ -6,7 +6,6 @@ Feature: As a user, I would like to apply an input on a current contract As a user I would like to apply an input on a current contract So that I can proceed through the contract - @dev Scenario: Creating a deposit with a Lace wallet Given I configure my lace wallet And I am on the "home" page @@ -30,32 +29,57 @@ Feature: As a user, I would like to apply an input on a current contract When I click the "checkbox" with "Deposit 0.000001 ₳" text And I click the "button" with "Make deposit" text And sign the transaction And I should see "Successfully applied the inputs. Input application transaction awaits to be included in the blockchain." text - And I pause the page Scenario: Creating a choice with a Lace wallet - Given I am on the "home" page - When I authorize my "lace" wallet + Given I configure my lace wallet + And I am on the "home" page + Then I should see a "heading" with "Choose a wallet" text + + When I authorize my lace wallet Then I should see a "button" with "Create a contract" text When I click the "button" with "Create a contract" text - And I enter the contents of "../support/contracts/lace-10-2024/choice.json" into the "contract-input" field + And I generate the contract "SimpleChoice" and write it to "/tmp/choice.json" + And I enter the contents of "/tmp/choice.json" into the "contract-input" field When I click the "button" with "Submit contract" text And sign the transaction - Then I should see a "button" with "Syncing" text + Then I should see the first "button" showing "Syncing" text + And I should see the first "button" showing "Advance" text And I should see "Successfully created and submitted the contract. Contract transaction awaits to be included in the blockchain." text - Scenario: Creating a notify contract with a Lace wallet + When I click the first "button" with "Advance" text + Then I should see a "button" with "Advance contract" text + + When I fill in the "choice-input" input with "1" + When I click the "button" with "Advance contract" text And sign the transaction + Then I should see the first "button" showing "Syncing" text + And I should see the first "button" showing "Advance" text + And I should see "Successfully applied the inputs. Input application transaction awaits to be included in the blockchain." text + + @dev + Scenario: Creating a timed-out contract with a Lace wallet + Given I configure my lace wallet Given I am on the "home" page - When I authorize my "lace" wallet + Then I should see a "heading" with "Choose a wallet" text + + When I authorize my lace wallet Then I should see a "button" with "Create a contract" text When I click the "button" with "Create a contract" text - And I enter the contents of "../support/contracts/lace-10-2024/notify.json" into the "contract-input" field + And I generate the contract "TimedOutSimpleChoice" and write it to "/tmp/timed-out-choice.json" + And I enter the contents of "/tmp/timed-out-choice.json" into the "contract-input" field When I click the "button" with "Submit contract" text And sign the transaction - Then I should see a "button" with "Syncing" text + Then I should see the first "button" showing "Syncing" text + And I should see the first "button" showing "Advance" text And I should see "Successfully created and submitted the contract. Contract transaction awaits to be included in the blockchain." text + When I click the first "button" with "Advance" text + Then I should see a "button" with "Advance contract" text + And I pause the page + + + # Scenario: Creating a notify contract with a Lace wallet # Given I am on the "home" page # When I authorize my "lace" wallet diff --git a/e2e/src/step-definitions/generate-contract.ts b/e2e/src/step-definitions/generate-contract.ts index ae0bb3a9..8f963ee0 100644 --- a/e2e/src/step-definitions/generate-contract.ts +++ b/e2e/src/step-definitions/generate-contract.ts @@ -1,20 +1,12 @@ -import playwright from 'playwright'; -import * as fs from 'fs'; import { When } from '@cucumber/cucumber'; import { ScenarioWorld } from './setup/world.js'; -import { ValidAccessibilityRoles } from '../env/global.js'; -import { waitFor } from "../support/wait-for-behavior.js"; import { - inputValue, -} from '../support/html-behavior.js'; -import { - Address, Contract, datetoTimeout, } from "@marlowe.io/language-core-v1"; import { MarloweJSON } from "@marlowe.io/adapter/codec"; -type ContractName = "SimpleDeposit"; +type ContractName = "SimpleDeposit" | "SimpleChoice" | "TimedOutSimpleChoice"; const mkSimpleDeposit = (address: string): Contract => { const twentyMinutesInMilliseconds = 20 * 60 * 1000; @@ -35,6 +27,55 @@ const mkSimpleDeposit = (address: string): Contract => { }; } +const mkSimpleChoice = (address: string): Contract => { + const twentyMinutesInMilliseconds = 20 * 60 * 1000; + const inTwentyMinutes = datetoTimeout(new Date(Date.now() + twentyMinutesInMilliseconds)); + return { + timeout: inTwentyMinutes, + timeout_continuation: "close", + when: [ + { case: { + choose_between: + [{ + from: 1n, + to: 2n + }], + for_choice: { + choice_owner: {address: address}, + choice_name: "simpleChoice", + } + }, + then: "close", + }, + ] + }; +} + +const mkTimedOutSimpleChoice = (address: string): Contract => { + const twentyMinutesInMilliseconds = 20 * 60 * 1000; + const inTwentyMinutes = datetoTimeout(new Date(Date.now() - twentyMinutesInMilliseconds)); + return { + timeout: inTwentyMinutes, + timeout_continuation: "close", + when: [ + { case: { + choose_between: + [{ + from: 1n, + to: 2n + }], + for_choice: { + choice_owner: {address: address}, + choice_name: "simpleChoice", + } + }, + then: "close", + }, + ] + }; +} + + // // And I generate the contract "SimpleDeposit" and write it to "/tmp/deposit.json" When( /^I generate the contract "([^"]*)" and write it to "([^"]*)"/, @@ -45,8 +86,16 @@ When( const walletAddress = globalStateManager.getValue("wallet-address"); switch (contractName) { case "SimpleDeposit": - const contract = mkSimpleDeposit(walletAddress); - globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract, null, 4)) + const contract1 = mkSimpleDeposit(walletAddress); + globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract1, null, 4)) + break; + case "SimpleChoice": + const contract2 = mkSimpleChoice(walletAddress); + globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract2, null, 4)) + break; + case "TimedOutSimpleChoice": + const contract3 = mkTimedOutSimpleChoice(walletAddress); + globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract3, null, 4)) break; } } diff --git a/src/Component/ApplyInputs.purs b/src/Component/ApplyInputs.purs index 2f0847e4..b18adb0c 100644 --- a/src/Component/ApplyInputs.purs +++ b/src/Component/ApplyInputs.purs @@ -41,6 +41,7 @@ import Data.Maybe (Maybe(..)) import Data.Monoid as Monoid import Data.Time.Duration (Milliseconds(..), Seconds(..)) import Data.Traversable (for) +import Data.Undefined.NoProblem as NoProblem import Data.Validation.Semigroup (V(..)) import Effect (Effect) import Effect.Aff (Aff) @@ -254,7 +255,7 @@ mkChoiceFormComponent = do formSpec = evalBuilder' $ ado choice <- choiceField { choices, validator, touched: true, initial: "0" } - value <- intInput {} + value <- intInput { role: NoProblem.opt "textarea", "aria-label": NoProblem.opt "choice-input" } in { choice, value } diff --git a/src/Contrib/ReactBootstrap/FormSpecBuilders/StatlessFormSpecBuilders.purs b/src/Contrib/ReactBootstrap/FormSpecBuilders/StatlessFormSpecBuilders.purs index 0b6d8af4..1ec914e3 100644 --- a/src/Contrib/ReactBootstrap/FormSpecBuilders/StatlessFormSpecBuilders.purs +++ b/src/Contrib/ReactBootstrap/FormSpecBuilders/StatlessFormSpecBuilders.purs @@ -256,6 +256,9 @@ renderTextInput , max :: Opt Number , min :: Opt Number , step :: Opt Number + , role :: Opt String + , "aria-label" :: Opt String + , "aria-labelledby" :: Opt String } -> InputState String -> JSX @@ -292,6 +295,9 @@ renderTextInput , step: props.step , min: props.min , max: props.max + , role: props.role + , "aria-label": props."aria-label" + , "aria-labelledby": props."aria-labelledby" } case layout of Inline -> case possibleHelpText of @@ -342,6 +348,9 @@ textInput props = formSpecBuilderT do , min: props'.min , sizing: props'.sizing , step: props'.step + , role: props'.role + , "aria-label": props'."aria-label" + , "aria-labelledby": props'."aria-labelledby" } ) props'.touched