Skip to content

Commit a76ff93

Browse files
committed
upgrade react-native 0.79.2; update tests
1 parent 856c2ce commit a76ff93

File tree

6 files changed

+585
-1126
lines changed

6 files changed

+585
-1126
lines changed

DropdownAlert.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ export type DropdownAlertProps = {
158158
activeStatusBarStyle?: StatusBarStyle;
159159
// StatusBarStyle when alert is dismissed and updateStatusBar must be true
160160
inactiveStatusBarStyle?: StatusBarStyle;
161-
renderImage?: (data: DropdownAlertData) => JSX.Element;
162-
renderCancel?: (data: DropdownAlertData, onCancel: () => void) => JSX.Element;
163-
renderTitle?: (data: DropdownAlertData) => JSX.Element;
164-
renderMessage?: (data: DropdownAlertData) => JSX.Element;
161+
renderImage?: (data: DropdownAlertData) => React.JSX.Element;
162+
renderCancel?: (data: DropdownAlertData, onCancel: () => void) => React.JSX.Element;
163+
renderTitle?: (data: DropdownAlertData) => React.JSX.Element;
164+
renderMessage?: (data: DropdownAlertData) => React.JSX.Element;
165165
titleTextProps?: TextProps;
166166
messageTextProps?: TextProps;
167167
animatedViewProps?: ViewProps;

__tests__/DropdownAlert.test.tsx

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import React from 'react';
2-
import {Image, LayoutChangeEvent, Pressable, Text, View} from 'react-native';
3-
import '@testing-library/jest-native/extend-expect';
2+
import {
3+
Image,
4+
LayoutChangeEvent,
5+
Platform,
6+
Pressable,
7+
StatusBar,
8+
Text,
9+
View,
10+
} from 'react-native';
411
import {
512
render,
613
act,
@@ -131,7 +138,7 @@ test('onDismissProgrammatic', async () => {
131138
/>,
132139
);
133140
expect(component).toBeDefined();
134-
await act(() => {
141+
act(() => {
135142
alert({
136143
type: 'custom',
137144
title: DropDownAlertTestID.Title,
@@ -148,7 +155,7 @@ test('onDismissProgrammatic', async () => {
148155
dismiss();
149156
await delay();
150157
});
151-
expect(_onDismissProgrammatic).toBeCalled();
158+
expect(_onDismissProgrammatic).toHaveBeenCalled();
152159
}, 2000);
153160

154161
test('onDismissPress', async () => {
@@ -180,7 +187,7 @@ test('onDismissPress', async () => {
180187
fireEvent.press(button);
181188
await delay();
182189
});
183-
expect(_onDismissPress).toBeCalled();
190+
expect(_onDismissPress).toHaveBeenCalled();
184191
}, 2000);
185192

186193
test('onDismissCancel', async () => {
@@ -211,7 +218,7 @@ test('onDismissCancel', async () => {
211218
expect(cancelImage).toBeDefined();
212219
await delay();
213220
});
214-
expect(_onDismissCancel).toBeCalled();
221+
expect(_onDismissCancel).toHaveBeenCalled();
215222
}, 5500);
216223

217224
test('renderImage, renderTitle, renderMessage and renderCancel props', async () => {
@@ -281,16 +288,30 @@ test('Animated.View onLayout function', async () => {
281288
<DropdownAlert alert={func => (alert = func)} dismissInterval={0} />,
282289
);
283290
expect(component).toBeDefined();
284-
await act(() => {
291+
act(() => {
285292
alert({type: DropdownAlertType.Warn, title: 'title', message: 'message'});
286293
});
287294
const height = 150;
288295
const animatedView = screen.getByTestId(DropDownAlertTestID.AnimatedView);
289296
expect(animatedView).toBeDefined();
290297
const event: LayoutChangeEvent = {
291298
nativeEvent: {layout: {x: 0, y: 0, height, width: 100}},
292-
currentTarget: 0,
293-
target: 0,
299+
currentTarget: {
300+
measure: jest.fn(),
301+
measureInWindow: jest.fn(),
302+
measureLayout: jest.fn(),
303+
setNativeProps: jest.fn(),
304+
focus: jest.fn(),
305+
blur: jest.fn(),
306+
},
307+
target: {
308+
measure: jest.fn(),
309+
measureInWindow: jest.fn(),
310+
measureLayout: jest.fn(),
311+
setNativeProps: jest.fn(),
312+
focus: jest.fn(),
313+
blur: jest.fn(),
314+
},
294315
bubbles: false,
295316
cancelable: false,
296317
defaultPrevented: false,
@@ -319,17 +340,7 @@ test('Animated.View onLayout function', async () => {
319340
});
320341

321342
test('it updates status bar on Android', async () => {
322-
jest.mock('react-native/Libraries/Utilities/Platform', () => ({
323-
OS: 'android',
324-
select: () => null,
325-
}));
326-
const currentHeight = 20;
327-
jest.mock('react-native/Libraries/Components/StatusBar/StatusBar', () => ({
328-
currentHeight,
329-
setBackgroundColor: jest.fn(),
330-
setTranslucent: jest.fn(),
331-
setBarStyle: jest.fn(),
332-
}));
343+
Platform.OS = 'android';
333344
let alert = (_data?: DropdownAlertData) =>
334345
new Promise<DropdownAlertData>(res => res);
335346
const component = render(
@@ -341,22 +352,12 @@ test('it updates status bar on Android', async () => {
341352
});
342353
const button = screen.getByTestId(DropDownAlertTestID.Alert);
343354
expect(button).toBeDefined();
344-
expect(button).toHaveStyle({marginTop: currentHeight});
355+
expect(button).toHaveStyle({marginTop: StatusBar.currentHeight});
345356
expect(component.toJSON()).toMatchSnapshot();
346357
}, 6000);
347358

348359
test('it updates status bar with containerStyle undefined backgroundColor on Android', async () => {
349-
jest.mock('react-native/Libraries/Utilities/Platform', () => ({
350-
OS: 'android',
351-
select: () => null,
352-
}));
353-
const currentHeight = 20;
354-
jest.mock('react-native/Libraries/Components/StatusBar/StatusBar', () => ({
355-
currentHeight,
356-
setBackgroundColor: jest.fn(),
357-
setTranslucent: jest.fn(),
358-
setBarStyle: jest.fn(),
359-
}));
360+
Platform.OS = 'android';
360361
let alert = (_data?: DropdownAlertData) =>
361362
new Promise<DropdownAlertData>(res => res);
362363
const component = render(
@@ -372,7 +373,8 @@ test('it updates status bar with containerStyle undefined backgroundColor on And
372373
});
373374
const button = screen.getByTestId(DropDownAlertTestID.Alert);
374375
expect(button).toBeDefined();
375-
expect(button).toHaveStyle({marginTop: currentHeight});
376+
expect(button).toHaveStyle({marginTop: StatusBar.currentHeight});
377+
expect(component.toJSON()).toMatchSnapshot();
376378
}, 6000);
377379

378380
test('children prop', async () => {

__tests__/__snapshots__/DropdownAlert.test.tsx.snap

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,101 @@ exports[`it updates status bar on Android 1`] = `
797797
style={
798798
{
799799
"backgroundColor": "#000000",
800-
"marginTop": 20,
800+
"marginTop": null,
801+
"opacity": 1,
802+
"padding": 8,
803+
}
804+
}
805+
testID="alert"
806+
>
807+
<View
808+
style={
809+
{
810+
"alignItems": "center",
811+
"flexDirection": "row",
812+
}
813+
}
814+
testID="safeView"
815+
>
816+
<View
817+
style={
818+
{
819+
"flex": 1,
820+
"marginHorizontal": 8,
821+
}
822+
}
823+
testID="textView"
824+
/>
825+
</View>
826+
</View>
827+
</View>
828+
`;
829+
830+
exports[`it updates status bar with containerStyle undefined backgroundColor on Android 1`] = `
831+
<View
832+
collapsable={false}
833+
onLayout={[Function]}
834+
onMoveShouldSetResponder={[Function]}
835+
onMoveShouldSetResponderCapture={[Function]}
836+
onResponderEnd={[Function]}
837+
onResponderGrant={[Function]}
838+
onResponderMove={[Function]}
839+
onResponderReject={[Function]}
840+
onResponderRelease={[Function]}
841+
onResponderStart={[Function]}
842+
onResponderTerminate={[Function]}
843+
onResponderTerminationRequest={[Function]}
844+
onStartShouldSetResponder={[Function]}
845+
onStartShouldSetResponderCapture={[Function]}
846+
style={
847+
{
848+
"elevation": 1,
849+
"left": 0,
850+
"position": "absolute",
851+
"right": 0,
852+
"top": 0,
853+
"transform": [
854+
{
855+
"translateY": -99,
856+
},
857+
],
858+
"zIndex": 1,
859+
}
860+
}
861+
testID="animatedView"
862+
>
863+
<View
864+
accessibilityState={
865+
{
866+
"busy": undefined,
867+
"checked": undefined,
868+
"disabled": false,
869+
"expanded": undefined,
870+
"selected": undefined,
871+
}
872+
}
873+
accessibilityValue={
874+
{
875+
"max": undefined,
876+
"min": undefined,
877+
"now": undefined,
878+
"text": undefined,
879+
}
880+
}
881+
accessible={true}
882+
collapsable={false}
883+
focusable={true}
884+
onClick={[Function]}
885+
onResponderGrant={[Function]}
886+
onResponderMove={[Function]}
887+
onResponderRelease={[Function]}
888+
onResponderTerminate={[Function]}
889+
onResponderTerminationRequest={[Function]}
890+
onStartShouldSetResponder={[Function]}
891+
style={
892+
{
893+
"backgroundColor": undefined,
894+
"marginTop": null,
801895
"opacity": 1,
802896
"padding": 8,
803897
}

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module.exports = {
135135
// setupFiles: [],
136136

137137
// A list of paths to modules that run some code to configure or set up the testing framework before each test
138-
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
138+
// setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
139139

140140
// The number of seconds after which a test is considered as slow and reported as such in the results.
141141
// slowTestThreshold: 5,

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@
3232
},
3333
"homepage": "https://github.com/testshallpass/react-native-dropdownalert#readme",
3434
"devDependencies": {
35-
"@react-native/babel-preset": "0.76.2",
36-
"@react-native/eslint-config": "0.76.2",
37-
"@react-native/typescript-config": "0.76.2",
38-
"@testing-library/jest-native": "5.4.3",
39-
"@testing-library/react-native": "12.8.1",
35+
"@react-native/babel-preset": "0.79.2",
36+
"@react-native/eslint-config": "0.79.2",
37+
"@react-native/metro-config": "0.79.2",
38+
"@react-native/typescript-config": "0.79.2",
39+
"@testing-library/react-native": "13.2.0",
4040
"@types/jest": "29.5.14",
41-
"@types/react": "18.3.12",
42-
"@types/react-test-renderer": "18.0.7",
41+
"@types/react": "19.0.0",
42+
"@types/react-test-renderer": "19.0.0",
4343
"babel-jest": "29.7.0",
4444
"eslint": "8.57.1",
4545
"jest": "29.7.0",
4646
"prettier": "3.3.3",
47-
"react": "18.3.1",
48-
"react-native": "0.76.2",
49-
"react-test-renderer": "18.3.1",
50-
"ts-jest": "29.2.5",
47+
"react": "19.0.0",
48+
"react-native": "0.79.2",
49+
"react-test-renderer": "19.0.0",
50+
"ts-jest": "29.3.4",
5151
"typescript": "5.5.4"
5252
},
53-
"packageManager": "yarn@4.5.1"
53+
"packageManager": "yarn@4.9.2"
5454
}

0 commit comments

Comments
 (0)