-
Notifications
You must be signed in to change notification settings - Fork 88
(DOCSP-26999): Connect to App Services page #2526
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a453e49
create code examples
mongodben d3bb34e
update docs
mongodben 347fd88
fix broken test
mongodben e9fccc4
Apply suggestions from code review
mongodben add70ad
implement AM feedback
mongodben fe8acfa
implement kyle feedback
mongodben b95de78
update examples to TS only
mongodben e0f8976
Apply suggestions from code review
mongodben 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
36 changes: 36 additions & 0 deletions
36
examples/react-native/__tests__/ts/app-services/app-provider.test.tsx
This file contains hidden or 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,36 @@ | ||
// :snippet-start: app-provider | ||
import React from 'react'; | ||
import {AppProvider} from '@realm/react'; | ||
// :remove-start: | ||
import {render} from '@testing-library/react-native'; | ||
import {useApp} from '@realm/react'; | ||
import {View, Text} from 'react-native'; | ||
|
||
const APP_ID = 'example-testers-kvjdy'; | ||
|
||
function MyApp() { | ||
const app = useApp(); | ||
if (app.id !== APP_ID) { | ||
throw new Error('Did not instantiate app client'); | ||
} | ||
return ( | ||
<View> | ||
<Text>Foo</Text> | ||
</View> | ||
); | ||
} | ||
// :remove-end: | ||
function AppWrapper() { | ||
return ( | ||
<View> | ||
<AppProvider id={APP_ID}> | ||
<MyApp /> | ||
</AppProvider> | ||
</View> | ||
); | ||
} | ||
// :snippet-end: | ||
|
||
test('Instantiate AppProvider correctly', () => { | ||
render(<AppWrapper />); | ||
}); |
42 changes: 42 additions & 0 deletions
42
examples/react-native/__tests__/ts/app-services/use-app.test.tsx
This file contains hidden or 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,42 @@ | ||
// :snippet-start: use-app | ||
import React from 'react'; | ||
import {useApp} from '@realm/react'; | ||
import {Credentials} from 'realm'; | ||
// :remove-start: | ||
import {App} from 'realm'; | ||
import {AppProvider} from '@realm/react'; | ||
import {render, fireEvent, waitFor} from '@testing-library/react-native'; | ||
import {View, Button} from 'react-native'; | ||
|
||
const APP_ID = 'example-testers-kvjdy'; | ||
|
||
function AppWrapper() { | ||
return ( | ||
<View> | ||
<AppProvider id={APP_ID}> | ||
<MyApp /> | ||
</AppProvider> | ||
</View> | ||
); | ||
} | ||
// :remove-end: | ||
function MyApp() { | ||
const app = useApp(); | ||
function logInAnonymousUser() { | ||
app.logIn(Credentials.anonymous()); | ||
} | ||
// ... | ||
// :remove-start: | ||
return <Button onPress={logInAnonymousUser} testID='test-use-app' title='Test Me!' />; | ||
// :remove-end: | ||
} | ||
// :snippet-end: | ||
|
||
afterEach(async () => await App.getApp(APP_ID).currentUser?.logOut()); | ||
|
||
test('useApp hook works correctly', async () => { | ||
const {getByTestId} = render(<AppWrapper />); | ||
const button = getByTestId('test-use-app'); | ||
fireEvent.press(button); | ||
await waitFor(() => expect(App.getApp(APP_ID).currentUser).not.toBeNull()); | ||
}); |
This file contains hidden or 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,16 @@ | ||
#!/bin/bash | ||
|
||
PROJECT=$(git rev-parse --show-toplevel) | ||
JS_RN_EXAMPLES=$PROJECT/examples/react-native/__tests__/js/ | ||
TS_RN_EXAMPLES=$PROJECT/examples/react-native/__tests__/ts | ||
|
||
echo $JS_RN_EXAMPLES | ||
|
||
JS_GENERATED_EXAMPLES=$PROJECT/source/examples/generated/react-native/js | ||
TS_GENERATED_EXAMPLES=$PROJECT/source/examples/generated/react-native/ts | ||
echo $JS_GENERATED_EXAMPLES | ||
|
||
bluehawk snip $JS_RN_EXAMPLES -o $JS_GENERATED_EXAMPLES | ||
|
||
bluehawk snip $TS_RN_EXAMPLES -o $TS_GENERATED_EXAMPLES | ||
|
12 changes: 12 additions & 0 deletions
12
source/examples/generated/react-native/ts/app-provider.test.snippet.app-provider.tsx
This file contains hidden or 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,12 @@ | ||
import React from 'react'; | ||
import {AppProvider} from '@realm/react'; | ||
|
||
function AppWrapper() { | ||
return ( | ||
<View> | ||
<AppProvider id={APP_ID}> | ||
<MyApp /> | ||
</AppProvider> | ||
</View> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
source/examples/generated/react-native/ts/use-app.test.snippet.use-app.tsx
This file contains hidden or 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,11 @@ | ||
import React from "react"; | ||
import { useApp } from "@realm/react"; | ||
import { Credentials } from "realm"; | ||
mongodben marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function MyApp() { | ||
const app = useApp(); | ||
function logInAnonymousUser() { | ||
app.logIn(Credentials.anonymous()); | ||
} | ||
// ... | ||
} |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.