mirror of
https://github.com/strapi/strapi.git
synced 2025-08-10 09:47:46 +00:00
Add tests
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
7c8140491d
commit
2e56b8c9a9
@ -116,15 +116,12 @@ const LeftMenu = forwardRef(({ version, plugins }, ref) => {
|
||||
getModels,
|
||||
}));
|
||||
|
||||
// console.log({ generalSectionLinks });
|
||||
|
||||
useEffect(() => {
|
||||
const getLinksPermissions = async () => {
|
||||
const generalSectionLinksArrayOfPromises = generateArrayOfPromises(generalSectionLinks);
|
||||
const pluginsSectionLinksArrayOfPromises = generateArrayOfPromises(pluginsSectionLinks);
|
||||
|
||||
await getModels();
|
||||
// TODO check permissions form models
|
||||
|
||||
const generalSectionResults = await Promise.all(generalSectionLinksArrayOfPromises);
|
||||
const pluginsSectionResults = await Promise.all(pluginsSectionLinksArrayOfPromises);
|
||||
|
@ -57,7 +57,7 @@ function SettingsPage() {
|
||||
[pluginsGlobalLinks]
|
||||
);
|
||||
|
||||
const pluginsLinksRoute = useMemo(() => {
|
||||
const pluginsLinksRoutes = useMemo(() => {
|
||||
return menu.reduce((acc, current) => {
|
||||
if (current.id === 'global') {
|
||||
return acc;
|
||||
@ -126,7 +126,7 @@ function SettingsPage() {
|
||||
<Route exact path={`${settingsBaseURL}/webhooks`} component={ListView} />
|
||||
<Route exact path={`${settingsBaseURL}/webhooks/:id`} component={EditView} />
|
||||
{createdRoutes}
|
||||
{pluginsLinksRoute}
|
||||
{pluginsLinksRoutes}
|
||||
<Route path={`${settingsBaseURL}/:pluginId`} component={SettingDispatcher} />
|
||||
</Switch>
|
||||
</div>
|
||||
|
@ -1,17 +1,15 @@
|
||||
import { useContext, useEffect, useReducer } from 'react';
|
||||
import { useIntl } from 'react-intl';
|
||||
import { useGlobalContext, hasPermissions, UserContext } from 'strapi-helper-plugin';
|
||||
|
||||
import reducer, { initialState } from './reducer';
|
||||
import init from './init';
|
||||
|
||||
const useSettingsMenu = () => {
|
||||
const { formatMessage } = useIntl();
|
||||
const permissions = useContext(UserContext);
|
||||
const { plugins, settingsBaseURL } = useGlobalContext();
|
||||
const { plugins } = useGlobalContext();
|
||||
|
||||
const [{ isLoading, menu }, dispatch] = useReducer(reducer, initialState, () =>
|
||||
init(initialState, plugins, formatMessage, settingsBaseURL)
|
||||
init(initialState, plugins)
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -1,21 +1,22 @@
|
||||
import { retrieveGlobalLinks, retrievePluginsMenu, sortLinks } from '../../utils';
|
||||
import { SETTINGS_BASE_URL } from '../../config';
|
||||
import formatLinks from './utils/formatLinks';
|
||||
|
||||
const init = (initialState, plugins, formatMessage, settingsBaseURL) => {
|
||||
const init = (initialState, plugins) => {
|
||||
// Retrieve the links that will be injected into the global section
|
||||
const pluginsGlobalLinks = retrieveGlobalLinks(plugins);
|
||||
// Sort the links by name
|
||||
const sortedGlobalLinks = sortLinks([
|
||||
{
|
||||
title: formatMessage({ id: 'Settings.webhooks.title' }),
|
||||
to: `${settingsBaseURL}/webhooks`,
|
||||
title: { id: 'Settings.webhooks.title' },
|
||||
to: `${SETTINGS_BASE_URL}/webhooks`,
|
||||
name: 'webhooks',
|
||||
isDisplayed: false,
|
||||
permissions: [
|
||||
{ action: 'admin::webhook.create', subject: null },
|
||||
{ action: 'admin::webhook.read', subject: null },
|
||||
{ action: 'admin::webhook.update', subject: null },
|
||||
{ action: 'admin::webhook.delete', subject: null },
|
||||
{ action: 'admin::webhooks.create', subject: null },
|
||||
{ action: 'admin::webhooks.read', subject: null },
|
||||
{ action: 'admin::webhooks.update', subject: null },
|
||||
{ action: 'admin::webhooks.delete', subject: null },
|
||||
],
|
||||
},
|
||||
...pluginsGlobalLinks,
|
||||
@ -35,8 +36,8 @@ const init = (initialState, plugins, formatMessage, settingsBaseURL) => {
|
||||
title: 'Settings.permissions',
|
||||
links: [
|
||||
{
|
||||
title: formatMessage({ id: 'Settings.permissions.menu.link.roles.label' }),
|
||||
to: `${settingsBaseURL}/roles`,
|
||||
title: { id: 'Settings.permissions.menu.link.roles.label' },
|
||||
to: `${SETTINGS_BASE_URL}/roles`,
|
||||
name: 'roles',
|
||||
isDisplayed: false,
|
||||
permissions: [
|
||||
@ -47,9 +48,9 @@ const init = (initialState, plugins, formatMessage, settingsBaseURL) => {
|
||||
],
|
||||
},
|
||||
{
|
||||
title: formatMessage({ id: 'Settings.permissions.menu.link.users.label' }),
|
||||
title: { id: 'Settings.permissions.menu.link.users.label' },
|
||||
// Init the search params directly
|
||||
to: `${settingsBaseURL}/users?pageSize=10&page=1&_sort=firstname%3AASC`,
|
||||
to: `${SETTINGS_BASE_URL}/users?pageSize=10&page=1&_sort=firstname%3AASC`,
|
||||
name: 'users',
|
||||
isDisplayed: false,
|
||||
permissions: [
|
||||
|
@ -0,0 +1,30 @@
|
||||
import formatLinks from '../formatLinks';
|
||||
|
||||
describe('ADMIN | hooks | useSettingsMenu | utils | formatLinks', () => {
|
||||
it('should add the isDisplayed key to all sections links', () => {
|
||||
const menu = [
|
||||
{
|
||||
links: [{ name: 'link 1' }, { name: 'link 2' }],
|
||||
},
|
||||
{
|
||||
links: [{ name: 'link 3' }, { name: 'link 4' }],
|
||||
},
|
||||
];
|
||||
const expected = [
|
||||
{
|
||||
links: [
|
||||
{ name: 'link 1', isDisplayed: false },
|
||||
{ name: 'link 2', isDisplayed: false },
|
||||
],
|
||||
},
|
||||
{
|
||||
links: [
|
||||
{ name: 'link 3', isDisplayed: false },
|
||||
{ name: 'link 4', isDisplayed: false },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
expect(formatLinks(menu)).toEqual(expected);
|
||||
});
|
||||
});
|
@ -248,38 +248,38 @@ const data = {
|
||||
// },
|
||||
|
||||
// Admin webhooks
|
||||
// {
|
||||
// action: 'admin::webhooks.create',
|
||||
// subject: null,
|
||||
// fields: null,
|
||||
// conditions: [],
|
||||
// },
|
||||
// {
|
||||
// action: 'admin::webhooks.read',
|
||||
// subject: null,
|
||||
// fields: null,
|
||||
// conditions: [],
|
||||
// },
|
||||
// {
|
||||
// action: 'admin::webhooks.update',
|
||||
// subject: null,
|
||||
// fields: null,
|
||||
// conditions: [],
|
||||
// },
|
||||
// {
|
||||
// action: 'admin::webhooks.delete',
|
||||
// subject: null,
|
||||
// fields: null,
|
||||
// conditions: [],
|
||||
// },
|
||||
{
|
||||
action: 'admin::webhooks.create',
|
||||
subject: null,
|
||||
fields: null,
|
||||
conditions: [],
|
||||
},
|
||||
{
|
||||
action: 'admin::webhooks.read',
|
||||
subject: null,
|
||||
fields: null,
|
||||
conditions: [],
|
||||
},
|
||||
{
|
||||
action: 'admin::webhooks.update',
|
||||
subject: null,
|
||||
fields: null,
|
||||
conditions: [],
|
||||
},
|
||||
{
|
||||
action: 'admin::webhooks.delete',
|
||||
subject: null,
|
||||
fields: null,
|
||||
conditions: [],
|
||||
},
|
||||
|
||||
// // Admin users
|
||||
// {
|
||||
// action: 'admin::users.create',
|
||||
// subject: null,
|
||||
// fields: null,
|
||||
// conditions: [],
|
||||
// },
|
||||
{
|
||||
action: 'admin::users.create',
|
||||
subject: null,
|
||||
fields: null,
|
||||
conditions: [],
|
||||
},
|
||||
// {
|
||||
// action: 'admin::users.read',
|
||||
// subject: null,
|
||||
|
@ -55,8 +55,6 @@ export default strapi => {
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
mainComponent: SettingsPage,
|
||||
},
|
||||
trads,
|
||||
menu: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user