Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
import { service } from "@ember/service";
Expand All @@ -12,6 +13,7 @@ export default class CustomHeaderTopicButton extends Component {
@service currentUser;
@service router;

@tracked
topic = this.router.currentRouteName.includes("topic")
? getOwner(this).lookup("controller:topic")
: null;
Expand Down
9 changes: 9 additions & 0 deletions spec/system/header_new_topic_button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
fab!(:user) { Fabricate(:user, trust_level: TrustLevel[1]) }
fab!(:category)
fab!(:category2, :category)
fab!(:topic) { Fabricate(:topic, category: category) }
fab!(:post) { Fabricate(:post, user:, topic:) }

context "with logged in user" do
before { sign_in(user) }
Expand All @@ -23,6 +25,13 @@
expect(page).to have_css(".category-input [data-category-id='#{category2.id}']")
end

it "should open the composer to the correct category when the header button is clicked from a topic page" do
visit(topic.url)
find("#new-create-topic").click

expect(page).to have_css(".category-input [data-category-id='#{category.id}']")
end

context "when new_topic_button_text is empty" do
before do
theme.update_setting(:new_topic_button_text, "")
Expand Down