mattermost-mobile/app/selectors/post_list.test.js
Harrison Healey 9c53852128
Reorganize post state and make postsInChannel into a sparse array (#2693)
* MM-13957 Reorganize post actions (#2553)

* MM-13957 Reorganize post actions

* Update mattermost-redux

* Update mattermost-redux

* Update package-lock.json to resolve build issues

* MM-13958/MM-13959 Make postsInChannel into a sparse array (#2600)

* MM-13960 Re-add combined system messages (#2637)

* MM-13960 Re-add combined system messages

* Pass entire post to PostOptions

* Update mattermost-redux

* Update mattermost-redux

* Address feedback

* Update mattermost-redux
2019-04-15 17:20:23 -04:00

90 lines
2.8 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import assert from 'assert';
import {makePreparePostIdsForSearchPosts} from 'app/selectors/post_list';
describe('makePreparePostIdsForSearchPosts', () => {
it('should return an empty array if there are no posts specified', () => {
const preparePostIdsForSearchPosts = makePreparePostIdsForSearchPosts();
const state = {
entities: {
posts: {
posts: {
1001: {id: '1001', create_at: 0, type: ''},
1002: {id: '1002', create_at: 1, type: ''},
},
},
users: {
currentUserId: '1234',
profiles: {
1234: {id: '1234', username: 'user'},
},
},
},
};
const postIds = [];
const actual = preparePostIdsForSearchPosts(state, postIds);
assert.deepEqual(actual, []);
});
it('should return an empty array if there are no matching posts', () => {
const preparePostIdsForSearchPosts = makePreparePostIdsForSearchPosts();
const state = {
entities: {
posts: {
posts: {},
},
users: {
currentUserId: '1234',
profiles: {
1234: {id: '1234', username: 'user'},
},
},
},
};
const postIds = ['1002', '1001'];
const actual = preparePostIdsForSearchPosts(state, postIds);
assert.deepEqual(actual, []);
});
it('should return results when there are posts', () => {
const preparePostIdsForSearchPosts = makePreparePostIdsForSearchPosts();
const state = {
entities: {
posts: {
posts: {
1001: {id: '1001', create_at: 0, type: ''},
1002: {id: '1002', create_at: 1000, type: ''},
// Same timestamp as 1002
1003: {id: '1003', create_at: 1000, type: ''},
},
},
users: {
currentUserId: '1234',
profiles: {
1234: {id: '1234', username: 'user'},
},
},
},
};
const postIds = ['1003', '1002', '1001'];
const actual = preparePostIdsForSearchPosts(state, postIds);
assert.deepEqual(actual, [
'date-1000-index-0',
'1003',
'date-1000-index-1',
'1002',
'date-0-index-2',
'1001',
]);
});
});