From b2ce33be267c8eafe0ea4d510faabbb4828ca18d Mon Sep 17 00:00:00 2001 From: James Kiesel Date: Wed, 22 Aug 2018 23:22:47 -0500 Subject: [PATCH] FIX: tag intersection not populating (#6296) * Fix for tag intersection not populating * Fix prettier * Add acceptance test for tags intersection --- .../discourse/routes/tags-show.js.es6 | 8 ++-- .../acceptance/tags-intersection-test.js.es6 | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 test/javascripts/acceptance/tags-intersection-test.js.es6 diff --git a/app/assets/javascripts/discourse/routes/tags-show.js.es6 b/app/assets/javascripts/discourse/routes/tags-show.js.es6 index 24e2326807c..437f3e4e821 100644 --- a/app/assets/javascripts/discourse/routes/tags-show.js.es6 +++ b/app/assets/javascripts/discourse/routes/tags-show.js.es6 @@ -184,9 +184,11 @@ export default Discourse.Route.extend({ var c = self.controllerFor("composer").get("model"); c.set( "tags", - _.flatten( - [controller.get("model.id")], - controller.get("additionalTags") + _.compact( + _.flatten([ + controller.get("model.id"), + controller.get("additionalTags") + ]) ) ); } diff --git a/test/javascripts/acceptance/tags-intersection-test.js.es6 b/test/javascripts/acceptance/tags-intersection-test.js.es6 new file mode 100644 index 00000000000..85787a68642 --- /dev/null +++ b/test/javascripts/acceptance/tags-intersection-test.js.es6 @@ -0,0 +1,43 @@ +import { acceptance } from "helpers/qunit-helpers"; + +acceptance("Tags intersection", { + loggedIn: true, + site: { can_tag_topics: true }, + settings: { tagging_enabled: true }, + pretend(server, helper) { + server.get("/tags/first/notifications", () => { + return helper.response({ + tag_notification: { id: "first", notification_level: 1 } + }); + }); + server.get("/tags/intersection/first/second.json", () => { + return helper.response({ + users: [], + primary_groups: [], + topic_list: { + can_create_topic: true, + draft_key: "new_topic", + topics: [{ id: 16, posters: [] }], + tags: [ + { id: 1, name: "first", topic_count: 1 }, + { id: 2, name: "second", topic_count: 1 } + ] + } + }); + }); + } +}); + +QUnit.test("Populate tags when creating new topic", async assert => { + await visit("/tags/intersection/first/second"); + await click("#create-topic"); + + assert.ok(exists(".mini-tag-chooser"), "The tag selector appears"); + assert.equal( + $(".mini-tag-chooser") + .text() + .trim(), + "first, second", + "populates the tags when clicking 'New topic'" + ); +});