Skip to content

Commit e093f65

Browse files
Mohammad Hunan ChughtaiMohammad Hunan Chughtaicbullinger
authored andcommitted
(DOCSP-26983): @realm/react-ify "Sets - React Native SDK" (#2477)
## Pull Request Info ### Jira - https://jira.mongodb.org/browse/DOCSP-26983 ### Staged Changes - [Sets - React Native SDK](https://docs-mongodbcom-staging.corp.mongodb.com/realm/docsworker-xlarge/DOCSP-26983-realmset/sdk/react-native/realm-database/schemas/sets/) ### Reminder Checklist If your PR modifies the docs, you might need to also update some corresponding pages. Check if completed or N/A. - [N/A] Create Jira ticket for corresponding docs-app-services update(s), if any - [N/A] Checked/updated Admin API - [N/A] Checked/updated CLI reference ### Review Guidelines [REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md) Co-authored-by: Mohammad Hunan Chughtai <[email protected]> Co-authored-by: cbullinger <[email protected]>
1 parent 0d21d49 commit e093f65

31 files changed

+1368
-368
lines changed

examples/react-native/__tests__/js/CRUD/create-test.jsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ describe('Create Data Tests', () => {
5151
return (
5252
<>
5353
<TextInput onChangeText={setDogName} value={dogName} />
54-
<Button
55-
onPress={() => handleAddDog()}
56-
title='Add Dog'
57-
testID='handleAddDogBtn'
58-
/>
54+
<Button onPress={() => handleAddDog()} title='Add Dog' testID='handleAddDogBtn' />
5955
</>
6056
);
6157
};
@@ -71,10 +67,7 @@ describe('Create Data Tests', () => {
7167
const {getByTestId} = render(<App />);
7268

7369
// press the "Add Dog" button
74-
const handleAddDogBtn = await waitFor(
75-
() => getByTestId('handleAddDogBtn'),
76-
{timeout: 5000},
77-
);
70+
const handleAddDogBtn = await waitFor(() => getByTestId('handleAddDogBtn'), {timeout: 5000});
7871
await act(async () => {
7972
fireEvent.press(handleAddDogBtn);
8073
});

examples/react-native/__tests__/js/CRUD/delete-test.jsx

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ describe('Delete Data Tests', () => {
5454
return (
5555
<>
5656
<Text>{dog.name}</Text>
57-
<Button
58-
onPress={() => deleteDog(dog)}
59-
title='Delete Dog'
60-
testID='deleteDog'
61-
/>
57+
<Button onPress={() => deleteDog(dog)} title='Delete Dog' testID='deleteDog' />
6258
</>
6359
);
6460
})}
@@ -120,16 +116,8 @@ describe('Delete Data Tests', () => {
120116
</>
121117
);
122118
})}
123-
<Button
124-
onPress={() => deleteAllYoungDogObjects()}
125-
title='Delete Young Dog Objects'
126-
testID='deleteYoungDogs'
127-
/>
128-
<Button
129-
onPress={() => deleteAllDogObjects()}
130-
title='Delete All Dog Objects'
131-
testID='deleteAllDogs'
132-
/>
119+
<Button onPress={() => deleteAllYoungDogObjects()} title='Delete Young Dog Objects' testID='deleteYoungDogs' />
120+
<Button onPress={() => deleteAllDogObjects()} title='Delete All Dog Objects' testID='deleteAllDogs' />
133121
</>
134122
);
135123
};
@@ -145,10 +133,7 @@ describe('Delete Data Tests', () => {
145133
await waitFor(() => getAllByTestId('dogItem'), {timeout: 5000}); // even though we don't use this as variable, react-native-testing-library requires us to waitFor() this to avoid the following error: "Unable to find an element with testID: dogItem"
146134

147135
// Test that the young Dog objects (Bronson, Bowie) have been deleted from the realm + from the UI when the "Delete All Dog Objects" is pressed, leaving 1 dog object (Blaise) remaining
148-
const deleteYoungDogsBtn = await waitFor(
149-
() => getByTestId('deleteYoungDogs'),
150-
{timeout: 5000},
151-
);
136+
const deleteYoungDogsBtn = await waitFor(() => getByTestId('deleteYoungDogs'), {timeout: 5000});
152137
await act(async () => {
153138
fireEvent.press(deleteYoungDogsBtn);
154139
});
@@ -183,11 +168,7 @@ describe('Delete Data Tests', () => {
183168
return (
184169
<>
185170
<Text>Delete all data in your profile:</Text>
186-
<Button
187-
onPress={deleteAllData}
188-
title='Delete all data'
189-
testID='deleteAllData'
190-
/>
171+
<Button onPress={deleteAllData} title='Delete all data' testID='deleteAllData' />
191172
</>
192173
);
193174
};

examples/react-native/__tests__/js/CRUD/read-test.jsx

Lines changed: 24 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,8 @@ describe('Read Data Tests', () => {
9191
const {getByTestId} = render(<App />);
9292

9393
// test that the 'useObject()' method worked and the correct sentence is rendered as expected
94-
const taskItemSentence = await waitFor(
95-
() => getByTestId('task-item-sentence'),
96-
{timeout: 5000},
97-
);
98-
expect(taskItemSentence.props.children.join('')).toBe(
99-
'Wash the dishes is a task with the priority of: 3',
100-
);
94+
const taskItemSentence = await waitFor(() => getByTestId('task-item-sentence'), {timeout: 5000});
95+
expect(taskItemSentence.props.children.join('')).toBe('Wash the dishes is a task with the priority of: 3');
10196
});
10297

10398
it('should filter data', async () => {
@@ -116,9 +111,7 @@ describe('Read Data Tests', () => {
116111
const highPriorityTasks = tasks.filtered('priority >= 4');
117112

118113
// filter for tasks that have just-started or short-running progress
119-
const lowProgressTasks = tasks.filtered(
120-
'1 <= progressMinutes && progressMinutes < 10',
121-
);
114+
const lowProgressTasks = tasks.filtered('1 <= progressMinutes && progressMinutes < 10');
122115
return (
123116
<>
124117
<Text>Your high priority tasks:</Text>
@@ -143,26 +136,14 @@ describe('Read Data Tests', () => {
143136
const {getAllByTestId} = render(<App />);
144137

145138
// test that the highPriorityTasks items Text renders
146-
const highPriorityTasksUIList = await waitFor(
147-
() => getAllByTestId('high-priority-element'),
148-
{timeout: 5000},
149-
);
150-
expect(highPriorityTasksUIList[0].children[0].toString()).toBe(
151-
'Do the laundry',
152-
); // Since only the 'Do the laundry' task is high priority
139+
const highPriorityTasksUIList = await waitFor(() => getAllByTestId('high-priority-element'), {timeout: 5000});
140+
expect(highPriorityTasksUIList[0].children[0].toString()).toBe('Do the laundry'); // Since only the 'Do the laundry' task is high priority
153141

154142
// test that the highPriorityTasks items Text renders
155-
const lowProgressTasksUIList = await waitFor(
156-
() => getAllByTestId('low-progress-element'),
157-
{timeout: 5000},
158-
);
143+
const lowProgressTasksUIList = await waitFor(() => getAllByTestId('low-progress-element'), {timeout: 5000});
159144
// test that both 'Wash the dishes' and 'Gym Workout' rendered because they are both low progress tasks
160-
expect(lowProgressTasksUIList[0].children[0].toString()).toBe(
161-
'Wash the dishes',
162-
);
163-
expect(lowProgressTasksUIList[1].children[0].toString()).toBe(
164-
'Gym Workout',
165-
);
145+
expect(lowProgressTasksUIList[0].children[0].toString()).toBe('Wash the dishes');
146+
expect(lowProgressTasksUIList[1].children[0].toString()).toBe('Gym Workout');
166147
});
167148

168149
it('should render sorted tasks', async () => {
@@ -208,13 +189,9 @@ describe('Read Data Tests', () => {
208189
<Text testID='tasks-by-name-descending-item'>{task.name}</Text>
209190
))}
210191

211-
<Text>
212-
Tasks sorted by priority descending, and name alphabetically:
213-
</Text>
192+
<Text>Tasks sorted by priority descending, and name alphabetically:</Text>
214193
{tasksByPriorityDescendingAndName.map(task => (
215-
<Text testID='tasks-by-priority-descending-and-name-item'>
216-
{task.name}
217-
</Text>
194+
<Text testID='tasks-by-priority-descending-and-name-item'>{task.name}</Text>
218195
))}
219196

220197
<Text>Tasks sorted by assignee name:</Text>
@@ -235,65 +212,33 @@ describe('Read Data Tests', () => {
235212
const {getAllByTestId} = render(<App />);
236213

237214
// test that tasks should be in the order that they were written
238-
const allTasksUIList = await waitFor(
239-
() => getAllByTestId('all-tasks-item'),
240-
{timeout: 5000},
241-
);
215+
const allTasksUIList = await waitFor(() => getAllByTestId('all-tasks-item'), {timeout: 5000});
242216
expect(allTasksUIList[0].children[0].toString()).toBe('Wash the dishes');
243217
expect(allTasksUIList[1].children[0].toString()).toBe('Do the laundry');
244218
expect(allTasksUIList[2].children[0].toString()).toBe('Gym Workout');
245219

246220
// test that tasksByName should be in alphabetical name order
247-
const taskByNameUIList = await waitFor(
248-
() => getAllByTestId('tasks-by-name-item'),
249-
{timeout: 5000},
250-
);
221+
const taskByNameUIList = await waitFor(() => getAllByTestId('tasks-by-name-item'), {timeout: 5000});
251222
expect(taskByNameUIList[0].children[0].toString()).toBe('Do the laundry');
252223
expect(taskByNameUIList[1].children[0].toString()).toBe('Gym Workout');
253224
expect(taskByNameUIList[2].children[0].toString()).toBe('Wash the dishes');
254225

255226
// test that tasksByNameDescending should be in reverse alphabetical name order
256-
const taskByNameDescendingUIList = await waitFor(
257-
() => getAllByTestId('tasks-by-name-descending-item'),
258-
{timeout: 5000},
259-
);
260-
expect(taskByNameDescendingUIList[0].children[0].toString()).toBe(
261-
'Wash the dishes',
262-
);
263-
expect(taskByNameDescendingUIList[1].children[0].toString()).toBe(
264-
'Gym Workout',
265-
);
266-
expect(taskByNameDescendingUIList[2].children[0].toString()).toBe(
267-
'Do the laundry',
268-
);
227+
const taskByNameDescendingUIList = await waitFor(() => getAllByTestId('tasks-by-name-descending-item'), {timeout: 5000});
228+
expect(taskByNameDescendingUIList[0].children[0].toString()).toBe('Wash the dishes');
229+
expect(taskByNameDescendingUIList[1].children[0].toString()).toBe('Gym Workout');
230+
expect(taskByNameDescendingUIList[2].children[0].toString()).toBe('Do the laundry');
269231

270232
// test that tasksByNameDescending should be in reverse alphabetical name order
271-
const tasksByPriorityDescendingAndNameUIList = await waitFor(() =>
272-
getAllByTestId('tasks-by-priority-descending-and-name-item'),
273-
);
274-
expect(
275-
tasksByPriorityDescendingAndNameUIList[0].children[0].toString(),
276-
).toBe('Do the laundry');
277-
expect(
278-
tasksByPriorityDescendingAndNameUIList[1].children[0].toString(),
279-
).toBe('Gym Workout');
280-
expect(
281-
tasksByPriorityDescendingAndNameUIList[2].children[0].toString(),
282-
).toBe('Wash the dishes');
233+
const tasksByPriorityDescendingAndNameUIList = await waitFor(() => getAllByTestId('tasks-by-priority-descending-and-name-item'));
234+
expect(tasksByPriorityDescendingAndNameUIList[0].children[0].toString()).toBe('Do the laundry');
235+
expect(tasksByPriorityDescendingAndNameUIList[1].children[0].toString()).toBe('Gym Workout');
236+
expect(tasksByPriorityDescendingAndNameUIList[2].children[0].toString()).toBe('Wash the dishes');
283237

284238
// test that tasksByNameDescending should be in reverse alphabetical name order
285-
const tasksByAssigneeNameUIList = await waitFor(
286-
() => getAllByTestId('tasks-by-assignee-name-item'),
287-
{timeout: 5000},
288-
);
289-
expect(tasksByAssigneeNameUIList[0].children[0].toString()).toBe(
290-
'Wash the dishes',
291-
);
292-
expect(tasksByAssigneeNameUIList[1].children[0].toString()).toBe(
293-
'Do the laundry',
294-
);
295-
expect(tasksByAssigneeNameUIList[2].children[0].toString()).toBe(
296-
'Gym Workout',
297-
);
239+
const tasksByAssigneeNameUIList = await waitFor(() => getAllByTestId('tasks-by-assignee-name-item'), {timeout: 5000});
240+
expect(tasksByAssigneeNameUIList[0].children[0].toString()).toBe('Wash the dishes');
241+
expect(tasksByAssigneeNameUIList[1].children[0].toString()).toBe('Do the laundry');
242+
expect(tasksByAssigneeNameUIList[2].children[0].toString()).toBe('Gym Workout');
298243
});
299244
});

examples/react-native/__tests__/js/CRUD/update-test.jsx

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ const realmConfig = {
1111
deleteRealmIfMigrationNeeded: true,
1212
};
1313

14-
const {RealmProvider, useRealm, useObject, useQuery} =
15-
createRealmContext(realmConfig);
14+
const {RealmProvider, useRealm, useObject, useQuery} = createRealmContext(realmConfig);
1615

1716
let assertionRealm;
1817

@@ -75,11 +74,7 @@ describe('Update Data Tests', () => {
7574
<Text>Task: {myTask.name}</Text>
7675
<Text>Progress made (in minutes):</Text>
7776
<Text testID='progressMinutes'>{myTask.progressMinutes}</Text>
78-
<Button
79-
onPress={() => incrementTaskProgress()}
80-
title='Increment Task Progress'
81-
testID='handleIncrementBtn'
82-
/>
77+
<Button onPress={() => incrementTaskProgress()} title='Increment Task Progress' testID='handleIncrementBtn' />
8378
</>
8479
);
8580
} else {
@@ -97,14 +92,8 @@ describe('Update Data Tests', () => {
9792
);
9893
const {getByTestId} = render(<App />);
9994

100-
const handleIncrementBtn = await waitFor(
101-
() => getByTestId('handleIncrementBtn'),
102-
{timeout: 5000},
103-
);
104-
const progressMinutesText = await waitFor(
105-
() => getByTestId('progressMinutes'),
106-
{timeout: 5000},
107-
);
95+
const handleIncrementBtn = await waitFor(() => getByTestId('handleIncrementBtn'), {timeout: 5000});
96+
const progressMinutesText = await waitFor(() => getByTestId('progressMinutes'), {timeout: 5000});
10897

10998
const paintTask = assertionRealm.objectForPrimaryKey(Task, 92140);
11099

@@ -135,20 +124,12 @@ describe('Update Data Tests', () => {
135124
realm.write(() => {
136125
// Add a new Task to the realm. Since no task with ID 1234
137126
// has been added yet, this adds the instance to the realm.
138-
myTask = realm.create(
139-
'Task',
140-
{_id: 1234, name: 'Wash the car', progressMinutes: 0},
141-
'modified',
142-
);
127+
myTask = realm.create('Task', {_id: 1234, name: 'Wash the car', progressMinutes: 0}, 'modified');
143128

144129
// If an object exists, setting the third parameter (`updateMode`) to
145130
// "modified" only updates properties that have changed, resulting in
146131
// faster operations.
147-
myTask = realm.create(
148-
'Task',
149-
{_id: 1234, name: 'Wash the car', progressMinutes: 5},
150-
'modified',
151-
);
132+
myTask = realm.create('Task', {_id: 1234, name: 'Wash the car', progressMinutes: 5}, 'modified');
152133
});
153134
return (
154135
<>
@@ -168,10 +149,7 @@ describe('Update Data Tests', () => {
168149
);
169150
const {getByTestId} = render(<App />);
170151

171-
const progressMinutesText = await waitFor(
172-
() => getByTestId('progressMinutes'),
173-
{timeout: 5000},
174-
);
152+
const progressMinutesText = await waitFor(() => getByTestId('progressMinutes'), {timeout: 5000});
175153
const carWashTask = assertionRealm.objectForPrimaryKey(Task, 1234);
176154

177155
// Test that the the 'Wash the car' task was upserted, and progressMinutesText is now displaying 5 minutes progressed
@@ -204,11 +182,7 @@ describe('Update Data Tests', () => {
204182
{task.name} has {task.progressMinutes} minutes progressed
205183
</Text>;
206184
})}
207-
<Button
208-
onPress={resetProgressOnAllTasks}
209-
title='Reset Progress'
210-
testID='resetProgressOnAllTasksBtn'
211-
/>
185+
<Button onPress={resetProgressOnAllTasks} title='Reset Progress' testID='resetProgressOnAllTasksBtn' />
212186
</>
213187
);
214188
};
@@ -222,10 +196,7 @@ describe('Update Data Tests', () => {
222196
);
223197
const {getByTestId} = render(<App />);
224198

225-
const resetProgressOnAllTasksBtn = await waitFor(
226-
() => getByTestId('resetProgressOnAllTasksBtn'),
227-
{timeout: 5000},
228-
);
199+
const resetProgressOnAllTasksBtn = await waitFor(() => getByTestId('resetProgressOnAllTasksBtn'), {timeout: 5000});
229200

230201
await act(async () => {
231202
fireEvent.press(resetProgressOnAllTasksBtn);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Realm from 'realm';
2+
3+
// :snippet-start: js-character-schema
4+
class Character extends Realm.Object {
5+
static schema = {
6+
name: 'Character',
7+
primaryKey: '_id',
8+
properties: {
9+
_id: 'objectId',
10+
name: 'string',
11+
levelsCompleted: 'int<>',
12+
inventory: 'string<>',
13+
},
14+
};
15+
}
16+
// :snippet-end:
17+
export default Character;

examples/react-native/__tests__/js/models/Book.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Book extends Realm.Object {
55
static schema = {
66
name: 'Book',
77
properties: {
8-
name: { type: 'string', indexed: true },
8+
name: {type: 'string', indexed: true},
99
price: 'int?',
1010
},
1111
};

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ describe('Mixed Tests', () => {
142142
const {getByTestId} = render(<App />);
143143
const catBirthDate = await waitFor(() => getByTestId('catBirthDate'));
144144
// Expect catBirthDate in the UI to be the same value we set in the beforeEach (which is clover's birthday 'January 21, 2016')
145-
expect(new Date(catBirthDate.props.children)).toStrictEqual(
146-
new Date('January 21, 2016'),
147-
);
145+
expect(new Date(catBirthDate.props.children)).toStrictEqual(new Date('January 21, 2016'));
148146
});
149147
});

0 commit comments

Comments
 (0)