FIX: handles starting draft dm from sidebar (#18946)

This commit is contained in:
Joffrey JAFFEUX 2022-11-08 23:58:11 +01:00 committed by GitHub
parent f8f55cef67
commit 074aa5eb5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 20 deletions

View File

@ -4,6 +4,7 @@ import { defaultHomepage } from "discourse/lib/utilities";
import { inject as service } from "@ember/service";
import { scrollTop } from "discourse/mixins/scroll-top";
import { schedule } from "@ember/runloop";
import { DRAFT_CHANNEL_VIEW } from "discourse/plugins/chat/discourse/services/chat";
export default class ChatRoute extends DiscourseRoute {
@service chat;
@ -18,14 +19,21 @@ export default class ChatRoute extends DiscourseRoute {
beforeModel(transition) {
if (
transition.from && // don't intercept when directly loading chat
this.chatPreferredMode.isDrawer &&
transition.intent?.name === "chat.channel" // sidebar can only load a channel
this.chatPreferredMode.isDrawer
) {
transition.abort();
const id = transition.intent.contexts[0];
return this.chat.getChannelBy("id", id).then((channel) => {
this.appEvents.trigger("chat:open-channel", channel);
});
if (transition.intent?.name === "chat.channel") {
transition.abort();
const id = transition.intent.contexts[0];
return this.chat.getChannelBy("id", id).then((channel) => {
this.appEvents.trigger("chat:open-channel", channel);
});
}
if (transition.intent?.name === "chat.draft-channel") {
transition.abort();
this.appEvents.trigger("chat:open-view", DRAFT_CHANNEL_VIEW);
return;
}
}
if (!this.chat.userCanChat) {

View File

@ -8,6 +8,7 @@ RSpec.describe "Navigation", type: :system, js: true do
fab!(:category_channel) { Fabricate(:category_channel) }
fab!(:message) { Fabricate(:chat_message, chat_channel: category_channel) }
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:sidebar_page) { PageObjects::Pages::Sidebar.new }
before do
# ensures we have one valid registered admin
@ -125,5 +126,28 @@ RSpec.describe "Navigation", type: :system, js: true do
)
end
end
context "when starting draft from sidebar with drawer preferred" do
it "opens draft in drawer" do
visit("/")
sidebar_page.start_draft_dm
expect(page).to have_current_path("/")
expect(page).to have_css(".topic-chat-container.expanded.visible")
end
end
context "when starting draft from sidebar with full page preferred" do
it "opens draft in full page" do
visit("/")
chat_page.open_from_header
chat_page.maximize_drawer
visit("/")
sidebar_page.start_draft_dm
expect(page).to have_current_path("/chat/draft-channel")
expect(page).not_to have_css(".topic-chat-container.expanded.visible")
end
end
end
end

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
module PageObjects
module Pages
class Sidebar < PageObjects::Pages::Base
def start_draft_dm
find(".sidebar-section-chat-dms .sidebar-section-header-button", visible: false).click
end
end
end
end

View File

@ -5,14 +5,7 @@ import {
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import {
click,
currentURL,
fillIn,
settled,
triggerKeyEvent,
visit,
} from "@ember/test-helpers";
import { click, currentURL, settled, visit } from "@ember/test-helpers";
import { directMessageChannels } from "discourse/plugins/chat/chat-fixtures";
import { cloneJSON } from "discourse-common/lib/object";
import I18n from "I18n";
@ -421,13 +414,11 @@ acceptance("Discourse Chat - Core Sidebar", function (needs) {
test("Open a new direct conversation", async function (assert) {
await visit("/");
await click(".sidebar-section-chat-dms .sidebar-section-header-button");
assert.ok(exists(".direct-message-creator"));
await fillIn(".filter-usernames", "hawk");
await triggerKeyEvent(".filter-usernames", "keydown", "Enter");
assert.strictEqual(currentURL(), "/chat/draft-channel");
assert.ok(exists(".direct-message-creator"));
assert.ok(exists(".topic-chat-container.expanded.visible"));
assert.strictEqual(currentURL(), "/");
});
test("Escapes public channel titles", async function (assert) {