👀 See comment on top of file for template.
We use @testing-library/react-native and our helper renderWithWrappersTL.
We try to use testID to find elements.
Links:
Similar to above. For relay testing we use mockEnvironmentPayload to mock the most recent operation.
Look at https://github.com/artsy/relay-workshop for a great tutorial of how we use relay and test with it.
Links:
We use easy-peasy for global state, and for non-persisted state we use something called sessionState. This can be in any model. If your global state is something small, you could add it in GlobalStoreModel.ts as part of the sessionState there, or you could create a new Model like ToastModel.ts that only uses non-persisted state, therefore only sessionState.
Links:
Similar to above, but if we want to persist, we put our state outside the sessionState. If your state fits in one of our existing Models in lib/store, you can use that. If it's a separate enough thing, then you can add a new Model, the VisualClueModel.ts is a good example. The state in that model will be persisted.
When changing/adding/removing persisted state, you must create a migration! For more info, look for a migration example in this file, and look at the adding_state_migrations.md docs.
Links:
Global state that is persisted needs migrations when you change/add/remove anything. That's so that the app can do any necessary preparation to the persisted storage then the app is launched, to make sure the app is in a consistent state.
There is documentation in adding_state_migrations.md, but here are the main steps are:
- Add a new version in
Versionsin migration.ts. - Change the
CURRENT_APP_VERSIONin migration.ts. - Add a migration in
artsyAppMigrationsin migration.ts. - Add a test for your migration in migration.tests.ts similar to the ones we have in there.
Links: