This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
emoji_actions.mock.test.js
78 lines (64 loc) · 2.6 KB
/
emoji_actions.mock.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import * as Actions from 'actions/emoji_actions.jsx';
import {getEmojiMap, getRecentEmojis} from 'selectors/emojis';
const mockStore = configureStore([thunk]);
const initialState = {
entities: {
general: {
config: {EnableCustomEmoji: 'true'},
},
},
};
jest.mock('selectors/emojis', () => ({
getEmojiMap: jest.fn(),
getRecentEmojis: jest.fn(),
}));
jest.mock('mattermost-redux/actions/emojis', () => ({
getCustomEmojiByName: (...args) => ({type: 'MOCK_GET_CUSTOM_EMOJI_BY_NAME', args}),
}));
describe('loadRecentlyUsedCustomEmojis', () => {
let testStore;
beforeEach(async () => {
testStore = await mockStore(initialState);
});
test('Get only emojis missing on the map', async () => {
getEmojiMap.mockImplementation(() => {
return new Map([['emoji1', {}], ['emoji3', {}], ['emoji4', {}]]);
});
getRecentEmojis.mockImplementation(() => {
return ['emoji1', 'emoji2', 'emoji3', 'emoji5'];
});
const expectedActions = [
{type: 'MOCK_GET_CUSTOM_EMOJI_BY_NAME', args: ['emoji2']},
{type: 'MOCK_GET_CUSTOM_EMOJI_BY_NAME', args: ['emoji5']},
];
testStore.dispatch(Actions.loadRecentlyUsedCustomEmojis());
expect(testStore.getActions()).toEqual(expectedActions);
});
test('Does not get any emojis if none is missing on the map', async () => {
getEmojiMap.mockImplementation(() => {
return new Map([['emoji1', {}], ['emoji3', {}], ['emoji4', {}]]);
});
getRecentEmojis.mockImplementation(() => {
return ['emoji1', 'emoji3'];
});
const expectedActions = [];
testStore.dispatch(Actions.loadRecentlyUsedCustomEmojis());
expect(testStore.getActions()).toEqual(expectedActions);
});
test('Does not get any emojis if they are not enabled', async () => {
testStore = await mockStore({entities: {general: {config: {EnableCustomEmoji: 'false'}}}});
getEmojiMap.mockImplementation(() => {
return new Map([['emoji1', {}], ['emoji3', {}], ['emoji4', {}]]);
});
getRecentEmojis.mockImplementation(() => {
return ['emoji1', 'emoji2', 'emoji3', 'emoji5'];
});
const expectedActions = [];
testStore.dispatch(Actions.loadRecentlyUsedCustomEmojis());
expect(testStore.getActions()).toEqual(expectedActions);
});
});