Fix TUI screen wrapping, channel selection/creation, and online members presence
This commit is contained in:
parent
cbc24e7672
commit
25696db42c
12 changed files with 582 additions and 109 deletions
|
|
@ -269,4 +269,95 @@ public class EndToEndChatTests : IAsyncLifetime
|
|||
string downloadedText = await File.ReadAllTextAsync(downloadedFilePath);
|
||||
Assert.Equal(fileContent, downloadedText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ChannelCreationAndSelection_ShouldSyncState()
|
||||
{
|
||||
var stateAlice = new ClientState { ServerUrl = _serverUrl };
|
||||
using var connAlice = new ChatClientConnection(stateAlice);
|
||||
|
||||
var regAlice = await connAlice.RegisterAsync("AliceChannelAdmin", "Password123!");
|
||||
Assert.True(regAlice.Success);
|
||||
stateAlice.Token = regAlice.Token!;
|
||||
stateAlice.CurrentUserId = regAlice.UserId!;
|
||||
stateAlice.CurrentUsername = regAlice.Username!;
|
||||
stateAlice.CurrentUserRole = regAlice.Role!;
|
||||
|
||||
await connAlice.StartWebSocketAsync();
|
||||
await Task.Delay(300);
|
||||
|
||||
Assert.True(stateAlice.Channels.Count >= 2);
|
||||
int initialCount = stateAlice.Channels.Count;
|
||||
|
||||
// Create new channel
|
||||
await connAlice.CreateChannelAsync("dev-team", "Developers room");
|
||||
|
||||
// Wait for channel list sync
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
if (stateAlice.Channels.Count > initialCount) break;
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
Assert.Equal(initialCount + 1, stateAlice.Channels.Count);
|
||||
var newChannel = stateAlice.Channels.Find(c => c.Name == "dev-team");
|
||||
Assert.NotNull(newChannel);
|
||||
|
||||
// Join new channel
|
||||
await connAlice.JoinChannelAsync(newChannel.Id);
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
if (stateAlice.ActiveChannelId == newChannel.Id) break;
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
Assert.Equal(newChannel.Id, stateAlice.ActiveChannelId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BroadcastUserList_ShouldMarkConnectedUsersAsOnline()
|
||||
{
|
||||
var stateAlice = new ClientState { ServerUrl = _serverUrl };
|
||||
using var connAlice = new ChatClientConnection(stateAlice);
|
||||
|
||||
var regAlice = await connAlice.RegisterAsync("AliceOnline", "Pass1234!");
|
||||
Assert.True(regAlice.Success);
|
||||
stateAlice.Token = regAlice.Token!;
|
||||
stateAlice.CurrentUserId = regAlice.UserId!;
|
||||
|
||||
var stateBob = new ClientState { ServerUrl = _serverUrl };
|
||||
using var connBob = new ChatClientConnection(stateBob);
|
||||
|
||||
var regBob = await connBob.RegisterAsync("BobOnline", "Pass1234!");
|
||||
Assert.True(regBob.Success);
|
||||
stateBob.Token = regBob.Token!;
|
||||
stateBob.CurrentUserId = regBob.UserId!;
|
||||
|
||||
await connAlice.StartWebSocketAsync();
|
||||
await connBob.StartWebSocketAsync();
|
||||
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
if (stateAlice.Users.Count(u => u.IsOnline) >= 2) break;
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
Assert.Equal(2, stateAlice.Users.Count(u => u.IsOnline));
|
||||
|
||||
// When Bob disconnects, Alice's user list should reflect Bob as offline
|
||||
connBob.Dispose();
|
||||
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
if (stateAlice.Users.Count(u => u.IsOnline) == 1) break;
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
Assert.Equal(1, stateAlice.Users.Count(u => u.IsOnline));
|
||||
var aliceUser = stateAlice.Users.Find(u => u.Username == "AliceOnline");
|
||||
Assert.NotNull(aliceUser);
|
||||
Assert.True(aliceUser.IsOnline);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue