mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 10:51:36 -04:00
Notifications without a URL are not links
Transcode, job, and Kiwix notifications send no URL, but every user notify toast said "Click here to view the shared page" and opened /null on click. Only a notification carrying a URL is followable now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
87e146487b
commit
e428fdbdc8
2 changed files with 45 additions and 8 deletions
|
|
@ -9,7 +9,7 @@ function eventToast(title, description, type = 'info', time = 5000, onClick = nu
|
|||
toast({type: type, title: title, description: description, time: time, onClick: onClick});
|
||||
}
|
||||
|
||||
function handleEvents(events) {
|
||||
export function handleEvents(events) {
|
||||
const newestEvents = {};
|
||||
|
||||
events.forEach(e => {
|
||||
|
|
@ -63,13 +63,17 @@ function handleEvents(events) {
|
|||
}
|
||||
|
||||
if (event === 'user_notify_message') {
|
||||
console.log(message, url);
|
||||
eventToast(
|
||||
message,
|
||||
'Click here to view the shared page',
|
||||
'info',
|
||||
10_000,
|
||||
() => window.open(url, '_self'));
|
||||
// Only a shared page carries a URL; other notifications (jobs, transcodes) are text.
|
||||
if (url) {
|
||||
eventToast(
|
||||
message,
|
||||
'Click here to view the shared page',
|
||||
'info',
|
||||
10_000,
|
||||
() => window.open(url, '_self'));
|
||||
} else {
|
||||
eventToast(message, null, 'info', 10_000);
|
||||
}
|
||||
}
|
||||
|
||||
if (event === 'deleted') {
|
||||
|
|
|
|||
33
app/src/Events.test.js
Normal file
33
app/src/Events.test.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import {handleEvents} from './Events';
|
||||
import {toast} from './components/ui';
|
||||
|
||||
jest.mock('./components/ui', () => ({toast: jest.fn()}));
|
||||
|
||||
const notify = (url) => ({event: 'user_notify_message', message: 'Transcoding video.mp4', dt: '2026-10-12', url});
|
||||
|
||||
afterEach(() => {
|
||||
toast.mockClear();
|
||||
});
|
||||
|
||||
describe('user_notify_message', () => {
|
||||
it('a notification without a URL is plain text, not a link', () => {
|
||||
handleEvents([notify(null)]);
|
||||
|
||||
expect(toast).toHaveBeenCalledTimes(1);
|
||||
const options = toast.mock.calls[0][0];
|
||||
expect(options.title).toBe('Transcoding video.mp4');
|
||||
expect(options.description).toBeFalsy();
|
||||
expect(options.onClick).toBeFalsy();
|
||||
});
|
||||
|
||||
it('a shared page opens its URL when clicked', () => {
|
||||
const open = jest.spyOn(window, 'open').mockImplementation(() => null);
|
||||
handleEvents([notify('/archive/1')]);
|
||||
|
||||
const options = toast.mock.calls[0][0];
|
||||
expect(options.description).toBe('Click here to view the shared page');
|
||||
options.onClick();
|
||||
expect(open).toHaveBeenCalledWith('/archive/1', '_self');
|
||||
open.mockRestore();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue