Fix calc displayname and add tests
This commit is contained in:
parent
9666b763a5
commit
3d59aae034
|
@ -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"],
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue