DEV: adds a has-preloaded-chat-channels body-class (#26394)

This class should help makes tests more reliable by ensuring we are in a known state.
This commit is contained in:
Joffrey JAFFEUX 2024-03-27 10:39:07 +01:00 committed by GitHub
parent 1cc8c72a98
commit 6f694d9d1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 7 deletions

View File

@ -0,0 +1,13 @@
import Component from "@glimmer/component";
import { service } from "@ember/service";
import bodyClass from "discourse/helpers/body-class";
export default class ChatBodyClass extends Component {
@service chatStateManager;
<template>
{{#if this.chatStateManager.hasPreloadedChannels}}
{{bodyClass "has-preloaded-chat-channels"}}
{{/if}}
</template>
}

View File

@ -52,9 +52,9 @@ module PageObjects
drawer?(expectation: false, channel_id: channel_id, expanded: expanded)
end
def visit_channel(channel, message_id: nil)
def visit_channel(channel, message_id: nil, with_preloaded_channels: true)
visit(channel.url + (message_id ? "/#{message_id}" : ""))
has_finished_loading?
has_finished_loading?(with_preloaded_channels: with_preloaded_channels)
end
def visit_user_threads
@ -102,7 +102,12 @@ module PageObjects
visit("/chat/new-message?recipients=#{recipients}")
end
def has_finished_loading?
def has_preloaded_channels?
has_css?("body.has-preloaded-chat-channels")
end
def has_finished_loading?(with_preloaded_channels: true)
has_preloaded_channels? if with_preloaded_channels
has_no_css?(".chat-channel--not-loaded-once")
has_no_css?(".chat-skeleton")
end

View File

@ -24,7 +24,7 @@ RSpec.describe "Visit channel", type: :system do
end
it "shows a not found page" do
chat.visit_channel(category_channel_1)
chat.visit_channel(category_channel_1, with_preloaded_channels: false)
expect(page).to have_content(I18n.t("page_not_found.title"))
end
@ -33,7 +33,7 @@ RSpec.describe "Visit channel", type: :system do
context "when chat enabled" do
context "when anonymous" do
it "redirects to homepage" do
chat.visit_channel(category_channel_1)
chat.visit_channel(category_channel_1, with_preloaded_channels: false)
expect(page).to have_current_path("/latest")
end
@ -46,7 +46,7 @@ RSpec.describe "Visit channel", type: :system do
before { current_user.user_option.update!(chat_enabled: false) }
it "redirects to homepage" do
chat.visit_channel(category_channel_1)
chat.visit_channel(category_channel_1, with_preloaded_channels: false)
expect(page).to have_current_path("/latest")
end
@ -56,7 +56,7 @@ RSpec.describe "Visit channel", type: :system do
before { SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:staff] }
it "redirects homepage" do
chat.visit_channel(category_channel_1)
chat.visit_channel(category_channel_1, with_preloaded_channels: false)
expect(page).to have_current_path("/latest")
end