Skip to content

A platform for community discussion. Free, open, simple.

FIX: flaky flags system spec (#29039)

Krzysztof Kotlarek4ea3d6997981
diff --git a/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs b/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs
index 1bb8ea51716..ea22786fd10 100644
--- a/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs
+++ b/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs
@@ -100,16 +100,20 @@ export default class AdminFlagItem extends Component {
message: i18n("admin.config_areas.flags.delete_confirm", {
name: this.args.flag.name,
}),
- didConfirm: () => {
- this.args.deleteFlagCallback(this.args.flag).finally(() => {
+ didConfirm: async () => {
+ try {
+ await this.args.deleteFlagCallback(this.args.flag);
this.isSaved = true;
- });
+ this.dMenu.close();
+ } catch (error) {
+ popupAjaxError(error);
+ }
},
didCancel: () => {
this.isSaved = true;
+ this.dMenu.close();
},
});
- this.dMenu.close();
}
<template>
diff --git a/app/models/post_action_type.rb b/app/models/post_action_type.rb
index b85129ce8f4..0cc352bdc02 100644
--- a/app/models/post_action_type.rb
+++ b/app/models/post_action_type.rb
@@ -17,14 +17,12 @@ class PostActionType < ActiveRecord::Base
*I18n.available_locales.map do |locale|
Discourse.cache.normalize_key("post_action_types_#{locale}")
end,
- )
- Discourse.cache.redis.del(
*I18n.available_locales.map do |locale|
Discourse.cache.normalize_key("post_action_flag_types_#{locale}")
end,
+ Discourse.cache.normalize_key(POST_ACTION_TYPE_ALL_FLAGS_KEY),
+ Discourse.cache.normalize_key(POST_ACTION_TYPE_PUBLIC_TYPE_IDS_KEY),
)
- Discourse.cache.delete(POST_ACTION_TYPE_ALL_FLAGS_KEY)
- Discourse.cache.delete(POST_ACTION_TYPE_PUBLIC_TYPE_IDS_KEY)
end
class << self
diff --git a/spec/system/admin_flags_spec.rb b/spec/system/admin_flags_spec.rb
index 2f77e198f91..9eee23110d9 100644
--- a/spec/system/admin_flags_spec.rb
+++ b/spec/system/admin_flags_spec.rb
@@ -15,7 +15,7 @@ describe "Admin Flags Page", type: :system do
SiteSetting.custom_flags_limit = 1
end
- xit "allows admin to disable, change order, create, update and delete flags" do
+ it "allows admin to disable, change order, create, update and delete flags" do
# disable
topic_page.visit_topic(post.topic).open_flag_topic_modal
@@ -146,9 +146,34 @@ describe "Admin Flags Page", type: :system do
"It's Illegal",
"Something Else",
)
+ end
+
+ it "has settings tab" do
+ admin_flags_page.visit
+
+ expect(admin_header).to have_tabs(
+ [I18n.t("admin_js.settings"), I18n.t("admin_js.admin.config_areas.flags.flags_tab")],
+ )
+
+ admin_flags_page.click_settings_tab
+ expect(page.all(".setting-label h3").map(&:text)).to eq(
+ [
+ "silence new user sensitivity",
+ "num users to silence new user",
+ "flag sockpuppets",
+ "num flaggers to close topic",
+ "auto respond to flag actions",
+ "high trust flaggers auto hide posts",
+ "max flags per day",
+ "tl2 additional flags per day multiplier",
+ "tl3 additional flags per day multiplier",
+ "tl4 additional flags per day multiplier",
+ ],
+ )
+ end
- # custom flag with same name as system flag
- admin_flags_page.visit.toggle("inappropriate")
+ it "allows to create custom flag with same name as system flag" do
+ admin_flags_page.visit
admin_flags_page.click_add_flag
admin_flag_form_page
.fill_in_name("Inappropriate")
@@ -170,40 +195,16 @@ describe "Admin Flags Page", type: :system do
topic_page.visit_topic(post.topic).open_flag_topic_modal
expect(flag_modal).to have_choices(
+ "It's Inappropriate",
"It's Spam",
"It's Illegal",
"Something Else",
"Inappropriate",
)
- Flag.system.where(name: "inappropriate").update!(enabled: true)
admin_flags_page.visit.click_delete_flag("custom_inappropriate").confirm_delete
end
- it "has settings tab" do
- admin_flags_page.visit
-
- expect(admin_header).to have_tabs(
- [I18n.t("admin_js.settings"), I18n.t("admin_js.admin.config_areas.flags.flags_tab")],
- )
-
- admin_flags_page.click_settings_tab
- expect(page.all(".setting-label h3").map(&:text)).to eq(
- [
- "silence new user sensitivity",
- "num users to silence new user",
- "flag sockpuppets",
- "num flaggers to close topic",
- "auto respond to flag actions",
- "high trust flaggers auto hide posts",
- "max flags per day",
- "tl2 additional flags per day multiplier",
- "tl3 additional flags per day multiplier",
- "tl4 additional flags per day multiplier",
- ],
- )
- end
-
it "does not allow to move notify user flag" do
admin_flags_page.visit
expect(admin_flags_page).to have_no_action_for_flag("notify_user")
diff --git a/spec/system/page_objects/pages/admin_flag_form.rb b/spec/system/page_objects/pages/admin_flag_form.rb
index 4b342a109dc..bd24cd2ef80 100644
--- a/spec/system/page_objects/pages/admin_flag_form.rb
+++ b/spec/system/page_objects/pages/admin_flag_form.rb
@@ -23,6 +23,11 @@ module PageObjects
def click_save
form.submit
+ expect(page).to have_no_css(
+ ".admin-config.flags.new",
+ wait: Capybara.default_max_wait_time * 3,
+ )
+ expect(page).to have_css(".admin-flag-item__name", wait: Capybara.default_max_wait_time * 3)
end
def form
diff --git a/spec/system/page_objects/pages/admin_flags.rb b/spec/system/page_objects/pages/admin_flags.rb
index 42807595e75..e01c1ebc599 100644
--- a/spec/system/page_objects/pages/admin_flags.rb
+++ b/spec/system/page_objects/pages/admin_flags.rb
@@ -60,7 +60,7 @@ module PageObjects
end
def has_no_flag?(flag)
- has_no_css?(".admin-flag-item.#{flag}")
+ has_no_css?(".admin-flag-item.#{flag}", wait: Capybara.default_max_wait_time * 3)
end
def has_saved_flag?(key)
@@ -103,6 +103,7 @@ module PageObjects
def confirm_delete
find(".dialog-footer .btn-primary").click
+ expect(page).to have_no_css(".dialog-body", wait: Capybara.default_max_wait_time * 3)
self
end