This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Infrastructure] Implementing Playwright e2e tests for main swap flows (
#63) * chore: wip playwright setup * chore: wip playwright setup * chore: refactoring wallet manager; first full e2e tests * chore: refining e2e tests; accessing components by ids * chore: refining ci for e2e on github actions * chore: testing ci * chore: testing ci * chore: testing ci * chore: testing ci * chore: testing ci * chore: tweaking ci * chore: testing ci * chore: testing ci * chore: testing ci * chore: testing ci * chore: testing ci * chore: testing ci * chore: testing ci * chore: testing ci * chore: testing ci * chore: testing ci * chore: testing ci * feat: testing ci * feat: testing ci * chore: tweaking ci * chore: tweaking readme * feat: bumping version * feat: testing ci * feat: testing ci * feat: fixing vercel error Co-authored-by: MillionAlgosFather <info@algoworld.io>
- Loading branch information
1 parent
a370729
commit b47d551
Showing
54 changed files
with
1,081 additions
and
454 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: E2E Tests | ||
on: | ||
pull_request: | ||
branches: [main] | ||
jobs: | ||
e2e_test: | ||
env: | ||
PR_NUMBER: ${{ github.event.number }} | ||
E2E_TESTS_BASE_URL: 'https://pr${{ github.event.number }}-${{ github.run_number }}.vercel-action.millionalgos.com' | ||
E2E_TESTS_BASE_URL_ALIAS: 'pr${{ github.event.number }}-${{ github.run_number }}.vercel-action.millionalgos.com' | ||
|
||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Expose e2e base url | ||
run: | | ||
echo "${{ env.E2E_TESTS_BASE_URL }}" | ||
shell: bash | ||
|
||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '16.x' | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: Install Playwright Browsers | ||
run: npx playwright install chromium | ||
|
||
- name: Deploy preview | ||
uses: amondnet/vercel-action@v25.0.0 | ||
with: | ||
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required | ||
github-token: ${{ secrets.GITHUB_TOKEN }} #Optional | ||
vercel-org-id: ${{ secrets.VERCEL_ORG_ID}} #Required | ||
vercel-project-id: ${{ secrets.VERCEL_STAGING_PROJECT_ID}} #Required | ||
working-directory: ./ | ||
alias-domains: ${{ env.E2E_TESTS_BASE_URL_ALIAS }} | ||
|
||
- name: Run Playwright tests | ||
run: | | ||
E2E_TESTS_BASE_URL=${{ env.E2E_TESTS_BASE_URL }} yarn run test:e2e:ci | ||
- uses: actions/upload-artifact@v2 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
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 |
---|---|---|
|
@@ -45,3 +45,6 @@ yarn-error.log* | |
|
||
# Sentry | ||
.sentryclirc | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
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,3 @@ | ||
export const AW_SWAPPER_BASE_URL = | ||
process.env.E2E_TESTS_BASE_URL ?? `http://localhost:3000/`; | ||
console.log(process.env.E2E_TESTS_BASE_URL); |
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,17 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { AW_SWAPPER_BASE_URL } from '../consts'; | ||
|
||
test(`should navigate to the about page`, async ({ page }) => { | ||
await page.goto(AW_SWAPPER_BASE_URL); | ||
await expect(page.locator(`h1`)).toContainText(`🏠 Dashboard`); | ||
|
||
await page.locator(`button:has-text("About")`).click(); | ||
await expect( | ||
page.locator(`text=AlgoWorld Swapper v0.2.2`).first(), | ||
).toBeVisible(); | ||
|
||
await page.locator(`button:has-text("Close")`).click(); | ||
await expect( | ||
page.locator(`text=AlgoWorld Swapper v0.2.2`).first(), | ||
).toBeHidden(); | ||
}); |
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,154 @@ | ||
import { test, expect, Page } from '@playwright/test'; | ||
import { AW_SWAPPER_BASE_URL } from '@/e2e/consts'; | ||
import { | ||
NAV_BAR_CONNECT_BTN_ID, | ||
NAV_BAR_SETTINGS_BTN_ID, | ||
NAV_BAR_SETTINGS_MENU_ITEM_ID, | ||
} from '@/components/Headers/constants'; | ||
import { | ||
CONNECT_WALLET_DIALOG_ID, | ||
FROM_ASSET_PICKER_DIALOG_SEARCH_ID, | ||
DIALOG_SELECT_BTN_ID, | ||
FROM_ASSET_PICKER_DIALOG_ID, | ||
TO_ASSET_PICKER_DIALOG_SEARCH_ID, | ||
TO_ASSET_PICKER_DIALOG_ID, | ||
CONFIRM_DIALOG_ID, | ||
SHARE_SWAP_DIALOG_ID, | ||
SHARE_SWAP_COPY_BTN_ID, | ||
DIALOG_CANCEL_BTN_ID, | ||
SWAP_DEACTIVATION_PERFORMED_MESSAGE, | ||
} from '@/components/Dialogs/constants'; | ||
import { | ||
SWAP_TYPE_PICKER_CARD_ID, | ||
FROM_SWAP_OFFERING_ASSET_BTN_ID, | ||
TO_SWAP_REQUESTING_BTN_ID, | ||
} from '@/components/Cards/constants'; | ||
import { | ||
ASA_TO_ASA_PAGE_HEADER_ID, | ||
CREATE_SWAP_BTN_ID, | ||
MY_SWAPS_PAGE_HEADER_ID, | ||
} from '@/common/constants'; | ||
import { MY_SWAPS_TABLE_MANAGE_BTN_ID } from '@/components/Tables/constants'; | ||
import { CRYPTO_TEXT_FIELD_ID } from '@/components/TextFields/constants'; | ||
|
||
const DUMMY_ASA_TO_OFFER = `96044943: AWS_TEST`; | ||
const DUMMY_ASA_TO_REQUEST_TITLE = `SASA`; | ||
const DUMMY_ASA_TO_REQUEST = `16040857: ${DUMMY_ASA_TO_REQUEST_TITLE}`; | ||
|
||
let page: Page; | ||
|
||
test.beforeAll(async ({ browser }) => { | ||
const context = await browser.newContext(); | ||
context.grantPermissions([`clipboard-read`, `clipboard-write`]); | ||
page = await context.newPage(); | ||
await page.goto(AW_SWAPPER_BASE_URL); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await page.close(); | ||
}); | ||
|
||
test.describe(`Asa to Asa Swap`, () => { | ||
test(`should be able to load and connect wallet`, async () => { | ||
await page.locator(`id=${NAV_BAR_CONNECT_BTN_ID}`).click(); | ||
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeVisible(); | ||
await page.locator(`div[role="button"]:has-text("Mnemonic")`).click(); | ||
await expect(page.locator(`id=${CONNECT_WALLET_DIALOG_ID}`)).toBeHidden(); | ||
}); | ||
|
||
test(`should be able to navigate to Asa to Asa page`, async () => { | ||
await expect(page.locator(`id=${ASA_TO_ASA_PAGE_HEADER_ID}`)).toBeHidden(); | ||
await Promise.all([ | ||
page.waitForNavigation(), | ||
page.locator(`id=${SWAP_TYPE_PICKER_CARD_ID(`ASA to ASA`)}`).click(), | ||
]); | ||
await expect(page.locator(`id=${ASA_TO_ASA_PAGE_HEADER_ID}`)).toBeVisible(); | ||
}); | ||
|
||
test(`should be able to select offering asset`, async () => { | ||
await expect( | ||
page.locator(`id=${FROM_ASSET_PICKER_DIALOG_ID}`), | ||
).toBeHidden(); | ||
await page.locator(`id=${FROM_SWAP_OFFERING_ASSET_BTN_ID}`).click(); | ||
await expect( | ||
page.locator(`id=${FROM_ASSET_PICKER_DIALOG_ID}`), | ||
).toBeVisible(); | ||
|
||
await page.locator(`id=${FROM_ASSET_PICKER_DIALOG_SEARCH_ID}`).click(); | ||
await page.locator(`text=${DUMMY_ASA_TO_OFFER}`).click(); | ||
|
||
await page.locator(`id=${CRYPTO_TEXT_FIELD_ID}`).click(); | ||
await page.locator(`id=${CRYPTO_TEXT_FIELD_ID}`).fill(`1`); | ||
await page.locator(`id=${DIALOG_SELECT_BTN_ID}`).click(); | ||
await expect( | ||
page.locator(`id=${FROM_ASSET_PICKER_DIALOG_ID}`), | ||
).toBeHidden(); | ||
}); | ||
|
||
test(`should be able to select requesting asset`, async () => { | ||
await expect(page.locator(`id=${TO_ASSET_PICKER_DIALOG_ID}`)).toBeHidden(); | ||
await page.locator(`id=${TO_SWAP_REQUESTING_BTN_ID}`).click(); | ||
await expect(page.locator(`id=${TO_ASSET_PICKER_DIALOG_ID}`)).toBeVisible(); | ||
|
||
await page | ||
.locator(`id=${TO_ASSET_PICKER_DIALOG_SEARCH_ID}`) | ||
.fill(DUMMY_ASA_TO_REQUEST_TITLE); | ||
await page.locator(`text=${DUMMY_ASA_TO_REQUEST}`).click(); | ||
|
||
await page.locator(`id=${CRYPTO_TEXT_FIELD_ID}`).click(); | ||
await page.locator(`id=${CRYPTO_TEXT_FIELD_ID}`).fill(`1`); | ||
await page.locator(`id=${DIALOG_SELECT_BTN_ID}`).click(); | ||
await expect(page.locator(`id=${TO_ASSET_PICKER_DIALOG_ID}`)).toBeHidden(); | ||
}); | ||
|
||
test(`should be able to initiate create swap`, async () => { | ||
await expect(page.locator(`id=${CONFIRM_DIALOG_ID}`)).toBeHidden(); | ||
await page.locator(`id=${CREATE_SWAP_BTN_ID}`).click({ timeout: 120000 }); | ||
await expect(page.locator(`id=${CONFIRM_DIALOG_ID}`)).toBeVisible(); | ||
await page.locator(`id=${DIALOG_SELECT_BTN_ID}`).click(); | ||
await expect(page.locator(`id=${CONFIRM_DIALOG_ID}`)).toBeHidden(); | ||
}); | ||
|
||
test(`should successfully create swap and display share dialog`, async () => { | ||
await expect(page.locator(`id=${SHARE_SWAP_DIALOG_ID}`)).toBeVisible({ | ||
timeout: 100000, | ||
}); | ||
await page.locator(`id=${SHARE_SWAP_COPY_BTN_ID}`).click(); | ||
expect( | ||
await page.evaluate(() => { | ||
const content = navigator.clipboard.readText(); | ||
return content; | ||
}), | ||
).toContain(`/swap/`); | ||
await page.locator(`id=${DIALOG_CANCEL_BTN_ID}`).click(); | ||
await expect(page.locator(`id=${SHARE_SWAP_DIALOG_ID}`)).toBeHidden(); | ||
}); | ||
|
||
test(`should successfully remove created swap`, async () => { | ||
await page.locator(`id=${NAV_BAR_SETTINGS_BTN_ID}`).click(); | ||
await Promise.all([ | ||
page.waitForNavigation(), | ||
page.locator(`id=${NAV_BAR_SETTINGS_MENU_ITEM_ID(`My Swaps`)}`).click(), | ||
]); | ||
await expect(page.locator(`id=${MY_SWAPS_PAGE_HEADER_ID}`)).toBeVisible(); | ||
|
||
const escrowAddress = await page.evaluate(async () => { | ||
const clipboardContent = await navigator.clipboard.readText(); | ||
const escrow = clipboardContent | ||
.substring(clipboardContent.lastIndexOf(`/`) + 1) | ||
.split(`?`)[0]; | ||
return escrow; | ||
}); | ||
|
||
await page | ||
.locator(`id=${MY_SWAPS_TABLE_MANAGE_BTN_ID(escrowAddress)}`) | ||
.click(); | ||
await page.locator(`text=Delete`).click(); | ||
|
||
await expect( | ||
page.locator(`text=${SWAP_DEACTIVATION_PERFORMED_MESSAGE}`), | ||
).toBeVisible({ | ||
timeout: 120000, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
b47d551
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for algoworld-swapper ready!
✅ Preview
https://algoworld-swapper-hqwy01yc1-algoworldexplorer.vercel.app
Built with commit b47d551.
This pull request is being automatically deployed with vercel-action