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

58 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-06-09 18:08:07 -07:00
import reducer from '../statuses';
2021-11-12 10:18:11 -08:00
import { Map as ImmutableMap, fromJS } from 'immutable';
import {
STATUS_CREATE_REQUEST,
STATUS_CREATE_FAIL,
} from 'soapbox/actions/statuses';
2022-01-07 14:57:58 -08:00
import { STATUS_IMPORT } from 'soapbox/actions/importer';
2020-06-09 18:08:07 -07:00
describe('statuses reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual(ImmutableMap());
});
2021-11-12 10:18:11 -08:00
2022-01-07 14:57:58 -08:00
describe('STATUS_IMPORT', () => {
it('fixes the order of mentions', () => {
const status = require('soapbox/__fixtures__/status-unordered-mentions.json');
const action = { type: STATUS_IMPORT, status };
const expected = ['NEETzsche', 'alex', 'Lumeinshin', 'sneeden'];
const result = reducer(undefined, action)
.getIn(['AFChectaqZjmOVkXZ2', 'mentions'])
.map(mention => mention.get('username'))
.toJS();
expect(result).toEqual(expected);
});
});
2021-11-12 10:18:11 -08:00
describe('STATUS_CREATE_REQUEST', () => {
it('increments the replies_count of its parent', () => {
const state = fromJS({ '123': { replies_count: 4 } });
const action = {
type: STATUS_CREATE_REQUEST,
params: { in_reply_to_id: '123' },
};
const result = reducer(state, action).getIn(['123', 'replies_count']);
expect(result).toEqual(5);
});
});
describe('STATUS_CREATE_FAIL', () => {
it('decrements the replies_count of its parent', () => {
const state = fromJS({ '123': { replies_count: 5 } });
const action = {
type: STATUS_CREATE_FAIL,
params: { in_reply_to_id: '123' },
};
const result = reducer(state, action).getIn(['123', 'replies_count']);
expect(result).toEqual(4);
});
});
2020-06-09 18:08:07 -07:00
});