From bf582290ba0a1bfacea3394a939b2dff0459ad41 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Fri, 7 Jul 2023 08:28:27 +0800 Subject: [PATCH] FIX: Can't dismiss new topics for experimental new new view (#22484) Regressed in 8b80132f8868500571ec1c80bb3e02f1873dbac2 due to a lack of tests. --- .../app/components/modal/dismiss-new.hbs | 6 +++--- .../app/components/modal/dismiss-new.js | 11 ++++++++++- .../discourse/app/mixins/dismiss-topics.js | 17 ++++++----------- spec/system/dismiss_topics_spec.rb | 11 +++++++++-- .../page_objects/components/topic_list.rb | 4 ++++ spec/system/page_objects/modals/dismiss_new.rb | 5 +++++ 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/modal/dismiss-new.hbs b/app/assets/javascripts/discourse/app/components/modal/dismiss-new.hbs index 9e140fefdbd..9563e469f63 100644 --- a/app/assets/javascripts/discourse/app/components/modal/dismiss-new.hbs +++ b/app/assets/javascripts/discourse/app/components/modal/dismiss-new.hbs @@ -6,17 +6,17 @@

diff --git a/app/assets/javascripts/discourse/app/components/modal/dismiss-new.js b/app/assets/javascripts/discourse/app/components/modal/dismiss-new.js index 0e6ae9e63ef..b9a161f53b4 100644 --- a/app/assets/javascripts/discourse/app/components/modal/dismiss-new.js +++ b/app/assets/javascripts/discourse/app/components/modal/dismiss-new.js @@ -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(); } } diff --git a/app/assets/javascripts/discourse/app/mixins/dismiss-topics.js b/app/assets/javascripts/discourse/app/mixins/dismiss-topics.js index 8af27490262..2d99c5c9d61 100644 --- a/app/assets/javascripts/discourse/app/mixins/dismiss-topics.js +++ b/app/assets/javascripts/discourse/app/mixins/dismiss-topics.js @@ -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); + }, }, }); }, diff --git a/spec/system/dismiss_topics_spec.rb b/spec/system/dismiss_topics_spec.rb index 80a3cefc54d..7a966121e1a 100644 --- a/spec/system/dismiss_topics_spec.rb +++ b/spec/system/dismiss_topics_spec.rb @@ -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 diff --git a/spec/system/page_objects/components/topic_list.rb b/spec/system/page_objects/components/topic_list.rb index 844f9a52ea5..69f6d775032 100644 --- a/spec/system/page_objects/components/topic_list.rb +++ b/spec/system/page_objects/components/topic_list.rb @@ -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 diff --git a/spec/system/page_objects/modals/dismiss_new.rb b/spec/system/page_objects/modals/dismiss_new.rb index 52ae68142bd..49a92d60285 100644 --- a/spec/system/page_objects/modals/dismiss_new.rb +++ b/spec/system/page_objects/modals/dismiss_new.rb @@ -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