discourse/plugins/chat/spec/system/channel_members_page_spec.rb
Joffrey JAFFEUX 12a18d4d55
DEV: properly namespace chat (#20690)
This commit main goal was to comply with Zeitwerk and properly rely on autoloading. To achieve this, most resources have been namespaced under the `Chat` module.

- Given all models are now namespaced with `Chat::` and would change the stored types in DB when using polymorphism or STI (single table inheritance), this commit uses various Rails methods to ensure proper class is loaded and the stored name in DB is unchanged, eg: `Chat::Message` model will be stored as `"ChatMessage"`, and `"ChatMessage"` will correctly load `Chat::Message` model.
- Jobs are now using constants only, eg: `Jobs::Chat::Foo` and should only be enqueued this way

Notes:
- This commit also used this opportunity to limit the number of registered css files in plugin.rb
- `discourse_dev` support has been removed within this commit and will be reintroduced later

<!-- NOTE: All pull requests should have tests (rspec in Ruby, qunit in JavaScript). If your code does not include test coverage, please include an explanation of why it was omitted. -->
2023-03-17 14:24:38 +01:00

73 lines
2.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 - Members page", type: :system, js: true 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 "cant 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 about page" do
chat_page.visit_channel_members(channel_1)
expect(page).to have_current_path("/chat/c/#{channel_1.slug}/#{channel_1.id}/info/about")
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)) }
end
it "shows all members" do
Jobs.run_immediately!
channel_1.update!(user_count_stale: true)
Jobs::Chat::UpdateChannelUserCount.new.execute(chat_channel_id: channel_1.id)
chat_page.visit_channel_members(channel_1)
expect(page).to have_selector(".channel-members-view__list-item", count: 50)
scroll_to(find(".channel-members-view__list-item:nth-child(50)"))
expect(page).to have_selector(".channel-members-view__list-item", count: 100, wait: 5)
scroll_to(find(".channel-members-view__list-item:nth-child(100)"))
expect(page).to have_selector(".channel-members-view__list-item", count: 100)
end
context "with filter" do
it "filters members" do
Jobs.run_immediately!
channel_1.update!(user_count_stale: true)
Jobs::Chat::UpdateChannelUserCount.new.execute(chat_channel_id: channel_1.id)
chat_page.visit_channel_members(channel_1)
find(".channel-members-view__search-input").fill_in(with: "cat")
expect(page).to have_selector(".channel-members-view__list-item", count: 1, text: "cat")
end
end
end
end
end