FIX: correctly sorts public channels (#19555)

This commit is contained in:
Joffrey JAFFEUX 2022-12-21 17:01:20 +01:00 committed by GitHub
parent a6af981e1b
commit 2304761223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 4 deletions

View File

@ -86,10 +86,12 @@ export default class ChatChannelsManager extends Service {
}
get publicMessageChannels() {
return this.channels.filter(
(channel) =>
channel.isCategoryChannel && channel.currentUserMembership.following
);
return this.channels
.filter(
(channel) =>
channel.isCategoryChannel && channel.currentUserMembership.following
)
.sort((a, b) => a.title.localeCompare(b.title));
}
get directMessageChannels() {

View File

@ -31,6 +31,23 @@ RSpec.describe "List channels | mobile", type: :system, js: true, mobile: true d
end
end
context "when multiple category channels are present" do
fab!(:channel_1) { Fabricate(:category_channel, name: "b channel") }
fab!(:channel_2) { Fabricate(:category_channel, name: "a channel") }
before do
channel_1.add(current_user)
channel_2.add(current_user)
end
it "sorts them alphabetically" do
visit("/chat")
expect(page.find("#public-channels a:nth-child(1)")["data-chat-channel-id"]).to eq(channel_2.id.to_s)
expect(page.find("#public-channels a:nth-child(2)")["data-chat-channel-id"]).to eq(channel_1.id.to_s)
end
end
context "when direct message channels" do
fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user]) }
fab!(:inaccessible_dm_channel_1) { Fabricate(:direct_message_channel) }

View File

@ -32,6 +32,23 @@ RSpec.describe "List channels | no sidebar", type: :system, js: true do
end
end
context "when multiple category channels are present" do
fab!(:channel_1) { Fabricate(:category_channel, name: "b channel") }
fab!(:channel_2) { Fabricate(:category_channel, name: "a channel") }
before do
channel_1.add(current_user)
channel_2.add(current_user)
end
it "sorts them alphabetically" do
visit("/chat")
expect(page.find("#public-channels a:nth-child(1)")["data-chat-channel-id"]).to eq(channel_2.id.to_s)
expect(page.find("#public-channels a:nth-child(2)")["data-chat-channel-id"]).to eq(channel_1.id.to_s)
end
end
context "when direct message channels" do
fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user]) }
fab!(:inaccessible_dm_channel_1) { Fabricate(:direct_message_channel) }

View File

@ -41,6 +41,23 @@ RSpec.describe "List channels | sidebar", type: :system, js: true do
end
end
context "when multiple category channels are present" do
fab!(:channel_1) { Fabricate(:category_channel, name: "b channel") }
fab!(:channel_2) { Fabricate(:category_channel, name: "a channel") }
before do
channel_1.add(current_user)
channel_2.add(current_user)
end
it "sorts them alphabetically" do
visit("/")
expect(page.find("#sidebar-section-content-chat-channels li:nth-child(1)")).to have_css(".channel-#{channel_2.id}")
expect(page.find("#sidebar-section-content-chat-channels li:nth-child(2)")).to have_css(".channel-#{channel_1.id}")
end
end
context "when direct message channels" do
fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user]) }
fab!(:inaccessible_dm_channel_1) { Fabricate(:direct_message_channel) }