mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 10:29:35 +08:00
12a18d4d55
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. -->
77 lines
1.9 KiB
Ruby
77 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
||
|
||
RSpec.describe "User card", type: :system, js: true do
|
||
fab!(:current_user) { Fabricate(:user) }
|
||
fab!(:topic_1) { Fabricate(:topic) }
|
||
|
||
let(:chat) { PageObjects::Pages::Chat.new }
|
||
|
||
before { chat_system_bootstrap }
|
||
|
||
shared_examples "not showing chat button" do
|
||
it "doesn’t show the chat buttton" do
|
||
expect(page).to have_no_css(".user-card-chat-btn")
|
||
end
|
||
end
|
||
|
||
shared_examples "showing chat button" do
|
||
it "shows the chat buttton" do
|
||
expect(page).to have_css(".user-card-chat-btn")
|
||
end
|
||
end
|
||
|
||
context "when user" do
|
||
context "when chat disabled" do
|
||
before do
|
||
SiteSetting.chat_enabled = false
|
||
sign_in(current_user)
|
||
end
|
||
|
||
context "when showing user card" do
|
||
before do
|
||
visit("/")
|
||
find("[data-user-card='#{topic_1.user.username}'").click
|
||
end
|
||
|
||
include_examples "not showing chat button"
|
||
end
|
||
end
|
||
|
||
context "when chat enabled" do
|
||
before { sign_in(current_user) }
|
||
|
||
context "when showing user card" do
|
||
before do
|
||
visit("/")
|
||
find("[data-user-card='#{topic_1.user.username}'").click
|
||
end
|
||
|
||
include_examples "showing chat button"
|
||
|
||
context "when clicking chat button" do
|
||
before { find(".user-card-chat-btn").click }
|
||
|
||
it "opens correct channel" do
|
||
# at this point the ChatChannel is not created yet
|
||
expect(page).to have_css(".chat-drawer.is-expanded")
|
||
expect(page).to have_css(
|
||
".chat-drawer.is-expanded[data-chat-channel-id='#{Chat::Channel.last.id}']",
|
||
)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
context "when anonymous" do
|
||
context "when showing user card" do
|
||
before do
|
||
visit("/")
|
||
find("[data-user-card='#{topic_1.user.username}'").click
|
||
end
|
||
|
||
include_examples "not showing chat button"
|
||
end
|
||
end
|
||
end
|