Fix calc displayname and add tests

This commit is contained in:
Christian Pauly 2019-07-03 11:27:46 +02:00
parent 9666b763a5
commit 3d59aae034
3 changed files with 12 additions and 1 deletions

View file

@ -137,6 +137,8 @@ class Event {
print("jsonObj decode of event content failed: ${e.toString()}");
content = {};
}
else
content = {};
return Event(
jsonObj["event_id"] ?? jsonObj["id"],

View file

@ -72,7 +72,7 @@ class User {
/// Returns the displayname or the local part of the Matrix ID if the user
/// has no displayname.
String calcDisplayname() => displayName.isEmpty
String calcDisplayname() => (displayName == null || displayName.isEmpty)
? id.replaceFirst("@", "").split(":")[0]
: displayName;

View file

@ -51,5 +51,14 @@ void main() {
expect(user.powerLevel, powerLevel);
expect(user.calcDisplayname(), displayName);
});
test("calcDisplayname", () async {
final User user1 = User("@alice:example.com");
final User user2 = User("@alice:example.com", displayName: "SuperAlice");
final User user3 = User("@alice:example.com", displayName: "");
expect(user1.calcDisplayname(), "alice");
expect(user2.calcDisplayname(), "SuperAlice");
expect(user3.calcDisplayname(), "alice");
});
});
}