mirror of
https://github.com/strapi/strapi.git
synced 2025-11-18 02:58:05 +00:00
Update tests
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
146ee5907e
commit
e40bc6ceed
@ -3,6 +3,7 @@
|
|||||||
const adminPermissions = require('./permissions/admin-permissions');
|
const adminPermissions = require('./permissions/admin-permissions');
|
||||||
const cmPermissions = require('./permissions/content-manager-permissions');
|
const cmPermissions = require('./permissions/content-manager-permissions');
|
||||||
const ctbPermissions = require('./permissions/content-type-builder-permissions');
|
const ctbPermissions = require('./permissions/content-type-builder-permissions');
|
||||||
|
const store = require('./store');
|
||||||
|
|
||||||
const permissions = [...adminPermissions, ...cmPermissions, ...ctbPermissions];
|
const permissions = [...adminPermissions, ...cmPermissions, ...ctbPermissions];
|
||||||
|
|
||||||
@ -11,4 +12,5 @@ module.exports = {
|
|||||||
cmPermissions,
|
cmPermissions,
|
||||||
ctbPermissions,
|
ctbPermissions,
|
||||||
permissions,
|
permissions,
|
||||||
|
store,
|
||||||
};
|
};
|
||||||
|
|||||||
56
packages/admin-test-utils/lib/fixtures/store/index.js
Normal file
56
packages/admin-test-utils/lib/fixtures/store/index.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// eslint-disable-next-line node/no-extraneous-require
|
||||||
|
const { combineReducers, createStore } = require('redux');
|
||||||
|
|
||||||
|
const reducers = {
|
||||||
|
app: jest.fn(() => ({ isLoading: true, uuid: false })),
|
||||||
|
language: jest.fn(() => ({ locale: 'en' })),
|
||||||
|
menu: jest.fn(() => ({
|
||||||
|
collectionTypesSectionLinks: [],
|
||||||
|
generalSectionLinks: [
|
||||||
|
{
|
||||||
|
icon: 'list',
|
||||||
|
label: 'app.components.LeftMenuLinkContainer.listPlugins',
|
||||||
|
destination: '/list-plugins',
|
||||||
|
isDisplayed: false,
|
||||||
|
permissions: [
|
||||||
|
{ action: 'admin::marketplace.read', subject: null },
|
||||||
|
{ action: 'admin::marketplace.plugins.install', subject: null },
|
||||||
|
{ action: 'admin::marketplace.plugins.uninstall', subject: null },
|
||||||
|
],
|
||||||
|
notificationsCount: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'shopping-basket',
|
||||||
|
label: 'app.components.LeftMenuLinkContainer.installNewPlugin',
|
||||||
|
destination: '/marketplace',
|
||||||
|
isDisplayed: false,
|
||||||
|
permissions: [
|
||||||
|
{ action: 'admin::marketplace.read', subject: null },
|
||||||
|
{ action: 'admin::marketplace.plugins.install', subject: null },
|
||||||
|
{ action: 'admin::marketplace.plugins.uninstall', subject: null },
|
||||||
|
],
|
||||||
|
notificationsCount: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'cog',
|
||||||
|
label: 'app.components.LeftMenuLinkContainer.settings',
|
||||||
|
isDisplayed: false,
|
||||||
|
destination: '/settings',
|
||||||
|
// Permissions of this link are retrieved in the init phase
|
||||||
|
// using the settings menu
|
||||||
|
permissions: [],
|
||||||
|
notificationsCount: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
singleTypesSectionLinks: [],
|
||||||
|
pluginsSectionLinks: [],
|
||||||
|
isLoading: true,
|
||||||
|
})),
|
||||||
|
rbacProvider: jest.fn(() => ({ allPermissions: null, collectionTypesRelatedPermissions: {} })),
|
||||||
|
};
|
||||||
|
|
||||||
|
const store = createStore(combineReducers(reducers)).getState();
|
||||||
|
|
||||||
|
module.exports = store;
|
||||||
@ -94,6 +94,12 @@ class StrapiApp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createStore = () => {
|
||||||
|
const store = configureStore(this.middlewares.middlewares, this.reducers.reducers);
|
||||||
|
|
||||||
|
return store;
|
||||||
|
};
|
||||||
|
|
||||||
getPlugin = pluginId => {
|
getPlugin = pluginId => {
|
||||||
return this.plugins[pluginId];
|
return this.plugins[pluginId];
|
||||||
};
|
};
|
||||||
@ -138,7 +144,8 @@ class StrapiApp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const store = configureStore(this.middlewares.middlewares, this.reducers.reducers);
|
const store = this.createStore();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
components: { components },
|
components: { components },
|
||||||
fields: { fields },
|
fields: { fields },
|
||||||
|
|||||||
@ -17,8 +17,6 @@ const AuthenticatedApp = () => {
|
|||||||
latestStrapiReleaseTag: strapiVersion,
|
latestStrapiReleaseTag: strapiVersion,
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: clean components that depends on this
|
|
||||||
// This part is just to prepare the refactoring of the Admin page
|
|
||||||
const [
|
const [
|
||||||
{ data: appInfos, status },
|
{ data: appInfos, status },
|
||||||
{ data: tag_name, status: releaseStatus, isLoading },
|
{ data: tag_name, status: releaseStatus, isLoading },
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import { LoadingIndicatorPage, RBACProviderContext } from '@strapi/helper-plugin
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { resetStore, setPermissions } from './actions';
|
import { resetStore, setPermissions } from './actions';
|
||||||
|
|
||||||
// TODO
|
|
||||||
const RBACProvider = ({ children, permissions, refetchPermissions }) => {
|
const RBACProvider = ({ children, permissions, refetchPermissions }) => {
|
||||||
const { allPermissions } = useSelector(state => state.rbacProvider);
|
const { allPermissions } = useSelector(state => state.rbacProvider);
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
class Plugin {
|
class Plugin {
|
||||||
constructor(pluginConf) {
|
constructor(pluginConf) {
|
||||||
this.apis = pluginConf.apis || {};
|
this.apis = pluginConf.apis || {};
|
||||||
// TODO
|
|
||||||
this.description = pluginConf.description;
|
this.description = pluginConf.description;
|
||||||
// TODO
|
|
||||||
this.icon = pluginConf.icon;
|
this.icon = pluginConf.icon;
|
||||||
// TODO
|
|
||||||
this.initializer = pluginConf.initializer || null;
|
this.initializer = pluginConf.initializer || null;
|
||||||
this.injectionZones = pluginConf.injectionZones || {};
|
this.injectionZones = pluginConf.injectionZones || {};
|
||||||
this.isReady = pluginConf.isReady !== undefined ? pluginConf.isReady : true;
|
this.isReady = pluginConf.isReady !== undefined ? pluginConf.isReady : true;
|
||||||
@ -15,10 +12,8 @@ class Plugin {
|
|||||||
this.mainComponent = pluginConf.mainComponent || null;
|
this.mainComponent = pluginConf.mainComponent || null;
|
||||||
// TODO
|
// TODO
|
||||||
this.menu = pluginConf.menu || null;
|
this.menu = pluginConf.menu || null;
|
||||||
// TODO
|
|
||||||
this.name = pluginConf.name;
|
this.name = pluginConf.name;
|
||||||
this.pluginId = pluginConf.id;
|
this.pluginId = pluginConf.id;
|
||||||
// TODO
|
|
||||||
this.pluginLogo = pluginConf.pluginLogo;
|
this.pluginLogo = pluginConf.pluginLogo;
|
||||||
// TODO
|
// TODO
|
||||||
this.settings = pluginConf.settings || null;
|
this.settings = pluginConf.settings || null;
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
import { render } from '@testing-library/react';
|
import { render } from '@testing-library/react';
|
||||||
|
import { fixtures } from '../../../../../admin-test-utils';
|
||||||
import StrapiApp from '../StrapiApp';
|
import StrapiApp from '../StrapiApp';
|
||||||
import appReducers from '../reducers';
|
import appReducers from '../reducers';
|
||||||
|
|
||||||
describe('ADMIN | StrapiApp', () => {
|
|
||||||
it('should render the app without plugins', () => {
|
|
||||||
const library = { fields: {}, components: {} };
|
const library = { fields: {}, components: {} };
|
||||||
const middlewares = { middlewares: [] };
|
const middlewares = { middlewares: [] };
|
||||||
const reducers = { reducers: appReducers };
|
const reducers = { reducers: appReducers };
|
||||||
|
|
||||||
|
describe('ADMIN | StrapiApp', () => {
|
||||||
|
it('should render the app without plugins', () => {
|
||||||
const app = StrapiApp({ middlewares, reducers, library });
|
const app = StrapiApp({ middlewares, reducers, library });
|
||||||
|
|
||||||
expect(render(app.render())).toMatchInlineSnapshot(`
|
expect(render(app.render())).toMatchInlineSnapshot(`
|
||||||
@ -144,4 +146,11 @@ describe('ADMIN | StrapiApp', () => {
|
|||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should create a valid store', () => {
|
||||||
|
const app = StrapiApp({ middlewares, reducers, library });
|
||||||
|
|
||||||
|
const store = app.createStore();
|
||||||
|
expect(store.getState()).toEqual(fixtures.store);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
|
import { fixtures } from '../../../../../admin-test-utils';
|
||||||
import { selectPermissions, selectCollectionTypePermissions } from '../selectors';
|
import { selectPermissions, selectCollectionTypePermissions } from '../selectors';
|
||||||
|
|
||||||
describe('selectors', () => {
|
describe('selectors', () => {
|
||||||
let store;
|
let store;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
store = {};
|
store = { ...fixtures.store };
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('selectPermissions', () => {
|
describe('selectPermissions', () => {
|
||||||
@ -25,13 +26,8 @@ describe('selectors', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('selectCollectionTypePermissions', () => {
|
describe('selectCollectionTypePermissions', () => {
|
||||||
// TODO add store fixture
|
|
||||||
it('resolves the permissions key of the "rbacProvider" store key', () => {
|
it('resolves the permissions key of the "rbacProvider" store key', () => {
|
||||||
store.rbacProvider = {
|
store.rbacProvider.collectionTypesRelatedPermissions.some = 'permission again';
|
||||||
collectionTypesRelatedPermissions: {
|
|
||||||
some: 'permission again',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const actual = selectCollectionTypePermissions(store);
|
const actual = selectCollectionTypePermissions(store);
|
||||||
const expected = {
|
const expected = {
|
||||||
|
|||||||
@ -21,9 +21,7 @@ export default {
|
|||||||
description: pluginDescription,
|
description: pluginDescription,
|
||||||
icon,
|
icon,
|
||||||
id: pluginId,
|
id: pluginId,
|
||||||
// TODO
|
|
||||||
isReady: true,
|
isReady: true,
|
||||||
// TODO
|
|
||||||
isRequired: pluginPkg.strapi.required || false,
|
isRequired: pluginPkg.strapi.required || false,
|
||||||
// TODO
|
// TODO
|
||||||
mainComponent: App,
|
mainComponent: App,
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { fixtures } from '../../../../../../admin-test-utils';
|
||||||
import addCommonFieldsToInitialDataMiddleware from '../addCommonFieldsToInitialDataMiddleware';
|
import addCommonFieldsToInitialDataMiddleware from '../addCommonFieldsToInitialDataMiddleware';
|
||||||
|
|
||||||
jest.mock('@strapi/helper-plugin', () => ({
|
jest.mock('@strapi/helper-plugin', () => ({
|
||||||
@ -14,13 +15,12 @@ describe('i18n | middlewares | addCommonFieldsToInitialDataMiddleware', () => {
|
|||||||
const dispatch = jest.fn();
|
const dispatch = jest.fn();
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const store = {};
|
const store = {
|
||||||
|
...fixtures.store,
|
||||||
store['content-manager_editViewCrudReducer'] = {
|
'content-manager_editViewCrudReducer': {
|
||||||
contentTypeDataStructure: { name: 'test', common: 'common default value' },
|
contentTypeDataStructure: { name: 'test', common: 'common default value' },
|
||||||
};
|
},
|
||||||
|
'content-manager_editViewLayoutManager': {
|
||||||
store['content-manager_editViewLayoutManager'] = {
|
|
||||||
currentLayout: {
|
currentLayout: {
|
||||||
components: {},
|
components: {},
|
||||||
contentType: {
|
contentType: {
|
||||||
@ -31,6 +31,7 @@ describe('i18n | middlewares | addCommonFieldsToInitialDataMiddleware', () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
getState = () => store;
|
getState = () => store;
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
|
import { fixtures } from '../../../../../../admin-test-utils';
|
||||||
import addLocaleColumnToListViewMiddleware from '../addLocaleColumnToListViewMiddleware';
|
import addLocaleColumnToListViewMiddleware from '../addLocaleColumnToListViewMiddleware';
|
||||||
|
|
||||||
describe('addLocaleColumnToListViewMiddleware', () => {
|
describe('addLocaleColumnToListViewMiddleware', () => {
|
||||||
let getState;
|
let getState;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const store = {};
|
const store = { ...fixtures.store, i18n_locales: { locales: [] } };
|
||||||
|
|
||||||
store.i18n_locales = { locales: [] };
|
|
||||||
|
|
||||||
getState = () => store;
|
getState = () => store;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,23 +1,25 @@
|
|||||||
|
import { fixtures } from '../../../../../../admin-test-utils';
|
||||||
import addLocaleToCollectionTypesMiddleware from '../addLocaleToCollectionTypesMiddleware';
|
import addLocaleToCollectionTypesMiddleware from '../addLocaleToCollectionTypesMiddleware';
|
||||||
|
|
||||||
describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
||||||
let getState;
|
let getState;
|
||||||
|
let store;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const store = {
|
store = {
|
||||||
|
...fixtures.store,
|
||||||
i18n_locales: { locales: [] },
|
i18n_locales: { locales: [] },
|
||||||
rbacProvider: {
|
};
|
||||||
allPermissions: [],
|
store.rbacProvider.allPermissions = [];
|
||||||
collectionTypesRelatedPermissions: {
|
|
||||||
|
store.rbacProvider.collectionTypesRelatedPermissions = {
|
||||||
test: {
|
test: {
|
||||||
'plugins::content-manager.explorer.read': [],
|
'plugins::content-manager.explorer.read': [],
|
||||||
'plugins::content-manager.explorer.create': [],
|
'plugins::content-manager.explorer.create': [],
|
||||||
},
|
},
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
getState = () => store;
|
getState = jest.fn(() => store);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should forward the action when the type is undefined', () => {
|
it('should forward the action when the type is undefined', () => {
|
||||||
@ -76,18 +78,10 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should add a search key with the default locale when the user has the right to read it', () => {
|
it('should add a search key with the default locale when the user has the right to read it', () => {
|
||||||
const tempStore = {
|
store.i18n_locales = { locales: [{ code: 'en', isDefault: true }] };
|
||||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
store.rbacProvider.collectionTypesRelatedPermissions.test[
|
||||||
rbacProvider: {
|
'plugins::content-manager.explorer.read'
|
||||||
allPermissions: [],
|
] = [{ properties: { locales: ['en'] } }];
|
||||||
collectionTypesRelatedPermissions: {
|
|
||||||
test: {
|
|
||||||
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
|
|
||||||
'plugins::content-manager.explorer.create': [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const action = {
|
const action = {
|
||||||
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
||||||
@ -96,7 +90,7 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
|||||||
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const middleware = addLocaleToCollectionTypesMiddleware()({ getState: () => tempStore });
|
const middleware = addLocaleToCollectionTypesMiddleware()({ getState });
|
||||||
|
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
|
|
||||||
@ -116,17 +110,10 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should set the isDisplayed key to false when the user does not have the right to read any locale', () => {
|
it('should set the isDisplayed key to false when the user does not have the right to read any locale', () => {
|
||||||
const tempStore = {
|
store.i18n_locales.locales = [{ code: 'en', isDefault: true }];
|
||||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
store.rbacProvider.collectionTypesRelatedPermissions.test[
|
||||||
rbacProvider: {
|
'plugins::content-manager.explorer.read'
|
||||||
allPermissions: [],
|
] = [{ properties: { locales: [] } }];
|
||||||
collectionTypesRelatedPermissions: {
|
|
||||||
test: {
|
|
||||||
'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const action = {
|
const action = {
|
||||||
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
||||||
@ -137,7 +124,7 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
|||||||
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const middleware = addLocaleToCollectionTypesMiddleware()({ getState: () => tempStore });
|
const middleware = addLocaleToCollectionTypesMiddleware()({ getState });
|
||||||
|
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
|
|
||||||
@ -161,18 +148,10 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should keep the previous search', () => {
|
it('should keep the previous search', () => {
|
||||||
const tempStore = {
|
store.i18n_locales.locales = [{ code: 'en', isDefault: true }];
|
||||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
store.rbacProvider.collectionTypesRelatedPermissions.test[
|
||||||
rbacProvider: {
|
'plugins::content-manager.explorer.read'
|
||||||
allPermissions: [],
|
] = [{ properties: { locales: ['en'] } }];
|
||||||
collectionTypesRelatedPermissions: {
|
|
||||||
test: {
|
|
||||||
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
|
|
||||||
'plugins::content-manager.explorer.create': [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const action = {
|
const action = {
|
||||||
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
||||||
@ -183,7 +162,7 @@ describe('i18n | middlewares | addLocaleToCollectionTypesMiddleware', () => {
|
|||||||
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const middleware = addLocaleToCollectionTypesMiddleware()({ getState: () => tempStore });
|
const middleware = addLocaleToCollectionTypesMiddleware()({ getState });
|
||||||
|
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
|
|
||||||
|
|||||||
@ -1,23 +1,25 @@
|
|||||||
|
import { fixtures } from '../../../../../../admin-test-utils';
|
||||||
import addLocaleToSingleTypesMiddleware from '../addLocaleToSingleTypesMiddleware';
|
import addLocaleToSingleTypesMiddleware from '../addLocaleToSingleTypesMiddleware';
|
||||||
|
|
||||||
describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
||||||
let getState;
|
let getState;
|
||||||
|
let store;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const store = {
|
store = {
|
||||||
|
...fixtures.store,
|
||||||
i18n_locales: { locales: [] },
|
i18n_locales: { locales: [] },
|
||||||
rbacProvider: {
|
};
|
||||||
allPermissions: [],
|
store.rbacProvider.allPermissions = [];
|
||||||
collectionTypesRelatedPermissions: {
|
|
||||||
|
store.rbacProvider.collectionTypesRelatedPermissions = {
|
||||||
test: {
|
test: {
|
||||||
'plugins::content-manager.explorer.read': [],
|
'plugins::content-manager.explorer.read': [],
|
||||||
'plugins::content-manager.explorer.create': [],
|
'plugins::content-manager.explorer.create': [],
|
||||||
},
|
},
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
getState = () => store;
|
getState = jest.fn(() => store);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should forward the action when the type is undefined', () => {
|
it('should forward the action when the type is undefined', () => {
|
||||||
@ -76,18 +78,10 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should add a search key with the default locale when the user has the right to read it', () => {
|
it('should add a search key with the default locale when the user has the right to read it', () => {
|
||||||
const tempStore = {
|
store.i18n_locales.locales = [{ code: 'en', isDefault: true }];
|
||||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
store.rbacProvider.collectionTypesRelatedPermissions.test[
|
||||||
rbacProvider: {
|
'plugins::content-manager.explorer.read'
|
||||||
allPermissions: [],
|
] = [{ properties: { locales: ['en'] } }];
|
||||||
collectionTypesRelatedPermissions: {
|
|
||||||
test: {
|
|
||||||
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
|
|
||||||
'plugins::content-manager.explorer.create': [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const action = {
|
const action = {
|
||||||
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
||||||
@ -96,7 +90,7 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
|||||||
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const middleware = addLocaleToSingleTypesMiddleware()({ getState: () => tempStore });
|
const middleware = addLocaleToSingleTypesMiddleware()({ getState });
|
||||||
|
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
|
|
||||||
@ -116,28 +110,11 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should set the isDisplayed key to false when the user does not have the right to read any locale', () => {
|
it('should set the isDisplayed key to false when the user does not have the right to read any locale', () => {
|
||||||
const tempStore = {
|
store.i18n_locales.locales = [{ code: 'en', isDefault: true }];
|
||||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
store.rbacProvider.collectionTypesRelatedPermissions.test[
|
||||||
rbacProvider: {
|
'plugins::content-manager.explorer.read'
|
||||||
allPermissions: [],
|
] = [{ properties: { locales: [] } }];
|
||||||
collectionTypesRelatedPermissions: {
|
|
||||||
test: {
|
|
||||||
'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }],
|
|
||||||
'plugins::content-manager.explorer.create': [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
// tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] });
|
|
||||||
// tempStore.set('rbacProvider', { allPermissions: [] });
|
|
||||||
// tempStore.set('rbacProvider', {
|
|
||||||
// collectionTypesRelatedPermissions: {
|
|
||||||
// test: {
|
|
||||||
// 'plugins::content-manager.explorer.read': [{ properties: { locales: [] } }],
|
|
||||||
// 'plugins::content-manager.explorer.create': [],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
const action = {
|
const action = {
|
||||||
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
||||||
data: {
|
data: {
|
||||||
@ -145,7 +122,7 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
|||||||
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const middleware = addLocaleToSingleTypesMiddleware()({ getState: () => tempStore });
|
const middleware = addLocaleToSingleTypesMiddleware()({ getState });
|
||||||
|
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
|
|
||||||
@ -163,28 +140,11 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should keep the previous search', () => {
|
it('should keep the previous search', () => {
|
||||||
const tempStore = {
|
store.i18n_locales.locales = [{ code: 'en', isDefault: true }];
|
||||||
i18n_locales: { locales: [{ code: 'en', isDefault: true }] },
|
store.rbacProvider.collectionTypesRelatedPermissions.test[
|
||||||
rbacProvider: {
|
'plugins::content-manager.explorer.read'
|
||||||
allPermissions: [],
|
] = [{ properties: { locales: ['en'] } }];
|
||||||
collectionTypesRelatedPermissions: {
|
|
||||||
test: {
|
|
||||||
'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
|
|
||||||
'plugins::content-manager.explorer.create': [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
// tempStore.set('i18n_locales', { locales: [{ code: 'en', isDefault: true }] });
|
|
||||||
// tempStore.set('rbacProvider', { allPermissions: [] });
|
|
||||||
// tempStore.set('rbacProvider', {
|
|
||||||
// collectionTypesRelatedPermissions: {
|
|
||||||
// test: {
|
|
||||||
// 'plugins::content-manager.explorer.read': [{ properties: { locales: ['en'] } }],
|
|
||||||
// 'plugins::content-manager.explorer.create': [],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
const action = {
|
const action = {
|
||||||
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
type: 'StrapiAdmin/LeftMenu/SET_CT_OR_ST_LINKS',
|
||||||
data: {
|
data: {
|
||||||
@ -194,7 +154,7 @@ describe('i18n | middlewares | addLocaleToSingleTypesMiddleware', () => {
|
|||||||
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
contentTypeSchemas: [{ uid: 'test', pluginOptions: { i18n: { localized: true } } }],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const middleware = addLocaleToSingleTypesMiddleware()({ getState: () => tempStore });
|
const middleware = addLocaleToSingleTypesMiddleware()({ getState });
|
||||||
|
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
import { fixtures } from '../../../../../../admin-test-utils';
|
||||||
|
import selectCollectionTypePermissions from '../selectCollectionTypesRelatedPermissions';
|
||||||
|
import selectI18NLocales from '../selectI18NLocales';
|
||||||
|
|
||||||
|
describe('i18n | selectors | selectCollectionTypePermissions', () => {
|
||||||
|
let store;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
store = { ...fixtures.store };
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves the permissions key of the "rbacProvider.collectionTypesRelatedPermissions" store key', () => {
|
||||||
|
const actual = selectCollectionTypePermissions(store);
|
||||||
|
|
||||||
|
expect(actual).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('i18n | selectors | selectI18NLocales', () => {
|
||||||
|
let store;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
store = { ...fixtures.store, i18n_locales: { isLoading: true, locales: [] } };
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves the permissions key of the "i18n_locales" store key', () => {
|
||||||
|
const actual = selectI18NLocales(store);
|
||||||
|
|
||||||
|
expect(actual).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user