From a7cd523fafe421b5876bd6a64deffe6169fb33e8 Mon Sep 17 00:00:00 2001 From: Osama Sayegh Date: Fri, 23 Aug 2024 20:08:24 +0300 Subject: [PATCH] FIX: Refresh the edit tag section when navigating to another tag (#28519) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you’re viewing a tag and you switch to a different tag via the sidebar or the tags dropdown, after expanding the info section of the tag page via the wrench button, the info section keeps showing the previous tag's details instead of the new one. This happens because the tag info section makes an ajax request to load the tag's details, and this request is made inside the `didInsertElement` hook which is only fired once when the component is rendered. To fix this, we need to set the result from the ajax request to null and add a `didUpdateAttrs` hook to trigger another request to load the info of the new tag. Internal topic: t/134809. --- .../discourse/app/components/tag-info.js | 6 ++++ .../discourse/tests/acceptance/tags-test.js | 17 ++++++++++ spec/system/page_objects/pages/tag.rb | 8 +++++ spec/system/tag_view_spec.rb | 31 +++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 spec/system/tag_view_spec.rb diff --git a/app/assets/javascripts/discourse/app/components/tag-info.js b/app/assets/javascripts/discourse/app/components/tag-info.js index 92caa939d37..a7fe447c34a 100644 --- a/app/assets/javascripts/discourse/app/components/tag-info.js +++ b/app/assets/javascripts/discourse/app/components/tag-info.js @@ -59,6 +59,12 @@ export default Component.extend({ this.loadTagInfo(); }, + didUpdateAttrs() { + this._super(...arguments); + this.set("tagInfo", null); + this.loadTagInfo(); + }, + loadTagInfo() { if (this.loading) { return; diff --git a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js b/app/assets/javascripts/discourse/tests/acceptance/tags-test.js index bac61702bfd..cb78d15ebba 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/tags-test.js @@ -388,6 +388,23 @@ acceptance("Tag info", function (needs) { }); }); + server.get("/tag/happy-monkey2/info", () => { + return helper.response({ + __rest_serializer: "1", + tag_info: { + id: 13, + name: "happy-monkey2", + description: "happy monkey description", + topic_count: 1, + staff: false, + synonyms: [], + tag_group_names: [], + category_ids: [], + }, + categories: [], + }); + }); + server.delete("/tag/planters/synonyms/containers", () => helper.response({ success: true }) ); diff --git a/spec/system/page_objects/pages/tag.rb b/spec/system/page_objects/pages/tag.rb index 101a8d42e2a..bee70f6b182 100644 --- a/spec/system/page_objects/pages/tag.rb +++ b/spec/system/page_objects/pages/tag.rb @@ -45,6 +45,14 @@ module PageObjects def tag_box(tag) find(".tag-box div[data-tag-name='#{tag}']") end + + def tag_name_within_tag_info + find(".tag-info .tag-name-wrapper .discourse-tag").text + end + + def tags_dropdown + PageObjects::Components::SelectKit.new(".select-kit.tag-drop") + end end end end diff --git a/spec/system/tag_view_spec.rb b/spec/system/tag_view_spec.rb new file mode 100644 index 00000000000..ef64a35518d --- /dev/null +++ b/spec/system/tag_view_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +describe "Tag view", type: :system do + fab!(:tag_1) { Fabricate(:tag, name: "design") } + fab!(:tag_2) { Fabricate(:tag, name: "art") } + fab!(:topic) { Fabricate(:topic, tags: [tag_2]) } + fab!(:current_user) { Fabricate(:admin) } + + let(:tags_page) { PageObjects::Pages::Tag.new } + let(:topic_list) { PageObjects::Components::TopicList.new } + + before { sign_in(current_user) } + + describe "the tag info section" do + context "when navigating to another tag" do + it "shows the details of the new tag" do + tags_page.visit_tag(tag_1) + + tags_page.tag_info_btn.click + expect(tags_page.tag_name_within_tag_info).to eq(tag_1.name) + + tags_page.tags_dropdown.expand + tags_page.tags_dropdown.search(tag_2.name) + tags_page.tags_dropdown.select_row_by_value(tag_2.name) + + expect(topic_list).to have_topic(topic) + expect(tags_page.tag_name_within_tag_info).to eq(tag_2.name) + end + end + end +end