Skip to content

Commit

Permalink
docs: migrate docs to RSPress (#1617)
Browse files Browse the repository at this point in the history
* chore: copy Re.pack docs

* chore: global configs

* docs: migrate getting started

* chore: migrate intro

* docs: move migration guides

* chore: remove some unused things

* docs: move API

* docs: re-organize docs

* docs: re-organize

* chore: fix file refs

* docs: tweaks and fixes

* docs: reorganize docs

* chore: replace website

* chore: deploy script
  • Loading branch information
mdjastrzebski authored May 24, 2024
1 parent 4c9a8e1 commit 3cdfb85
Show file tree
Hide file tree
Showing 68 changed files with 4,275 additions and 13,355 deletions.
46 changes: 21 additions & 25 deletions website/.gitignore
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Yarn 4.x
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
doc_build
12 changes: 12 additions & 0 deletions website/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
singleQuote: true,
trailingComma: 'es5',
overrides: [
{
files: '*.css',
options: {
printWidth: 120,
},
},
],
};
894 changes: 0 additions & 894 deletions website/.yarn/releases/yarn-4.2.1.cjs

This file was deleted.

1 change: 0 additions & 1 deletion website/.yarnrc.yml

This file was deleted.

33 changes: 0 additions & 33 deletions website/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions website/docker/.dockerignore

This file was deleted.

9 changes: 0 additions & 9 deletions website/docker/Dockerfile

This file was deleted.

11 changes: 0 additions & 11 deletions website/docker/docker-compose.yml

This file was deleted.

6 changes: 6 additions & 0 deletions website/docs/12.x/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"text": "Examples",
"link": "https://github.com/callstack/react-native-testing-library/tree/main/examples"
}
]
24 changes: 24 additions & 0 deletions website/docs/12.x/docs/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"type": "dir",
"name": "start",
"label": "Getting started"
},
{ "type": "dir", "name": "api", "label": "API reference" },
{
"type": "dir",
"name": "guides",
"label": "Guides"
},
{
"type": "dir",
"name": "advanced",
"label": "Advanced Guides"
},
{
"type": "dir",
"name": "migration",
"label": "Migration Guides",
"collapsed": true
}
]
1 change: 1 addition & 0 deletions website/docs/12.x/docs/advanced/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["testing-env", "understanding-act"]
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
id: testing-env
title: Testing Environment
---
# Testing environment

:::info

This document is intended for a more advanced audience who want to understand the internals of our testing environment better, e.g., to contribute to the codebase. You should be able to write integration or component tests without reading this.

:::

React Native Testing Library allows you to write integration and component tests for your React Native app or library. While the JSX code used in tests closely resembles your React Native app, things are not as simple as they might appear. This document will describe the key elements of our testing environment and highlight things to be aware of when writing more advanced tests or diagnosing issues.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
---
id: understanding-act
title: Understanding Act function
---

import TOCInline from '@theme/TOCInline';
# Understanding `act` function

