Skip to content

Commit 5cbcb60

Browse files
committed
review feedback
1 parent e31bc4d commit 5cbcb60

File tree

5 files changed

+46
-19
lines changed

5 files changed

+46
-19
lines changed

examples/react-native/__tests__/js/realm-database/schemas/embedded-objects-test.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,30 +158,35 @@ describe('embedded objects tests', () => {
158158
const {getByTestId} = render(<App />);
159159

160160
// test that querying for name works
161-
const contactAddress = await waitFor(() => getByTestId('addressText'));
161+
const contactAddress = await waitFor(() => getByTestId('addressText'), {
162+
timeout: 5000,
163+
});
162164
expect(contactAddress.props.children).toBe('1 Home Street');
163165
});
164166
it('should delete an embedded object', async () => {
165167
// :snippet-start: delete-embedded-object
166168
// :replace-start: {
167169
// "terms": {
170+
// " testID = 'contactNameText'": "",
168171
// " testID = 'deleteContactBtn'": ""
169172
// }
170173
// }
171174
const ContactInfo = ({contactName}) => {
172175
const contacts = useQuery(Contact);
176+
const toDelete = contacts.filtered(`name == '${contactName}'`)[0]
173177
const realm = useRealm();
174178

175179
const deleteContact = () => {
176180
realm.write(() => {
177181
// Deleting the contact also deletes the embedded address of that contact
178182
realm.delete(
179-
contacts.filtered(`name == '${contactName}'`)[0]
183+
toDelete
180184
);
181185
});
182186
};
183187
return (
184188
<View>
189+
<Text testID='contactNameText'>{contactName}</Text>
185190
<Button testID='deleteContactBtn' onPress={deleteContact} title='Delete Contact' />
186191
</View>
187192
);
@@ -194,6 +199,11 @@ describe('embedded objects tests', () => {
194199
</RealmProvider>
195200
);
196201
const {findByTestId} = render(<App />);
202+
const contactNameText = await waitFor(() => findByTestId('contactNameText'), {
203+
timeout: 5000,
204+
});
205+
expect(contactNameText.props.children).toBe('John Smith');
206+
197207
const deleteContactBtn = await waitFor(() => findByTestId('deleteContactBtn'), {
198208
timeout: 5000,
199209
});

examples/react-native/__tests__/ts/realm-database/schemas/embedded-objects-test.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,35 @@ describe('embedded objects tests', () => {
157157
const {getByTestId} = render(<App />);
158158

159159
// test that querying for name works
160-
const contactAddress = await waitFor(() => getByTestId('addressText'));
160+
const contactAddress = await waitFor(() => getByTestId('addressText'), {
161+
timeout: 5000,
162+
});
161163
expect(contactAddress.props.children).toBe('1 Home Street');
162164
});
163165
it('should delete an embedded object', async () => {
164166
// :snippet-start: delete-embedded-object
165167
// :replace-start: {
166168
// "terms": {
167-
// " testID = 'deleteContactBtn'": ""
169+
// " testID = 'deleteContactBtn'": "",
170+
// " testID = 'contactNameText'": ""
168171
// }
169172
// }
170173
const ContactInfo = ({contactName}: {contactName: string}) => {
171174
const contacts = useQuery(Contact);
175+
const toDelete = contacts.filtered(`name == '${contactName}'`)[0]
172176
const realm = useRealm();
173177

174178
const deleteContact = () => {
175179
realm.write(() => {
176180
// Deleting the contact also deletes the embedded address of that contact
177181
realm.delete(
178-
contacts.filtered(`name == '${contactName}'`)[0]
182+
toDelete
179183
);
180184
});
181185
};
182186
return (
183187
<View>
188+
<Text testID='contactNameText'>{contactName}</Text>
184189
<Button testID='deleteContactBtn' onPress={deleteContact} title='Delete Contact' />
185190
</View>
186191
);
@@ -193,6 +198,11 @@ describe('embedded objects tests', () => {
193198
</RealmProvider>
194199
);
195200
const {findByTestId} = render(<App />);
201+
const contactNameText = await waitFor(() => findByTestId('contactNameText'), {
202+
timeout: 5000,
203+
});
204+
expect(contactNameText.props.children).toBe('John Smith');
205+
196206
const deleteContactBtn = await waitFor(() => findByTestId('deleteContactBtn'), {
197207
timeout: 5000,
198208
});
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
const ContactInfo = ({contactName}) => {
22
const contacts = useQuery(Contact);
3+
const toDelete = contacts.filtered(`name == '${contactName}'`)[0]
34
const realm = useRealm();
45

56
const deleteContact = () => {
67
realm.write(() => {
78
// Deleting the contact also deletes the embedded address of that contact
89
realm.delete(
9-
contacts.filtered(`name == '${contactName}'`)[0]
10+
toDelete
1011
);
1112
});
1213
};
1314
return (
1415
<View>
15-
<Button testID='deleteContactBtn' onPress={deleteContact} title='Delete Contact' />
16+
<Text>{contactName}</Text>
17+
<Button onPress={deleteContact} title='Delete Contact' />
1618
</View>
1719
);
18-
};
20+
};
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
const ContactInfo = ({contactName}: {contactName: string}) => {
22
const contacts = useQuery(Contact);
3+
const toDelete = contacts.filtered(`name == '${contactName}'`)[0]
34
const realm = useRealm();
45

56
const deleteContact = () => {
67
realm.write(() => {
78
// Deleting the contact also deletes the embedded address of that contact
89
realm.delete(
9-
contacts.filtered(`name == '${contactName}'`)[0]
10+
toDelete
1011
);
1112
});
1213
};
1314
return (
1415
<View>
15-
<Button testID='deleteContactBtn' onPress={deleteContact} title='Delete Contact' />
16+
<Text>{contactName}</Text>
17+
<Button onPress={deleteContact} title='Delete Contact' />
1618
</View>
1719
);
1820
};

source/sdk/react-native/realm-database/schemas/embedded-objects.txt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The ``CreateContact`` component does the following:
122122
to create a new ``Address`` embedded object and ``Contact`` parent object based
123123
on the ``TextInput`` values for the contact's name and address.
124124
- Adds an `onPress <https://reactnative.dev/docs/handling-touches>`__ event on the
125-
``'Submit Contact'`` button that calls ``submitContact()``.
125+
"Submit Contact" button that calls ``submitContact()``.
126126

127127
.. tabs-realm-languages::
128128

@@ -158,7 +158,7 @@ In the following ``ContactList`` example, we filter and query an embedded
158158
The ``ContactList`` component does the following:
159159

160160
- Performs a query for all contacts by passing the ``Contact`` class to the ``useQuery`` hook.
161-
- Filters for contacts with the name ``"John Smith"`` by passing :js-sdk:`collection.filtered()
161+
- Filters for contacts with the name "John Smith" by passing :js-sdk:`collection.filtered()
162162
<Realm.Collection.html#filtered>` on the query ``"name == 'John Smith'"``.
163163
- Retrieves the contact's street address by using dot notation.
164164

@@ -197,7 +197,8 @@ The ``UpdateContact`` component does the following:
197197
- Creates a React `state <https://reactjs.org/docs/react-component.html#state>`__ variable
198198
that represents the contact's new street address.
199199
- Performs a query for all contacts by passing the ``Contact`` class to the ``useQuery`` hook
200-
and filters for the contact that matches the name passed into the component as a prop.
200+
and filters for the contact that matches the name passed into the component as a `prop
201+
<https://reactjs.org/docs/components-and-props.html>`__.
201202
- Gets access to an opened realm instance by calling the ``useRealm()`` hook within the
202203
component.
203204
- Creates a component method ``updateStreet()`` that performs a write transaction and
@@ -240,7 +241,8 @@ The ``OverwriteContact`` component does the following:
240241
- Creates React `state <https://reactjs.org/docs/react-component.html#state>`__ variables
241242
that represent the contact's new address.
242243
- Performs a query for all contacts by passing the ``Contact`` class to the ``useQuery`` hook
243-
and filters for the contact that matches the name passed into the component as a prop.
244+
and filters for the contact that matches the name passed into the component as a `prop
245+
<https://reactjs.org/docs/components-and-props.html>`__.
244246
- Gets access to an opened realm instance by calling the ``useRealm()`` hook within the
245247
component.
246248
- Creates a component method ``updateAddress()`` that performs a write transaction and
@@ -282,11 +284,12 @@ parent object.
282284
The ``DeleteContact`` component does the following:
283285

284286
- Performs a query for all contacts by passing the ``Contact`` class to the ``useQuery`` hook.
287+
- Filters for the ``Contact`` object that matches the name passed into the component as a
288+
`prop <https://reactjs.org/docs/components-and-props.html>`__.
285289
- Gets access to an open realm instance by calling the ``useRealm()`` hook within the component.
286290
- Creates a component method ``deleteContact()`` that performs a write transaction and calls
287-
:js-sdk:`Realm.delete() <Realm.html#delete>` to remove the ``Contact`` object that matches
288-
the name passed into the component as a prop.
289-
- Add an `onPress <https://reactnative.dev/docs/handling-touches>`__ event on the ``'Delete Contact'``
291+
:js-sdk:`Realm.delete() <Realm.html#delete>` to remove the ``Contact`` object.
292+
- Add an `onPress <https://reactnative.dev/docs/handling-touches>`__ event on the "Delete Contact"
290293
button that calls ``deleteContact()``.
291294

292295
.. tabs-realm-languages::
@@ -296,13 +299,13 @@ The ``DeleteContact`` component does the following:
296299

297300
.. literalinclude:: /examples/generated/react-native/ts/embedded-objects-test.snippet.delete-embedded-object.tsx
298301
:language: typescript
299-
:emphasize-lines: 2-3, 6-11
302+
:emphasize-lines: 2-4, 7-12
300303
:linenos:
301304

302305
.. tab::
303306
:tabid: javascript
304307

305308
.. literalinclude:: /examples/generated/react-native/js/embedded-objects-test.snippet.delete-embedded-object.jsx
306309
:language: javascript
307-
:emphasize-lines: 2-3, 6-11
310+
:emphasize-lines: 2-4, 7-12
308311
:linenos:

0 commit comments

Comments
 (0)