discourse/plugins/chat/spec/system/channel_about_page_spec.rb
Alan Guo Xiang Tan 7218da7510
DEV: Fix and improve chat system test for editing name and slug (#21810)
This commit introduces a couple of changes:

1. When editing a chat channel's slug, we were using `this.model.set("title", title)` when the `set`
   function does not exist. This was actually throwing the error in the
   "can edit slug" system test where the modal was not closed after
   saving and was flashing an error.

2. Introduce `PageObjects::Pages::ChatChannelAbout` and
   `PageObjects::Modals::ChatChannelEdit` page object to encapsulate
   logic better.
2023-05-29 18:00:59 +02:00

139 lines
4.2 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
RSpec.describe "Channel - Info - About page", type: :system, js: true do
fab!(:channel_1) { Fabricate(:category_channel) }
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:chat_channel_about_page) { PageObjects::Pages::ChatChannelAbout.new }
before { chat_system_bootstrap }
context "as regular user" do
fab!(:current_user) { Fabricate(:user) }
before { sign_in(current_user) }
it "shows channel info" do
chat_page.visit_channel_about(channel_1)
expect(page.find(".category-name")).to have_content(channel_1.chatable.name)
expect(page.find(".channel-info-about-view__name")).to have_content(channel_1.title)
expect(page.find(".channel-info-about-view__slug")).to have_content(channel_1.slug)
end
it "escapes channel title" do
channel_1.update!(name: "<script>alert('hello')</script>")
chat_page.visit_channel_about(channel_1)
expect(page.find(".channel-info-about-view__name")["innerHTML"].strip).to eq(
"&lt;script&gt;alert('hello')&lt;/script&gt;",
)
expect(page.find(".chat-channel-title__name")["innerHTML"].strip).to eq(
"&lt;script&gt;alert('hello')&lt;/script&gt;",
)
end
it "cant edit name or slug" do
chat_page.visit_channel_about(channel_1)
expect(page).to have_no_selector(".edit-name-slug-btn")
end
it "cant edit description" do
chat_page.visit_channel_about(channel_1)
expect(page).to have_no_selector(".edit-description-btn")
end
context "as a member" do
before { channel_1.add(current_user) }
it "can leave channel" do
chat_page.visit_channel_about(channel_1)
membership = channel_1.membership_for(current_user)
expect {
click_button(I18n.t("js.chat.channel_settings.leave_channel"))
expect(page).to have_content(I18n.t("js.chat.channel_settings.join_channel"))
}.to change { membership.reload.following }.from(true).to(false)
end
end
context "as not a member" do
it "can join channel" do
chat_page.visit_channel_about(channel_1)
expect {
click_button(I18n.t("js.chat.channel_settings.join_channel"))
expect(page).to have_content(I18n.t("js.chat.channel_settings.leave_channel"))
}.to change {
Chat::UserChatChannelMembership.where(user_id: current_user.id, following: true).count
}.by(1)
end
end
end
context "as admin" do
fab!(:current_user) { Fabricate(:admin) }
before { sign_in(current_user) }
it "can edit name" do
chat_page.visit_channel_about(channel_1)
edit_modal = chat_channel_about_page.open_edit_modal
expect(edit_modal).to have_name_input(channel_1.title)
name = "A new name"
edit_modal.fill_and_save_name(name)
expect(chat_channel_about_page).to have_name(name)
end
it "can edit description" do
chat_page.visit_channel_about(channel_1)
find(".edit-description-btn").click
expect(page).to have_selector(
".chat-channel-edit-description-modal__description-input",
text: channel_1.description,
)
description = "A new description"
find(".chat-channel-edit-description-modal__description-input").fill_in(with: description)
find(".create").click
expect(page).to have_content(description)
end
it "can edit slug" do
chat_page.visit_channel_about(channel_1)
edit_modal = chat_channel_about_page.open_edit_modal
slug = "gonzo-slug"
expect(edit_modal).to have_slug_input(channel_1.slug)
edit_modal.fill_and_save_slug(slug)
expect(chat_channel_about_page).to have_slug(slug)
end
it "can clear the slug to use the autogenerated version based on the name" do
channel_1.update!(name: "test channel")
chat_page.visit_channel_about(channel_1)
edit_modal = chat_channel_about_page.open_edit_modal
expect(edit_modal).to have_slug_input(channel_1.slug)
edit_modal.fill_in_slug_input("")
edit_modal.wait_for_auto_generated_slug
edit_modal.save_changes
expect(chat_channel_about_page).to have_slug("test-channel")
end
end
end