DEV: more reliable thread level spec (#22173)

Rely on frontend state instead of checking backend state.
This commit is contained in:
Joffrey JAFFEUX 2023-06-17 14:28:22 +02:00 committed by GitHub
parent afa6c0a9a4
commit 7e1d015657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 5 deletions

View File

@ -16,7 +16,12 @@
{{replace-emoji this.label}} {{replace-emoji this.label}}
</span> </span>
<div class="chat-thread-header__buttons"> <div
class={{concat-class
"chat-thread-header__buttons"
(if this.persistedNotificationLevel "-persisted")
}}
>
<ThreadNotificationsButton <ThreadNotificationsButton
@value={{this.threadNotificationLevel}} @value={{this.threadNotificationLevel}}
@onChange={{this.updateThreadNotificationLevel}} @onChange={{this.updateThreadNotificationLevel}}

View File

@ -5,12 +5,15 @@ import showModal from "discourse/lib/show-modal";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
import { action } from "@ember/object"; import { action } from "@ember/object";
import UserChatThreadMembership from "discourse/plugins/chat/discourse/models/user-chat-thread-membership"; import UserChatThreadMembership from "discourse/plugins/chat/discourse/models/user-chat-thread-membership";
import { tracked } from "@glimmer/tracking";
export default class ChatThreadHeader extends Component { export default class ChatThreadHeader extends Component {
@service currentUser; @service currentUser;
@service chatApi; @service chatApi;
@service router; @service router;
@tracked persistedNotificationLevel = true;
get label() { get label() {
return this.args.thread.escapedTitle; return this.args.thread.escapedTitle;
} }
@ -42,6 +45,8 @@ export default class ChatThreadHeader extends Component {
@action @action
updateThreadNotificationLevel(newNotificationLevel) { updateThreadNotificationLevel(newNotificationLevel) {
this.persistedNotificationLevel = false;
let currentNotificationLevel; let currentNotificationLevel;
if (this.membership) { if (this.membership) {
@ -63,6 +68,8 @@ export default class ChatThreadHeader extends Component {
.then((response) => { .then((response) => {
this.membership.last_read_message_id = this.membership.last_read_message_id =
response.membership.last_read_message_id; response.membership.last_read_message_id;
this.persistedNotificationLevel = true;
}) })
.catch((err) => { .catch((err) => {
this.membership.notificationLevel = currentNotificationLevel; this.membership.notificationLevel = currentNotificationLevel;

View File

@ -35,6 +35,16 @@ module PageObjects
) )
end end
def has_notification_level?(level)
select_kit =
PageObjects::Components::SelectKit.new(
".chat-thread-header__buttons.-persisted .thread-notifications-button",
)
select_kit.has_selected_value?(
::Chat::UserChatThreadMembership.notification_levels[level.to_sym],
)
end
def selection_management def selection_management
@selection_management ||= @selection_management ||=
PageObjects::Components::Chat::SelectionManagement.new(".chat-channel") PageObjects::Components::Chat::SelectionManagement.new(".chat-channel")

View File

@ -64,8 +64,8 @@ RSpec.describe "Reply to message - channel - mobile", type: :system, mobile: tru
channel_page.reply_to(original_message) channel_page.reply_to(original_message)
thread_page.send_message("reply to message") thread_page.send_message("reply to message")
expect(thread_page).to have_message(text: message_1.message) expect(thread_page.messages).to have_message(text: message_1.message)
expect(thread_page).to have_message(text: "reply to message") expect(thread_page.messages).to have_message(text: "reply to message")
thread_page.close thread_page.close

View File

@ -66,7 +66,7 @@ describe "Thread tracking state | full page", type: :system do
it "allows the user to change their tracking level for an existing thread" do it "allows the user to change their tracking level for an existing thread" do
chat_page.visit_thread(thread) chat_page.visit_thread(thread)
thread_page.notification_level = :normal thread_page.notification_level = :normal
expect(thread.reload.membership_for(current_user).notification_level).to eq("normal") expect(thread_page).to have_notification_level("normal")
end end
it "allows the user to start tracking a thread they have not replied to" do it "allows the user to start tracking a thread they have not replied to" do
@ -74,7 +74,7 @@ describe "Thread tracking state | full page", type: :system do
Fabricate(:chat_message, chat_channel: channel, thread: new_thread) Fabricate(:chat_message, chat_channel: channel, thread: new_thread)
chat_page.visit_thread(new_thread) chat_page.visit_thread(new_thread)
thread_page.notification_level = :tracking thread_page.notification_level = :tracking
expect(new_thread.reload.membership_for(current_user).notification_level).to eq("tracking") expect(thread_page).to have_notification_level("tracking")
chat_page.visit_channel(channel) chat_page.visit_channel(channel)
channel_page.open_thread_list channel_page.open_thread_list
expect(thread_list_page).to have_thread(new_thread) expect(thread_list_page).to have_thread(new_thread)