[Tests] Fix some tests
This commit is contained in:
parent
898767875a
commit
cacf7cc530
|
@ -149,24 +149,25 @@ class Connection {
|
|||
client.lazyLoadMembers = newLazyLoadMembers;
|
||||
client.prevBatch = newPrevBatch;
|
||||
|
||||
List<Room> rooms = [];
|
||||
if (client.store != null) {
|
||||
client.store.storeClient();
|
||||
|
||||
List<Room> rooms = await client.store
|
||||
rooms = await client.store
|
||||
.getRoomList(onlyLeft: false, onlyGroups: false, onlyDirect: false);
|
||||
client.roomList = RoomList(
|
||||
client: client,
|
||||
onlyLeft: false,
|
||||
onlyDirect: false,
|
||||
onlyGroups: false,
|
||||
onUpdate: null,
|
||||
onInsert: null,
|
||||
onRemove: null,
|
||||
rooms: rooms);
|
||||
client.accountData = await client.store.getAccountData();
|
||||
client.presences = await client.store.getPresences();
|
||||
}
|
||||
|
||||
client.roomList = RoomList(
|
||||
client: client,
|
||||
onlyLeft: false,
|
||||
onlyDirect: false,
|
||||
onlyGroups: false,
|
||||
onUpdate: null,
|
||||
onInsert: null,
|
||||
onRemove: null,
|
||||
rooms: rooms);
|
||||
|
||||
_userEventSub ??= onUserEvent.stream.listen(client.handleUserUpdate);
|
||||
|
||||
onLoginStateChanged.add(LoginState.logged);
|
||||
|
|
|
@ -54,9 +54,9 @@ class Room {
|
|||
int mJoinedMemberCount;
|
||||
int mInvitedMemberCount;
|
||||
|
||||
Map<String, State> states;
|
||||
Map<String, State> states = {};
|
||||
|
||||
Map<String, RoomAccountData> roomAccountData;
|
||||
Map<String, RoomAccountData> roomAccountData = {};
|
||||
|
||||
/// Time when the user has last read the chat.
|
||||
ChatTime unread;
|
||||
|
@ -105,7 +105,7 @@ class Room {
|
|||
/// Must be one of [all, mention]
|
||||
String notificationSettings;
|
||||
|
||||
Event get lastEvent => states["m.room.message"] as Event;
|
||||
Event get lastEvent => states["m.room.message"]?.timelineEvent;
|
||||
|
||||
/// Your current client instance.
|
||||
final Client client;
|
||||
|
|
|
@ -103,6 +103,8 @@ class RoomList {
|
|||
mHeroes: chatUpdate.summary?.mHeroes,
|
||||
mJoinedMemberCount: chatUpdate.summary?.mJoinedMemberCount,
|
||||
mInvitedMemberCount: chatUpdate.summary?.mInvitedMemberCount,
|
||||
states: {},
|
||||
roomAccountData: {},
|
||||
);
|
||||
rooms.insert(position, newRoom);
|
||||
if (onInsert != null) onInsert(position);
|
||||
|
|
|
@ -80,7 +80,19 @@ class State extends RawEvent {
|
|||
room: room);
|
||||
}
|
||||
|
||||
Event get timelineEvent => Event(
|
||||
content: content,
|
||||
typeKey: typeKey,
|
||||
eventId: eventId,
|
||||
room: room,
|
||||
roomId: roomId,
|
||||
senderId: senderId,
|
||||
time: time,
|
||||
unsigned: unsigned,
|
||||
status: 1,
|
||||
);
|
||||
|
||||
/// The unique key of this event. For events with a [stateKey], it will be the
|
||||
/// stateKey. Otherwise it will be the [type] as a string.
|
||||
String get key => stateKey != null || stateKey.isEmpty ? type : stateKey;
|
||||
String get key => stateKey == null || stateKey.isEmpty ? typeKey : stateKey;
|
||||
}
|
||||
|
|
|
@ -107,6 +107,9 @@ void main() {
|
|||
expect(loginState, LoginState.logged);
|
||||
expect(firstSync, true);
|
||||
expect(sync["next_batch"] == matrix.prevBatch, true);
|
||||
|
||||
expect(matrix.accountData.length, 1);
|
||||
expect(matrix.presences.length, 0);
|
||||
});
|
||||
|
||||
test('Try to get ErrorResponse', () async {
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:famedlysdk/src/Event.dart';
|
||||
import 'package:famedlysdk/src/User.dart';
|
||||
import 'package:famedlysdk/src/RawEvent.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'FakeMatrixApi.dart';
|
||||
|
@ -36,9 +35,6 @@ void main() {
|
|||
final int timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
final String id = "!4fsdfjisjf:server.abc";
|
||||
final String senderID = "@alice:server.abc";
|
||||
final String senderDisplayname = "Alice";
|
||||
final String empty = "";
|
||||
final Membership membership = Membership.join;
|
||||
final String type = "m.room.message";
|
||||
final String msgtype = "m.text";
|
||||
final String body = "Hello World";
|
||||
|
@ -49,24 +45,18 @@ void main() {
|
|||
|
||||
Map<String, dynamic> jsonObj = {
|
||||
"event_id": id,
|
||||
"matrix_id": senderID,
|
||||
"displayname": senderDisplayname,
|
||||
"avatar_url": empty,
|
||||
"membership": membership.toString().split('.').last,
|
||||
"sender": senderID,
|
||||
"origin_server_ts": timestamp,
|
||||
"state_key": empty,
|
||||
"type": type,
|
||||
"content_json": contentJson,
|
||||
"status": 2,
|
||||
"content": contentJson,
|
||||
};
|
||||
|
||||
test("Create from json", () async {
|
||||
Event event = Event.fromJson(jsonObj, null);
|
||||
|
||||
expect(event.id, id);
|
||||
expect(event.sender.id, senderID);
|
||||
expect(event.sender.displayName, senderDisplayname);
|
||||
expect(event.sender.avatarUrl.mxc, empty);
|
||||
expect(event.sender.membership, membership);
|
||||
expect(event.eventId, id);
|
||||
expect(event.senderId, senderID);
|
||||
expect(event.status, 2);
|
||||
expect(event.text, body);
|
||||
expect(event.formattedText, formatted_body);
|
||||
|
@ -121,7 +111,7 @@ void main() {
|
|||
expect(event.type, EventTypes.HistoryVisibility);
|
||||
|
||||
jsonObj["type"] = "m.room.message";
|
||||
jsonObj["content"] = json.decode(jsonObj["content_json"]);
|
||||
jsonObj["content"] = json.decode(jsonObj["content"]);
|
||||
|
||||
jsonObj["content"]["msgtype"] = "m.notice";
|
||||
event = Event.fromJson(jsonObj, null);
|
||||
|
|
Loading…
Reference in a new issue