mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 22:13:41 +08:00
ab832cc865
Group channels will allow users to create channels with a name and invite people. It's possible to add people even after creation of the channel. Removing users is not yet possible but will be added in the near future. Technically a group channel is `direct_message_channel` with a group attribute set to true on its direct message (chatable). This model might evolve in the future but offers much flexibility for now without having to rely on a complex migration. The commit essentially consists of: - a migration to set existing direct message channels with more than 2 users to a group - a new message creator which allows to search, add members, and create groups - a new `AddUsersToChannel` service - a modified `SearchChatable` service
106 lines
3.2 KiB
Ruby
106 lines
3.2 KiB
Ruby
# frozen_string_literal: true
|
||
|
||
RSpec.describe "Channel - Info - Members page", type: :system do
|
||
let(:chat_page) { PageObjects::Pages::Chat.new }
|
||
|
||
fab!(:current_user) { Fabricate(:user) }
|
||
fab!(:channel_1) { Fabricate(:category_channel) }
|
||
|
||
before do
|
||
chat_system_bootstrap
|
||
sign_in(current_user)
|
||
end
|
||
|
||
context "as unauthorized user" do
|
||
before { SiteSetting.chat_allowed_groups = Fabricate(:group).id }
|
||
|
||
it "can't see channel members" do
|
||
chat_page.visit_channel_members(channel_1)
|
||
|
||
expect(page).to have_current_path("/latest")
|
||
end
|
||
end
|
||
|
||
context "as authorized user" do
|
||
context "with no members" do
|
||
it "redirects to settings page" do
|
||
chat_page.visit_channel_members(channel_1)
|
||
|
||
expect(page).to have_current_path("/chat/c/#{channel_1.slug}/#{channel_1.id}/info/members")
|
||
end
|
||
end
|
||
|
||
context "with members" do
|
||
before do
|
||
channel_1.add(current_user)
|
||
channel_1.add(Fabricate(:user, username: "cat"))
|
||
98.times { channel_1.add(Fabricate(:user)) }
|
||
Jobs.run_immediately!
|
||
channel_1.update!(user_count_stale: true)
|
||
Jobs::Chat::UpdateChannelUserCount.new.execute(chat_channel_id: channel_1.id)
|
||
end
|
||
|
||
xit "shows all members" do
|
||
chat_page.visit_channel_members(channel_1)
|
||
|
||
expect(page).to have_selector(".chat-channel-members__list-item", count: 60)
|
||
|
||
scroll_to(find(".chat-channel-members__list-item:nth-child(60)"))
|
||
|
||
expect(page).to have_selector(".chat-channel-members__list-item", count: 100)
|
||
|
||
scroll_to(find(".chat-channel-members__list-item:nth-child(100)"))
|
||
|
||
expect(page).to have_selector(".chat-channel-members__list-item", count: 100)
|
||
end
|
||
|
||
context "with filter" do
|
||
it "filters members" do
|
||
chat_page.visit_channel_members(channel_1)
|
||
find(".chat-channel-members__filter").fill_in(with: "cat")
|
||
|
||
expect(page).to have_selector(".chat-channel-members__list-item", count: 1, text: "cat")
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
context "when category channel" do
|
||
it "doesn’t allow to add members" do
|
||
chat_page.visit_channel_members(channel_1)
|
||
|
||
expect(chat_page).to have_no_css(".chat-channel-members__list-item.-add-member")
|
||
end
|
||
end
|
||
|
||
context "when category channel" do
|
||
fab!(:channel_1) do
|
||
Fabricate(
|
||
:direct_message_channel,
|
||
slug: "test-channel",
|
||
users: [current_user, Fabricate(:user), Fabricate(:user)],
|
||
group: true,
|
||
)
|
||
end
|
||
|
||
it "allows to add members" do
|
||
new_user = Fabricate(:user)
|
||
chat_page.visit_channel_members(channel_1)
|
||
chat_page.find(".chat-channel-members__list-item.-add-member").click
|
||
chat_page.find(".chat-message-creator__members-input").fill_in(with: new_user.username)
|
||
chat_page.find(".chat-message-creator__list-item").click
|
||
chat_page.find(".add-to-channel").click
|
||
|
||
expect(chat_page).to have_current_path("/chat/c/#{channel_1.slug}/#{channel_1.id}")
|
||
expect(chat_page).to have_content(
|
||
I18n.t(
|
||
"chat.channel.users_invited_to_channel",
|
||
invited_users: "@#{new_user.username}",
|
||
inviting_user: "@#{current_user.username}",
|
||
count: 1,
|
||
),
|
||
)
|
||
end
|
||
end
|
||
end
|