From 3cd14bf1b1bfc2fd422ddc8d38aac710788c5c05 Mon Sep 17 00:00:00 2001 From: LJ <81748770+elle-j@users.noreply.github.com> Date: Wed, 10 Jul 2024 08:44:04 +0200 Subject: [PATCH] Add test with key path on embedded object. --- .../tests/src/tests/observable.ts | 60 ++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/integration-tests/tests/src/tests/observable.ts b/integration-tests/tests/src/tests/observable.ts index 3f35325a71..fdaf55f6c7 100644 --- a/integration-tests/tests/src/tests/observable.ts +++ b/integration-tests/tests/src/tests/observable.ts @@ -795,8 +795,7 @@ describe("Observable", () => { ]); }); - // TODO: Add link to issue with collection listener not being fired on updates to embedded object. - it.skip("calls listener when embedded object is updated", async function (this: RealmObjectContext) { + it("calls listener when embedded object is updated", async function (this: RealmObjectContext) { const collection = this.realm.objects("Person"); await expectCollectionNotifications(collection, undefined, [ @@ -994,6 +993,63 @@ describe("Observable", () => { ); }); + it("fires on relevant changes to an embedded object", async function (this: RealmObjectContext) { + const collection = this.realm.objects("Person"); + + await expectCollectionNotifications( + collection, + ["embeddedAddress"], + [ + EMPTY_COLLECTION_CHANGESET, + () => { + this.realm.write(() => { + this.object.embeddedAddress = { street: "1633 Broadway", city: "New York" }; + }); + expect(this.object.embeddedAddress).deep.equals({ street: "1633 Broadway", city: "New York" }); + }, + { + deletions: [], + insertions: [], + newModifications: [0], + oldModifications: [0], + }, + () => { + this.realm.write(() => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.object.embeddedAddress!.street = "88 Kearny Street"; + }); + expect(this.object.embeddedAddress?.street).equals("88 Kearny Street"); + }, + { + deletions: [], + insertions: [], + newModifications: [0], + oldModifications: [0], + }, + () => { + this.realm.write(() => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.object.embeddedAddress!.city = "San Francisco"; + }); + expect(this.object.embeddedAddress?.city).equals("San Francisco"); + }, + { + deletions: [], + insertions: [], + newModifications: [0], + oldModifications: [0], + }, + // Perform a couple of changes that shouldn't trigger the listener. + () => { + this.realm.write(() => { + this.object.name = "New Name"; + }); + expect(this.object.name).equals("New Name"); + }, + ], + ); + }); + it("fires on relevant changes to a wildcard", async function (this: RealmObjectContext) { const collection = this.realm.objects("Person").filtered("name = $0 OR age = 42", "Alice"); await expectCollectionNotifications(