Skip to content
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

test: Setup testing environment & Implement tests for Homepage #55

Merged
merged 21 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bfe92bd
test: Setup testing environment
carina-akaia May 30, 2024
caf572e
wip: Add primitive tests
carina-akaia May 30, 2024
32ef8ad
Merge branch 'main' of https://github.com/PotLock/potlock-nextjs-app …
carina-akaia May 30, 2024
a1f0f03
Merge branch 'main' of https://github.com/PotLock/potlock-nextjs-app …
carina-akaia May 30, 2024
19ffa3c
doc: Add testing convention examples
carina-akaia Jun 2, 2024
d01c268
chore: Add ESLint plugin for tests
carina-akaia Jun 2, 2024
3af3885
wip: Update homepage tests
carina-akaia Jun 2, 2024
90c7ed6
wip: Update docs & Adjust command naming
carina-akaia Jun 2, 2024
1d63426
ci: Add GH action for unit tests
carina-akaia Jun 2, 2024
3774478
Merge branch 'main' of https://github.com/PotLock/potlock-nextjs-app …
carina-akaia Jun 2, 2024
ebc0e89
nit: Fix typos
carina-akaia Jun 2, 2024
dae241b
test: Set global test timeout
carina-akaia Jun 2, 2024
439b0fe
test: Update homepage tests
carina-akaia Jun 2, 2024
6d7e282
chore: Rename GH actions directory
carina-akaia Jun 2, 2024
7658b92
Merge branch 'main' of https://github.com/PotLock/potlock-nextjs-app …
carina-akaia Jun 3, 2024
e2af1e2
chore: Discard unused code
carina-akaia Jun 3, 2024
f8a0619
Fix post-merge issues
carina-akaia Jun 3, 2024
ed2272d
ci: Fix test workflow steps
carina-akaia Jun 3, 2024
47f5157
ci: Use Nodejs v20 for tests
carina-akaia Jun 3, 2024
2cc80d2
wip: Set timeouts for `waitFor` explicitly
carina-akaia Jun 3, 2024
c4a036d
fix: Use correct test case for fundraising amounts
carina-akaia Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
"env": {
"node": true
},
"plugins": ["@typescript-eslint", "prettier", "import", "@tanstack/query"],
"plugins": [
"@typescript-eslint",
"prettier",
"import",
"@tanstack/query",
"testing-library"
],
"extends": [
"next/core-web-vitals",
"eslint:recommended",
Expand All @@ -21,17 +27,32 @@
"prettier"
],
"rules": {
"camelcase": ["warn", { "properties": "never" }],
"camelcase": [
"warn",
{
"properties": "never"
}
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": "off",
"prettier/prettier": ["error", { "endOfLine": "auto" }],
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
],
"sort-imports": [
"error",
{
"ignoreCase": false,
"ignoreDeclarationSort": true, // don"t want to sort import lines, use eslint-plugin-import instead
"ignoreMemberSort": false,
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"],
"memberSyntaxSortOrder": [
"none",
"all",
"multiple",
"single"
],
"allowSeparatedGroups": true
}
],
Expand All @@ -45,14 +66,23 @@
"builtin", // Built-in imports (come from NodeJS native) go first
"external", // <- External imports
"internal", // <- Absolute imports
["sibling", "parent"], // <- Relative imports, the sibling and parent types they can be mingled together
[
"sibling",
"parent"
], // <- Relative imports, the sibling and parent types they can be mingled together
"index", // <- index imports
"unknown" // <- unknown
],
"pathGroups": [
{ "pattern": "react", "group": "external", "position": "before" }
{
"pattern": "react",
"group": "external",
"position": "before"
}
],
"pathGroupsExcludedImportTypes": [
"react"
],
"pathGroupsExcludedImportTypes": ["react"],
"newlines-between": "always",
"alphabetize": {
/* sort in ascending order. Options: ["ignore", "asc", "desc"] */
Expand All @@ -63,4 +93,4 @@
}
]
}
}
}
33 changes: 33 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Execute all unit tests

on:
push:
branches: ["*"]

pull_request:
branches: [main, staging]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3

with:
node-version: ${{ matrix.node-version }}
cache: "yarn"

- name: Install dependencies
run: yarn install --immutable --immutable-cache --check-cache

- name: Execute Unit tests
run: yarn test:unit
9 changes: 7 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"recommendations": ["antfu.unocss"]
}
"recommendations": [
"antfu.unocss",
"aaron-bond.better-comments",
"streetsidesoftware.code-spell-checker",
"gruntfuggly.todo-tree"
]
}
26 changes: 22 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
{
"editor.formatOnSave": true,
"eslint.validate": ["typescript"],
"eslint.validate": [
"typescript"
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.fixAll": "explicit"
}
}

},
"cSpell.words": [
"bitget",
"colocation",
"data-testid",
"NADABOT",
"narwallets",
"naxios",
"nearfi",
"POTLOCK",
"ramper",
"shadcn",
"typecheck",
"unocss",
"welldone",
"wpdas",
"xdefi"
]
}
132 changes: 109 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,61 @@

PotLock application.

You can access BOS Potlock Version using one of the environments below:
You can access BOS PotLock version using one of the environments below:

