Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
migrate searchForTerm into redux-style action (#1957)
Browse files Browse the repository at this point in the history
  • Loading branch information
saturninoabril authored Nov 2, 2018
1 parent 1c28a3d commit 8cb5192
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions actions/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function executeCommand(message, args) {

switch (cmd) {
case '/search':
PostActions.searchForTerm(msg.substring(cmdLength + 1, msg.length));
dispatch(PostActions.searchForTerm(msg.substring(cmdLength + 1, msg.length)));
return {data: true};
case '/shortcuts':
if (UserAgent.isMobile()) {
Expand Down Expand Up @@ -113,4 +113,4 @@ export function executeCommand(message, args) {

return {data: true};
};
}
}
6 changes: 4 additions & 2 deletions actions/post_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ export function increasePostVisibility(channelId, focusedPostId) {
}

export function searchForTerm(term) {
dispatch(RhsActions.updateSearchTerms(term));
dispatch(RhsActions.showSearchResults());
return (doDispatch) => {
doDispatch(RhsActions.updateSearchTerms(term));
doDispatch(RhsActions.showSearchResults());
};
}

export function pinPost(postId) {
Expand Down
25 changes: 23 additions & 2 deletions tests/redux/actions/post_actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ describe('Actions.Posts', () => {
users: {
currentUserId: 'current_user_id',
profiles: {
current_user_id: {roles: 'system_role'},
current_user_id: {
id: 'current_user_id',
username: 'current_username',
roles: 'system_role',
useAutomaticTimezone: true,
automaticTimezone: '',
manualTimezone: '',
},
},
},
general: {
Expand Down Expand Up @@ -126,6 +133,7 @@ describe('Actions.Posts', () => {
loadingPosts: {},
postVisibility: {current_channel_id: 60},
},
rhs: {searchTerms: ''},
},
};

Expand Down Expand Up @@ -224,6 +232,19 @@ describe('Actions.Posts', () => {
args: ['current_channel_id', 'latest_post_id', 2, 30],
type: 'MOCK_GET_POSTS_BEFORE',
},
{channelId: 'current_channel_id', data: false, type: 'LOADING_POSTS'}]);
{channelId: 'current_channel_id', data: false, type: 'LOADING_POSTS'},
]);
});

test('searchForTerm', async () => {
const testStore = await mockStore(initialState);

await testStore.dispatch(Actions.searchForTerm('hello'));
expect(testStore.getActions()).toEqual([
{terms: 'hello', type: 'UPDATE_RHS_SEARCH_TERMS'},
{state: 'search', type: 'UPDATE_RHS_STATE'},
{terms: '', type: 'UPDATE_RHS_SEARCH_RESULTS_TERMS'},
{isGettingMore: false, type: 'SEARCH_POSTS_REQUEST'},
]);
});
});
2 changes: 1 addition & 1 deletion utils/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ export function handleFormattedTextClick(e) {
if (hashtagAttribute) {
e.preventDefault();

searchForTerm(hashtagAttribute.value);
store.dispatch(searchForTerm(hashtagAttribute.value));
} else if (linkAttribute) {
const MIDDLE_MOUSE_BUTTON = 1;

Expand Down

0 comments on commit 8cb5192

Please sign in to comment.