mirror of
https://github.com/strapi/strapi.git
synced 2025-08-10 09:47:46 +00:00
adding tests for selectors
This commit is contained in:
parent
285db5d3e8
commit
84ec6945bc
@ -1,12 +1,7 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import pluginId from '../../pluginId';
|
|
||||||
import { resetPermissions, setPermissions } from './actions';
|
import { resetPermissions, setPermissions } from './actions';
|
||||||
|
import { selectPermissions, selectCollectionTypePermissions } from '../../selectors';
|
||||||
const selectPermissions = state => state.get(`${pluginId}_rbacManager`).permissions;
|
|
||||||
|
|
||||||
const selectCollectionTypePermissions = state =>
|
|
||||||
state.get('permissionsManager').collectionTypesRelatedPermissions;
|
|
||||||
|
|
||||||
const useSyncRbac = (query, collectionTypeUID) => {
|
const useSyncRbac = (query, collectionTypeUID) => {
|
||||||
const collectionTypesRelatedPermissions = useSelector(selectCollectionTypePermissions);
|
const collectionTypesRelatedPermissions = useSelector(selectCollectionTypePermissions);
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
import pluginId from './pluginId';
|
||||||
|
|
||||||
|
export const selectPermissions = state => state.get(`${pluginId}_rbacManager`).permissions;
|
||||||
|
|
||||||
|
export const selectCollectionTypePermissions = state =>
|
||||||
|
state.get('permissionsManager').collectionTypesRelatedPermissions;
|
@ -0,0 +1,43 @@
|
|||||||
|
import { selectPermissions, selectCollectionTypePermissions } from '../selectors';
|
||||||
|
|
||||||
|
describe('selectors', () => {
|
||||||
|
let store;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
store = new Map();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('selectPermissions', () => {
|
||||||
|
it('resolves the permissions key of the "content-manager_rbacManager" store key', () => {
|
||||||
|
store.set('content-manager_rbacManager', {
|
||||||
|
permissions: {
|
||||||
|
some: 'permission',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const actual = selectPermissions(store);
|
||||||
|
const expected = {
|
||||||
|
some: 'permission',
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(actual).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('selectCollectionTypePermissions', () => {
|
||||||
|
it('resolves the permissions key of the "permissionsManager" store key', () => {
|
||||||
|
store.set('permissionsManager', {
|
||||||
|
collectionTypesRelatedPermissions: {
|
||||||
|
some: 'permission again',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const actual = selectCollectionTypePermissions(store);
|
||||||
|
const expected = {
|
||||||
|
some: 'permission again',
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(actual).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user