mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Notifications: Don't show toasts after refreshing (#74712)
* user essentials mob! 🔱 lastFile:public/app/core/reducers/appNotification.ts * user essentials mob! 🔱 --------- Co-authored-by: eledobleefe <laura.fernandez@grafana.com> Co-authored-by: Joao Silva <joao.silva@grafana.com> Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com> Co-authored-by: L-M-K-B <48948963+L-M-K-B@users.noreply.github.com>
This commit is contained in:
parent
4f329e9fa6
commit
b84aab5add
@ -178,4 +178,70 @@ describe('notify', () => {
|
||||
|
||||
expect(result).toEqual(expectedResult);
|
||||
});
|
||||
|
||||
it('persists notifications to localStorage', () => {
|
||||
const setItemSpy = jest.spyOn(Storage.prototype, 'setItem');
|
||||
|
||||
const id1 = '696da53b-6ae7-4824-9e0e-d6a3b54a2c74';
|
||||
const id2 = '4477fcd9-246c-45a5-8818-e22a16683dae';
|
||||
|
||||
const initialState: AppNotificationsState = {
|
||||
byId: {
|
||||
[id1]: {
|
||||
id: id1,
|
||||
severity: AppNotificationSeverity.Warning,
|
||||
icon: 'warning',
|
||||
title: 'test',
|
||||
text: 'test alert',
|
||||
showing: false,
|
||||
timestamp,
|
||||
},
|
||||
},
|
||||
lastRead: timestamp - 10,
|
||||
};
|
||||
|
||||
appNotificationsReducer(
|
||||
initialState,
|
||||
notifyApp({
|
||||
id: id2,
|
||||
severity: AppNotificationSeverity.Error,
|
||||
icon: 'error',
|
||||
title: 'test2',
|
||||
text: 'test alert info 2',
|
||||
showing: true,
|
||||
timestamp: 1649802870373,
|
||||
})
|
||||
);
|
||||
|
||||
expect(setItemSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
const [calledKey, calledValue] = setItemSpy.mock.calls[0];
|
||||
const parsedJsonCalledValue = JSON.parse(calledValue);
|
||||
expect(calledKey).toBe('notifications');
|
||||
|
||||
// Assert showing toasts are not still showing after page refresh
|
||||
expect(parsedJsonCalledValue[id1].showing).toBeFalsy(); // old notification that was false anyway
|
||||
expect(parsedJsonCalledValue[id2].showing).toBeFalsy(); // new notification that we store as false
|
||||
|
||||
expect(parsedJsonCalledValue).toEqual({
|
||||
[id1]: {
|
||||
id: id1,
|
||||
severity: AppNotificationSeverity.Warning,
|
||||
icon: 'warning',
|
||||
title: 'test',
|
||||
text: 'test alert',
|
||||
showing: false,
|
||||
timestamp,
|
||||
},
|
||||
[id2]: {
|
||||
id: id2,
|
||||
severity: AppNotificationSeverity.Error,
|
||||
icon: 'error',
|
||||
title: 'test2',
|
||||
text: 'test alert info 2',
|
||||
showing: false,
|
||||
timestamp: 1649802870373,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -109,7 +109,9 @@ function serializeNotifications(notifs: Record<string, StoredNotification>) {
|
||||
text: cur.text,
|
||||
traceId: cur.traceId,
|
||||
timestamp: cur.timestamp,
|
||||
showing: cur.showing,
|
||||
// we don't care about still showing toasts after refreshing
|
||||
// https://github.com/grafana/grafana/issues/71932
|
||||
showing: false,
|
||||
};
|
||||
|
||||
return prev;
|
||||
|
Loading…
Reference in New Issue
Block a user