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
/
admin_actions.test.js
56 lines (47 loc) · 2.41 KB
/
admin_actions.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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import * as Actions from 'actions/admin_actions.jsx';
import configureStore from 'store';
describe('Actions.Admin', () => {
let store;
beforeEach(async () => {
store = await configureStore();
});
test('Register a plugin adds the plugin to the state', async () => {
const func = jest.fn();
expect(store.getState().plugins.adminConsoleReducers).toEqual({});
store.dispatch(Actions.registerAdminConsolePlugin('plugin-id', func));
expect(store.getState().plugins.adminConsoleReducers).toEqual({'plugin-id': func});
});
test('Unregister a plugin removes an existing plugin from the state', async () => {
const func = jest.fn();
expect(store.getState().plugins.adminConsoleReducers).toEqual({});
store.dispatch(Actions.registerAdminConsolePlugin('plugin-id', func));
expect(store.getState().plugins.adminConsoleReducers).toEqual({'plugin-id': func});
store.dispatch(Actions.unregisterAdminConsolePlugin('plugin-id'));
expect(store.getState().plugins.adminConsoleReducers).toEqual({});
});
test('Unregister an unexisting plugin do nothing', async () => {
const func = jest.fn();
expect(store.getState().plugins.adminConsoleReducers).toEqual({});
store.dispatch(Actions.registerAdminConsolePlugin('plugin-id', func));
expect(store.getState().plugins.adminConsoleReducers).toEqual({'plugin-id': func});
store.dispatch(Actions.unregisterAdminConsolePlugin('invalid-plugin-id'));
expect(store.getState().plugins.adminConsoleReducers).toEqual({'plugin-id': func});
});
test('Register a custom plugin setting adds the component to the state', async () => {
expect(store.getState().plugins.adminConsoleCustomComponents).toEqual({});
store.dispatch(Actions.registerAdminConsoleCustomSetting('plugin-id', 'settingA', React.Component, {showTitle: true}));
expect(store.getState().plugins.adminConsoleCustomComponents).toEqual(
{'plugin-id': {
settinga: {
key: 'settingA',
pluginId: 'plugin-id',
component: React.Component,
options: {
showTitle: true,
},
}}});
});
});