-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Bruno Menezes <brunodmenezes@gmail.com>
- Loading branch information
1 parent
72cfb78
commit 1f4385c
Showing
9 changed files
with
177 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Page, Route, test as baseTest } from "@playwright/test"; | ||
|
||
/** | ||
* For validations purposes if needed. e.g. check if API | ||
* was called correctly. | ||
*/ | ||
type CalledWith = Record<string, unknown>; | ||
|
||
/** | ||
* Function to register as an interceptor. | ||
* Interceptions are per-operation, so multiple can be registered without the risk | ||
* of overwriting one another. | ||
* @param page {Page} playwright page client. | ||
* @param operationName Graphql operation name. | ||
* @param resp The expected return for the mock. | ||
* @returns | ||
*/ | ||
export async function interceptGQL( | ||
page: Page, | ||
operationName: string, | ||
resp: Record<string, unknown>, | ||
): Promise<CalledWith[]> { | ||
const reqs: CalledWith[] = []; | ||
|
||
await page.route("**/graphql", function (route: Route) { | ||
const req = route.request().postDataJSON(); | ||
|
||
// Pass along to the previous handler in case the operation does not match. | ||
if (req.operationName !== operationName) { | ||
return route.fallback(); | ||
} | ||
|
||
// Store what variables the API was called with; | ||
reqs.push(req.variables); | ||
|
||
return route.fulfill({ | ||
status: 200, | ||
contentType: "application/json", | ||
body: JSON.stringify({ data: resp }), | ||
}); | ||
}); | ||
|
||
return reqs; | ||
} | ||
|
||
export const test = baseTest.extend<{ interceptGQL: typeof interceptGQL }>({ | ||
interceptGQL: async ({ browser }, use) => { | ||
await use(interceptGQL); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("inputs"); | ||
}); | ||
|
||
test("should have correct page title", async ({ page }) => { | ||
await expect(page).toHaveTitle(/Inputs \| CartesiScan/); | ||
}); | ||
|
||
test("should have correct title", async ({ page }) => { | ||
const title = page.getByRole("heading", { name: "Inputs" }); | ||
await expect(title.first()).toBeVisible(); | ||
}); | ||
|
||
test("should display 'All inputs' table", async ({ page }) => { | ||
await expect( | ||
page.getByRole("row", { name: "From To Method Index Age Data" }), | ||
).toBeVisible(); | ||
await expect(page.getByRole("row")).toHaveCount(31); | ||
}); | ||
|
||
test("should open application inputs page", async ({ page }) => { | ||
await expect(page.getByTestId("inputs-table-spinner")).not.toBeVisible(); | ||
const applicationSummaryLinks = page | ||
.getByTestId("application-inputs-link") | ||
.getByRole("link"); | ||
|
||
const firstLink = applicationSummaryLinks.first(); | ||
const href = (await firstLink.getAttribute("href")) as string; | ||
const [hrefPart] = href | ||
.split(/applications|inputs|\//) | ||
.filter((p) => p !== ""); | ||
|
||
await firstLink.click(); | ||
|
||
await page.waitForURL(`/applications/${hrefPart}/inputs`); | ||
}); | ||
|
||
test("should open input details", async ({ page }) => { | ||
await expect(page.getByTestId("inputs-table-spinner")).not.toBeVisible(); | ||
const inputRowToggle = await page.getByTestId("input-row-toggle"); | ||
|
||
const firstInputRowToggle = inputRowToggle.first(); | ||
await firstInputRowToggle.click(); | ||
await expect(page.getByText("Notices")).toBeVisible(); | ||
await expect(page.getByText("Reports")).toBeVisible(); | ||
await expect(page.getByText("Vouchers")).toBeVisible(); | ||
await expect(page.getByText("Raw")).toBeVisible(); | ||
await expect(page.getByText("As Text")).toBeVisible(); | ||
await expect(page.getByText("As JSON")).toBeVisible(); | ||
}); | ||
|
||
test("should search for specific input", async ({ page }) => { | ||
await expect(page.getByTestId("inputs-table-spinner")).not.toBeVisible(); | ||
let fromAddress = page | ||
.getByTestId("application-from-address") | ||
.getByRole("paragraph"); | ||
|
||
const firstLink = fromAddress.first(); | ||
const href = (await firstLink.textContent()) as string; | ||
const [addressPrefix] = href.split("..."); | ||
|
||
const search = await page.getByTestId("search-input"); | ||
await search.focus(); | ||
await page.keyboard.type(addressPrefix); | ||
await page.keyboard.press("Enter"); | ||
await page.waitForTimeout(2000); | ||
|
||
fromAddress = page | ||
.getByTestId("application-from-address") | ||
.getByRole("paragraph"); | ||
|
||
const addresses = await fromAddress.all(); | ||
addresses.map(async (address) => { | ||
const linkHref = (await address.textContent()) as string; | ||
|
||
expect( | ||
linkHref.toLowerCase().startsWith(addressPrefix.toLowerCase()), | ||
).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const checkStatusSuccessResponse = { | ||
inputs: { | ||
totalCount: 41, | ||
}, | ||
vouchers: { | ||
totalCount: 0, | ||
}, | ||
reports: { | ||
totalCount: 41, | ||
}, | ||
notices: { | ||
totalCount: 0, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters