A platform for community discussion. Free, open, simple.
UX: Fix tag revert rename 404 error (#31049)
Martin Brennan092a892a4866
diff --git a/app/assets/javascripts/discourse/app/routes/tag-show.js b/app/assets/javascripts/discourse/app/routes/tag-show.jsindex 846e1de7a2b..deb27a3b210 100644--- a/app/assets/javascripts/discourse/app/routes/tag-show.js+++ b/app/assets/javascripts/discourse/app/routes/tag-show.js@@ -42,10 +42,17 @@ export default class TagShowRoute extends DiscourseRoute {}async model(params, transition) {+ const tagIdFromParams = escapeExpression(params.tag_id);const tag = this.store.createRecord("tag", {- id: escapeExpression(params.tag_id),+ id: tagIdFromParams,});+ // Handles renaming a tag, since we refer to the tag.id instead+ // of tag.name which is the actual identifier.+ if (tag.id !== tagIdFromParams) {+ tag.set("id", tagIdFromParams);+ }+let additionalTags;if (params.additional_tags) {diff --git a/spec/system/page_objects/pages/tag.rb b/spec/system/page_objects/pages/tag.rbindex bee70f6b182..ea98be1a48c 100644--- a/spec/system/page_objects/pages/tag.rb+++ b/spec/system/page_objects/pages/tag.rb@@ -24,6 +24,26 @@ module PageObjectsfind(".dialog-footer .btn-primary")end+ def open_edit_tag+ find(".tag-name-wrapper .edit-tag").click+ end++ def fill_tag_name(new_name)+ find("#edit-name").fill_in(with: new_name)+ end++ def fill_tag_description(new_description)+ find("#edit-description").fill_in(with: new_description)+ end++ def save_edit+ find(".edit-controls .submit-edit").click+ end++ def cancel_edit+ find(".edit-controls .cancel-edit").click+ end+def add_synonyms_dropdownPageObjects::Components::SelectKit.new("#add-synonyms")end@@ -46,8 +66,16 @@ module PageObjectsfind(".tag-box div[data-tag-name='#{tag}']")end+ def tag_info+ find(".tag-info")+ end+def tag_name_within_tag_info- find(".tag-info .tag-name-wrapper .discourse-tag").text+ tag_info.find(".tag-name-wrapper .discourse-tag").text+ end++ def tag_description_within_tag_info+ tag_info.find(".tag-description-wrapper").textenddef tags_dropdowndiff --git a/spec/system/tag_edit_spec.rb b/spec/system/tag_edit_spec.rbnew file mode 100644index 00000000000..c7165c743ed--- /dev/null+++ b/spec/system/tag_edit_spec.rb@@ -0,0 +1,33 @@+# frozen_string_literal: true++describe "Tag Edit", type: :system do+ let(:tags_page) { PageObjects::Pages::Tag.new }+ fab!(:tag_1) { Fabricate(:tag, name: "design") }+ fab!(:current_user) { Fabricate(:admin) }++ before { sign_in(current_user) }++ it "allows the admin to edit a tag name and description" do+ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click+ tags_page.open_edit_tag+ tags_page.fill_tag_name("ux")+ tags_page.fill_tag_description("new description")+ tags_page.save_edit+ expect(tags_page.tag_info).to have_content("ux")+ expect(tags_page.tag_info).to have_content("new description")+ end++ it "does not error when editing a tag name to something then reverting back to the original name" do+ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click+ tags_page.open_edit_tag+ tags_page.fill_tag_name("ux")+ tags_page.save_edit+ expect(tags_page.tag_info).to have_content("ux")+ tags_page.open_edit_tag+ tags_page.fill_tag_name("design")+ tags_page.save_edit+ expect(tags_page.tag_info).to have_content("design")+ end+end