When writing RNTL tests one of the things that confuses developers the most are cryptic [`act()`](https://reactjs.org/docs/testing-recipes.html#act) function errors logged into console. In this article I will try to build an understanding of the purpose and behaviour of `act()` so you can build your tests with more confidence.

<TOCInline toc={toc} />

## `act` warnings

Let’s start with typical `act()` warnings logged to console. There are two kinds of these issues, let’s call the first one the "sync `act()`" warning:
Expand Down
22 changes: 22 additions & 0 deletions website/docs/12.x/docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
uri: /api
---
# API Overview

React Native Testing Library consists of following APIs:

- [`render` function](docs/api/render) - render your UI components for testing purposes
- [`screen` object](docs/api/screen) - access rendered UI:
- [Queries](docs/api/queries) - find relevant components by various predicates: role, text, test ids, etc
- Lifecycle methods: [`rerender`](docs/api/screen#rerender), [`unmount`](docs/api/screen#unmount)
- Helpers: [`debug`](docs/api/screen#debug), [`toJSON`](docs/api/screen#tojson), [`root`](docs/api/screen#root)
- [Jest matchers](docs/api/jest-matchers) - validate assumptions about your UI
- [User Event](docs/api/events/user-event) - simulate common user interactions like [`press`](docs/api/events/user-event#press) or [`type`](docs/api/events/user-event#type) in a realistic way
- [Fire Event](docs/api/events/fire-event) - simulate any component event in a simplified way
purposes
- Misc APIs:
- [`renderHook` function](docs/api/misc/render-hook) - render hooks for testing
- [Async utils](docs/api/misc/async): `findBy*` queries, `wait`, `waitForElementToBeRemoved`
- [Configuration](docs/api/misc/config): `configure`, `resetToDefaults`
- [Accessibility](docs/api/misc/accessibility): `isHiddenFromAccessibility`
- [Other](docs/api/misc/other): `within`, `act`, `cleanup`
8 changes: 8 additions & 0 deletions website/docs/12.x/docs/api/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{ "type": "file", "name": "render", "label": "Render function" },
{ "type": "file", "name": "screen", "label": "Screen object" },
"queries",
"jest-matchers",
{ "type": "dir", "name": "events", "label": "Triggering events" },
{ "type": "dir", "name": "misc", "label": "Miscellaneous" }
]
4 changes: 4 additions & 0 deletions website/docs/12.x/docs/api/events/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{ "type": "file", "name": "user-event", "label": "User Event" },
{ "type": "file", "name": "fire-event", "label": "Fire Event" }
]
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
---
id: fire-event
title: Fire Event
---
# Fire Event API

```ts
function fireEvent(
element: ReactTestInstance,
eventName: string,
...data: unknown[],
): void;
function fireEvent(element: ReactTestInstance, eventName: string, ...data: unknown[]): void;
```

:::note
For common events like `press` or `type` it's recommended to use [User Event API](UserEvent.md) as it offers
For common events like `press` or `type` it's recommended to use [User Event API](docs/api/events/user-event) as it offers
more realistic event simulation by emitting a sequence of events with proper event objects that mimic React Native runtime behavior.

Use Fire Event for cases not supported by User Event and for triggering event handlers on composite components.
Expand All @@ -30,7 +23,7 @@ test('fire changeText event', () => {
render(
// MyComponent renders TextInput which has a placeholder 'Enter details'
// and with `onChangeText` bound to handleChangeText
<MyComponent handleChangeText={onEventMock} />,
<MyComponent handleChangeText={onEventMock} />
);

fireEvent(screen.getByPlaceholderText('change'), 'onChangeText', 'ab');
Expand All @@ -53,7 +46,7 @@ const onBlurMock = jest.fn();
render(
<View>
<TextInput placeholder="my placeholder" onBlur={onBlurMock} />
</View>,
</View>
);

// you can omit the `on` prefix
Expand All @@ -69,7 +62,7 @@ fireEvent.press: (element: ReactTestInstance, ...data: Array<any>) => void
```

:::note
It is recommended to use the User Event [`press()`](UserEvent.md#press) helper instead as it offers more realistic simulation of press interaction, including pressable support.
It is recommended to use the User Event [`press()`](docs/api/events/user-event#press) helper instead as it offers more realistic simulation of press interaction, including pressable support.
:::

Invokes `press` event handler on the element or parent element in the tree.
Expand All @@ -91,7 +84,7 @@ render(
<TouchableOpacity onPress={onPressMock}>
<Text>Press me</Text>
</TouchableOpacity>
</View>,
</View>
);

fireEvent.press(screen.getByText('Press me'), eventData);
Expand All @@ -105,7 +98,7 @@ fireEvent.changeText: (element: ReactTestInstance, ...data: Array<any>) => void
```

:::note
It is recommended to use the User Event [`type()`](UserEvent.md#type) helper instead as it offers more realistic simulation of text change interaction, including key-by-key typing, element focus, and other editing events.
It is recommended to use the User Event [`type()`](docs/api/events/user-event#type) helper instead as it offers more realistic simulation of text change interaction, including key-by-key typing, element focus, and other editing events.
:::

Invokes `changeText` event handler on the element or parent element in the tree.
Expand All @@ -120,7 +113,7 @@ const CHANGE_TEXT = 'content';
render(
<View>
<TextInput placeholder="Enter data" onChangeText={onChangeTextMock} />
</View>,
</View>
);

fireEvent.changeText(screen.getByPlaceholderText('Enter data'), CHANGE_TEXT);
Expand Down Expand Up @@ -152,14 +145,14 @@ const eventData = {
render(
<ScrollView onScroll={onScrollMock}>
<Text>XD</Text>
</ScrollView>,
</ScrollView>
);

fireEvent.scroll(screen.getByText('scroll-view'), eventData);
```

:::note

Prefer using [`user.scrollTo`](./UserEvent.md#scrollto) over `fireEvent.scroll` for `ScrollView`, `FlatList`, and `SectionList` components. User Event provides a more realistic event simulation based on React Native runtime behavior.
Prefer using [`user.scrollTo`](docs/api/events/user-event#scrollto) over `fireEvent.scroll` for `ScrollView`, `FlatList`, and `SectionList` components. User Event provides a more realistic event simulation based on React Native runtime behavior.

:::
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
id: user-event
title: User Event
---
# User Event interactions

:::info RNTL minimal version

:::note
User Event interactions require RNTL v12.2.0 or later.

:::

## Comparison with Fire Event API
Expand Down Expand Up @@ -54,7 +53,7 @@ await user.press(element);

This helper simulates a press on any pressable element, e.g. `Pressable`, `TouchableOpacity`, `Text`, `TextInput`, etc. Unlike `fireEvent.press()`, a more straightforward API that will only call the `onPress` prop, this function simulates the entire press interaction in a more realistic way by reproducing the event sequence emitted by React Native runtime. This helper will trigger additional events like `pressIn` and `pressOut`.

## `longPress()`
## `longPress()` \{#long-press}

```ts
longPress(
Expand Down Expand Up @@ -188,7 +187,7 @@ The `textInput` event is sent only for multiline text inputs.
- `endEditing`
- `blur`
## `scrollTo()`
## `scrollTo()` \{#scroll-to}
:::note
`scrollTo` interaction has been introduced in RNTL v12.4.0.
Expand Down
Loading

0 comments on commit 3cdfb85

Please sign in to comment.