2022-11-04 22:06:24 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "Navigation", type: :system, js: true do
|
2022-11-07 16:04:43 +08:00
|
|
|
fab!(:category) { Fabricate(:category) }
|
|
|
|
fab!(:topic) { Fabricate(:topic) }
|
|
|
|
fab!(:post) { Fabricate(:post, topic: topic) }
|
|
|
|
fab!(:user) { Fabricate(:admin) }
|
2022-11-04 22:06:24 +08:00
|
|
|
fab!(:category_channel) { Fabricate(:category_channel) }
|
2022-11-11 13:39:15 +08:00
|
|
|
fab!(:category_channel_2) { Fabricate(:category_channel) }
|
2022-11-04 22:06:24 +08:00
|
|
|
fab!(:message) { Fabricate(:chat_message, chat_channel: category_channel) }
|
2022-11-07 21:48:18 +08:00
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
2022-11-09 06:58:11 +08:00
|
|
|
let(:sidebar_page) { PageObjects::Pages::Sidebar.new }
|
2022-11-11 13:39:15 +08:00
|
|
|
let(:chat_drawer_page) { PageObjects::Pages::ChatDrawer.new }
|
2022-11-04 22:06:24 +08:00
|
|
|
|
|
|
|
before do
|
FEATURE: Generic hashtag autocomplete lookup and markdown cooking (#18937)
This commit fleshes out and adds functionality for the new `#hashtag` search and
lookup system, still hidden behind the `enable_experimental_hashtag_autocomplete`
feature flag.
**Serverside**
We have two plugin API registration methods that are used to define data sources
(`register_hashtag_data_source`) and hashtag result type priorities depending on
the context (`register_hashtag_type_in_context`). Reading the comments in plugin.rb
should make it clear what these are doing. Reading the `HashtagAutocompleteService`
in full will likely help a lot as well.
Each data source is responsible for providing its own **lookup** and **search**
method that returns hashtag results based on the arguments provided. For example,
the category hashtag data source has to take into account parent categories and
how they relate, and each data source has to define their own icon to use for the
hashtag, and so on.
The `Site` serializer has two new attributes that source data from `HashtagAutocompleteService`.
There is `hashtag_icons` that is just a simple array of all the different icons that
can be used for allowlisting in our markdown pipeline, and there is `hashtag_context_configurations`
that is used to store the type priority orders for each registered context.
When sending emails, we cannot render the SVG icons for hashtags, so
we need to change the HTML hashtags to the normal `#hashtag` text.
**Markdown**
The `hashtag-autocomplete.js` file is where I have added the new `hashtag-autocomplete`
markdown rule, and like all of our rules this is used to cook the raw text on both the clientside
and on the serverside using MiniRacer. Only on the server side do we actually reach out to
the database with the `hashtagLookup` function, on the clientside we just render a plainer
version of the hashtag HTML. Only in the composer preview do we do further lookups based
on this.
This rule is the first one (that I can find) that uses the `currentUser` based on a passed
in `user_id` for guardian checks in markdown rendering code. This is the `last_editor_id`
for both the post and chat message. In some cases we need to cook without a user present,
so the `Discourse.system_user` is used in this case.
**Chat Channels**
This also contains the changes required for chat so that chat channels can be used
as a data source for hashtag searches and lookups. This data source will only be
used when `enable_experimental_hashtag_autocomplete` is `true`, so we don't have
to worry about channel results suddenly turning up.
------
**Known Rough Edges**
- Onebox excerpts will not render the icon svg/use tags, I plan to address that in a follow up PR
- Selecting a hashtag + pressing the Quote button will result in weird behaviour, I plan to address that in a follow up PR
- Mixed hashtag contexts for hashtags without a type suffix will not work correctly, e.g. #ux which is both a category and a channel slug will resolve to a category when used inside a post or within a [chat] transcript in that post. Users can get around this manually by adding the correct suffix, for example ::channel. We may get to this at some point in future
- Icons will not show for the hashtags in emails since SVG support is so terrible in email (this is not likely to be resolved, but still noting for posterity)
- Additional refinements and review fixes wil
2022-11-21 06:37:06 +08:00
|
|
|
chat_system_bootstrap(user, [category_channel, category_channel_2])
|
2022-11-07 16:04:43 +08:00
|
|
|
sign_in(user)
|
2022-11-04 22:06:24 +08:00
|
|
|
end
|
|
|
|
|
2022-11-25 22:12:32 +08:00
|
|
|
context "when clicking chat icon and drawer is viewing channel" do
|
|
|
|
it "navigates to index" do
|
2022-12-23 00:03:27 +08:00
|
|
|
visit("/")
|
|
|
|
|
2022-11-25 22:12:32 +08:00
|
|
|
chat_page.open_from_header
|
|
|
|
chat_drawer_page.open_channel(category_channel_2)
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(page).to have_content(I18n.t("js.chat.direct_messages.title"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when clicking chat icon on mobile and is viewing channel" do
|
DEV: start glimmer-ification and optimisations of chat plugin (#19531)
Note this is a very large PR, and some of it could have been splited, but keeping it one chunk made it to merge conflicts and to revert if necessary. Actual new code logic is also not that much, as most of the changes are removing js tests, adding system specs or moving things around.
To make it possible this commit is doing the following changes:
- converting (and adding new) existing js acceptances tests into system tests. This change was necessary to ensure as little regressions as possible while changing paradigm
- moving away from store. Using glimmer and tracked properties requires to have class objects everywhere and as a result works well with models. However store/adapters are suffering from many bugs and limitations. As a workaround the `chat-api` and `chat-channels-manager` are an answer to this problem by encapsulating backend calls and frontend storage logic; while still using js models.
- dropping `appEvents` as much as possible. Using tracked properties and a better local storage of channel models, allows to be much more reactive and doesn’t require arbitrary manual updates everywhere in the app.
- while working on replacing store, the existing work of a chat api (backend) has been continued to support more cases.
- removing code from the `chat` service to separate concerns, `chat-subscriptions-manager` and `chat-channels-manager`, being the largest examples of where the code has been rewritten/moved.
Future wok:
- improve behavior when closing/deleting a channel, it's already slightly buggy on live, it's rare enough that it's not a big issue, but should be improved
- improve page objects used in chat
- move more endpoints to the API
- finish temporarily skipped tests
- extract more code from the `chat` service
- use glimmer for `chat-messages`
- separate concerns in `chat-live-pane`
- eventually add js tests for `chat-api`, `chat-channels-manager` and `chat-subscriptions-manager`, they are indirectly heavy tested through system tests but it would be nice to at least test the public API
<!-- 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. -->
2022-12-21 20:21:02 +08:00
|
|
|
it "navigates to index", mobile: true do
|
|
|
|
visit("/chat")
|
2022-11-25 22:12:32 +08:00
|
|
|
chat_page.visit_channel(category_channel_2)
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(page).to have_current_path(chat_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when clicking chat icon on desktop and is viewing channel" do
|
|
|
|
it "stays on channel page" do
|
|
|
|
visit("/chat")
|
|
|
|
chat_page.visit_channel(category_channel_2)
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(page).to have_current_path(
|
2023-01-27 20:58:12 +08:00
|
|
|
chat.channel_path(category_channel_2.slug, category_channel_2.id),
|
2022-11-25 22:12:32 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-04 22:06:24 +08:00
|
|
|
context "when visiting /chat" do
|
2022-11-07 16:04:43 +08:00
|
|
|
it "opens full page" do
|
2022-11-11 13:39:15 +08:00
|
|
|
chat_page.open
|
2022-11-04 22:06:24 +08:00
|
|
|
|
|
|
|
expect(page).to have_current_path(
|
2023-01-27 20:58:12 +08:00
|
|
|
chat.channel_path(category_channel.slug, category_channel.id),
|
2022-11-04 22:06:24 +08:00
|
|
|
)
|
|
|
|
expect(page).to have_css("html.has-full-page-chat")
|
|
|
|
expect(page).to have_css(".chat-message-container[data-id='#{message.id}']")
|
|
|
|
end
|
|
|
|
end
|
2022-11-07 16:04:43 +08:00
|
|
|
|
|
|
|
context "when opening chat" do
|
|
|
|
it "opens the drawer by default" do
|
|
|
|
visit("/")
|
2022-11-07 21:48:18 +08:00
|
|
|
chat_page.open_from_header
|
2022-11-07 16:04:43 +08:00
|
|
|
|
2022-11-25 21:15:38 +08:00
|
|
|
expect(page).to have_css(".chat-drawer.is-expanded")
|
2022-11-07 16:04:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when opening chat with full page as preferred mode" do
|
|
|
|
it "opens the full page" do
|
|
|
|
visit("/")
|
2022-11-07 21:48:18 +08:00
|
|
|
chat_page.open_from_header
|
2022-11-11 13:39:15 +08:00
|
|
|
chat_drawer_page.maximize
|
2022-11-07 16:04:43 +08:00
|
|
|
|
|
|
|
expect(page).to have_current_path(
|
2023-01-27 20:58:12 +08:00
|
|
|
chat.channel_path(category_channel.slug, category_channel.id),
|
2022-11-07 16:04:43 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
visit("/")
|
2022-11-07 21:48:18 +08:00
|
|
|
chat_page.open_from_header
|
2022-11-07 16:04:43 +08:00
|
|
|
|
|
|
|
expect(page).to have_current_path(
|
2023-01-27 20:58:12 +08:00
|
|
|
chat.channel_path(category_channel.slug, category_channel.id),
|
2022-11-07 16:04:43 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when opening chat with drawer as preferred mode" do
|
|
|
|
it "opens the full page" do
|
2022-11-11 13:39:15 +08:00
|
|
|
chat_page.open
|
2022-11-07 21:48:18 +08:00
|
|
|
chat_page.minimize_full_page
|
2022-11-07 16:04:43 +08:00
|
|
|
|
2022-11-25 21:15:38 +08:00
|
|
|
expect(page).to have_css(".chat-drawer.is-expanded")
|
2022-11-07 16:04:43 +08:00
|
|
|
|
|
|
|
visit("/")
|
2022-11-07 21:48:18 +08:00
|
|
|
chat_page.open_from_header
|
2022-11-07 16:04:43 +08:00
|
|
|
|
2022-11-25 21:15:38 +08:00
|
|
|
expect(page).to have_css(".chat-drawer.is-expanded")
|
2022-11-07 16:04:43 +08:00
|
|
|
end
|
|
|
|
end
|
2022-11-07 21:48:18 +08:00
|
|
|
|
|
|
|
context "when collapsing full page with no previous state" do
|
|
|
|
it "redirects to home page" do
|
2022-11-11 13:39:15 +08:00
|
|
|
chat_page.open
|
2022-11-07 21:48:18 +08:00
|
|
|
chat_page.minimize_full_page
|
|
|
|
|
2022-11-08 02:31:08 +08:00
|
|
|
expect(page).to have_current_path(latest_path)
|
2022-11-07 21:48:18 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when collapsing full page with previous state" do
|
|
|
|
it "redirects to previous state" do
|
|
|
|
visit("/t/-/#{topic.id}")
|
|
|
|
chat_page.open_from_header
|
2022-11-11 13:39:15 +08:00
|
|
|
chat_drawer_page.maximize
|
2022-11-07 21:48:18 +08:00
|
|
|
chat_page.minimize_full_page
|
|
|
|
|
|
|
|
expect(page).to have_current_path("/t/#{topic.slug}/#{topic.id}")
|
|
|
|
expect(page).to have_css(".chat-message-container[data-id='#{message.id}']")
|
|
|
|
end
|
|
|
|
end
|
2022-11-08 23:23:13 +08:00
|
|
|
|
2022-12-08 09:44:29 +08:00
|
|
|
context "when sidebar is configured as the navigation menu" do
|
DEV: start glimmer-ification and optimisations of chat plugin (#19531)
Note this is a very large PR, and some of it could have been splited, but keeping it one chunk made it to merge conflicts and to revert if necessary. Actual new code logic is also not that much, as most of the changes are removing js tests, adding system specs or moving things around.
To make it possible this commit is doing the following changes:
- converting (and adding new) existing js acceptances tests into system tests. This change was necessary to ensure as little regressions as possible while changing paradigm
- moving away from store. Using glimmer and tracked properties requires to have class objects everywhere and as a result works well with models. However store/adapters are suffering from many bugs and limitations. As a workaround the `chat-api` and `chat-channels-manager` are an answer to this problem by encapsulating backend calls and frontend storage logic; while still using js models.
- dropping `appEvents` as much as possible. Using tracked properties and a better local storage of channel models, allows to be much more reactive and doesn’t require arbitrary manual updates everywhere in the app.
- while working on replacing store, the existing work of a chat api (backend) has been continued to support more cases.
- removing code from the `chat` service to separate concerns, `chat-subscriptions-manager` and `chat-channels-manager`, being the largest examples of where the code has been rewritten/moved.
Future wok:
- improve behavior when closing/deleting a channel, it's already slightly buggy on live, it's rare enough that it's not a big issue, but should be improved
- improve page objects used in chat
- move more endpoints to the API
- finish temporarily skipped tests
- extract more code from the `chat` service
- use glimmer for `chat-messages`
- separate concerns in `chat-live-pane`
- eventually add js tests for `chat-api`, `chat-channels-manager` and `chat-subscriptions-manager`, they are indirectly heavy tested through system tests but it would be nice to at least test the public API
<!-- 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. -->
2022-12-21 20:21:02 +08:00
|
|
|
before { SiteSetting.navigation_menu = "sidebar" }
|
2022-11-08 23:23:13 +08:00
|
|
|
|
|
|
|
context "when opening channel from sidebar with drawer preferred" do
|
|
|
|
it "opens channel in drawer" do
|
|
|
|
visit("/t/-/#{topic.id}")
|
|
|
|
chat_page.open_from_header
|
2022-11-11 13:39:15 +08:00
|
|
|
chat_drawer_page.close
|
2022-11-22 09:24:39 +08:00
|
|
|
find("a[class*='sidebar-section-link-#{category_channel.slug}']").click
|
2022-11-08 23:23:13 +08:00
|
|
|
|
|
|
|
expect(page).to have_css(".chat-message-container[data-id='#{message.id}']")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when opening channel from sidebar with full page preferred" do
|
|
|
|
it "opens channel in full page" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
2022-11-11 13:39:15 +08:00
|
|
|
chat_drawer_page.maximize
|
2022-11-08 23:23:13 +08:00
|
|
|
visit("/")
|
2022-11-22 09:24:39 +08:00
|
|
|
find("a[class*='sidebar-section-link-#{category_channel.slug}']").click
|
2022-11-08 23:23:13 +08:00
|
|
|
|
|
|
|
expect(page).to have_current_path(
|
2023-01-27 20:58:12 +08:00
|
|
|
chat.channel_path(category_channel.slug, category_channel.id),
|
2022-11-08 23:23:13 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2022-11-09 06:58:11 +08:00
|
|
|
|
|
|
|
context "when starting draft from sidebar with drawer preferred" do
|
|
|
|
it "opens draft in drawer" do
|
|
|
|
visit("/")
|
2022-11-11 13:39:15 +08:00
|
|
|
sidebar_page.open_draft_channel
|
2022-11-09 06:58:11 +08:00
|
|
|
|
|
|
|
expect(page).to have_current_path("/")
|
2022-11-25 21:15:38 +08:00
|
|
|
expect(page).to have_css(".chat-drawer.is-expanded .direct-message-creator")
|
2022-11-11 13:39:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when starting draft from drawer with drawer preferred" do
|
|
|
|
it "opens draft in drawer" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
chat_drawer_page.open_draft_channel
|
|
|
|
|
|
|
|
expect(page).to have_current_path("/")
|
2022-11-25 21:15:38 +08:00
|
|
|
expect(page).to have_css(".chat-drawer.is-expanded .direct-message-creator")
|
2022-11-09 06:58:11 +08:00
|
|
|
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
|
2022-11-11 13:39:15 +08:00
|
|
|
chat_drawer_page.maximize
|
2022-11-09 06:58:11 +08:00
|
|
|
visit("/")
|
2022-11-11 13:39:15 +08:00
|
|
|
sidebar_page.open_draft_channel
|
2022-11-09 06:58:11 +08:00
|
|
|
|
|
|
|
expect(page).to have_current_path("/chat/draft-channel")
|
2022-11-25 21:15:38 +08:00
|
|
|
expect(page).not_to have_css(".chat-drawer.is-expanded")
|
2022-11-09 06:58:11 +08:00
|
|
|
end
|
|
|
|
end
|
2022-11-11 13:39:15 +08:00
|
|
|
|
|
|
|
context "when opening browse page from drawer in drawer mode" do
|
|
|
|
it "opens browser page in full page" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
chat_drawer_page.open_browse
|
|
|
|
|
|
|
|
expect(page).to have_current_path("/chat/browse/open")
|
2022-11-25 21:15:38 +08:00
|
|
|
expect(page).not_to have_css(".chat-drawer.is-expanded")
|
2022-11-11 13:39:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when opening browse page from sidebar in drawer mode" do
|
|
|
|
it "opens browser page in full page" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
sidebar_page.open_browse
|
|
|
|
|
|
|
|
expect(page).to have_current_path("/chat/browse/open")
|
2022-11-25 21:15:38 +08:00
|
|
|
expect(page).not_to have_css(".chat-drawer.is-expanded")
|
2022-11-11 13:39:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when re-opening drawer after navigating to a channel" do
|
|
|
|
it "opens drawer on correct channel" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
chat_drawer_page.open_channel(category_channel_2)
|
|
|
|
chat_drawer_page.open_index
|
|
|
|
chat_drawer_page.close
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(page).to have_current_path("/")
|
2022-11-25 21:15:38 +08:00
|
|
|
expect(page).to have_css(".chat-drawer.is-expanded")
|
2022-11-11 13:39:15 +08:00
|
|
|
expect(page).to have_content(category_channel_2.title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when re-opening full page chat after navigating to a channel" do
|
|
|
|
it "opens full page chat on correct channel" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
chat_drawer_page.maximize
|
|
|
|
sidebar_page.open_channel(category_channel_2)
|
|
|
|
find("#site-logo").click
|
|
|
|
chat_page.open_from_header
|
|
|
|
|
|
|
|
expect(page).to have_current_path(
|
2023-01-27 20:58:12 +08:00
|
|
|
chat.channel_path(category_channel_2.slug, category_channel_2.id),
|
2022-11-11 13:39:15 +08:00
|
|
|
)
|
|
|
|
expect(page).to have_content(category_channel_2.title)
|
|
|
|
end
|
|
|
|
end
|
2022-11-12 05:32:06 +08:00
|
|
|
|
|
|
|
context "when opening a channel in full page" do
|
|
|
|
it "activates the channel in the sidebar" do
|
2023-01-27 20:58:12 +08:00
|
|
|
visit("/chat/c/#{category_channel.slug}/#{category_channel.id}")
|
2022-11-12 05:32:06 +08:00
|
|
|
expect(page).to have_css(
|
|
|
|
".sidebar-section-link-#{category_channel.slug}.sidebar-section-link--active",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-06 05:42:35 +08:00
|
|
|
context "when going back to channel from channel settings in full page" do
|
|
|
|
it "activates the channel in the sidebar" do
|
2023-01-27 20:58:12 +08:00
|
|
|
visit("/chat/c/#{category_channel.slug}/#{category_channel.id}/info/settings")
|
2022-12-06 05:42:35 +08:00
|
|
|
find(".chat-full-page-header__back-btn").click
|
|
|
|
expect(page).to have_content(message.message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-12 05:32:06 +08:00
|
|
|
context "when clicking logo from a channel in full page" do
|
|
|
|
it "deactivates the channel in the sidebar" do
|
2023-01-27 20:58:12 +08:00
|
|
|
visit("/chat/c/#{category_channel.slug}/#{category_channel.id}")
|
2022-11-12 05:32:06 +08:00
|
|
|
find("#site-logo").click
|
|
|
|
|
|
|
|
expect(page).not_to have_css(
|
|
|
|
".sidebar-section-link-#{category_channel.slug}.sidebar-section-link--active",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when opening a channel in drawer" do
|
|
|
|
it "activates the channel in the sidebar" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
2022-11-22 09:24:39 +08:00
|
|
|
find("a[class*='#{category_channel.slug}']").click
|
2022-11-12 05:32:06 +08:00
|
|
|
|
|
|
|
expect(page).to have_css(
|
|
|
|
".sidebar-section-link-#{category_channel.slug}.sidebar-section-link--active",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when closing drawer in a channel" do
|
|
|
|
it "deactivates the channel in the sidebar" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
2022-11-22 09:24:39 +08:00
|
|
|
find("a[class*='sidebar-section-link-#{category_channel.slug}']").click
|
2022-11-12 05:32:06 +08:00
|
|
|
chat_drawer_page.close
|
|
|
|
|
|
|
|
expect(page).not_to have_css(
|
|
|
|
".sidebar-section-link-#{category_channel.slug}.sidebar-section-link--active",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2022-11-08 23:23:13 +08:00
|
|
|
end
|
2022-11-04 22:06:24 +08:00
|
|
|
end
|