Skip to content
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

feat: add AccountsChanged and AccountsItemChanged events #6118

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Simon-Laux
Copy link
Member

@Simon-Laux Simon-Laux commented Oct 27, 2024

  • feat: add AccountsChanged and AccountsItemChanged events
  • emit event and add tests

closes #6106

TODO:

  • test receiving synced config from second device
  • bug: investigate how to delay the configuration event until it is actually configured - because desktop gets the event but still shows account as if it was unconfigured, maybe event is emitted before the value is written to the database?
  • update node bindings constants

deltachat-ffi/deltachat.h Outdated Show resolved Hide resolved
deltachat-ffi/deltachat.h Outdated Show resolved Hide resolved
deltachat-ffi/deltachat.h Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/events/account_events.rs Outdated Show resolved Hide resolved
@Simon-Laux Simon-Laux force-pushed the simon/i6106-accountlist-events branch from a2db1c6 to 43f5813 Compare October 29, 2024 15:42
@Simon-Laux Simon-Laux marked this pull request as ready for review October 29, 2024 18:21
@Simon-Laux Simon-Laux force-pushed the simon/i6106-accountlist-events branch from 12ec30a to 391bf59 Compare October 29, 2024 18:24
src/tests/account_events.rs Outdated Show resolved Hide resolved
Some(new_name.to_owned())
);

assert!(alice0.get_config(Config::Selfavatar).await?.is_none());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be omitted. There's also PrivateTag, but testing events for all synchronised settings looks superfluous, having tests for all settings set locally + one for synchronisation, say, of Displayname, is good enough, all the logic for account events is implemented in the only place anyway

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is private tag synced? I thought it was only local

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private tag is not synchronized, at least currently.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea was to test everything that changes in jsonrpc Account type:

pub enum Account {
#[serde(rename_all = "camelCase")]
Configured {
id: u32,
display_name: Option<String>,
addr: Option<String>,
// size: u32,
profile_image: Option<String>, // TODO: This needs to be converted to work with blob http server.
color: String,
/// Optional tag as "Work", "Family".
/// Meant to help profile owner to differ between profiles with similar names.
private_tag: Option<String>,
},
#[serde(rename_all = "camelCase")]
Unconfigured { id: u32 },
}

(except for address and color, address is not shown anymore in account list and I doubt that color changes that often (maybe with aeap when address changes? but we can add a test for that then, when this is more common))

Copy link
Collaborator

@iequidoo iequidoo Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, private tag isn't synced, but this isn't important. The idea is to avoid combinatorial explosion of testcases:

  • We already have tests on synchronisation of Displayname and Selfavatar
  • You add also tests that account events for them are emitted as expected
  • Then it's sufficient to have only one test that account events are emitted on the second device for a synchronised setting, no need to test this for all settings, moreover all the core logic is implemented in the only place.

EDIT: So, if a test doesn't cover anything in addition to the existing tests (at least theoretically), it better should be removed, otherwise it's just an extra code to maintain.

Copy link
Member Author

@Simon-Laux Simon-Laux Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree that tests should rely on implementation details or on other tests of different files. IMO tests should test all cases. how it's implemented shouldn't matter to the tests.

We could add the event check to the old test and remove the new test, but then we would have less separation of concern - so I think it's ok to have duplicated test code.

Copy link
Collaborator

@iequidoo iequidoo Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't like the idea of "only white-box testing", i just can't imagine how this code block can test anything in addition to other tests (i.e. how the core code should be changed to create a new uncovered path). And if we don't want to rely on what other tests do, we always need to go through all cases combinatorially which is just impossible.

We could add the event check to the old test and remove the new test

I don't suggest to remove the whole test, only the block for Selfavatar. And yes, we can add event checks to some existing tests (even just in case), that will still be less code.

This is not critical for merging this PR of course, i just suggest to find some practical compromise for the amount of test code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could remove the checks if it worked and just test if the action triggered the event. But I still think the more tests the better.
Also this is not very hard to maintain code in my view, the code is straight forward and easy to understand in this case.

Copy link
Member

@r10s r10s Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am lost a bit in the exact discussion, but, in general, i agree with @Simon-Laux - the more tests the better.

when i write tests for sth, i do not care if the things i assert() are already checked elsewhere, or if some assert()s are not strictly related. i even think, there is worth in different tests about the same thing, esp when written by different ppl. some test may change - or do not cover the exact same cornercase, this is not always obvious, and often also not worth to think about.

i would also not like to have too much conventions/compliance how to do tests etc. -- that would only lead to less tests written. review should focus on the implementation mostly - and complain about missing tests

src/imex.rs Outdated Show resolved Hide resolved
tracker
.get_matching(|evt| matches!(evt, EventType::AccountsChanged))
.await;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also call .clear_events() in between to make sure we don't accidentally succeed because previous action emitted event twice.

src/imex.rs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Account list update events
4 participants