-
Notifications
You must be signed in to change notification settings - Fork 171
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
Js/sectioned notification #5926
Merged
+78
−0
Merged
Changes from 2 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
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 |
---|---|---|
|
@@ -1554,6 +1554,70 @@ TEST_CASE("sectioned results", "[sectioned_results]") { | |
} | ||
} | ||
|
||
TEST_CASE("sectioned results link notification bug", "[sectioned_results]") { | ||
_impl::RealmCoordinator::assert_no_open_realms(); | ||
|
||
InMemoryTestFile config; | ||
config.automatic_change_notifications = false; | ||
|
||
auto r = Realm::get_shared_realm(config); | ||
r->update_schema( | ||
{{"Transaction", | ||
{{"_id", PropertyType::String, Property::IsPrimary{true}}, | ||
{"date", PropertyType::Date}, | ||
{"account", PropertyType::Object | PropertyType::Nullable, "Account"}}}, | ||
{"Account", {{"_id", PropertyType::String, Property::IsPrimary{true}}, {"name", PropertyType::String}}}}); | ||
|
||
auto coordinator = _impl::RealmCoordinator::get_coordinator(config.path); | ||
auto transaction_table = r->read_group().get_table("class_Transaction"); | ||
transaction_table->get_column_key("date"); | ||
auto account_col = transaction_table->get_column_key("account"); | ||
auto account_table = r->read_group().get_table("class_Account"); | ||
auto account_name_col = account_table->get_column_key("name"); | ||
|
||
r->begin_transaction(); | ||
auto t1 = transaction_table->create_object_with_primary_key("t"); | ||
auto a1 = account_table->create_object_with_primary_key("a"); | ||
t1.set(account_col, a1.get_key()); | ||
r->commit_transaction(); | ||
|
||
Results results(r, transaction_table); | ||
auto sorted = results.sort({{"date", false}}); | ||
auto sectioned_results = sorted.sectioned_results([](Mixed value, SharedRealm realm) { | ||
auto obj = Object(realm, value.get_link()); | ||
auto ts = obj.get_column_value<Timestamp>("date"); | ||
auto tp = ts.get_time_point(); | ||
auto day = std::chrono::floor<std::chrono::hours>(tp); | ||
return Timestamp{day}; | ||
}); | ||
|
||
REQUIRE(sectioned_results.size() == 1); | ||
REQUIRE(sectioned_results[0].size() == 1); | ||
|
||
SectionedResultsChangeSet changes; | ||
size_t callback_count = 0; | ||
auto token = sectioned_results.add_notification_callback([&](SectionedResultsChangeSet c) { | ||
changes = c; | ||
++callback_count; | ||
}); | ||
coordinator->on_change(); | ||
|
||
REQUIRE(callback_count == 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a |
||
|
||
r->begin_transaction(); | ||
a1.set(account_name_col, "a2"); | ||
r->commit_transaction(); | ||
advance_and_notify(*r); | ||
|
||
REQUIRE(callback_count == 2); | ||
REQUIRE(changes.sections_to_insert.empty()); | ||
REQUIRE(changes.sections_to_delete.empty()); | ||
REQUIRE(changes.insertions.size() == 0); | ||
REQUIRE(changes.deletions.size() == 0); | ||
REQUIRE(changes.modifications.size() == 1); | ||
REQUIRE_INDICES(changes.modifications[0], 0); | ||
} | ||
|
||
namespace cf = realm::sectioned_results_fixtures; | ||
|
||
TEMPLATE_TEST_CASE("sectioned results primitive types", "[sectioned_results]", cf::MixedVal, cf::Int, cf::Bool, | ||
|
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.
I think it might make more sense to assert that these are empty rather than clearing them? If they're non-empty then something's gone wrong.