Files
zed/crates/collab/tests/integration/collab_panel_tests.rs
T
Joseph T. Lyons 64315583c8 Add the ability to reorder favorited collab channels (#52649)
Currently, if you try to re-order a favorite, the favorite will not
reorder, but the actual channels will.


https://github.com/user-attachments/assets/1fbab9ea-4ff4-473f-8de3-d3b60696c5a1

Additionally, a new bug seems to be that if you reorder channels, focus
jumps to a favorite:


https://github.com/user-attachments/assets/fa776ad2-8648-4e68-a253-a98f57bd4951

This PR allows for re-ordering of favorites independent of the actual
channels, and fixes the focusing bug


https://github.com/user-attachments/assets/977e575a-055c-4f26-8183-2744ff7f8f56

I didn't feel comfortable adding just the functionality/fixes alone, so
I added a function to represent the state of the collab panel as a list
of strings, like how testing around the project panel is, and wrote a
few tests to ensure the behavior was pinned down.

The tests cover testing:

- Favoriting/unfavoriting
- Reordering favorites without impacting order of channels in the
channels list
- Reordering channels in the channels list without impacting order of
favorites

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- Added the ability to reorder favorited collab channels.
2026-03-30 13:07:13 +00:00

357 lines
11 KiB
Rust

use crate::TestServer;
use collab_ui::CollabPanel;
use collab_ui::collab_panel::{MoveChannelDown, MoveChannelUp, ToggleSelectedChannelFavorite};
use gpui::TestAppContext;
use menu::{SelectNext, SelectPrevious};
#[gpui::test]
async fn test_reorder_favorite_channels_independently_of_channels(cx: &mut TestAppContext) {
let (server, client) = TestServer::start1(cx).await;
let root = server
.make_channel("root", None, (&client, cx), &mut [])
.await;
let _ = server
.make_channel("channel-a", Some(root), (&client, cx), &mut [])
.await;
let _ = server
.make_channel("channel-b", Some(root), (&client, cx), &mut [])
.await;
let _ = server
.make_channel("channel-c", Some(root), (&client, cx), &mut [])
.await;
let (workspace, cx) = client.build_test_workspace(cx).await;
let panel = workspace.update_in(cx, |workspace, window, cx| {
let panel = CollabPanel::new(workspace, window, cx);
workspace.add_panel(panel.clone(), window, cx);
panel
});
cx.run_until_parked();
// Verify initial state.
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Select channel-b.
panel.update_in(cx, |panel, window, cx| {
panel.select_next(&SelectNext, window, cx);
panel.select_next(&SelectNext, window, cx);
panel.select_next(&SelectNext, window, cx);
panel.select_next(&SelectNext, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b <== selected",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Favorite channel-b.
panel.update_in(cx, |panel, window, cx| {
panel.toggle_selected_channel_favorite(&ToggleSelectedChannelFavorite, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-b",
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b <== selected",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Select channel-c.
panel.update_in(cx, |panel, window, cx| {
panel.select_next(&SelectNext, window, cx);
});
// Favorite channel-c.
panel.update_in(cx, |panel, window, cx| {
panel.toggle_selected_channel_favorite(&ToggleSelectedChannelFavorite, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b",
" #️⃣ channel-c <== selected",
"[Contacts]",
]
);
// Navigate up to favorite channel-b .
panel.update_in(cx, |panel, window, cx| {
panel.select_previous(&SelectPrevious, window, cx);
panel.select_previous(&SelectPrevious, window, cx);
panel.select_previous(&SelectPrevious, window, cx);
panel.select_previous(&SelectPrevious, window, cx);
panel.select_previous(&SelectPrevious, window, cx);
panel.select_previous(&SelectPrevious, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-b <== selected",
" #️⃣ channel-c",
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Move favorite channel-b down.
// The Channels section should remain unchanged
panel.update_in(cx, |panel, window, cx| {
panel.move_channel_down(&MoveChannelDown, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-c",
" #️⃣ channel-b <== selected",
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Move favorite channel-b down again when it's already last (should be no-op).
panel.update_in(cx, |panel, window, cx| {
panel.move_channel_down(&MoveChannelDown, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-c",
" #️⃣ channel-b <== selected",
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Move favorite channel-b back up.
// The Channels section should remain unchanged.
panel.update_in(cx, |panel, window, cx| {
panel.move_channel_up(&MoveChannelUp, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-b <== selected",
" #️⃣ channel-c",
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Move favorite channel-b up again when it's already first (should be no-op).
panel.update_in(cx, |panel, window, cx| {
panel.move_channel_up(&MoveChannelUp, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-b <== selected",
" #️⃣ channel-c",
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Unfavorite channel-b.
// Selection should move to the next favorite (channel-c).
panel.update_in(cx, |panel, window, cx| {
panel.toggle_selected_channel_favorite(&ToggleSelectedChannelFavorite, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-c <== selected",
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Unfavorite channel-c.
// Favorites section should disappear entirely.
// Selection should move to the next available item.
panel.update_in(cx, |panel, window, cx| {
panel.toggle_selected_channel_favorite(&ToggleSelectedChannelFavorite, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Channels]",
" v root <== selected",
" #️⃣ channel-a",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Contacts]",
]
);
}
#[gpui::test]
async fn test_reorder_channels_independently_of_favorites(cx: &mut TestAppContext) {
let (server, client) = TestServer::start1(cx).await;
let root = server
.make_channel("root", None, (&client, cx), &mut [])
.await;
let _ = server
.make_channel("channel-a", Some(root), (&client, cx), &mut [])
.await;
let _ = server
.make_channel("channel-b", Some(root), (&client, cx), &mut [])
.await;
let _ = server
.make_channel("channel-c", Some(root), (&client, cx), &mut [])
.await;
let (workspace, cx) = client.build_test_workspace(cx).await;
let panel = workspace.update_in(cx, |workspace, window, cx| {
let panel = CollabPanel::new(workspace, window, cx);
workspace.add_panel(panel.clone(), window, cx);
panel
});
cx.run_until_parked();
// Select channel-a.
panel.update_in(cx, |panel, window, cx| {
panel.select_next(&SelectNext, window, cx);
panel.select_next(&SelectNext, window, cx);
panel.select_next(&SelectNext, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Channels]",
" v root",
" #️⃣ channel-a <== selected",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Favorite channel-a.
panel.update_in(cx, |panel, window, cx| {
panel.toggle_selected_channel_favorite(&ToggleSelectedChannelFavorite, window, cx);
});
// Select channel-b.
// Favorite channel-b.
panel.update_in(cx, |panel, window, cx| {
panel.select_next(&SelectNext, window, cx);
panel.toggle_selected_channel_favorite(&ToggleSelectedChannelFavorite, window, cx);
});
cx.run_until_parked();
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-a",
" #️⃣ channel-b",
"[Channels]",
" v root",
" #️⃣ channel-a",
" #️⃣ channel-b <== selected",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Select channel-a in the Channels section.
panel.update_in(cx, |panel, window, cx| {
panel.select_previous(&SelectPrevious, window, cx);
});
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-a",
" #️⃣ channel-b",
"[Channels]",
" v root",
" #️⃣ channel-a <== selected",
" #️⃣ channel-b",
" #️⃣ channel-c",
"[Contacts]",
]
);
// Move channel-a down.
// The Favorites section should remain unchanged.
// Selection should remain on channel-a in the Channels section,
// not jump to channel-a in Favorites.
panel.update_in(cx, |panel, window, cx| {
panel.move_channel_down(&MoveChannelDown, window, cx);
});
cx.run_until_parked();
assert_eq!(
panel.read_with(cx, |panel, _| panel.entries_as_strings()),
&[
"[Favorites]",
" #️⃣ channel-a",
" #️⃣ channel-b",
"[Channels]",
" v root",
" #️⃣ channel-b",
" #️⃣ channel-a <== selected",
" #️⃣ channel-c",
"[Contacts]",
]
);
}