Skip to content

Commit 954bf33

Browse files
committed
chore: update React-Native example app
1 parent 2e0c293 commit 954bf33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3367
-4561
lines changed

examples/publish-ci/react-native/.eslintrc.json

-34
This file was deleted.

examples/publish-ci/react-native/.gitignore

+15-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23-
ios/.xcode.env.local
23+
**/.xcode.env.local
2424

2525
# Android/IntelliJ
2626
#
2727
build/
28+
dist/
2829
.idea
2930
.gradle
3031
local.properties
@@ -33,13 +34,13 @@ local.properties
3334
.cxx/
3435
*.keystore
3536
!debug.keystore
37+
.kotlin/
3638

3739
# node.js
3840
#
3941
node_modules/
4042
npm-debug.log
4143
yarn-error.log
42-
.yarn/
4344

4445
# fastlane
4546
#
@@ -57,7 +58,7 @@ yarn-error.log
5758
*.jsbundle
5859

5960
# Ruby / CocoaPods
60-
/ios/Pods/
61+
**/Pods/
6162
/vendor/bundle/
6263

6364
# Temporary files created by Metro to check the health of the file watcher
@@ -66,5 +67,16 @@ yarn-error.log
6667
# testing
6768
/coverage
6869

70+
# Yarn
71+
.yarn/*
72+
!.yarn/patches
73+
!.yarn/plugins
74+
!.yarn/releases
75+
!.yarn/sdks
76+
!.yarn/versions
77+
6978
#IDE
7079
.vscode
80+
81+
.yalc/
82+
yalc.lock
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"arrowParens": "avoid",
3-
"semi": false
3+
"semi": false,
4+
"singleQuote": true
45
}

examples/publish-ci/react-native/App.test.tsx

+108-72
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,171 @@
1-
import type { Action, Dispatch } from "@reduxjs/toolkit"
2-
import { configureStore } from "@reduxjs/toolkit"
3-
import { screen, waitFor } from "@testing-library/react-native"
4-
import { Component, PureComponent, type PropsWithChildren } from "react"
5-
import type { TextStyle } from "react-native"
6-
import { Button, Text, View } from "react-native"
7-
import { connect, Provider } from "react-redux"
8-
import { App } from "./App"
9-
import { renderWithProviders } from "./src/utils/test-utils"
10-
11-
test("App should have correct initial render", () => {
1+
import type { Action } from '@reduxjs/toolkit'
2+
import { configureStore } from '@reduxjs/toolkit'
3+
import { act, screen } from '@testing-library/react-native'
4+
import type { Dispatch, PropsWithChildren } from 'react'
5+
import { Component, PureComponent } from 'react'
6+
import type { TextStyle } from 'react-native'
7+
import { Button, Text, View } from 'react-native'
8+
import { connect, Provider } from 'react-redux'
9+
import { App } from './App'
10+
import { renderWithProviders } from './src/utils/test-utils'
11+
12+
test('App should have correct initial render', () => {
1213
renderWithProviders(<App />)
1314

15+
const countLabel = screen.getByLabelText('Count')
16+
17+
const incrementValueInput = screen.getByLabelText('Set increment amount')
18+
1419
// The app should be rendered correctly
1520
expect(screen.getByText(/learn more redux/i)).toBeOnTheScreen()
1621

1722
// Initial state: count should be 0, incrementValue should be 2
18-
expect(screen.getByLabelText("Count")).toHaveTextContent("0")
19-
expect(screen.getByLabelText("Set increment amount")).toHaveDisplayValue("2")
23+
expect(countLabel).toHaveTextContent('0')
24+
expect(incrementValueInput).toHaveDisplayValue('2')
2025
})
2126

22-
test("Increment value and Decrement value should work as expected", async () => {
27+
test('Increment value and Decrement value should work as expected', async () => {
2328
const { user } = renderWithProviders(<App />)
2429

30+
const countLabel = screen.getByLabelText('Count')
31+
32+
const incrementValueButton = screen.getByLabelText('Increment value')
33+
34+
const decrementValueButton = screen.getByLabelText('Decrement value')
35+
2536
// Click on "+" => Count should be 1
26-
await user.press(screen.getByLabelText("Increment value"))
27-
expect(screen.getByLabelText("Count")).toHaveTextContent("1")
37+
await user.press(incrementValueButton)
38+
expect(countLabel).toHaveTextContent('1')
2839

2940
// Click on "-" => Count should be 0
30-
await user.press(screen.getByLabelText("Decrement value"))
31-
expect(screen.getByLabelText("Count")).toHaveTextContent("0")
41+
await user.press(decrementValueButton)
42+
expect(countLabel).toHaveTextContent('0')
3243
})
3344

34-
test("Add Amount should work as expected", async () => {
45+
test('Add Amount should work as expected', async () => {
3546
const { user } = renderWithProviders(<App />)
3647

48+
const countLabel = screen.getByLabelText('Count')
49+
50+
const incrementValueInput = screen.getByLabelText('Set increment amount')
51+
52+
const addAmountButton = screen.getByText('Add Amount')
53+
3754
// "Add Amount" button is clicked => Count should be 2
38-
await user.press(screen.getByText("Add Amount"))
39-
expect(screen.getByLabelText("Count")).toHaveTextContent("2")
55+
await user.press(addAmountButton)
56+
expect(countLabel).toHaveTextContent('2')
4057

41-
const incrementValueInput = screen.getByLabelText("Set increment amount")
4258
// incrementValue is 2, click on "Add Amount" => Count should be 4
4359
await user.clear(incrementValueInput)
44-
await user.type(incrementValueInput, "2")
45-
await user.press(screen.getByText("Add Amount"))
46-
expect(screen.getByLabelText("Count")).toHaveTextContent("4")
60+
await user.type(incrementValueInput, '2')
61+
await user.press(addAmountButton)
62+
expect(countLabel).toHaveTextContent('4')
4763

4864
// [Negative number] incrementValue is -1, click on "Add Amount" => Count should be 3
4965
await user.clear(incrementValueInput)
50-
await user.type(incrementValueInput, "-1")
51-
await user.press(screen.getByText("Add Amount"))
52-
expect(screen.getByLabelText("Count")).toHaveTextContent("3")
66+
await user.type(incrementValueInput, '-1')
67+
await user.press(addAmountButton)
68+
expect(countLabel).toHaveTextContent('3')
5369
})
5470

55-
it("Add Async should work as expected", async () => {
71+
it('Add Async should work as expected', async () => {
5672
const { user } = renderWithProviders(<App />)
5773

74+
const addAsyncButton = screen.getByText('Add Async')
75+
76+
const countLabel = screen.getByLabelText('Count')
77+
78+
const incrementValueInput = screen.getByLabelText('Set increment amount')
79+
5880
// "Add Async" button is clicked => Count should be 2
59-
await user.press(screen.getByText("Add Async"))
81+
await user.press(addAsyncButton)
6082

61-
await waitFor(() => {
62-
expect(screen.getByLabelText("Count")).toHaveTextContent("2")
83+
await act(async () => {
84+
await jest.advanceTimersByTimeAsync(500)
6385
})
6486

65-
const incrementValueInput = screen.getByLabelText("Set increment amount")
87+
expect(countLabel).toHaveTextContent('2')
88+
6689
// incrementValue is 2, click on "Add Async" => Count should be 4
6790
await user.clear(incrementValueInput)
68-
await user.type(incrementValueInput, "2")
91+
await user.type(incrementValueInput, '2')
92+
93+
await user.press(addAsyncButton)
6994

70-
await user.press(screen.getByText("Add Async"))
71-
await waitFor(() => {
72-
expect(screen.getByLabelText("Count")).toHaveTextContent("4")
95+
await act(async () => {
96+
await jest.advanceTimersByTimeAsync(500)
7397
})
7498

99+
expect(countLabel).toHaveTextContent('4')
100+
75101
// [Negative number] incrementValue is -1, click on "Add Async" => Count should be 3
76102
await user.clear(incrementValueInput)
77-
await user.type(incrementValueInput, "-1")
78-
await user.press(screen.getByText("Add Async"))
79-
await waitFor(() => {
80-
expect(screen.getByLabelText("Count")).toHaveTextContent("3")
103+
await user.type(incrementValueInput, '-1')
104+
await user.press(addAsyncButton)
105+
106+
await act(async () => {
107+
await jest.advanceTimersByTimeAsync(500)
81108
})
109+
110+
expect(countLabel).toHaveTextContent('3')
82111
})
83112

84-
test("Add If Odd should work as expected", async () => {
113+
test('Add If Odd should work as expected', async () => {
85114
const { user } = renderWithProviders(<App />)
86115

116+
const countLabel = screen.getByLabelText('Count')
117+
118+
const addIfOddButton = screen.getByText('Add If Odd')
119+
120+
const incrementValueInput = screen.getByLabelText('Set increment amount')
121+
122+
const incrementValueButton = screen.getByLabelText('Increment value')
123+
87124
// "Add If Odd" button is clicked => Count should stay 0
88-
await user.press(screen.getByText("Add If Odd"))
89-
expect(screen.getByLabelText("Count")).toHaveTextContent("0")
125+
await user.press(addIfOddButton)
126+
expect(countLabel).toHaveTextContent('0')
90127

91128
// Click on "+" => Count should be updated to 1
92-
await user.press(screen.getByLabelText("Increment value"))
93-
expect(screen.getByLabelText("Count")).toHaveTextContent("1")
129+
await user.press(incrementValueButton)
130+
expect(countLabel).toHaveTextContent('1')
94131

95132
// "Add If Odd" button is clicked => Count should be updated to 3
96-
await user.press(screen.getByText("Add If Odd"))
97-
expect(screen.getByLabelText("Count")).toHaveTextContent("3")
133+
await user.press(addIfOddButton)
134+
expect(countLabel).toHaveTextContent('3')
98135

99-
const incrementValueInput = screen.getByLabelText("Set increment amount")
100136
// incrementValue is 1, click on "Add If Odd" => Count should be updated to 4
101137
await user.clear(incrementValueInput)
102-
await user.type(incrementValueInput, "1")
103-
await user.press(screen.getByText("Add If Odd"))
104-
expect(screen.getByLabelText("Count")).toHaveTextContent("4")
138+
await user.type(incrementValueInput, '1')
139+
await user.press(addIfOddButton)
140+
expect(countLabel).toHaveTextContent('4')
105141

106142
// click on "Add If Odd" => Count should stay 4
107143
await user.clear(incrementValueInput)
108-
await user.type(incrementValueInput, "-1")
109-
await user.press(screen.getByText("Add If Odd"))
110-
expect(screen.getByLabelText("Count")).toHaveTextContent("4")
144+
await user.type(incrementValueInput, '-1')
145+
await user.press(addIfOddButton)
146+
expect(countLabel).toHaveTextContent('4')
111147
})
112148

113-
test("React-Redux issue #2150: Nested component updates should be properly batched when using connect", async () => {
149+
test('React-Redux issue #2150: Nested component updates should be properly batched when using connect', async () => {
114150
// Original Issue: https://github.com/reduxjs/react-redux/issues/2150
115151
// Solution: https://github.com/reduxjs/react-redux/pull/2156
116152

117153
// Actions
118-
const ADD = "ADD"
119-
const DATE = "DATE"
154+
const ADD = 'ADD'
155+
const DATE = 'DATE'
120156

121157
// Action types
122-
interface AddAction extends Action<string> {}
123-
interface DateAction extends Action<string> {
158+
type AddAction = {} & Action
159+
type DateAction = {
124160
payload?: { date: number }
125-
}
161+
} & Action
126162

127163
// Reducer states
128-
interface DateState {
164+
type DateState = {
129165
date: number | null
130166
}
131167

132-
interface CounterState {
168+
type CounterState = {
133169
count: number
134170
}
135171

@@ -173,7 +209,7 @@ test("React-Redux issue #2150: Nested component updates should be properly batch
173209
})
174210

175211
// ======== COMPONENTS =========
176-
interface CounterProps {
212+
type CounterProps = {
177213
count?: number
178214
date?: number | null
179215
dispatch: Dispatch<AddAction | DateAction>
@@ -192,7 +228,7 @@ test("React-Redux issue #2150: Nested component updates should be properly batch
192228
render() {
193229
return (
194230
<View style={{ paddingVertical: 20 }}>
195-
<Text testID={`${this.props.testID}-child`}>
231+
<Text testID={`${this.props.testID ?? ''}-child`}>
196232
Counter Value: {this.props.count}
197233
</Text>
198234
<Text>date Value: {this.props.date}</Text>
@@ -241,7 +277,7 @@ test("React-Redux issue #2150: Nested component updates should be properly batch
241277
}
242278
}
243279

244-
const mapStateToPropsBreaking = (_state: any) => ({})
280+
const mapStateToPropsBreaking = (_state: unknown) => ({})
245281

246282
const ContainerBad = connect(mapStateToPropsBreaking, null)(Container)
247283

@@ -254,7 +290,7 @@ test("React-Redux issue #2150: Nested component updates should be properly batch
254290
null,
255291
)(Container)
256292

257-
const mapStateToPropsNonBlocking2 = (state: any) => ({ state })
293+
const mapStateToPropsNonBlocking2 = (state: unknown) => ({ state })
258294

259295
const ContainerNonBlocking2 = connect(
260296
mapStateToPropsNonBlocking2,
@@ -303,13 +339,13 @@ test("React-Redux issue #2150: Nested component updates should be properly batch
303339

304340
const { user, getByTestId, getByText } = renderWithProviders(<MainApp />)
305341

306-
expect(getByTestId("undesired-child")).toHaveTextContent("Counter Value: 0")
342+
expect(getByTestId('undesired-child')).toHaveTextContent('Counter Value: 0')
307343

308-
await user.press(getByText("Increment Counter"))
344+
await user.press(getByText('Increment Counter'))
309345

310-
expect(getByTestId("inconsistent-child")).toHaveTextContent(
311-
"Counter Value: 1",
346+
expect(getByTestId('inconsistent-child')).toHaveTextContent(
347+
'Counter Value: 1',
312348
)
313349

314-
expect(getByTestId("undesired-child")).toHaveTextContent("Counter Value: 1")
350+
expect(getByTestId('undesired-child')).toHaveTextContent('Counter Value: 1')
315351
})

0 commit comments

Comments
 (0)