Commit 028e7863 authored by Joram Wilander's avatar Joram Wilander Committed by JoramWilander
Browse files

MM-14456 Minor updates to search (#812)

* Add getCurrentSearchForCurrentTeam selector

* Set isEnd for search if returned less posts than asked for
parent ea818389
......@@ -72,7 +72,7 @@ export function searchPostsWithParams(teamId, params) {
data: {
teamId,
params,
isEnd: (posts.order.length === 0),
isEnd: (posts.order.length < params.per_page),
},
},
{
......
......@@ -62,12 +62,14 @@ describe('Actions.Search', () => {
const state = getState();
const {recent, results} = state.entities.search;
const {posts} = state.entities.posts;
const current = state.entities.search.current[TestHelper.basicTeam.id];
assert.ok(recent[TestHelper.basicTeam.id]);
const searchIsPresent = recent[TestHelper.basicTeam.id].findIndex((r) => r.terms === search1);
assert.ok(searchIsPresent !== -1);
assert.equal(Object.keys(recent[TestHelper.basicTeam.id]).length, 1);
assert.equal(results.length, 1);
assert.ok(posts[results[0]]);
assert.ok(current.isEnd);
// DISABLED
// Test for posts from a user in a channel
......
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {createSelector} from 'reselect';
import {getCurrentTeamId} from 'selectors/entities/teams';
export const getCurrentSearchForCurrentTeam = createSelector(
(state) => state.entities.search.current,
getCurrentTeamId,
(current, teamId) => {
return current[teamId];
}
);
\ No newline at end of file
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import assert from 'assert';
import deepFreezeAndThrowOnMutation from 'utils/deep_freeze';
import TestHelper from 'test/test_helper';
import * as Selectors from 'selectors/entities/search';
describe('Selectors.Search', () => {
const team1 = TestHelper.fakeTeamWithId();
const team1CurrentSearch = {params: {page: 0, per_page: 20}, isEnd: true};
const testState = deepFreezeAndThrowOnMutation({
entities: {
teams: {
currentTeamId: team1.id,
},
search: {
current: {[team1.id]: team1CurrentSearch},
},
},
});
it('should return current search for current team', () => {
assert.deepEqual(Selectors.getCurrentSearchForCurrentTeam(testState), team1CurrentSearch);
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment