FIX: correctly untrack topics when dismiss unread (#23894)

Bug introduced when dismiss modal was moved to new component-based API - https://github.com/discourse/discourse/pull/22262

We need to track `dismissTopics` property to send correct request to  server.

Meta: https://meta.discourse.org/t/dismiss-all-unread/280948
This commit is contained in:
Krzysztof Kotlarek 2023-10-11 13:51:43 +11:00 committed by GitHub
parent abb8a0730e
commit b061631c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 1 deletions

View File

@ -8,6 +8,7 @@
<PreferenceCheckbox <PreferenceCheckbox
@labelKey="topics.bulk.also_dismiss_topics" @labelKey="topics.bulk.also_dismiss_topics"
@checked={{this.dismissTopics}} @checked={{this.dismissTopics}}
class="dismiss-read-modal__stop-tracking"
/> />
</p> </p>
</:body> </:body>

View File

@ -0,0 +1,6 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
export default class DismissRead extends Component {
@tracked dismissTopics = false;
}

View File

@ -6,6 +6,7 @@ RSpec.describe "Dismissing New", type: :system do
let(:topic_list_controls) { PageObjects::Components::TopicListControls.new } let(:topic_list_controls) { PageObjects::Components::TopicListControls.new }
let(:topic_list) { PageObjects::Components::TopicList.new } let(:topic_list) { PageObjects::Components::TopicList.new }
let(:dismiss_new_modal) { PageObjects::Modals::DismissNew.new } let(:dismiss_new_modal) { PageObjects::Modals::DismissNew.new }
let(:topic_view) { PageObjects::Components::TopicView.new }
describe "when a user has an unread post" do describe "when a user has an unread post" do
fab!(:topic) { Fabricate(:topic, user: user) } fab!(:topic) { Fabricate(:topic, user: user) }
@ -33,6 +34,24 @@ RSpec.describe "Dismissing New", type: :system do
using_session(:tab_1) { expect(topic_list_controls).to have_unread(count: 0) } using_session(:tab_1) { expect(topic_list_controls).to have_unread(count: 0) }
end end
it "should untrack topics across sessions after the user dismisses it" do
sign_in(user)
visit("/unread")
using_session(:tab_1) do
sign_in(user)
visit("/t/#{topic.id}")
expect(topic_view).to have_tracking_status("tracking")
end
topic_list_controls.dismiss_unread(untrack: true)
using_session(:tab_1) { expect(topic_view).to have_tracking_status("regular") }
end
end end
describe "when a user has a new topic" do describe "when a user has a new topic" do

View File

@ -25,8 +25,9 @@ module PageObjects
has_css?(".nav-item_unread", text: text) has_css?(".nav-item_unread", text: text)
end end
def dismiss_unread def dismiss_unread(untrack: false)
click_button("dismiss-topics-bottom") click_button("dismiss-topics-bottom")
find(".dismiss-read-modal__stop-tracking").click if untrack
click_button("dismiss-read-confirm") click_button("dismiss-read-confirm")
self self
end end

View File

@ -10,6 +10,14 @@ module PageObjects
wait: Capybara.default_max_wait_time * 2, wait: Capybara.default_max_wait_time * 2,
) )
end end
def has_tracking_status?(name)
select_kit =
PageObjects::Components::SelectKit.new(
"#topic-footer-buttons .topic-notifications-options",
)
expect(select_kit).to have_selected_name(name)
end
end end
end end
end end