Skip to content

Commit 661cb68

Browse files
authored
test: new end to end tests (#9)
* test: adding end to end test for login and send pay txn flow * refactor: fixing algoexplorer url handling * refactor: adding gitattributes; improving e2e test * chore: adding playwright plugin * chore: fixing typo * chore: addressing pr comments
1 parent 35c192e commit 661cb68

File tree

29 files changed

+143
-36
lines changed

29 files changed

+143
-36
lines changed

template_content/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=lf

template_content/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function App() {
5858
</button>
5959

6060
{activeAddress && (
61-
<button className="btn m-2" onClick={toggleDemoModal}>
61+
<button data-test-id="transactions-demo" className="btn m-2" onClick={toggleDemoModal}>
6262
Transactions Demo
6363
</button>
6464
)}

template_content/src/components/Account.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const Account = () => {
1010
<a
1111
className="text-xl"
1212
target="_blank"
13-
href={`https://${algoConfig.network == 'mainnet' ? '' : `${algoConfig.network}.`}algoexplorer.io/address/${activeAddress}`}
13+
href={`https://${
14+
['mainnet', ''].includes(algoConfig.network.toLowerCase()) ? '' : `${algoConfig.network.toLowerCase()}.`
15+
}algoexplorer.io/address/${activeAddress}`}
1416
>
1517
Address: {ellipseAddress(activeAddress)}
1618
</a>

template_content/src/components/ConnectWallet.tsx.jinja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => {
4444

4545
<div className="modal-action {% if use_daisy_ui == false -%}grid{% endif -%}">
4646
<button
47+
data-test-id="close-wallet-modal"
4748
className="btn"
4849
onClick={() => {
4950
closeModal()
@@ -54,6 +55,7 @@ const ConnectWallet = ({ openModal, closeModal }: ConnectWalletInterface) => {
5455
{activeAddress && (
5556
<button
5657
className="btn btn-warning"
58+
data-test-id="logout"
5759
onClick={() => {
5860
providers?.find((p) => p.isActive)?.disconnect()
5961
}}

template_content/src/components/Transact.tsx.jinja

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const Transact = ({ openModal, setModalState }: TransactInterface) => {
6767
<br />
6868
<input
6969
type="text"
70+
data-test-id="receiver-address"
7071
placeholder="Provide wallet address"
7172
className="input input-bordered w-full"
7273
value={receiverAddress}
@@ -78,7 +79,11 @@ const Transact = ({ openModal, setModalState }: TransactInterface) => {
7879
<button className="btn" onClick={() => setModalState(!openModal)}>
7980
Close
8081
</button>
81-
<button className={`btn ${receiverAddress.length === 58 ? '' : 'btn-disabled'} lo`} onClick={handleSubmitAlgo}>
82+
<button
83+
data-test-id="send-algo"
84+
className={`btn ${receiverAddress.length === 58 ? '' : 'btn-disabled'} lo`}
85+
onClick={handleSubmitAlgo}
86+
>
8287
{loading ? <span className="loading loading-spinner" /> : 'Send 1 Algo'}
8388
</button>
8489
</div>

template_content/{% if ide_vscode %}.vscode{% endif %}/extensions.json.jinja

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
{
22
"recommendations": [
33
"EditorConfig.EditorConfig",
4-
"dotenv.dotenv-vscode"
4+
"dotenv.dotenv-vscode",
55
{% if use_eslint_prettier -%}
66
"esbenp.prettier-vscode",
77
"dbaeumer.vscode-eslint",
88
"krysenlo.vite-plugin-eslint-problemmatcher",
99
{% endif -%}
10+
{% if use_playwright -%}
11+
"ms-playwright.playwright",
12+
{% endif -%}
13+
{% if use_jest -%}
14+
"Orta.vscode-jest",
15+
{% endif -%}
1016
{% if use_tailwind -%}
1117
"bradlc.vscode-tailwindcss",
1218
"csstools.postcss",

template_content/{% if use_playwright %}playwright.config.ts{% endif %}.jinja

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ export default defineConfig({
4343
use: { ...devices['Desktop Firefox'] },
4444
},
4545

46-
{
47-
name: 'webkit',
48-
use: { ...devices['Desktop Safari'] },
49-
},
50-
5146
/* Test against mobile viewports. */
5247
// {
5348
// name: 'Mobile Chrome',
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
1-
import { test, expect } from '@playwright/test'
1+
import { randomAccount } from '@algorandfoundation/algokit-utils'
2+
import { expect, test } from '@playwright/test'
23

34
test.beforeEach(async ({ page }) => {
45
await page.goto('http://localhost:5173/')
56
})
67

78
test('has title', async ({ page }) => {
89
// Expect a title "to contain" a substring.
9-
await expect(page).toHaveTitle(/Algorand front-end template/)
10+
await expect(page).toHaveTitle('AlgoKit React Template')
1011
})
1112

1213
test('get started link', async ({ page }) => {
1314
await expect(page.getByTestId('getting-started')).toHaveText('Getting started')
1415
})
16+
17+
test('authentication and dummy payment transaction', async ({ page }) => {
18+
page.on('dialog', async (dialog) => {
19+
dialog.message() === 'KMD password' ? await dialog.accept() : await dialog.dismiss()
20+
})
21+
22+
// 1. Must be able to connect to a KMD wallet provider
23+
await page.getByTestId('connect-wallet').click()
24+
await page.getByTestId('kmd-connect').click()
25+
await page.getByTestId('close-wallet-modal').click()
26+
27+
// 2. Must be able to send a dummy payment transaction
28+
await page.getByTestId('transactions-demo').click()
29+
30+
const dummyAccount = randomAccount()
31+
await page.getByTestId('receiver-address').fill(dummyAccount.addr)
32+
await page.getByTestId('send-algo').click()
33+
34+
// 3. Must be able to see a notification that the transaction was sent
35+
const notification = await page.getByText('Transaction sent:')
36+
await notification.waitFor()
37+
expect(notification).toBeTruthy()
38+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=lf

tests_generated/test_all_default_parameters_off/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default function App() {
5858
</button>
5959

6060
{activeAddress && (
61-
<button className="btn m-2" onClick={toggleDemoModal}>
61+
<button data-test-id="transactions-demo" className="btn m-2" onClick={toggleDemoModal}>
6262
Transactions Demo
6363
</button>
6464
)}

0 commit comments

Comments
 (0)