Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
claireolmstead committed Oct 9, 2024
1 parent c88435e commit 3a310c8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 44 deletions.
13 changes: 8 additions & 5 deletions client/src/app.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/x-icon" href="%sveltekit.assets%/favicon-192.png" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<meta name="viewport" content="width=device-width" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet"
/>
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>

Expand Down
4 changes: 2 additions & 2 deletions client/src/lib/utils/networkData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const Paseo: NetworkData = {
};

export const Networks: { network: NetworkData; url: string }[] = [
{ network: Frequency, url: "/" },
{ network: Paseo, url: "https://faucet.polkadot.io/paseo" },
{ network: Frequency, url: "/" },
{ network: Paseo, url: "https://faucet.polkadot.io/paseo" }
];

export function getChainName(network: NetworkData, id: number): string | null {
Expand Down
66 changes: 36 additions & 30 deletions client/tests/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
type Frame,
type FullConfig,
type Locator,
type Page,
expect,
test, type ElementHandle, type Route
type Frame,
type FullConfig,
type Locator,
type Page,
expect,
test,
type ElementHandle,
type Route
} from "@playwright/test";

type FormSubmit = {
Expand All @@ -17,8 +19,10 @@ const getFormElements = async (page: Page, getCaptcha = false) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
let captcha: Locator = {} as Locator;
if (getCaptcha) {
const iframe = await page.locator('iframe[title="Widget containing checkbox for hCaptcha security challenge"]');
captcha = iframe.contentFrame().getByLabel('hCaptcha checkbox with text');
const iframe = await page.locator(
'iframe[title="Widget containing checkbox for hCaptcha security challenge"]'
);
captcha = iframe.contentFrame().getByLabel("hCaptcha checkbox with text");
}
return {
address: page.getByTestId("address"),
Expand Down Expand Up @@ -67,7 +71,7 @@ export class FaucetTests {
};

runTests(): void {
const validAddress = '5G3r2K1cEi4vtdBjMNHpjWCofRdyg2AFSdVVxMGkDGvuJgaG';
const validAddress = "5G3r2K1cEi4vtdBjMNHpjWCofRdyg2AFSdVVxMGkDGvuJgaG";

test.describe(`${this.faucetName} tests`, () => {
test.describe("on page load", () => {
Expand Down Expand Up @@ -172,27 +176,29 @@ export class FaucetTests {
await expect(submit).toBeEnabled();
});

test("submit form becomes valid when click captcha first", async ({ page }) => {
await page.goto(this.url);
const { address, captcha, submit } = await getFormElements(page, true);
await expect(submit).toBeDisabled();
await captcha.click();
// simulate the captcha check / human wait
await page.waitForTimeout(500);
await address.fill(validAddress);
await expect(submit).toBeEnabled();
});

test("Shows address invalid message when invalid address is entered", async ({page}, {config}) => {
await page.goto(this.url);
const { address, captcha, submit } = await getFormElements(page, true);
const expectedErrorMessage = "Address is invalid";
await address.fill('garbage');
await captcha.click();
const errorMessage = page.getByTestId("error");
await expect(errorMessage).toBeVisible();
expect((await errorMessage.allInnerTexts())[0]).toContain(expectedErrorMessage);
})
test("submit form becomes valid when click captcha first", async ({ page }) => {
await page.goto(this.url);
const { address, captcha, submit } = await getFormElements(page, true);
await expect(submit).toBeDisabled();
await captcha.click();
// simulate the captcha check / human wait
await page.waitForTimeout(500);
await address.fill(validAddress);
await expect(submit).toBeEnabled();
});

test("Shows address invalid message when invalid address is entered", async ({ page }, {
config
}) => {
await page.goto(this.url);
const { address, captcha, submit } = await getFormElements(page, true);
const expectedErrorMessage = "Address is invalid";
await address.fill("garbage");
await captcha.click();
const errorMessage = page.getByTestId("error");
await expect(errorMessage).toBeVisible();
expect((await errorMessage.allInnerTexts())[0]).toContain(expectedErrorMessage);
});

test("sends data on submit", async ({ page }, { config }) => {
await page.goto(this.url);
Expand Down
16 changes: 9 additions & 7 deletions client/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ type FormSubmit = {
parachain_id?: string;
};

const testAddress = '5G3r2K1cEi4vtdBjMNHpjWCofRdyg2AFSdVVxMGkDGvuJgaG';
const testAddress = "5G3r2K1cEi4vtdBjMNHpjWCofRdyg2AFSdVVxMGkDGvuJgaG";

const getFormElements = async (page: Page, getCaptcha = false) => {
let captcha: Locator = {} as Locator;
let captchaFrame: Locator = {} as Locator;
let captchaFrame: Locator = {} as Locator;
if (getCaptcha) {
captchaFrame = await page.locator('iframe[title="Widget containing checkbox for hCaptcha security challenge"]');
captcha = await captchaFrame.locator("#anchor")
captchaFrame = await page.locator(
'iframe[title="Widget containing checkbox for hCaptcha security challenge"]'
);
captcha = await captchaFrame.locator("#anchor");
}
return {
address: page.getByTestId("address"),
Expand Down Expand Up @@ -100,7 +102,7 @@ test.describe("form interaction", () => {
const { address, captcha, submit } = await getFormElements(page, true);
await expect(submit).toBeDisabled();
await address.fill(testAddress);
await captcha.click();
await captcha.click();
await expect(submit).toBeEnabled();
});

Expand All @@ -110,7 +112,7 @@ test.describe("form interaction", () => {
await expect(submit).toBeDisabled();
const myAddress = "0x000000001";
await address.fill(myAddress);
await captcha.click();
await captcha.click();
const url = getFaucetUrl(config);
await page.route(url, (route) =>
route.fulfill({
Expand Down Expand Up @@ -156,7 +158,7 @@ test.describe("form interaction", () => {
const { address, captcha, submit } = await getFormElements(page, true);
await expect(submit).toBeDisabled();
await address.fill("0x123");
await captcha.click();
await captcha.click();
await page.route(getFaucetUrl(config), (route) =>
route.fulfill({
body: JSON.stringify({ error })
Expand Down

0 comments on commit 3a310c8

Please sign in to comment.