From 1d9c371bfb3c97060e755e70e1eb05dd3012cd11 Mon Sep 17 00:00:00 2001 From: Joseph Baylon Date: Thu, 17 Mar 2022 17:35:26 -0700 Subject: [PATCH] Detox/E2E: Migrate e2e javascript to typescript (#6059) * Detox/E2E: Migrate to typescript * Add jest.config.js * Add moduleMapper to config.json * Add cookie jar to axios client, fix tsconfig.json and default_config.json * Take keyboard into consideration; clean test for now for this migration PR * Revert changes on path_builder * Attempt to fix dep issues * Update detox dep * Added missing @type dev dependencies * Fix dep order * Fix unit tests * Added dynamic year to email.ts --- app/components/badge/index.tsx | 3 + .../__snapshots__/server_icon.test.tsx.snap | 4 + app/components/server_icon/index.tsx | 4 + .../server_icon/server_icon.test.tsx | 2 + app/screens/bottom_sheet/button.tsx | 4 +- app/screens/bottom_sheet/content.tsx | 17 +- .../home/channel_list/servers/index.tsx | 1 + .../servers/servers_list/index.tsx | 1 + .../server_item/options/index.tsx | 6 + .../server_item/options/option.tsx | 8 +- .../servers_list/server_item/server_item.tsx | 5 + detox/.detoxrc.json | 2 +- detox/e2e/config.js | 28 -- detox/e2e/config.json | 16 + .../e2e/support/server_api/{bot.js => bot.ts} | 2 +- .../server_api/{channel.js => channel.ts} | 25 +- .../server_api/{client.js => client.ts} | 8 +- .../server_api/{common.js => common.ts} | 4 +- .../support/server_api/default_config.json | 14 +- .../support/server_api/{index.js => index.ts} | 0 .../support/server_api/{ldap.js => ldap.ts} | 6 +- .../server_api/{plugin.js => plugin.ts} | 16 +- .../support/server_api/{post.js => post.ts} | 10 +- .../{preference.js => preference.ts} | 8 +- .../support/server_api/{setup.js => setup.ts} | 4 +- .../server_api/{status.js => status.ts} | 4 +- .../server_api/{system.js => system.ts} | 38 +- .../support/server_api/{team.js => team.ts} | 31 +- .../support/server_api/{user.js => user.ts} | 38 +- detox/e2e/support/test_config.js | 13 - detox/e2e/support/test_config.ts | 15 + .../ui/component/{alert.js => alert.ts} | 2 +- .../ui/component/{index.js => index.ts} | 0 .../ui/screen/{account.js => account.ts} | 5 +- .../{channel_list.js => channel_list.ts} | 4 +- .../support/ui/screen/{home.js => home.ts} | 3 +- .../support/ui/screen/{index.js => index.ts} | 2 + .../support/ui/screen/{login.js => login.ts} | 7 +- .../ui/screen/{server.js => server.ts} | 4 +- detox/e2e/support/ui/screen/server_list.ts | 74 ++++ .../e2e/support/utils/{email.js => email.ts} | 50 +-- .../e2e/support/utils/{index.js => index.ts} | 18 +- ...server.e2e.js => connect_to_server.e2e.ts} | 1 + ..._by_email.e2e.js => login_by_email.e2e.ts} | 1 + detox/e2e/{init.js => test/setup.ts} | 0 ...erver_login.e2e.js => server_login.e2e.ts} | 1 + detox/package-lock.json | 400 +++++++++++++++--- detox/package.json | 26 +- detox/tsconfig.json | 29 ++ .../{e2e/plugins => utils}/post_message_as.js | 0 detox/{e2e => }/utils/webhook_utils.js | 0 detox/webhook_server.js | 4 +- package-lock.json | 236 ++++++++++- package.json | 10 +- tsconfig.json | 1 + 55 files changed, 933 insertions(+), 282 deletions(-) delete mode 100644 detox/e2e/config.js create mode 100644 detox/e2e/config.json rename detox/e2e/support/server_api/{bot.js => bot.ts} (93%) rename detox/e2e/support/server_api/{channel.js => channel.ts} (84%) rename detox/e2e/support/server_api/{client.js => client.ts} (55%) rename detox/e2e/support/server_api/{common.js => common.ts} (88%) rename detox/e2e/support/server_api/{index.js => index.ts} (100%) rename detox/e2e/support/server_api/{ldap.js => ldap.ts} (90%) rename detox/e2e/support/server_api/{plugin.js => plugin.ts} (86%) rename detox/e2e/support/server_api/{post.js => post.ts} (86%) rename detox/e2e/support/server_api/{preference.js => preference.ts} (85%) rename detox/e2e/support/server_api/{setup.js => setup.ts} (93%) rename detox/e2e/support/server_api/{status.js => status.ts} (89%) rename detox/e2e/support/server_api/{system.js => system.ts} (85%) rename detox/e2e/support/server_api/{team.js => team.ts} (84%) rename detox/e2e/support/server_api/{user.js => user.ts} (84%) delete mode 100644 detox/e2e/support/test_config.js create mode 100644 detox/e2e/support/test_config.ts rename detox/e2e/support/ui/component/{alert.js => alert.ts} (92%) rename detox/e2e/support/ui/component/{index.js => index.ts} (100%) rename detox/e2e/support/ui/screen/{account.js => account.ts} (85%) rename detox/e2e/support/ui/screen/{channel_list.js => channel_list.ts} (83%) rename detox/e2e/support/ui/screen/{home.js => home.ts} (92%) rename detox/e2e/support/ui/screen/{index.js => index.ts} (85%) rename detox/e2e/support/ui/screen/{login.js => login.ts} (90%) rename detox/e2e/support/ui/screen/{server.js => server.ts} (93%) create mode 100644 detox/e2e/support/ui/screen/server_list.ts rename detox/e2e/support/utils/{email.js => email.ts} (77%) rename detox/e2e/support/utils/{index.js => index.ts} (78%) rename detox/e2e/test/server_login/{connect_to_server.e2e.js => connect_to_server.e2e.ts} (99%) rename detox/e2e/test/server_login/{login_by_email.e2e.js => login_by_email.e2e.ts} (99%) rename detox/e2e/{init.js => test/setup.ts} (100%) rename detox/e2e/test/smoke_test/{server_login.e2e.js => server_login.e2e.ts} (98%) create mode 100644 detox/tsconfig.json rename detox/{e2e/plugins => utils}/post_message_as.js (100%) rename detox/{e2e => }/utils/webhook_utils.js (100%) diff --git a/app/components/badge/index.tsx b/app/components/badge/index.tsx index c9943aecde..ff309ff52a 100644 --- a/app/components/badge/index.tsx +++ b/app/components/badge/index.tsx @@ -11,6 +11,7 @@ type Props = { borderColor?: string; color?: string; style?: Animated.WithAnimatedValue>; + testID?: string; type?: 'Normal' | 'Small'; /** @@ -27,6 +28,7 @@ export default function Badge({ type = 'Normal', value, style, + testID, ...rest }: Props) { const [opacity] = React.useState(() => new Animated.Value(visible ? 1 : 0)); @@ -114,6 +116,7 @@ export default function Badge({ additionalStyle, restStyle, ]} + testID={testID} {...rest} > {badge} diff --git a/app/components/server_icon/__snapshots__/server_icon.test.tsx.snap b/app/components/server_icon/__snapshots__/server_icon.test.tsx.snap index 6fd6cf2db6..95b0a60fec 100644 --- a/app/components/server_icon/__snapshots__/server_icon.test.tsx.snap +++ b/app/components/server_icon/__snapshots__/server_icon.test.tsx.snap @@ -56,6 +56,7 @@ exports[`Server Icon Server Icon Component should match snapshot with mentions 1 "opacity": 1, } } + testID="server_icon" > 1 @@ -122,6 +124,7 @@ exports[`Server Icon Server Icon Component should match snapshot with unreads 1` "opacity": 1, } } + testID="server_icon" > diff --git a/app/components/server_icon/index.tsx b/app/components/server_icon/index.tsx index 28207a175d..a730ab3414 100644 --- a/app/components/server_icon/index.tsx +++ b/app/components/server_icon/index.tsx @@ -21,6 +21,7 @@ type Props = { onPress?: () => void; size?: number; style?: StyleProp; + testID?: string; unreadStyle?: StyleProp; } @@ -46,6 +47,7 @@ export default function ServerIcon({ onPress, size = 24, style, + testID, unreadStyle, }: Props) { const theme = useTheme(); @@ -61,6 +63,7 @@ export default function ServerIcon({ disabled={onPress === undefined} onPress={onPress} type='opacity' + testID={testID} > diff --git a/app/components/server_icon/server_icon.test.tsx b/app/components/server_icon/server_icon.test.tsx index dc9c498e92..53cb5da7db 100644 --- a/app/components/server_icon/server_icon.test.tsx +++ b/app/components/server_icon/server_icon.test.tsx @@ -24,6 +24,7 @@ describe('Server Icon', () => { , ); @@ -35,6 +36,7 @@ describe('Server Icon', () => { , ); diff --git a/app/screens/bottom_sheet/button.tsx b/app/screens/bottom_sheet/button.tsx index fe7efe1eb9..d6ec0582d4 100644 --- a/app/screens/bottom_sheet/button.tsx +++ b/app/screens/bottom_sheet/button.tsx @@ -12,9 +12,10 @@ import {makeStyleSheetFromTheme} from '@utils/theme'; type Props = { onPress?: (e: GestureResponderEvent) => void; icon?: string; + testID?: string; text?: string; } -export default function BottomSheetButton({onPress, icon, text}: Props) { +export default function BottomSheetButton({onPress, icon, testID, text}: Props) { const theme = useTheme(); const styles = getStyleSheet(theme); @@ -23,6 +24,7 @@ export default function BottomSheetButton({onPress, icon, text}: Props) { onPress={onPress} type='opacity' style={styles.button} + testID={testID} > {icon && ( diff --git a/app/screens/bottom_sheet/content.tsx b/app/screens/bottom_sheet/content.tsx index 1479f3df05..684ea2f0a7 100644 --- a/app/screens/bottom_sheet/content.tsx +++ b/app/screens/bottom_sheet/content.tsx @@ -16,6 +16,7 @@ type Props = { onPress?: (e: GestureResponderEvent) => void; showButton: boolean; showTitle: boolean; + testID?: string; title?: string; } @@ -42,18 +43,27 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => { }; }); -const BottomSheetContent = ({buttonText, buttonIcon, children, onPress, showButton, showTitle, title}: Props) => { +const BottomSheetContent = ({buttonText, buttonIcon, children, onPress, showButton, showTitle, testID, title}: Props) => { const dimensions = useWindowDimensions(); const theme = useTheme(); const isTablet = useIsTablet(); const styles = getStyleSheet(theme); const separatorWidth = Math.max(dimensions.width, 450); + const buttonTestId = `${testID}.${buttonText?.replace(/ /g, '_').toLocaleLowerCase()}.button`; return ( - + {showTitle && - {title} + + {title} + } <> @@ -65,6 +75,7 @@ const BottomSheetContent = ({buttonText, buttonIcon, children, onPress, showButt