DEV: Plugin-api methods for user-notifications route customizations (#24873)

This commit is contained in:
Mark VanLandingham
2023-12-13 15:15:42 -06:00
committed by GitHub
parent f7aefffea7
commit c051bfc2fc
9 changed files with 96 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
describe "User notifications", type: :system do
fab!(:user)
let(:user_notifications_page) { PageObjects::Pages::UserNotifications.new }
let(:user_page) { PageObjects::Pages::User.new }
fab!(:read_notification) { Fabricate(:notification, user: user, read: true) }
fab!(:unread_notification) { Fabricate(:notification, user: user, read: false) }
@@ -10,7 +11,7 @@ describe "User notifications", type: :system do
before { sign_in(user) }
describe "filtering" do
it "saves custom picture and system assigned pictures" do
it "correctly filters all / read / unread notifications" do
user_notifications_page.visit(user)
user_notifications_page.filter_dropdown
expect(user_notifications_page).to have_selected_filter_value("all")
@@ -28,4 +29,26 @@ describe "User notifications", type: :system do
expect(user_notifications_page).to have_notification(unread_notification)
end
end
describe "setNotificationLimit & addBeforeLoadMoreNotificationsCallback plugin-api functions" do
it "Allows blocking loading via callback and limit" do
user_page.visit(user)
page.execute_script <<~JS
require("discourse/lib/plugin-api").withPluginApi("1.19.0", (api) => {
api.setNotificationsLimit(1);
api.addBeforeLoadMoreNotificationsCallback(() => {
return false;
})
})
JS
user_page.click_primary_navigation_item("notifications")
# It is 1 here because we blocked infinite scrolling. Even though the limit is 1,
# without the callback, we would have 2 items here as it immediately fires another request.
expect(user_notifications_page).to have_notification_count_of(1)
end
end
end