mirror of
https://github.com/discourse/discourse.git
synced 2025-05-08 02:12:54 +08:00

This commit replaces two existing screens: - draft - channel selection modal Main features compared to existing solutions - features are now combined, meaning you can for example create multi users DM - it will show users with chat disabled - it shows unread state - hopefully a better look/feel - lots of small details and fixes... Other noticeable fixes - starting a DM with a user, even from the user card and clicking <kbd>Chat</kbd> will not show a green dot for the target user (or even the channel) until a message is actually sent - it should almost never do a full page reload anymore --------- Co-authored-by: Martin Brennan <mjrbrennan@gmail.com> Co-authored-by: Jordan Vidrine <30537603+jordanvidrine@users.noreply.github.com> Co-authored-by: chapoi <101828855+chapoi@users.noreply.github.com> Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
376 lines
12 KiB
Ruby
376 lines
12 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "New message", type: :system do
|
|
fab!(:current_user) { Fabricate(:admin) }
|
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
|
|
before do
|
|
# simpler user search without having to worry about user search data
|
|
SiteSetting.enable_names = false
|
|
|
|
chat_system_bootstrap
|
|
sign_in(current_user)
|
|
end
|
|
|
|
it "cmd + k opens new message" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
|
|
expect(chat_page.message_creator).to be_opened
|
|
end
|
|
|
|
context "when the the content is not filtered" do
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
fab!(:channel_2) { Fabricate(:chat_channel) }
|
|
fab!(:user_1) { Fabricate(:user) }
|
|
fab!(:user_2) { Fabricate(:user) }
|
|
fab!(:direct_message_channel_1) do
|
|
Fabricate(:direct_message_channel, users: [current_user, user_1])
|
|
end
|
|
fab!(:direct_message_channel_2) { Fabricate(:direct_message_channel, users: [user_1, user_2]) }
|
|
|
|
before { channel_1.add(current_user) }
|
|
|
|
it "lists channels the user is following" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
|
|
expect(chat_page.message_creator).to be_listing(channel_1)
|
|
# it lists user_1 instead of this channel as it's a 1:1 channel
|
|
expect(chat_page.message_creator).to be_not_listing(channel_2)
|
|
expect(chat_page.message_creator).to be_not_listing(
|
|
direct_message_channel_1,
|
|
current_user: current_user,
|
|
)
|
|
expect(chat_page.message_creator).to be_not_listing(
|
|
direct_message_channel_2,
|
|
current_user: current_user,
|
|
)
|
|
expect(chat_page.message_creator).to be_listing(user_1)
|
|
expect(chat_page.message_creator).to be_not_listing(user_2)
|
|
end
|
|
end
|
|
|
|
context "with no selection" do
|
|
context "when clicking a row" do
|
|
context "when the row is a channel" do
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
|
|
before { channel_1.add(current_user) }
|
|
|
|
it "opens the channel" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.click_row(channel_1)
|
|
|
|
expect(chat_page).to have_drawer(channel_id: channel_1.id)
|
|
end
|
|
end
|
|
|
|
context "when the row is a user" do
|
|
fab!(:user_1) { Fabricate(:user) }
|
|
fab!(:channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
|
|
|
|
it "opens the channel" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.click_row(user_1)
|
|
|
|
expect(chat_page).to have_drawer(channel_id: channel_1.id)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when shift clicking a row" do
|
|
context "when the row is a channel" do
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
|
|
before { channel_1.add(current_user) }
|
|
|
|
it "opens the channel" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.shift_click_row(channel_1)
|
|
|
|
expect(chat_page).to have_drawer(channel_id: channel_1.id)
|
|
end
|
|
end
|
|
|
|
context "when the row is a user" do
|
|
fab!(:user_1) { Fabricate(:user) }
|
|
fab!(:channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
|
|
|
|
it "adds the user" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.shift_click_row(user_1)
|
|
|
|
expect(chat_page.message_creator).to be_selecting(user_1)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when pressing enter" do
|
|
context "when the row is a channel" do
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
|
|
before { channel_1.add(current_user) }
|
|
|
|
it "opens the channel" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.click_row(channel_1)
|
|
|
|
expect(chat_page).to have_drawer(channel_id: channel_1.id)
|
|
end
|
|
end
|
|
|
|
context "when the row is a user" do
|
|
fab!(:user_1) { Fabricate(:user) }
|
|
fab!(:channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
|
|
|
|
it "opens the channel" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.click_row(user_1)
|
|
|
|
expect(chat_page).to have_drawer(channel_id: channel_1.id)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when pressing shift+enter" do
|
|
context "when the row is a channel" do
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
|
|
|
before { channel_1.add(current_user) }
|
|
|
|
it "opens the channel" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.shift_enter_shortcut
|
|
|
|
expect(chat_page).to have_drawer(channel_id: channel_1.id)
|
|
end
|
|
end
|
|
|
|
context "when the row is a user" do
|
|
fab!(:user_1) { Fabricate(:user) }
|
|
fab!(:channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
|
|
|
|
it "adds the user" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.shift_enter_shortcut
|
|
|
|
expect(chat_page.message_creator).to be_selecting(user_1)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when navigating content with arrows" do
|
|
fab!(:channel_1) { Fabricate(:chat_channel, name: "channela") }
|
|
fab!(:channel_2) { Fabricate(:chat_channel, name: "channelb") }
|
|
|
|
before do
|
|
channel_1.add(current_user)
|
|
channel_2.add(current_user)
|
|
end
|
|
|
|
it "changes active content" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
|
|
expect(chat_page.message_creator).to be_listing(channel_1, active: true)
|
|
|
|
chat_page.message_creator.arrow_down_shortcut
|
|
|
|
expect(chat_page.message_creator).to be_listing(channel_2, active: true)
|
|
|
|
chat_page.message_creator.arrow_down_shortcut
|
|
|
|
expect(chat_page.message_creator).to be_listing(channel_1, active: true)
|
|
|
|
chat_page.message_creator.arrow_up_shortcut
|
|
|
|
expect(chat_page.message_creator).to be_listing(channel_2, active: true)
|
|
end
|
|
end
|
|
|
|
context "with disabled content" do
|
|
fab!(:user_1) { Fabricate(:user) }
|
|
fab!(:channel_1) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
|
|
|
|
before { user_1.user_option.update!(chat_enabled: false) }
|
|
|
|
it "doesn’t make the content active" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
|
|
expect(chat_page.message_creator).to be_listing(user_1, inactive: true, disabled: true)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when filtering" do
|
|
fab!(:channel_1) { Fabricate(:chat_channel, name: "bob-channel") }
|
|
fab!(:user_1) { Fabricate(:user, username: "bob-user") }
|
|
fab!(:user_2) { Fabricate(:user) }
|
|
fab!(:channel_2) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
|
|
fab!(:channel_3) { Fabricate(:direct_message_channel, users: [current_user, user_1, user_2]) }
|
|
|
|
before { channel_1.add(current_user) }
|
|
|
|
context "with no prefix" do
|
|
it "lists all matching content" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
|
|
chat_page.message_creator.filter("bob")
|
|
|
|
expect(chat_page.message_creator).to be_listing(channel_1)
|
|
expect(chat_page.message_creator).to be_not_listing(channel_2)
|
|
expect(chat_page.message_creator).to be_listing(channel_3)
|
|
expect(chat_page.message_creator).to be_listing(user_1)
|
|
expect(chat_page.message_creator).to be_not_listing(user_2)
|
|
end
|
|
end
|
|
|
|
context "with channel prefix" do
|
|
it "lists matching channel" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
|
|
chat_page.message_creator.filter("#bob")
|
|
|
|
expect(chat_page.message_creator).to be_listing(channel_1)
|
|
expect(chat_page.message_creator).to be_not_listing(channel_2)
|
|
expect(chat_page.message_creator).to be_listing(channel_3)
|
|
expect(chat_page.message_creator).to be_not_listing(user_1)
|
|
expect(chat_page.message_creator).to be_not_listing(user_2)
|
|
end
|
|
end
|
|
|
|
context "with user prefix" do
|
|
it "lists matching users" do
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
|
|
chat_page.message_creator.filter("@bob")
|
|
|
|
expect(chat_page.message_creator).to be_not_listing(channel_1)
|
|
expect(chat_page.message_creator).to be_not_listing(channel_2)
|
|
expect(chat_page.message_creator).to be_not_listing(channel_3)
|
|
expect(chat_page.message_creator).to be_listing(user_1)
|
|
expect(chat_page.message_creator).to be_not_listing(user_2)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "with selection" do
|
|
fab!(:channel_1) { Fabricate(:chat_channel, name: "bob-channel") }
|
|
fab!(:user_1) { Fabricate(:user, username: "bob-user") }
|
|
fab!(:user_2) { Fabricate(:user, username: "bobby-user") }
|
|
fab!(:user_3) { Fabricate(:user, username: "sam-user") }
|
|
fab!(:channel_2) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
|
|
fab!(:channel_3) { Fabricate(:direct_message_channel, users: [current_user, user_2]) }
|
|
|
|
before do
|
|
channel_1.add(current_user)
|
|
visit("/")
|
|
chat_page.open_new_message
|
|
chat_page.message_creator.shift_click_row(user_1)
|
|
end
|
|
|
|
context "when pressing enter" do
|
|
it "opens the channel" do
|
|
chat_page.message_creator.enter_shortcut
|
|
|
|
expect(chat_page).to have_drawer(channel_id: channel_2.id)
|
|
end
|
|
end
|
|
|
|
context "when clicking cta" do
|
|
it "opens the channel" do
|
|
chat_page.message_creator.click_cta
|
|
|
|
expect(chat_page).to have_drawer(channel_id: channel_2.id)
|
|
end
|
|
end
|
|
|
|
context "when filtering" do
|
|
it "shows only matching users regarless of prefix" do
|
|
chat_page.message_creator.filter("#bob")
|
|
|
|
expect(chat_page.message_creator).to be_listing(user_1)
|
|
expect(chat_page.message_creator).to be_listing(user_2)
|
|
expect(chat_page.message_creator).to be_not_listing(user_3)
|
|
expect(chat_page.message_creator).to be_not_listing(channel_1)
|
|
expect(chat_page.message_creator).to be_not_listing(channel_2)
|
|
expect(chat_page.message_creator).to be_not_listing(channel_3)
|
|
end
|
|
|
|
it "shows selected user as selected in content" do
|
|
chat_page.message_creator.filter("@bob")
|
|
|
|
expect(chat_page.message_creator).to be_listing(user_1, selected: true)
|
|
expect(chat_page.message_creator).to be_listing(user_2, selected: false)
|
|
end
|
|
end
|
|
|
|
context "when clicking another user" do
|
|
it "adds it to the selection" do
|
|
chat_page.message_creator.filter("@bob")
|
|
chat_page.message_creator.click_row(user_2)
|
|
|
|
expect(chat_page.message_creator).to be_selecting(user_1)
|
|
expect(chat_page.message_creator).to be_selecting(user_2)
|
|
end
|
|
end
|
|
|
|
context "when pressing backspace" do
|
|
it "removes it" do
|
|
chat_page.message_creator.backspace_shortcut
|
|
|
|
expect(chat_page.message_creator).to be_selecting(user_1, active: true)
|
|
|
|
chat_page.message_creator.backspace_shortcut
|
|
|
|
expect(chat_page.message_creator).to be_not_selecting(user_1)
|
|
end
|
|
end
|
|
|
|
context "when navigating selection with arrow left/right" do
|
|
it "changes active item" do
|
|
chat_page.message_creator.filter("@bob")
|
|
chat_page.message_creator.click_row(user_2)
|
|
|
|
chat_page.message_creator.arrow_left_shortcut
|
|
|
|
expect(chat_page.message_creator).to be_selecting(user_2, active: true)
|
|
|
|
chat_page.message_creator.arrow_left_shortcut
|
|
|
|
expect(chat_page.message_creator).to be_selecting(user_1, active: true)
|
|
|
|
chat_page.message_creator.arrow_left_shortcut
|
|
|
|
expect(chat_page.message_creator).to be_selecting(user_2, active: true)
|
|
|
|
chat_page.message_creator.arrow_right_shortcut
|
|
|
|
expect(chat_page.message_creator).to be_selecting(user_1, active: true)
|
|
end
|
|
end
|
|
|
|
context "when clicking selection" do
|
|
it "removes it" do
|
|
chat_page.message_creator.click_item(user_1)
|
|
|
|
expect(chat_page.message_creator).to be_not_selecting(user_1)
|
|
end
|
|
end
|
|
end
|
|
end
|