FIX: Can't dismiss new topics for experimental new new view (#22484)

Regressed in 8b80132f88 due to a lack of
tests.
This commit is contained in:
Alan Guo Xiang Tan 2023-07-07 08:28:27 +08:00 committed by GitHub
parent 7ffe0997d7
commit bf582290ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 17 deletions

View File

@ -6,17 +6,17 @@
<p>
<PreferenceCheckbox
@labelKey="topics.bulk.dismiss_new_modal.topics"
@checked={{@model.dismissTopics}}
@checked={{this.dismissTopics}}
@class="dismiss-topics"
/>
<PreferenceCheckbox
@labelKey="topics.bulk.dismiss_new_modal.posts"
@checked={{@model.dismissPosts}}
@checked={{this.dismissPosts}}
@class="dismiss-posts"
/>
<PreferenceCheckbox
@labelKey="topics.bulk.dismiss_new_modal.untrack"
@checked={{@model.untrack}}
@checked={{this.untrack}}
@class="untrack"
/>
</p>

View File

@ -2,9 +2,18 @@ import Component from "@glimmer/component";
import { action } from "@ember/object";
export default class DismissNew extends Component {
dismissTopics = true;
dismissPosts = true;
untrack = false;
@action
dismissed() {
this.args.model.dismissCallback();
this.args.model.dismissCallback({
dismissTopics: this.dismissTopics,
dismissPosts: this.dismissPosts,
untrack: this.untrack,
});
this.args.closeModal();
}
}

View File

@ -1,28 +1,23 @@
import Mixin from "@ember/object/mixin";
import User from "discourse/models/user";
import { inject as service } from "@ember/service";
import { action } from "@ember/object";
import DismissNewModal from "discourse/components/modal/dismiss-new";
export default Mixin.create({
modal: service(),
currentUser: service(),
@action
resetNew() {
const user = User.current();
if (!user.new_new_view_enabled) {
if (!this.currentUser.new_new_view_enabled) {
return this.callResetNew();
}
this.modal.show(DismissNewModal, {
model: {
dismissTopics: true,
dismissPosts: true,
dismissCallback: () =>
this.callResetNew(
this.model.dismissPosts,
this.model.dismissTopics,
this.model.untrack
),
dismissCallback: ({ dismissPosts, dismissTopics, untrack }) => {
this.callResetNew(dismissPosts, dismissTopics, untrack);
},
},
});
},

View File

@ -2,11 +2,12 @@
describe "Filtering topics", type: :system, js: true do
fab!(:user) { Fabricate(:user) }
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:dismiss_new_modal) { PageObjects::Modals::DismissNew.new }
fab!(:group) { Fabricate(:group).tap { |g| g.add(user) } }
fab!(:topic) { Fabricate(:topic) }
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:dismiss_new_modal) { PageObjects::Modals::DismissNew.new }
before { SiteSetting.experimental_new_new_view_groups = group.id }
it "displays confirmation modal with preselected options" do
@ -15,9 +16,15 @@ describe "Filtering topics", type: :system, js: true do
visit("/new")
expect(topic_list).to have_topic(topic)
find(".dismiss-read", text: "Dismiss…").click
expect(dismiss_new_modal).to have_dismiss_topics_checked
expect(dismiss_new_modal).to have_dismiss_posts_checked
expect(dismiss_new_modal).to have_untrack_unchecked
dismiss_new_modal.click_dismiss
expect(topic_list).to have_no_topics
end
end

View File

@ -14,6 +14,10 @@ module PageObjects
page.has_css?(TOPIC_LIST_ITEM_SELECTOR, count: count)
end
def has_no_topics?
page.has_no_css?(TOPIC_LIST_ITEM_SELECTOR)
end
def has_topic?(topic)
page.has_css?(topic_list_item_class(topic))
end

View File

@ -14,6 +14,11 @@ module PageObjects
def has_untrack_unchecked?
find(".untrack label").has_no_checked_field?
end
def click_dismiss
click_button("dismiss-read-confirm")
self
end
end
end
end