DEV: flaky reorder flags specs (#27684)

Before checking if flags were reordered on the topic page, we need to ensure that the reorder action was finished. To achieve it "saving" CSS is added and removed when AJAX call is completed.
This commit is contained in:
Krzysztof Kotlarek 2024-07-03 12:02:18 +10:00 committed by GitHub
parent 13c297e4ff
commit 4157161578
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import { not } from "truth-helpers";
import DButton from "discourse/components/d-button";
import DToggleSwitch from "discourse/components/d-toggle-switch";
import DropdownMenu from "discourse/components/dropdown-menu";
import concatClass from "discourse/helpers/concat-class";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { SYSTEM_FLAG_IDS } from "discourse/lib/constants";
@ -20,6 +21,7 @@ export default class AdminFlagItem extends Component {
@service router;
@tracked enabled = this.args.flag.enabled;
@tracked isSaving = false;
get canMove() {
return this.args.flag.id !== SYSTEM_FLAG_IDS.notify_user;
@ -47,6 +49,7 @@ export default class AdminFlagItem extends Component {
@action
toggleFlagEnabled(flag) {
this.enabled = !this.enabled;
this.isSaving = true;
return ajax(`/admin/config/flags/${flag.id}/toggle`, {
type: "PUT",
@ -57,6 +60,9 @@ export default class AdminFlagItem extends Component {
.catch((error) => {
this.enabled = !this.enabled;
return popupAjaxError(error);
})
.finally(() => {
this.isSaving = false;
});
}
@ -67,14 +73,20 @@ export default class AdminFlagItem extends Component {
@action
moveUp() {
this.args.moveFlagCallback(this.args.flag, "up");
this.isSaving = true;
this.dMenu.close();
this.args.moveFlagCallback(this.args.flag, "up").finally(() => {
this.isSaving = false;
});
}
@action
moveDown() {
this.args.moveFlagCallback(this.args.flag, "down");
this.isSaving = true;
this.dMenu.close();
this.args.moveFlagCallback(this.args.flag, "down").finally(() => {
this.isSaving = false;
});
}
@action
edit() {
@ -83,19 +95,31 @@ export default class AdminFlagItem extends Component {
@action
delete() {
this.isSaving = true;
this.dialog.yesNoConfirm({
message: i18n("admin.config_areas.flags.delete_confirm", {
name: this.args.flag.name,
}),
didConfirm: () => {
this.args.deleteFlagCallback(this.args.flag);
this.args.deleteFlagCallback(this.args.flag).finally(() => {
this.isSaving = false;
});
},
didCancel: () => {
this.isSaving = false;
},
});
this.dMenu.close();
}
<template>
<tr class="admin-flag-item {{@flag.name_key}}">
<tr
class={{concatClass
"admin-flag-item"
@flag.name_key
(if this.isSaving "saving")
}}
>
<td>
<p class="admin-flag-item__name">{{@flag.name}}</p>
<p class="admin-flag-item__description">{{htmlSafe

View File

@ -20,6 +20,7 @@ describe "Admin Flags Page", type: :system do
visit "/admin/config/flags"
admin_flags_page.toggle("spam")
expect(page).not_to have_css(".admin-flag-item.spam.saving")
topic_page.visit_topic(post.topic)
topic_page.open_flag_topic_modal
@ -39,6 +40,7 @@ describe "Admin Flags Page", type: :system do
visit "/admin/config/flags"
admin_flags_page.move_down("spam")
expect(page).not_to have_css(".admin-flag-item.spam.saving")
topic_page.visit_topic(post.topic)
topic_page.open_flag_topic_modal
@ -48,6 +50,7 @@ describe "Admin Flags Page", type: :system do
visit "/admin/config/flags"
admin_flags_page.move_up("spam")
expect(page).not_to have_css(".admin-flag-item.spam.saving")
topic_page.visit_topic(post.topic)
topic_page.open_flag_topic_modal
@ -109,6 +112,7 @@ describe "Admin Flags Page", type: :system do
visit "/admin/config/flags"
admin_flags_page.click_delete_flag("tasteless")
admin_flags_page.confirm_delete
expect(page).not_to have_css(".admin-flag-item.tasteless.saving")
topic_page.visit_topic(post.topic)
topic_page.open_flag_topic_modal