bigbuffet-rw/app/soapbox/reducers/__tests__/notifications-test.js

655 lines
18 KiB
JavaScript
Raw Normal View History

2020-07-10 16:45:10 -07:00
import * as actions from 'soapbox/actions/notifications';
2020-06-09 18:08:07 -07:00
import reducer from '../notifications';
import notifications from 'soapbox/__fixtures__/notifications.json';
2020-06-09 18:08:07 -07:00
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import { take } from 'lodash';
2020-07-13 19:49:42 -07:00
import { ACCOUNT_BLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS } from 'soapbox/actions/accounts';
2020-07-10 16:45:10 -07:00
import notification from 'soapbox/__fixtures__/notification.json';
2020-07-13 18:00:55 -07:00
import intlMessages from 'soapbox/__fixtures__/intlMessages.json';
2020-07-13 20:04:29 -07:00
import relationship from 'soapbox/__fixtures__/relationship.json';
2020-07-13 19:49:42 -07:00
import { TIMELINE_DELETE, TIMELINE_DISCONNECT } from 'soapbox/actions/timelines';
2020-06-09 18:08:07 -07:00
describe('notifications reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual(ImmutableMap({
items: ImmutableList(),
hasMore: true,
top: false,
unread: 0,
isLoading: false,
queuedNotifications: ImmutableList(),
totalQueuedNotificationsCount: 0,
lastRead: -1,
}));
});
2020-07-10 16:45:10 -07:00
it('should handle NOTIFICATIONS_EXPAND_SUCCESS', () => {
const state = undefined;
const action = {
2020-07-10 16:45:10 -07:00
type: actions.NOTIFICATIONS_EXPAND_SUCCESS,
notifications: take(notifications, 3),
next: null,
skipLoading: true,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([
ImmutableMap({
id: '10744',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
is_seen: false,
}),
ImmutableMap({
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
is_seen: true,
}),
ImmutableMap({
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
is_seen: true,
}),
]),
hasMore: false,
top: false,
unread: 1,
isLoading: false,
queuedNotifications: ImmutableList(),
totalQueuedNotificationsCount: 0,
lastRead: -1,
}));
});
2020-07-10 16:45:10 -07:00
it('should handle NOTIFICATIONS_EXPAND_REQUEST', () => {
const state = ImmutableMap({
isLoading: false,
});
const action = {
type: actions.NOTIFICATIONS_EXPAND_REQUEST,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
isLoading: true,
}));
});
it('should handle NOTIFICATIONS_EXPAND_FAIL', () => {
const state = ImmutableMap({
isLoading: true,
});
const action = {
type: actions.NOTIFICATIONS_EXPAND_FAIL,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
isLoading: false,
}));
});
it('should handle NOTIFICATIONS_FILTER_SET', () => {
const state = ImmutableMap({
items: ImmutableList([
ImmutableMap({
id: '10744',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-10 16:45:10 -07:00
is_seen: false,
}),
ImmutableMap({
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-10 16:45:10 -07:00
is_seen: true,
}),
ImmutableMap({
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-10 16:45:10 -07:00
is_seen: true,
}),
]),
hasMore: false,
top: false,
unread: 1,
isLoading: false,
queuedNotifications: ImmutableList(),
totalQueuedNotificationsCount: 0,
lastRead: -1,
});
const action = {
type: actions.NOTIFICATIONS_FILTER_SET,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList(),
hasMore: true,
top: false,
unread: 1,
isLoading: false,
queuedNotifications: ImmutableList(),
totalQueuedNotificationsCount: 0,
lastRead: -1,
}));
});
it('should handle NOTIFICATIONS_SCROLL_TOP by changing unread to 0 when top = true', () => {
const state = ImmutableMap({
unread: 1,
});
const action = {
type: actions.NOTIFICATIONS_SCROLL_TOP,
top: true,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
unread: 0,
top: true,
}));
});
it('should handle NOTIFICATIONS_SCROLL_TOP by not changing unread val when top = false', () => {
const state = ImmutableMap({
unread: 3,
});
const action = {
type: actions.NOTIFICATIONS_SCROLL_TOP,
top: false,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
unread: 3,
top: false,
}));
});
it('should handle NOTIFICATIONS_UPDATE, when top = false, increment unread', () => {
const state = ImmutableMap({
items: ImmutableList(),
top: false,
unread: 1,
});
const action = {
type: actions.NOTIFICATIONS_UPDATE,
notification: notification,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([
2020-07-28 12:13:29 -07:00
ImmutableMap({
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-28 12:13:29 -07:00
is_seen: true,
}),
]),
2020-07-10 16:45:10 -07:00
top: false,
unread: 2,
}));
});
2020-07-13 18:00:55 -07:00
it('should handle NOTIFICATIONS_UPDATE_QUEUE', () => {
const state = ImmutableMap({
items: ImmutableList([]),
queuedNotifications: ImmutableList([]),
totalQueuedNotificationsCount: 0,
});
const action = {
type: actions.NOTIFICATIONS_UPDATE_QUEUE,
notification: notification,
intlMessages: intlMessages,
intlLocale: 'en',
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([]),
queuedNotifications: ImmutableList([{
notification: notification,
intlMessages: intlMessages,
intlLocale: 'en',
}]),
totalQueuedNotificationsCount: 1,
}));
});
2020-07-11 15:34:14 -07:00
it('should handle NOTIFICATIONS_DEQUEUE', () => {
2020-07-10 19:59:19 -07:00
const state = ImmutableMap({
2020-07-11 15:34:14 -07:00
items: ImmutableList([]),
queuedNotifications: take(notifications, 1),
totalQueuedNotificationsCount: 1,
2020-07-10 19:59:19 -07:00
});
const action = {
2020-07-11 15:34:14 -07:00
type: actions.NOTIFICATIONS_DEQUEUE,
2020-07-10 19:59:19 -07:00
};
expect(reducer(state, action)).toEqual(ImmutableMap({
2020-07-11 15:34:14 -07:00
items: ImmutableList([]),
queuedNotifications: ImmutableList([]),
totalQueuedNotificationsCount: 0,
2020-07-10 19:59:19 -07:00
}));
});
2020-07-11 20:37:52 -07:00
it('should handle NOTIFICATIONS_EXPAND_SUCCESS with non-empty items and next set true', () => {
const state = ImmutableMap({
items: ImmutableList([
ImmutableMap({
2020-07-11 20:50:02 -07:00
id: '10734',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-11 20:37:52 -07:00
is_seen: false,
}),
]),
unread: 1,
hasMore: true,
isLoading: false,
});
const action = {
type: actions.NOTIFICATIONS_EXPAND_SUCCESS,
notifications: take(notifications, 3),
next: true,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([
ImmutableMap({
2020-07-11 20:50:02 -07:00
id: '10744',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-11 20:37:52 -07:00
is_seen: false,
}),
ImmutableMap({
2020-07-11 20:50:02 -07:00
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
2020-07-11 20:37:52 -07:00
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-11 20:37:52 -07:00
is_seen: true,
}),
ImmutableMap({
2020-07-11 20:50:02 -07:00
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
2020-07-11 20:37:52 -07:00
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-11 20:37:52 -07:00
is_seen: true,
}),
ImmutableMap({
2020-07-11 20:50:02 -07:00
id: '10734',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-11 20:37:52 -07:00
is_seen: false,
}),
]),
unread: 1,
hasMore: true,
isLoading: false,
}));
});
it('should handle NOTIFICATIONS_EXPAND_SUCCESS with empty items and next set true', () => {
const state = ImmutableMap({
items: ImmutableList([]),
unread: 1,
hasMore: true,
isLoading: false,
});
const action = {
type: actions.NOTIFICATIONS_EXPAND_SUCCESS,
notifications: take(notifications, 3),
next: true,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([
ImmutableMap({
2020-07-11 20:50:02 -07:00
id: '10744',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-11 20:37:52 -07:00
is_seen: false,
}),
ImmutableMap({
2020-07-11 20:50:02 -07:00
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
2020-07-11 20:37:52 -07:00
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-11 20:37:52 -07:00
is_seen: true,
}),
ImmutableMap({
2020-07-11 20:50:02 -07:00
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
2020-07-11 20:37:52 -07:00
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-11 20:37:52 -07:00
is_seen: true,
}),
]),
unread: 1,
hasMore: true,
isLoading: false,
}));
});
2020-07-13 19:49:42 -07:00
it('should handle ACCOUNT_BLOCK_SUCCESS', () => {
const state = ImmutableMap({
items: ImmutableList([
ImmutableMap({
id: '10744',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: false,
}),
ImmutableMap({
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
ImmutableMap({
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
]),
});
const action = {
type: ACCOUNT_BLOCK_SUCCESS,
relationship: relationship,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([
ImmutableMap({
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
ImmutableMap({
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
]),
}));
});
it('should handle ACCOUNT_MUTE_SUCCESS', () => {
const state = ImmutableMap({
items: ImmutableList([
ImmutableMap({
id: '10744',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: false,
}),
ImmutableMap({
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
ImmutableMap({
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
]),
});
const action = {
type: ACCOUNT_MUTE_SUCCESS,
relationship: relationship,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([
ImmutableMap({
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
ImmutableMap({
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
]),
}));
});
2020-07-12 15:52:58 -07:00
it('should handle NOTIFICATIONS_CLEAR', () => {
const state = ImmutableMap({
items: ImmutableList([]),
hasMore: true,
});
const action = {
type: actions.NOTIFICATIONS_CLEAR,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([]),
hasMore: false,
}));
});
it('should handle NOTIFICATIONS_MARK_READ_REQUEST', () => {
const state = ImmutableMap({
items: ImmutableList([]),
});
const action = {
type: actions.NOTIFICATIONS_MARK_READ_REQUEST,
lastRead: 35098814,
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([]),
lastRead: 35098814,
}));
});
2020-07-13 19:49:42 -07:00
it('should handle TIMELINE_DELETE', () => {
const state = ImmutableMap({
items: ImmutableList([
ImmutableMap({
id: '10744',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: false,
}),
ImmutableMap({
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
ImmutableMap({
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
]),
});
const action = {
type: TIMELINE_DELETE,
id: '9vvNxoo5EFbbnfdXQu',
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([]),
}));
});
2020-07-12 15:52:58 -07:00
2020-07-13 19:49:42 -07:00
it('should handle TIMELINE_DISCONNECT', () => {
const state = ImmutableMap({
items: ImmutableList([
ImmutableMap({
id: '10744',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: false,
}),
ImmutableMap({
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
ImmutableMap({
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
]),
});
const action = {
type: TIMELINE_DISCONNECT,
timeline: 'home',
};
expect(reducer(state, action)).toEqual(ImmutableMap({
items: ImmutableList([
null,
ImmutableMap({
id: '10744',
type: 'pleroma:emoji_reaction',
account: '9vMAje101ngtjlMj7w',
created_at: '2020-06-10T02:54:39.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: '😢',
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: false,
}),
ImmutableMap({
id: '10743',
type: 'favourite',
account: '9v5c6xSEgAi3Zu1Lv6',
created_at: '2020-06-10T02:51:05.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
ImmutableMap({
id: '10741',
type: 'favourite',
account: '9v5cKMOPGqPcgfcWp6',
created_at: '2020-06-10T02:05:06.000Z',
status: '9vvNxoo5EFbbnfdXQu',
emoji: undefined,
2020-08-27 14:20:45 -07:00
chat_message: undefined,
2020-07-13 19:49:42 -07:00
is_seen: true,
}),
]),
}));
});
2020-07-12 15:52:58 -07:00
2020-06-09 18:08:07 -07:00
});