Table of Contents
- Treetracker Web Map Site
- Troubleshooting
Displays location and details of all trees that have been tracked in Greenstand.
Live site is at www.treetracker.org
NOTE
For the new web map site development, we are working on the branch: web-map-site, now we have set it as default branch.
The current version online is still deployed from master.
So, for issues, the issue for the new web map site, should use the branch: web-map-site
, the issue for the current version online, like fix bug, add tiny features, should use master
, generally, we will freeze new big feature on the master
branch.
This project must be installed and used with Node v16. Node Version Manager is an excellent tool for quickly installing and selecting Node releases.
-
Make sure all npm modules are installed for client.
npm i
-
Start the client
npm run dev
NOTE: There is a bug running the project, need some manually steps to work around it, check this issue
- Open the web map in the browser with URL: http://localhost:3000
Setup for WSL users
In order to launch Cypress in WSL you will need to have an X-Server running on Windows. This guide outlines the steps necessary to configure your WSL shell to work with an X-server. If this still isn't working try launching vcxsrv.exe from the command line like this:
WSL 1
start "" "C:\Program Files\VcXsrv\vcxsrv.exe" :0 -multiwindow -clipboard -wgl`
WSL 2
start "" "C:\Program Files\VcXsrv\vcxsrv.exe" :0 -multiwindow -clipboard -wgl -ac`
-
Feel free to pick tasks that interests you in the issue page, and leave some comment on it if you are going to work on it.
-
We tag issues with:
good first issue
: easy and good for getting started.medium
: medium difficulty or needs more work.challenge
: hardest or big tasks, or needs some special skill or tricky or even hack in some way.documentation
: writing job, sometimes it's good for new dev to learn and do some simple job.bug
: just bug.wontfix
: some issue still in discussion, or can not be implemented at current stage, or just outdated problem.high-priority
: urgent problem, like some crucial bug or feature.- We also tag issue with other aspects like the skill needed, the device related and so on.
-
Fork the repo.
-
Coding (In the process, you can rebase/merge the newest code from the main working branch online to get the new changes, check below link to get tutorial on how to update code from upstream)
-
Raise the PR, if possible, add
resolves #xx
in the description to link the PR with the issue, in this way, Github will automatically close that issue for us. -
Optional, if you haven't fully conficence about your code, it's always a good idea that create a PR in
draft
status as early as possible, so you can draw others attention on it and give you suggestions. (to do it, just expand the PR button, there is adraft
selection) -
If necessary, add some screenshot or video record to show the work, especial when you are doing some UI work, like build a component.
More resource is here: https://app.gitbook.com/@greenstand/s/engineering/tools#github
We encourage Test Driven Development, with tool like Cypress, especially the component tool of Cypress, and the intercept API, it's been pretty easy to mock and build the case for tests, so we can write the test case first, let the case fail and then implement the real code.
-
Unit test: tests against a single class, object, function or file, covering the most small unit in codebase. It's a good practice to code in TDD, but we don't enforce writing a unit test for every unit. Use Cypress component-testing to cover component units and Jest test to cover model file and utility functions.
-
Integration test: test a single piece of functionality in the app, like: a page, a module, an API endpoint. We require integration test for every page. Use Cypress for page integration tests
-
End to End test: test the real app like a human being, against real app/environment. We will implement few E2E test to cover most basic workflow, like: visit the root of the website, then jump into the detailed pages. Use Cypress to cover E2E tests.
-
Component test files should be in the same directory as the test target and have the same name as the test target file with the suffix:
.cy.js
. -
Unit test files should be in the same directory as the test target and have the same name as the test target file with the suffix:
.test.js
. -
Put all integration tests into
/cypress/tests/integration
directory with suffix:.cy.js
; -
Put all e2e tests into
/cypress/tests/e2e/
directory with suffix:.cy.js
;
We recommend using Cypress's component testing tool to build components in isolation:
To run Cypress unit/component tests:
npm run cyu
Video tutorial for building component
NOTE if you met : not test found
problem, check this issue for fixing: issue229
When developing component tests use the custom mountWithTheme
function found in src/models/test-utils.js
instead of the mount function in the @cypress/react
library. This will include the material-ui theme configuration when rendering your test component in cypress.
Do not use next/link
or @mui/material/Link
. Instead use the custom Link component in src/components/Link
. This component will ensure that an anchor tag is created with the appropriate href value for SEO purposes. If your component uses this Link component then you will need to include router mocking for component tests to pass.
https://greenstand.gitbook.io/wallet-web-app/css-and-materialui-guideline
Use Material UI's sx prop to style your components. tss-react
is included for maintaining backwards compatibility with the legacy code base.
Use the custom mountWithThemeAndRouter
function found in src/models/test-utils.js
instead of the mountWithTheme
function. This will include a basic router context mock to allow component tests to pass.
If your component uses a static image file then you will need to mock it in your component tests. Place the following code in your test file. Replace the fixture value with the path to an example image in the cypress/fixtures
directory.
beforeEach(() => {
cy.intercept('/_next/**', {
fixture: 'images/greenstand_logo_full.png',
});
});
Glossary:
- Page/Route: every unique path of url on the app is a page or route, like a single tree page:
http://map.treetracker/trees/123
.
We need to build Cypress integration tests for every page/route. The integration tests will be run in CI when merging code and deploying to protect the app from breaking.
Also, integration tests bring some benefits for the development workflow - by mocking API requests we can separately develop every single page. If you'd like to practice Test Driven Development, you can mock the API and write the tests first, then implement the real page later.
To run Cypress integration tests:
npm run cy
Note
Cypress will initialize a Nextjs dev server when run in integration mode. This means you do not need to run a local dev/production server before starting cypress.
Cypress Integration testing also includes the cypress-watch-and-reload
plugin which will restart any loaded tests when you save any changes inside the src
directory.
Video tutorial for mock the API
API calls made inside nextJs serverless functions like getServerSideProps()
can be mocked with the nock task we have added to cypress. The following example provides a mock response at the address being fetched during SSR.
Note
Cypress must start a custom Nextjs server to mock SSR functions. Use cypress open --env nock=true
or npm run cy:nock
to start cypress with a Nextjs server (this means you do not need to use npm run dev
or npm start
). You can use Cypress.env('nock')
in your test files to check if the cypress nextjs server is active.
beforeEach(() => {
Cypress.env('nock') && cy.task('clearNock'); // This will clear any mocks that have been set
});
it('getServerSideProps returns mock', () => {
const path = `/trees/${tree.id}`;
const testData = {
// expected data here
};
Cypress.env('nock') &&
cy.task('nock', {
hostname: 'http://127.0.0.1:4010/mock',
method: 'GET',
path,
statusCode: 200,
body: {
...testData,
status: 200,
},
});
cy.visit(path);
cy.contains(testData.someValue);
});
https://github.com/Greenstand/treetracker-query-api
For convenience, we also use openAPI protocol to present the URL spec:
Please import to http://editor.swagger.io to view it.
Our Figma design resource is here: https://www.figma.com/file/XdYFdjlsHvxehlrkPVYq0l/Greenstand-Webmap?node-id=2497%3A9322
Make sure you are logged in to Figma so that you can inspect the style details in Figma's editor.
To access the projects design sandbox, please run Cypress unit/component tests:
npm run cyu
Open DesignSandbox.cy.js test file in the component test browser. This component will have a color swatch, background gradient swatch, and typography information that matches the project's design file.
Please use colors from MUI's theme when working on the style of the project for better maintainability, at readability. DO NOT write colors manually!
We use Prettier, Eslint along with husky to style our code.
Prettier reformats the code, but does not do code rule checking. If you are using VSCode as your IDE, please follow this guide to set up Prettier and automatically format your code on file save.
You can find the Prettier rules in the .prettierrc file.
To check the coding rules we use Eslint. To validate the rules manually, you must run:
npm run lint
To fix automatic rules run:
npm run lint:fix
In .eslintrc.js, there is a set of rules with status off or warn. Whenever you are developing a new file or an existing file try to correct some warnings, because in the future the rules will be activated.
Once the rules are activated, you can't make a commit until you fix the lint errors!
You can find the Eslint rules in the .eslintrc.js file.
With husky we can use any git hook. Git Hooks are actions that can be executed if a certain Git event occurs. For example when a developer makes a 'git commit' or a 'git push'. Pre-commit hooks are listed in .husky/pre-commit
Lint-staged is used with husky to run actions exclusively on staged files. This allows us to lint staged files and automatically add fixes to the commit.
We use commitlint, to format our commit messages. Commitlint checks if your commit messages meet the conventional commit format.
You need to use a proper commit message format or you will not be able to commit your changes! husky checks your commit messages before every commit.
Your commit messages will need to follow the Conventional Commits format, for example:
feat: add new button
chore: run tests on travis ci
fix(server): send cors headers
In some area like China, there might be some problem with installing the Cypress, throws error log like this:
npm ERR! URL: https://download.cypress.io/desktop/8.6.0?platform=darwin&arch=x64
npm ERR! Error: read ECONNRESET
To sole this problem, download the zip file directly from Cypress CDN following guide here: https://docs.cypress.io/guides/getting-started/installing-cypress#Direct-download
Then install the project with a env variable:
CYPRESS_INSTALL_BINARY=[path/to/Cypress/zip/file] npm ci
We have more tech guides and handbook here: