DEV: Fix or remove flaky chat specs (#22406)

* DEV: Fix flaky thread nav spec

When we transitioned from the chat thread panel under some conditions
the request for the thread would come back and realise the component
was destroyed, which was trying to do a transition to the channel
itself.

Now we check for the previous route here too and transition to the
correct route.

* DEV: Fix chat transcript spec relying on animation

The on-animation-end modifier is not reliable in system specs
because it fires instantly (we have disabled capybara animations)
so the showCopySuccess boolean can be mutated back to false straight
away.

Better to have a separate boolean tracked with a data-attr that we
can reliably inspect in the system spec.
This commit is contained in:
Martin Brennan 2023-07-04 16:23:04 +10:00 committed by GitHub
parent bb0698858f
commit 56aef3c082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 12 deletions

View File

@ -25,6 +25,7 @@ export default class ChatThreadPanel extends Component {
@service chatThreadPaneSubscriptionsManager; @service chatThreadPaneSubscriptionsManager;
@service appEvents; @service appEvents;
@service capabilities; @service capabilities;
@service chatHistory;
@tracked loading; @tracked loading;
@tracked uploadDropZone; @tracked uploadDropZone;
@ -168,7 +169,15 @@ export default class ChatThreadPanel extends Component {
this._selfDeleted || this._selfDeleted ||
this.args.thread.channel.id !== result.meta.channel_id this.args.thread.channel.id !== result.meta.channel_id
) { ) {
this.router.transitionTo("chat.channel", "-", result.meta.channel_id); if (this.chatHistory.previousRoute?.name === "chat.channel.index") {
this.router.transitionTo(
"chat.channel",
"-",
result.meta.channel_id
);
} else {
this.router.transitionTo("chat.channel.threads");
}
} }
const [messages, meta] = this.afterFetchCallback( const [messages, meta] = this.afterFetchCallback(

View File

@ -1,4 +1,7 @@
<div class="chat-selection-management"> <div
class="chat-selection-management"
data-last-copy-successful={{this.lastCopySuccessful}}
>
<div class="chat-selection-management__buttons"> <div class="chat-selection-management__buttons">
<DButton <DButton
@id="chat-quote-btn" @id="chat-quote-btn"

View File

@ -15,7 +15,12 @@ export default class ChatSelectionManager extends Component {
@service site; @service site;
@service("chat-api") api; @service("chat-api") api;
// NOTE: showCopySuccess is used to display the message which animates
// after a delay. The on-animation-end helper is not really usable in
// system specs because it fires straight away, so we use lastCopySuccessful
// with a data attr instead so it's not instantly mutated.
@tracked showCopySuccess = false; @tracked showCopySuccess = false;
@tracked lastCopySuccessful = false;
get enableMove() { get enableMove() {
return this.args.enableMove ?? false; return this.args.enableMove ?? false;
@ -88,6 +93,7 @@ export default class ChatSelectionManager extends Component {
@action @action
async copyMessages() { async copyMessages() {
try { try {
this.lastCopySuccessful = false;
this.showCopySuccess = false; this.showCopySuccess = false;
if (!isTesting()) { if (!isTesting()) {
@ -96,6 +102,7 @@ export default class ChatSelectionManager extends Component {
} }
this.showCopySuccess = true; this.showCopySuccess = true;
this.lastCopySuccessful = true;
} catch (error) { } catch (error) {
popupAjaxError(error); popupAjaxError(error);
} }

View File

@ -18,20 +18,21 @@ export default class ChatThreadHeader extends Component {
@tracked persistedNotificationLevel = true; @tracked persistedNotificationLevel = true;
get backLink() { get backLink() {
let route;
if ( if (
this.chatHistory.previousRoute?.name === "chat.channel.index" && this.chatHistory.previousRoute?.name === "chat.channel.index" &&
this.site.mobileView this.site.mobileView
) { ) {
route = "chat.channel.index";
} else {
route = "chat.channel.threads";
}
return { return {
route: "chat.channel.index", route,
models: this.args.channel.routeModels, models: this.args.channel.routeModels,
}; };
} else {
return {
route: "chat.channel.threads",
models: [],
};
}
} }
get label() { get label() {

View File

@ -20,7 +20,7 @@ RSpec.describe "Quoting chat message transcripts", type: :system do
messages = Array.wrap(messages) messages = Array.wrap(messages)
messages.each { |message| channel_page.messages.select(message) } messages.each { |message| channel_page.messages.select(message) }
channel_page.selection_management.copy channel_page.selection_management.copy
expect(page).to have_selector(".chat-selection-management__copy-success") expect(page).to have_css(".chat-selection-management[data-last-copy-successful]")
clip_text = cdp.read_clipboard clip_text = cdp.read_clipboard
expect(clip_text.chomp).to eq(generate_transcript(messages, current_user)) expect(clip_text.chomp).to eq(generate_transcript(messages, current_user))
clip_text clip_text
@ -116,7 +116,7 @@ RSpec.describe "Quoting chat message transcripts", type: :system do
channel_page.selection_management.cancel channel_page.selection_management.cancel
channel_page.send_message(clip_text) channel_page.send_message(clip_text)
expect(page).to have_selector(".chat-message", count: 2) expect(page).to have_css(".chat-message", count: 2)
expect(page).to have_css(".chat-transcript") expect(page).to have_css(".chat-transcript")
end end
end end