- [Production](https://app.potlock.org/)
- [Staging](https://app.potlock.org/staging.potlock.near/widget/IndexLoader)

## Getting Started
## Development

### Getting Started

```bash
# using the right node version
nvm use;
# enable Yarn support
corepack enable;
# install dependencies
yarn;
# create config for environment variables
cp .env.example .env.local
cp .env.example .env.local;
# if required, edit .env.local
# then run the development server
# then run the development server ( dependencies will be installed automatically )
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) in your browser.

## DJango Indexer API
### DJango Indexer API

This project is using a indexer service. You can access its docs here: <https://github.com/PotLock/django-indexer?tab=readme-ov-file#api-endpoints>
This project is using an indexer service.
You can access its docs here: <https://github.com/PotLock/django-indexer?tab=readme-ov-file#api-endpoints>

**URI**: `http://ec2-100-27-57-47.compute-1.amazonaws.com/api/v1`

## Project Structure
### Project Structure

Maintains explicit separation between abstract and business-logic-heavy parts of the codebase.
This structure offers a highly modular approach, defining clear boundaries for different aspects of the application within each module:
Provides explicit separation between abstract and business-logic-heavy parts of the codebase,
for which it offers a highly modular approach, defining clear boundaries for different
aspects of the application within each module:

```sh

[ src/ ]
├── [ app ] <--- # Entry point of the application. Follows Nextjs App routing specification ( see link 1. )
├── [ app ] <--- # Entry point of the application.
│ │ # Follows Nextjs App routing specification ( see link 1. )
│ │
│ ...
│ │
│ └── [ _store ] <--- # Application state root. Uses Rematch state management library, based on Redux
│ └── [ _store ] <--- # Application state root.
# Uses Rematch state management library, based on Redux.
├── [ common ] <--- # Low-level foundation of the app, containing endpoint bindings, utility libraries,
│ │ # reusable primitives, and assets, used in layouts and business logic across the codebase.
│ │ # MUST NOT itself contain business logic. AKA "shared" ( see link 2. )
├── [ common ] <--- # Low-level foundation of the app, containing endpoint bindings,
│ │ # utility libraries, reusable primitives, and assets, used in layouts and
│ │ # business logic across the codebase. MUST NOT contain business logic by itself.
│ │ # AKA "shared" ( see link 2. )
│ │
│ ├── constants.ts <--- # Static reusable values, e.g.
│ │ export const DEFAULT_NETWORK = "testnet"
Expand All @@ -72,14 +77,14 @@ This structure offers a highly modular approach, defining clear boundaries for d
│ │
│ ├── [ components ] <--- # React components implementing UI design primitives
│ │
│ └── [ utils ] <--- # UI-specific utilities, like DOM manipulations or TailwindCSS class transformers
│ └── [ utils ] <--- # UI-specific utilities, like DOM manipulations
│ # or TailwindCSS class transformers
└── [ modules ] <--- # Business logic units broken down into categories.
│ # Simply put, this is a collection of directories that contain code implementing specific
└── [ modules ] <--- # Business logic units broken down into categories. Simply put, this is
│ # a collection of directories that contain code implementing specific
│ # groups of app use cases and are named after functionalities they provide.
...
Expand All @@ -93,7 +98,7 @@ This structure offers a highly modular approach, defining clear boundaries for d
│ ├── constants.ts <--- # Module-specific static reusable values, e.g.
│ │ export const POTLOCK_REGISTRY_LIST_ID = 1
│ │
│ ├── models.ts <--- # Feature state definitions ( See link 2. )
│ ├── models.ts <--- # Feature state definitions ( See link 3. )
│ │ # If this file grows over 300 LoC, consider turning it into a directory
│ │ # with the same name by applying code-splitting techniques.
│ │
Expand All @@ -112,8 +117,89 @@ This structure offers a highly modular approach, defining clear boundaries for d

```

### Links
#### Links

1. [Nextjs Routing](https://nextjs.org/docs/app/building-your-application/routing)
2. [Shared layer from Feature-Sliced Design methodology](https://feature-sliced.design/docs/reference/layers#shared)
3. [Rematch models](https://rematchjs.org/docs/api-reference/models)

### Testing

We use Vitest testing framework coupled with React Testing Library to specifically target UI.

For details, please refer to the corresponding documentation resources:

- [Vitest API reference](https://vitest.dev/api/)
- [React Testing Library guideline](https://testing-library.com/docs/react-testing-library/example-intro)

#### Commands

Execute all unit tests:

```bash
yarn test:unit
```

Run dev server for unit tests:

```bash
yarn dev:test
```

#### File colocation

The project convention implies keeping the test scenarios alongside the code they're meant for
( See examples below ).

##### Pages

Tests for each page must be placed in `tests.tsx`
within the same directory where `page.tsx` is located:

```bash

─── [ app ]
├── page.tsx <--- # Homepage ( URL "/" )
├── tests.tsx <--- # Tests for Homepage
├── [ pots ]
│ │
│ ├── page.tsx <--- # Pots page ( URL "/pots" )
│ │
│ └── tests.tsx <--- # Tests for Pots page
└── [ users ]
└── [ [userId] ]
├── page.tsx <--- # User page ( e.g. "/users/builder.near" )
└── tests.tsx <--- # Tests for User page

```

##### Modules

For modules, we target specific implementation details:

```bash

─── [ modules ]
└── [ profile ] <--- # Profile module
├── [ components ]
│ │
│ ├── ProfileCard.tsx <--- # Profile card component
│ │
│ └── ProfileCard.test.tsx <--- # Tests for profile card component
└── [ utils ]
├── validation.ts <--- # Profile validation functions
└── validation.test.ts <--- # Profile validation tests

```
Loading
Loading