-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(DOCSP-33540): React Native: Update Connect to an App Services App with auth hooks #3176
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...es/react-native/v12/TestApp/ios/TestApp.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
24 changes: 24 additions & 0 deletions
24
examples/react-native/v12/TestApp/src/components/app-services/use-app.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'react-native'; | ||
import React from 'react'; | ||
import {AppWithAuthHook} from './use-app'; | ||
import {render, screen, userEvent} from '@testing-library/react-native'; | ||
import '@testing-library/jest-dom'; | ||
|
||
test('App with auth hook', async () => { | ||
render(<AppWithAuthHook />); | ||
|
||
const user = userEvent.setup(); | ||
|
||
const logInButton = screen.queryByTestId('log-in'); | ||
|
||
if (logInButton) { | ||
await user.press(logInButton); | ||
} | ||
|
||
const loggedInUserText = await screen.findByTestId('logged-in-user-id'); | ||
expect(loggedInUserText).not.toEqual(null); | ||
|
||
const notYetLoggedIn = screen.queryByText('No one is logged in yet.'); | ||
|
||
expect(notYetLoggedIn).not.toBeInTheDocument(); | ||
}); |
93 changes: 93 additions & 0 deletions
93
examples/react-native/v12/TestApp/src/components/app-services/use-app.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// :snippet-start: app-config-imports | ||
import React from 'react'; | ||
import {AppProvider, UserProvider} from '@realm/react'; | ||
// :snippet-end: | ||
// :snippet-start: import-use-app | ||
// :uncomment-start: | ||
//import React from 'react'; | ||
// :uncomment-end: | ||
import {useApp} from '@realm/react'; | ||
// :snippet-end: | ||
import {useAuth} from '@realm/react'; | ||
import {Text, View, Pressable, StyleSheet} from 'react-native'; | ||
import {APP_ID} from '../../../appServicesConfig'; | ||
|
||
// :snippet-start: app-config | ||
export const AppWithAuthHook = () => { | ||
return ( | ||
<View> | ||
<AppProvider id={APP_ID}> | ||
<UserProvider fallback={LogIn}> | ||
<MyApp /> | ||
</UserProvider> | ||
</AppProvider> | ||
</View> | ||
); | ||
}; | ||
// :snippet-end: | ||
|
||
const LogIn = () => { | ||
const {logInWithAnonymous} = useAuth(); | ||
|
||
return ( | ||
<View> | ||
<Text>No one is logged in yet.</Text> | ||
<Pressable | ||
testID="log-in" | ||
style={styles.button} | ||
onPress={logInWithAnonymous}> | ||
<Text style={styles.buttonText}>Log in</Text> | ||
</Pressable> | ||
</View> | ||
); | ||
}; | ||
|
||
// :snippet-start: use-app | ||
function MyApp() { | ||
const app = useApp(); | ||
// Proceed to app logic... | ||
// :remove-start: | ||
return ( | ||
<Text testID="logged-in-user-id">"Logged in as user with ID: {app.currentUser?.id}"</Text> | ||
); | ||
// :remove-end: | ||
} | ||
// :snippet-end: | ||
|
||
const styles = StyleSheet.create({ | ||
section: { | ||
flex: 1, | ||
marginTop: 8, | ||
paddingVertical: 12, | ||
alignItems: 'center', | ||
}, | ||
textInput: { | ||
backgroundColor: '#C5CAE9', | ||
borderBottomWidth: StyleSheet.hairlineWidth, | ||
marginVertical: 5, | ||
}, | ||
inputGroup: { | ||
width: '100%', | ||
}, | ||
buttonGroup: { | ||
flexDirection: 'row', | ||
flexWrap: 'wrap', | ||
marginVertical: 12, | ||
paddingVertical: 8, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
button: { | ||
backgroundColor: '#3F51B5', | ||
borderWidth: StyleSheet.hairlineWidth, | ||
borderColor: '#ffffff', | ||
paddingVertical: 5, | ||
paddingHorizontal: 8, | ||
marginVertical: 5, | ||
marginHorizontal: 8, | ||
}, | ||
buttonText: { | ||
color: '#ffffff', | ||
textAlign: 'center', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
source/examples/generated/react-native/ts/use-app.test.snippet.use-app.tsx
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
.../examples/generated/react-native/v12/use-app.snippet.app-config-imports.tsx.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.. code-block:: typescript | ||
|
||
import React from 'react'; | ||
import {AppProvider, UserProvider} from '@realm/react'; |
13 changes: 13 additions & 0 deletions
13
source/examples/generated/react-native/v12/use-app.snippet.app-config.tsx.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.. code-block:: typescript | ||
|
||
export const AppWithAuthHook = () => { | ||
return ( | ||
<View> | ||
<AppProvider id={APP_ID}> | ||
<UserProvider fallback={LogIn}> | ||
<MyApp /> | ||
</UserProvider> | ||
</AppProvider> | ||
</View> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
source/examples/generated/react-native/v12/use-app.snippet.import-use-app.tsx.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.. code-block:: typescript | ||
|
||
import React from 'react'; | ||
import {useApp} from '@realm/react'; |
6 changes: 6 additions & 0 deletions
6
source/examples/generated/react-native/v12/use-app.snippet.use-app.tsx.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.. code-block:: typescript | ||
|
||
function MyApp() { | ||
const app = useApp(); | ||
// Proceed to app logic... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I wish we could use the
findBy*
for everything because we canawait
results, but as you probably noticed, you can't test a negative with them. IffindBy*
doesn't find what it wants, it errors the whole test. 😢This does mean there could be edge cases where
queryByText
isn't in sync with the rendered UI (because it's not waiting to find UI elements). But this is a great use for it.