-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds Testing Guide #513
Merged
Merged
Adds Testing Guide #513
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
02222a6
adds tests guide
elliotBraem 905ca56
fix
elliotBraem dddc4f3
Merge branch 'main' into tests
elliotBraem 1427dc6
updates bos-workspace
elliotBraem be100d3
Revert "updates bos-workspace"
elliotBraem 7d2b5ba
init more tests
elliotBraem d31ea7d
Merge branch 'main' into tests
elliotBraem b7e52c4
working tests
elliotBraem 351ea45
Merge branch 'main' into tests
elliotBraem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,39 @@ | ||
name: CI | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
prettier: | ||
name: Prettier | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: "npm" | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Run code formatting check | ||
run: npm run fmt:check | ||
playwright-tests: | ||
name: Playwright tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: "npm" | ||
- name: Install dependencies | ||
run: | | ||
npm ci | ||
npm install bos-workspace | ||
npx playwright install-deps | ||
npx playwright install | ||
- name: Run tests | ||
run: | | ||
npx playwright test |
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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
{ | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true, | ||
"[javascript]": { | ||
"editor.formatOnSave": true | ||
}, | ||
"prettier.semi": false, | ||
"prettier.singleQuote": true | ||
} | ||
|
||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true, | ||
"[javascript]": { | ||
"editor.formatOnSave": true | ||
}, | ||
"prettier.semi": false, | ||
"prettier.singleQuote": 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
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 |
---|---|---|
|
@@ -2,13 +2,7 @@ const title = props.title; | |
const description = props.description; | ||
|
||
const icon = ( | ||
<svg | ||
width="20" | ||
height="20" | ||
viewBox="0 0 20 20" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also from |
||
<path | ||
d="M10.0001 13.3327V9.99935M10.0001 6.66602H10.0084M18.3334 9.99935C18.3334 14.6017 14.6025 18.3327 10.0001 18.3327C5.39771 18.3327 1.66675 14.6017 1.66675 9.99935C1.66675 5.39698 5.39771 1.66602 10.0001 1.66602C14.6025 1.66602 18.3334 5.39698 18.3334 9.99935Z" | ||
stroke="#475467" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Testing Guide | ||
|
||
This project uses [playwright](https://playwright.dev/) for end-to-end testing. Please become familiar with this documentation. | ||
|
||
## Writing tests | ||
|
||
Tests should be written for each change or addition to the codebase. | ||
If a new feature is introduced, tests should be written to validate its functionality. If a bug is fixed, tests should be written to prevent regression. Writing tests not only safeguards against future breaks by other developers but also accelerates development by minimizing manual coding and browser interactions. | ||
|
||
When writing tests, remember to: | ||
|
||
- Test user-visible behavior | ||
- Make tests as isolated as possible | ||
- Avoid testing third-party dependencies | ||
|
||
> **[LEARN BEST PRACTICES](https://playwright.dev/docs/best-practices)** | ||
|
||
See the [cookbook](#cookbook) for help in covering scenerios. It is possible to [generate tests](https://playwright.dev/docs/codegen) via the [VS Code Extension](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright). | ||
|
||
## Running tests | ||
|
||
To run the tests, you may do so through the command line: | ||
|
||
```cmd | ||
npm run test | ||
``` | ||
|
||
Or through VS Code **(recommended)**, see [Getting started - VS Code](https://playwright.dev/docs/getting-started-vscode). | ||
|
||
## Recording video | ||
|
||
You may automatically record video with your tests by setting | ||
|
||
``` | ||
use: { | ||
video: "on" | ||
} | ||
``` | ||
|
||
in the [playwright.config.js](../playwright.config.js). After running tests, you will find the output as a `.webm` in `./test-results`. Then, [convert to MP4](https://video.online-convert.com/convert/webm-to-mp4) and share. | ||
|
||
It is encouraged to include video in pull requests in order to demonstrate functionality and prove thorough testing. | ||
|
||
## Cookbook | ||
|
||
### Capturing the VM Confirmation Popup | ||
|
||
Currently, none of the tests post actual transactions to the smart contracts. Still you should try writing your tests so that they do the actual function call, but just skip the final step of sending the transaction. You can do this by capturing the transaction confirmation popup provided by the NEAR social VM. | ||
|
||
```javascript | ||
// click button that triggers transaction | ||
await page.getByRole("button", { name: "Donate" }).nth(1).click(); | ||
|
||
const transactionObj = JSON.parse(await page.locator("div.modal-body code").innerText()); | ||
|
||
// do something with transactionObj | ||
expect(transactionObj).toMatchObject({ | ||
amount: 100, | ||
message: "", | ||
projectId: DEFAULT_PROJECT_ID, | ||
}); | ||
``` | ||
|
||
See the test called "project with no active pot should donate direct with correct amount" in donate.spec.js for a full example. |
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,27 @@ | ||
/** | ||
* root of the app | ||
* general sanity tests | ||
*/ | ||
|
||
import { expect, test } from "@playwright/test"; | ||
import { ROOT_SRC, ROUTER_CONFIG } from "../util/constants"; | ||
|
||
// currently skipping | ||
test.skip("should load the correct pages per route", async ({ page }) => { | ||
ROUTER_CONFIG.routes.forEach(async (route) => { | ||
await page.goto(`${ROOT_SRC}?${ROUTER_CONFIG.param}=${route.path}`); | ||
|
||
const pageSelector = `div[data-component="${route.element.src}"]`; // because this gets applied via bos-workspace v1.0.0 | ||
// and we have not updated yet | ||
|
||
await page.waitForSelector(pageSelector, { | ||
state: "visible", | ||
}); | ||
|
||
// Find all matching elements | ||
const elements = await page.$$(pageSelector); | ||
|
||
// Assert that at at least one element was found | ||
expect(elements.length).toBeGreaterThan(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* donate modal | ||
*/ | ||
|
||
import { test, expect } from "@playwright/test"; | ||
import { ROOT_SRC, DEFAULT_PROJECT_ID } from "../util/constants"; | ||
|
||
test("should open donate modal", async ({ page }) => { | ||
test.setTimeout(120000); // 2 minutes... we want to improve performance | ||
await page.goto(`${ROOT_SRC}?tab=project&projectId=${DEFAULT_PROJECT_ID}`); | ||
await page.getByRole("button", { name: "Donate" }).click(); | ||
expect(await page.isVisible("text=Donate to project")).toBeTruthy(); | ||
}); | ||
|
||
test("project with no active pot should donate direct with correct amount", async ({ page }) => { | ||
test.setTimeout(120000); // 2 minutes... we want to improve performance | ||
await page.goto(`${ROOT_SRC}?tab=project&projectId=${DEFAULT_PROJECT_ID}`); | ||
await page.getByRole("button", { name: "Donate" }).click(); | ||
expect(await page.isVisible("text=Donate to project")).toBeTruthy(); | ||
await page.fill("input[name=amount]", "100"); | ||
await page.getByRole("button", { name: "Donate" }).nth(1).click(); | ||
|
||
// Confirmation modal should be visible | ||
const transactionObj = JSON.parse(await page.locator("div.modal-body code").innerText()); | ||
expect(transactionObj).toMatchObject({ | ||
bypass_protocol_fee: false, | ||
message: "", | ||
recipient_id: DEFAULT_PROJECT_ID, | ||
}); | ||
}); |
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,18 @@ | ||
/** | ||
* ?tab=pot | ||
*/ | ||
|
||
import { test, expect } from "@playwright/test"; | ||
import { ROOT_SRC, DEFAULT_POT_ID } from "../util/constants"; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto(`${ROOT_SRC}?tab=pot&potId=${DEFAULT_POT_ID}`); | ||
}); | ||
|
||
test("clicking pot card should go to pot page", async ({ page }) => { | ||
await page.getByText("NEAR Retroactive Builders").click(); | ||
|
||
const url = page.url(); | ||
|
||
expect(url).toContain("?tab=pot&potId=build.v1.potfactory.potlock.near"); | ||
}); |
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,42 @@ | ||
/** | ||
* ?tab=pots | ||
*/ | ||
|
||
import { test, expect } from "@playwright/test"; | ||
import { ROOT_SRC, DEFAULT_POT_ID } from "../util/constants"; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto(`${ROOT_SRC}?tab=pots`); | ||
}); | ||
|
||
test("clicking pot card should go to pot page", async ({ page }) => { | ||
await page.getByText("NEAR Retroactive Builders").click(); | ||
|
||
const url = page.url(); | ||
|
||
expect(url).toContain(`?tab=pot&potId=${DEFAULT_POT_ID}`); | ||
}); | ||
|
||
test("clicking deploy button should go to deploypot page", async ({ page }) => { | ||
// TODO: | ||
}); | ||
|
||
test("clicking learn more button should...", async ({ page }) => { | ||
// TODO: | ||
}); | ||
|
||
test("should show active pots", async ({ page }) => { | ||
// TODO: | ||
}); | ||
|
||
test("should show completed pots", async ({ page }) => { | ||
// TODO: | ||
}); | ||
|
||
test("should sort pots", async ({ page }) => { | ||
// TODO: | ||
}); | ||
|
||
test("should filter pots", async ({ page }) => { | ||
// TODO: | ||
}); |
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 @@ | ||
/** | ||
* donate modal | ||
*/ | ||
|
||
import { test, expect } from "@playwright/test"; | ||
import { ROOT_SRC, DEFAULT_PROJECT_ID } from "../util/constants"; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto(`${ROOT_SRC}?tab=project&projectId=${DEFAULT_PROJECT_ID}`); | ||
}); | ||
|
||
test.skip("clicking donate button should show donate modal", async ({ page }) => { | ||
await page.getByRole("button", { name: "Donate" }).click(); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is from
npm run fmt