This commit is contained in:
@@ -13,6 +13,8 @@ type NotificationRecord = {
|
||||
recipient?: { full_name: string };
|
||||
};
|
||||
|
||||
const notificationHistoryPattern = /\/api\/proxy\/notifications(?:\?|$)/;
|
||||
|
||||
const makeNotification = (
|
||||
overrides: Partial<NotificationRecord> = {},
|
||||
): NotificationRecord => ({
|
||||
@@ -46,11 +48,18 @@ const historyResponse = (
|
||||
},
|
||||
});
|
||||
|
||||
const stubHeaderNotifications = () => {
|
||||
cy.intercept("GET", "**/api/proxy/notifications/my**", {
|
||||
statusCode: 200,
|
||||
body: historyResponse([]),
|
||||
}).as("myNotifications");
|
||||
const stubHeaderNotifications = (times = 1) => {
|
||||
cy.intercept(
|
||||
{
|
||||
method: "GET",
|
||||
url: "**/api/proxy/notifications/my**",
|
||||
times,
|
||||
},
|
||||
{
|
||||
statusCode: 200,
|
||||
body: historyResponse([]),
|
||||
},
|
||||
).as("myNotifications");
|
||||
};
|
||||
|
||||
describe("notification history", () => {
|
||||
@@ -62,7 +71,7 @@ describe("notification history", () => {
|
||||
it("renders breadcrumbs, actions, columns, API rows, and details navigation", () => {
|
||||
const notification = makeNotification();
|
||||
|
||||
cy.intercept("GET", /\/api\/proxy\/notifications(?:\?|$)/, (req) => {
|
||||
cy.intercept("GET", notificationHistoryPattern, (req) => {
|
||||
expect(req.query).to.include({
|
||||
sort_by: "created_at",
|
||||
sort_order: "desc",
|
||||
@@ -100,7 +109,7 @@ describe("notification history", () => {
|
||||
"status",
|
||||
"actions",
|
||||
].forEach((column) => {
|
||||
cy.contains("th", new RegExp(`^${column}$`, "i")).should("be.visible");
|
||||
cy.contains("th", new RegExp(`^${column}$`, "i")).should("exist");
|
||||
});
|
||||
|
||||
cy.contains("tr", notification.title)
|
||||
@@ -130,7 +139,7 @@ describe("notification history", () => {
|
||||
seen: true,
|
||||
});
|
||||
|
||||
cy.intercept("GET", /\/api\/proxy\/notifications(?:\?|$)/, (req) => {
|
||||
cy.intercept("GET", notificationHistoryPattern, (req) => {
|
||||
const isFiltered =
|
||||
req.query.seen === "true" && req.query.search === "urgent";
|
||||
req.alias = isFiltered ? "filteredNotifications" : "defaultNotifications";
|
||||
@@ -165,8 +174,114 @@ describe("notification history", () => {
|
||||
cy.contains(defaultNotification.title).should("be.visible");
|
||||
});
|
||||
|
||||
it("filters notification history by user when a user is selected", () => {
|
||||
const currentUserNotification = makeNotification({
|
||||
id: "notification-current-user",
|
||||
title: "Current user notification",
|
||||
});
|
||||
const selectedUserNotification = makeNotification({
|
||||
id: "notification-selected-user",
|
||||
title: "Selected user notification",
|
||||
recipient: { full_name: "Notification Admin" },
|
||||
});
|
||||
|
||||
cy.intercept("GET", notificationHistoryPattern, {
|
||||
statusCode: 200,
|
||||
body: historyResponse([currentUserNotification]),
|
||||
}).as("currentUserNotifications");
|
||||
|
||||
cy.intercept("GET", "**/api/proxy/users**", {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
success: true,
|
||||
message: "ok",
|
||||
data: {
|
||||
users: [
|
||||
{
|
||||
id: "64f9b24d2f1b2f0012345678",
|
||||
full_name: "Notification Admin",
|
||||
username: "notification-admin",
|
||||
email: "notification-admin@example.com",
|
||||
role: "admin",
|
||||
status: "active",
|
||||
},
|
||||
],
|
||||
},
|
||||
meta: {
|
||||
offset: 0,
|
||||
limit: 20,
|
||||
total: 1,
|
||||
page: 1,
|
||||
pages: 1,
|
||||
has_more: false,
|
||||
},
|
||||
},
|
||||
}).as("users");
|
||||
|
||||
cy.intercept("GET", notificationHistoryPattern, (req) => {
|
||||
expect(req.query.user_id).to.eq("64f9b24d2f1b2f0012345678");
|
||||
req.reply({
|
||||
statusCode: 200,
|
||||
body: historyResponse([selectedUserNotification]),
|
||||
});
|
||||
}).as("selectedUserNotifications");
|
||||
|
||||
cy.visit("/notification-history");
|
||||
cy.wait("@currentUserNotifications");
|
||||
cy.contains(currentUserNotification.title).should("be.visible");
|
||||
|
||||
cy.getByCy("notification-history-filter-panel-toggle").click();
|
||||
cy.getByCy("notification-history-filter-user-select")
|
||||
.siblings("button")
|
||||
.click();
|
||||
cy.getByCy("notification-history-filter-user-select-search").type(
|
||||
"Notification Admin",
|
||||
);
|
||||
cy.wait("@users");
|
||||
cy.getByCy("notification-history-filter-user-select-option")
|
||||
.filter('[data-value="64f9b24d2f1b2f0012345678"]')
|
||||
.click();
|
||||
cy.getByCy("notification-history-filter-submit-button").click();
|
||||
|
||||
cy.wait("@selectedUserNotifications");
|
||||
cy.location("search").should(
|
||||
"include",
|
||||
"user_id=64f9b24d2f1b2f0012345678",
|
||||
);
|
||||
cy.contains(selectedUserNotification.title).should("be.visible");
|
||||
cy.contains(currentUserNotification.title).should("not.exist");
|
||||
});
|
||||
|
||||
it("shows the current user filter when notification history is opened for the current user", () => {
|
||||
const notification = makeNotification({
|
||||
id: "notification-current-user-filter",
|
||||
title: "Current user filtered notification",
|
||||
});
|
||||
|
||||
cy.intercept("GET", notificationHistoryPattern, (req) => {
|
||||
expect(req.query.user_id).to.eq("507f1f77bcf86cd799439011");
|
||||
req.reply({
|
||||
statusCode: 200,
|
||||
body: historyResponse([notification]),
|
||||
});
|
||||
}).as("currentUserFilteredNotifications");
|
||||
|
||||
cy.visit("/notification-history?user_id=507f1f77bcf86cd799439011");
|
||||
cy.wait("@currentUserFilteredNotifications");
|
||||
|
||||
cy.getByCy("notification-history-filter-panel-toggle").should(
|
||||
"contain.text",
|
||||
"1 active",
|
||||
);
|
||||
cy.getByCy("notification-history-filter-panel-toggle").click();
|
||||
cy.getByCy("notification-history-filter-user-select")
|
||||
.siblings("button")
|
||||
.should("contain.text", "E2E Admin One");
|
||||
cy.contains(notification.title).should("be.visible");
|
||||
});
|
||||
|
||||
it("shows loading and empty states, and opens the create page", () => {
|
||||
cy.intercept("GET", /\/api\/proxy\/notifications(?:\?|$)/, (req) => {
|
||||
cy.intercept("GET", notificationHistoryPattern, (req) => {
|
||||
req.reply({
|
||||
delay: 900,
|
||||
statusCode: 200,
|
||||
|
||||
Reference in New Issue
Block a user