Skip to content

Commit

Permalink
MM-14456 Minor updates to search (mattermost#812)
Browse files Browse the repository at this point in the history
* Add getCurrentSearchForCurrentTeam selector

* Set isEnd for search if returned less posts than asked for
  • Loading branch information
jwilander authored Apr 22, 2019
1 parent 4771504 commit 9c81cb4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function searchPostsWithParams(teamId, params) {
data: {
teamId,
params,
isEnd: (posts.order.length === 0),
isEnd: (posts.order.length < params.per_page),
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/actions/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/selectors/entities/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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];
}
);
29 changes: 29 additions & 0 deletions src/selectors/entities/search.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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);
});
});

0 comments on commit 9c81cb4

Please sign in to comment.