Skip to content

Commit

Permalink
PLT-7826 finish deposit contract test
Browse files Browse the repository at this point in the history
  • Loading branch information
ladamesny committed Oct 23, 2023
1 parent f7e57b4 commit 6bbbbdc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2,746 deletions.
9 changes: 4 additions & 5 deletions e2e/src/features/apply-inputs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ Feature: As a user, I would like to apply an input on a current contract
When I click the "button" with "Create a contract" text
And I generate the contract "SimpleDeposit" and write it to "/tmp/deposit.json"
And I enter the contents of "/tmp/deposit.json" into the "contract-input" field
# # And I enter the contents of "../support/contracts/lace-10-2024/deposit.json" into the "contract-input" field
# Then I pause the page

# When I click the "button" with "Submit contract" text And sign the transaction
# Then I should see a "button" with "Syncing" 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 "button" with "Submit 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 created and submitted the contract. Contract transaction awaits to be included in the blockchain." text

Scenario: Creating a choice with a Lace wallet
Given I am on the "home" page
Expand Down
11 changes: 4 additions & 7 deletions e2e/src/step-definitions/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,19 @@ When('I press {string} on the keyboard {string} times', async function (this: Sc
});

When('I enter the contents of {string} into the {string} field',
async function (this: ScenarioWorld, fileNameAndPath: string, name: string) {
async function (this: ScenarioWorld, fileName: string, name: string) {
const {
screen: { page },
globalConfig
globalConfig,
globalStateManager
} = this;

const filePath = path.join(__dirname, fileNameAndPath);
const input = fs.readFileSync(filePath, 'utf-8');

console.log("INPUT", input);

const role = "textbox";

await waitFor(async() => {
const locator = await page.getByRole(role as ValidAccessibilityRoles, { name })
const result = await locator.isVisible();
const input = globalStateManager.getValue(fileName)

if (result) {
await inputValue(locator, input);
Expand Down
137 changes: 6 additions & 131 deletions e2e/src/step-definitions/generate-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ import { MarloweJSON } from "@marlowe.io/adapter/codec";

type ContractName = "SimpleDeposit";

const mkSimpleDeposit = (address: Address): Contract => {
const mkSimpleDeposit = (address: string): Contract => {
const twentyMinutesInMilliseconds = 20 * 60 * 1000;
const inTwentyMinutes = datetoTimeout(new Date(Date.now() + twentyMinutesInMilliseconds));
return {
timeout: inTwentyMinutes,
timeout_continuation: "close",
when: [
{ case: {
party: address,
party: {address: address},
deposits: 1n,
of_token: { currency_symbol: "", token_name: "" },
into_account: address
into_account: {address: address}
},
then: "close",
},
Expand All @@ -42,137 +42,12 @@ When(
const {
globalStateManager
} = this;
const walletAddress = globalStateManager.getValue("wallet-address") as Address;
const walletAddress = globalStateManager.getValue("wallet-address");
switch (contractName) {
case "SimpleDeposit":
const contract = mkSimpleDeposit(walletAddress);
fs.writeFileSync(fileName, MarloweJSON.stringify(contract, null, 4));
globalStateManager.appendValue(fileName, MarloweJSON.stringify(contract, null, 4))
break;
}
}
);


When(
/^I click the "([^"]*)" with "([^"]*)" text And sign the transaction$/,
async function(this: ScenarioWorld, role: ValidAccessibilityRoles, name: string) {
const {
screen: { page },
globalStateManager
} = this;

let newPagePromise;

newPagePromise = new Promise(resolve => page.context().once('page', resolve));

await waitFor(async() => {
const locator = await page.getByRole(role, { name, exact: true });
const result = await locator.isVisible();
if (result) {
await locator.click();
return result;
}
});

// Await for new page to popup
const newPage = await newPagePromise as playwright.Page;

await waitFor(async() => {
await newPage.reload();
return true;
});

await waitFor(async() => {
const buttonName = "Confirm"
const locator = await newPage.getByRole("button", { name: buttonName, exact: true });
const result = await locator.isVisible();
if (result) {
await locator.click();
return result;
}
});

await waitFor(async() => {
// const locator = await page.getByRole(role as ValidAccessibilityRoles, { name })
// const locator = await newPage.getByRole("textbox", { name: "Password" })
const locator = await newPage.getByTestId("password-input")
const result = await locator.isVisible();

if (result) {
const password = process.env.LACE_WALLET_PASSWORD as string
await inputValue(locator, password);
return result;
}
});

await waitFor(async() => {
const buttonName = "Confirm"
const locator = await newPage.getByRole("button", { name: buttonName, exact: true });
const result = await locator.isVisible();
if (result) {
await locator.click();
return result;
}
});

await waitFor(async() => {
const buttonName = "Close"
const locator = await newPage.getByRole("button", { name: buttonName, exact: true });
const result = await locator.isVisible();
if (result) {
await locator.click();
return result;
}
});


}
);


When(
/^I click the new tab "link" with "([^"]*)" text$/,
async function(this: ScenarioWorld, name: string) {
const {
screen: { page },
globalStateManager
} = this;

let newPagePromise;

newPagePromise = new Promise(resolve => page.context().once('page', resolve));

await waitFor(async() => {
const locator = await page.getByRole("link", { name, exact: true });
const result = await locator.isVisible();
if (result) {
await locator.click();
return result;
}
});

// Await for new page to popup and store it in the global state manager
const newPage = await newPagePromise as playwright.Page;
globalStateManager.appendValue(name, newPage);
}
);



When(
/^I click the "([^"]*)" (?:button|link)$/,
async function(this: ScenarioWorld, name: string, role: ValidAccessibilityRoles) {
const {
screen: { page },
} = this;

await waitFor(async() => {
const locator = await page.getByRole(role, { name, exact: true });
const result = await locator.isVisible();
if (result) {
await locator.click();
return result;
}
});
}
)
);
Loading

0 comments on commit 6bbbbdc

Please sign in to comment.