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> <p>
<PreferenceCheckbox <PreferenceCheckbox
@labelKey="topics.bulk.dismiss_new_modal.topics" @labelKey="topics.bulk.dismiss_new_modal.topics"
@checked={{@model.dismissTopics}} @checked={{this.dismissTopics}}
@class="dismiss-topics" @class="dismiss-topics"
/> />
<PreferenceCheckbox <PreferenceCheckbox
@labelKey="topics.bulk.dismiss_new_modal.posts" @labelKey="topics.bulk.dismiss_new_modal.posts"
@checked={{@model.dismissPosts}} @checked={{this.dismissPosts}}
@class="dismiss-posts" @class="dismiss-posts"
/> />
<PreferenceCheckbox <PreferenceCheckbox
@labelKey="topics.bulk.dismiss_new_modal.untrack" @labelKey="topics.bulk.dismiss_new_modal.untrack"
@checked={{@model.untrack}} @checked={{this.untrack}}
@class="untrack" @class="untrack"
/> />
</p> </p>

View File

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

View File

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

View File

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

View File

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

View File

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