mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
The new channel form was looking a little long in the tooth, and updating it to formkit makes a lot of general improvements. Before: <img width="350" alt="image" src="https://github.com/user-attachments/assets/20836a59-86e8-4989-a2c5-9c104208b2b9" /> After: <img width="350" alt="image" src="https://github.com/user-attachments/assets/f3bdec2f-49b2-4dbc-ba54-c6e3f51288c6" /> Also updated some general chat styles... we were missing a lot of general shared styles here before/after <img width="450" alt="image" src="https://github.com/user-attachments/assets/58bd6e4e-584f-49c9-9b61-ac36dac13626" /> <img width="450" alt="image" src="https://github.com/user-attachments/assets/82b9da42-854c-4829-a09d-3f258e846fb1" /> before/after <img width="450" alt="image" src="https://github.com/user-attachments/assets/5885866d-7955-4b0c-92f7-dad8a29dd7ca" /> <img width="450" alt="image" src="https://github.com/user-attachments/assets/1d6b6a47-d47e-4005-912d-a6108e15d2b3" /> before/after <img width="400" alt="image" src="https://github.com/user-attachments/assets/c948521c-7571-4281-975f-f2f41fe8bad5" /> <img width="400" alt="image" src="https://github.com/user-attachments/assets/a87df09c-0574-4f2f-95c1-afd06ad6f6e4" />
323 lines
11 KiB
Ruby
Vendored
323 lines
11 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Create channel" do
|
|
fab!(:category_1, :category)
|
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
let(:channel_modal) { PageObjects::Modals::ChatChannelCreate.new }
|
|
|
|
before { chat_system_bootstrap }
|
|
|
|
context "when user cannot create channel" do
|
|
fab!(:current_user, :user)
|
|
|
|
before { sign_in(current_user) }
|
|
|
|
it "does not show the create channel button" do
|
|
chat_page.visit_browse
|
|
expect(chat_page).to have_no_new_channel_button
|
|
end
|
|
end
|
|
|
|
context "when can create channel" do
|
|
fab!(:current_admin_user, :admin)
|
|
before { sign_in(current_admin_user) }
|
|
|
|
context "when selecting a category" do
|
|
it "shows access hint" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.select_category(category_1)
|
|
|
|
expect(channel_modal).to have_create_hint(Group[:everyone].name)
|
|
end
|
|
|
|
it "shows threading toggle" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.select_category(category_1)
|
|
|
|
expect(channel_modal).to have_threading_toggle
|
|
end
|
|
|
|
it "does not override channel name if that was already specified" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.fill_name("My Cool Channel")
|
|
channel_modal.select_category(category_1)
|
|
|
|
expect(channel_modal).to have_name_prefilled("My Cool Channel")
|
|
end
|
|
|
|
context "when category is private" do
|
|
fab!(:group_1, :group)
|
|
fab!(:private_category_1) { Fabricate(:private_category, group: group_1) }
|
|
|
|
it "shows access hint when selecting the category" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.select_category(private_category_1)
|
|
|
|
expect(channel_modal).to have_create_hint(group_1.name)
|
|
end
|
|
|
|
context "when category is a child" do
|
|
fab!(:group_2, :group)
|
|
fab!(:child_category) do
|
|
Fabricate(:private_category, parent_category_id: private_category_1.id, group: group_2)
|
|
end
|
|
|
|
it "shows access hint when selecting the category" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.select_category(child_category)
|
|
|
|
expect(channel_modal).to have_create_hint(group_2.name)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when category has a malicious group name" do
|
|
fab!(:group_1) do
|
|
group = Group.new(name: "<script>e</script>")
|
|
group.save(validate: false)
|
|
group
|
|
end
|
|
fab!(:private_category_1) { Fabricate(:private_category, group: group_1) }
|
|
|
|
it "escapes the group name" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.select_category(private_category_1)
|
|
expect(page).to have_no_css(".loading-permissions")
|
|
|
|
expect(channel_modal.create_channel_hint["innerHTML"].strip).to include(
|
|
"<script>e</script>",
|
|
)
|
|
end
|
|
end
|
|
|
|
it "autogenerates slug from name and changes slug placeholder" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
name = "Cats & Dogs"
|
|
channel_modal.select_category(category_1)
|
|
channel_modal.fill_name(name)
|
|
channel_modal.fill_description("All kind of cute cats")
|
|
|
|
wait_for_attribute(channel_modal.slug_input, :placeholder, "cats-dogs")
|
|
|
|
channel_modal.click_primary_button
|
|
|
|
expect(page).to have_content(name)
|
|
created_channel = Chat::Channel.find_by(chatable_id: category_1.id)
|
|
expect(created_channel.slug).to eq("cats-dogs")
|
|
expect(page).to have_current_path(chat.channel_path(created_channel.slug, created_channel.id))
|
|
end
|
|
|
|
it "allows the user to set a slug independently of name" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
name = "Cats & Dogs"
|
|
channel_modal.select_category(category_1)
|
|
channel_modal.fill_name(name)
|
|
channel_modal.fill_description("All kind of cute cats")
|
|
channel_modal.fill_slug("pets-everywhere")
|
|
channel_modal.click_primary_button
|
|
|
|
expect(page).to have_content(name)
|
|
created_channel = Chat::Channel.find_by(chatable_id: category_1.id)
|
|
expect(created_channel.slug).to eq("pets-everywhere")
|
|
expect(page).to have_current_path(chat.channel_path(created_channel.slug, created_channel.id))
|
|
end
|
|
|
|
context "when saving" do
|
|
context "when user has chosen to automatically add users" do
|
|
let(:dialog) { PageObjects::Components::Dialog.new }
|
|
let(:name) { "Cats & Dogs" }
|
|
|
|
before do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.fill_name(name)
|
|
end
|
|
|
|
context "for a public category" do
|
|
before do
|
|
channel_modal.select_category(category_1)
|
|
channel_modal.toggle_auto_join
|
|
channel_modal.click_primary_button
|
|
end
|
|
|
|
it "displays the correct warning" do
|
|
expect(dialog).to have_content(
|
|
I18n.t(
|
|
"js.chat.create_channel.auto_join_users.public_category_warning",
|
|
category: category_1.name,
|
|
),
|
|
)
|
|
end
|
|
|
|
it "allows the user to proceed with channel creation" do
|
|
dialog.click_yes
|
|
expect(page).to have_content(name)
|
|
created_channel = Chat::Channel.find_by(chatable_id: category_1.id)
|
|
expect(page).to have_current_path(
|
|
chat.channel_path(created_channel.slug, created_channel.id),
|
|
)
|
|
end
|
|
|
|
it "does nothing if no is clicked" do
|
|
dialog.click_no
|
|
expect(page).to have_css(".chat-modal-create-channel")
|
|
expect(Chat::Channel.exists?(chatable_id: category_1.id)).to eq(false)
|
|
end
|
|
end
|
|
|
|
context "for a private category" do
|
|
fab!(:group_1, :group)
|
|
fab!(:user_1, :user)
|
|
fab!(:private_category) { Fabricate(:private_category, group: group_1) }
|
|
|
|
before do
|
|
group_1.add(user_1)
|
|
channel_modal.select_category(private_category)
|
|
channel_modal.toggle_auto_join
|
|
channel_modal.click_primary_button
|
|
end
|
|
|
|
context "when only 1 group can access the category" do
|
|
it "displays the correct warning" do
|
|
expect(dialog).to have_content(
|
|
I18n.t(
|
|
"js.chat.create_channel.auto_join_users.warning_1_group",
|
|
count: 1,
|
|
group: "@#{group_1.name}",
|
|
),
|
|
)
|
|
end
|
|
end
|
|
|
|
context "when 2 groups can access the category" do
|
|
fab!(:group_2, :group)
|
|
fab!(:category_group_2) do
|
|
CategoryGroup.create(group: group_2, category: private_category)
|
|
end
|
|
|
|
it "displays the correct warning" do
|
|
sorted_names = [group_1.name, group_2.name].sort
|
|
expect(dialog).to have_content(
|
|
I18n.t(
|
|
"js.chat.create_channel.auto_join_users.warning_2_groups",
|
|
count: 1,
|
|
group1: "@#{sorted_names.first}",
|
|
group2: "@#{sorted_names.second}",
|
|
),
|
|
)
|
|
end
|
|
end
|
|
|
|
context "when > 2 groups can access the category" do
|
|
fab!(:group_2, :group)
|
|
fab!(:category_group_2) do
|
|
CategoryGroup.create(group: group_2, category: private_category)
|
|
end
|
|
|
|
fab!(:group_3, :group)
|
|
fab!(:category_group_3) do
|
|
CategoryGroup.create(group: group_3, category: private_category)
|
|
end
|
|
|
|
it "displays the correct warning" do
|
|
# NOTE: This has to be hardcoded because the I18n module in ruby
|
|
# does not support messageFormat.
|
|
first_group = [group_1.name, group_2.name, group_3.name].sort.first
|
|
expect(dialog).to have_content(
|
|
"Automatically add 1 user from @#{first_group} and 2 other groups?",
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when error" do
|
|
it "displays the error" do
|
|
existing_channel = Fabricate(:chat_channel)
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.select_category(existing_channel.chatable)
|
|
channel_modal.fill_name(existing_channel.name)
|
|
channel_modal.click_primary_button
|
|
|
|
expect(page).to have_content(I18n.t("chat.errors.channel_exists_for_category"))
|
|
end
|
|
end
|
|
|
|
context "when slug is already being used" do
|
|
it "displays the error" do
|
|
Fabricate(:chat_channel, slug: "pets-everywhere")
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.select_category(category_1)
|
|
channel_modal.fill_name("Testing")
|
|
channel_modal.fill_slug("pets-everywhere")
|
|
channel_modal.click_primary_button
|
|
|
|
expect(page).to have_content(
|
|
"Slug " + I18n.t("chat.category_channel.errors.is_already_in_use"),
|
|
)
|
|
end
|
|
end
|
|
|
|
context "when successful" do
|
|
it "redirects to created channel" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.select_category(category_1)
|
|
|
|
expect(channel_modal).to have_name_prefilled(category_1.name)
|
|
|
|
channel_modal.fill_description("All kind of cute cats")
|
|
channel_modal.click_primary_button
|
|
|
|
expect(channel_modal).to be_closed
|
|
|
|
created_channel = Chat::Channel.find_by(chatable_id: category_1.id)
|
|
expect(page).to have_current_path(
|
|
chat.channel_path(created_channel.slug, created_channel.id),
|
|
)
|
|
end
|
|
|
|
it "persists the selected emoji" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.select_category(category_1)
|
|
channel_modal.fill_name("Cats & Dogs")
|
|
channel_modal.select_emoji("cat")
|
|
channel_modal.click_primary_button
|
|
|
|
expect(channel_modal).to be_closed
|
|
|
|
created_channel = Chat::Channel.find_by(chatable_id: category_1.id)
|
|
expect(created_channel.emoji).to eq("cat")
|
|
end
|
|
|
|
it "clears the emoji when reset before saving" do
|
|
chat_page.visit_browse
|
|
chat_page.new_channel_button.click
|
|
channel_modal.select_category(category_1)
|
|
channel_modal.fill_name("Cats & Dogs")
|
|
channel_modal.select_emoji("cat")
|
|
channel_modal.reset_emoji
|
|
channel_modal.click_primary_button
|
|
|
|
expect(channel_modal).to be_closed
|
|
|
|
created_channel = Chat::Channel.find_by(chatable_id: category_1.id)
|
|
expect(created_channel.emoji).to be_nil
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|