Timelines: add tests

This commit is contained in:
Alex Gleason
2021-07-08 17:10:01 -05:00
parent 628dc92775
commit 5f40ae1d48
2 changed files with 119 additions and 6 deletions

View File

@ -1,5 +1,5 @@
import reducer from '../status_lists';
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
describe('status_lists reducer', () => {
it('should return the initial state', () => {
@ -7,22 +7,22 @@ describe('status_lists reducer', () => {
favourites: ImmutableMap({
next: null,
loaded: false,
items: ImmutableList(),
items: ImmutableOrderedSet(),
}),
bookmarks: ImmutableMap({
next: null,
loaded: false,
items: ImmutableList(),
items: ImmutableOrderedSet(),
}),
pins: ImmutableMap({
next: null,
loaded: false,
items: ImmutableList(),
items: ImmutableOrderedSet(),
}),
scheduled_statuses: ImmutableMap({
next: null,
loaded: false,
items: ImmutableList(),
items: ImmutableOrderedSet(),
}),
}));
});

View File

@ -1,8 +1,121 @@
import reducer from '../timelines';
import { Map as ImmutableMap } from 'immutable';
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable';
import {
TIMELINE_EXPAND_REQUEST,
TIMELINE_EXPAND_FAIL,
TIMELINE_EXPAND_SUCCESS,
} from 'soapbox/actions/timelines';
describe('timelines reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual(ImmutableMap());
});
describe('TIMELINE_EXPAND_REQUEST', () => {
it('sets loading to true', () => {
const action = {
type: TIMELINE_EXPAND_REQUEST,
timeline: 'home',
};
const result = reducer(undefined, action);
expect(result.getIn(['home', 'isLoading'])).toBe(true);
});
});
describe('TIMELINE_EXPAND_FAIL', () => {
it('sets loading to false', () => {
const state = fromJS({
home: { isLoading: true },
});
const action = {
type: TIMELINE_EXPAND_FAIL,
timeline: 'home',
};
const result = reducer(state, action);
expect(result.getIn(['home', 'isLoading'])).toBe(false);
});
});
describe('TIMELINE_EXPAND_SUCCESS', () => {
it('sets loading to false', () => {
const state = fromJS({
home: { isLoading: true },
});
const action = {
type: TIMELINE_EXPAND_SUCCESS,
timeline: 'home',
};
const result = reducer(state, action);
expect(result.getIn(['home', 'isLoading'])).toBe(false);
});
it('adds the status IDs', () => {
const expected = ImmutableOrderedSet(['1', '2', '5']);
const action = {
type: TIMELINE_EXPAND_SUCCESS,
timeline: 'home',
statuses: [{ id: '1' }, { id: '2' }, { id: '5' }],
};
const result = reducer(undefined, action);
expect(result.getIn(['home', 'items'])).toEqual(expected);
});
it('merges new status IDs', () => {
const state = fromJS({
home: { items: ImmutableOrderedSet(['5', '2', '1']) },
});
const expected = ImmutableOrderedSet(['6', '5', '4', '2', '1']);
const action = {
type: TIMELINE_EXPAND_SUCCESS,
timeline: 'home',
statuses: [{ id: '6' }, { id: '5' }, { id: '4' }],
};
const result = reducer(state, action);
expect(result.getIn(['home', 'items'])).toEqual(expected);
});
it('merges old status IDs', () => {
const state = fromJS({
home: { items: ImmutableOrderedSet(['6', '4', '3']) },
});
const expected = ImmutableOrderedSet(['6', '4', '3', '5', '2', '1']);
const action = {
type: TIMELINE_EXPAND_SUCCESS,
timeline: 'home',
statuses: [{ id: '5' }, { id: '2' }, { id: '1' }],
};
const result = reducer(state, action);
expect(result.getIn(['home', 'items'])).toEqual(expected);
});
it('overrides pinned post IDs', () => {
const state = fromJS({
'account:1:pinned': { items: ImmutableOrderedSet(['5', '2', '1']) },
});
const expected = ImmutableOrderedSet(['9', '8', '7']);
const action = {
type: TIMELINE_EXPAND_SUCCESS,
timeline: 'home',
statuses: [{ id: '9' }, { id: '8' }, { id: '7' }],
};
const result = reducer(state, action);
expect(result.getIn(['home', 'items'])).toEqual(expected);
});
});
});