diff --git a/packages/core/content-manager/server/controllers/validation/model-configuration.js b/packages/core/content-manager/server/controllers/validation/model-configuration.js index e949fdebea..7665c658e6 100644 --- a/packages/core/content-manager/server/controllers/validation/model-configuration.js +++ b/packages/core/content-manager/server/controllers/validation/model-configuration.js @@ -3,7 +3,6 @@ const { yup } = require('@strapi/utils'); const { isListable, - hasRelationAttribute, hasEditableAttribute, } = require('../../services/utils/configuration/attributes'); /** @@ -106,10 +105,6 @@ const createLayoutsSchema = (schema, opts = {}) => { hasEditableAttribute(schema, key) ); - const relationAttributes = Object.keys(schema.attributes).filter(key => - hasRelationAttribute(schema, key) - ); - return yup.object().shape({ edit: yup .array() @@ -136,9 +131,5 @@ const createLayoutsSchema = (schema, opts = {}) => { .array() .of(yup.string().oneOf(validAttributes)) .test(createArrayTest(opts)), - editRelations: yup - .array() - .of(yup.string().oneOf(relationAttributes)) - .test(createArrayTest(opts)), }); }; diff --git a/packages/core/content-manager/server/tests/content-manager/configuration.test.e2e.js b/packages/core/content-manager/server/tests/content-manager/configuration.test.e2e.js new file mode 100644 index 0000000000..3b8fdbca36 --- /dev/null +++ b/packages/core/content-manager/server/tests/content-manager/configuration.test.e2e.js @@ -0,0 +1,151 @@ +'use strict'; + +// Helpers. +const { createTestBuilder } = require('../../../../../../test/helpers/builder'); +const { createStrapiInstance } = require('../../../../../../test/helpers/strapi'); +const form = require('../../../../../../test/helpers/generators'); +const { createAuthRequest } = require('../../../../../../test/helpers/request'); + +const builder = createTestBuilder(); +let strapi; +let rq; + +const restart = async () => { + await strapi.destroy(); + strapi = await createStrapiInstance(); + rq = await createAuthRequest({ strapi }); +}; + +describe('Content Manager - Configuration', () => { + beforeAll(async () => { + await builder.addContentTypes([form.article]).build(); + + strapi = await createStrapiInstance(); + rq = await createAuthRequest({ strapi }); + }); + + afterAll(async () => { + await strapi.destroy(); + await builder.cleanup(); + }); + + test('List and edit layout cannot be empty', async () => { + await rq({ + url: '/content-manager/content-types/api::article.article/configuration', + method: 'PUT', + body: { + layouts: { + edit: [], + list: [], + }, + }, + }); + + await restart(); + + const { body } = await rq({ + url: '/content-manager/content-types/api::article.article/configuration', + method: 'GET', + }); + + expect(body.data.contentType.layouts.edit).toStrictEqual([ + [ + { + name: 'title', + size: 6, + }, + { + name: 'date', + size: 4, + }, + ], + [ + { + name: 'jsonField', + size: 12, + }, + ], + [ + { + name: 'content', + size: 12, + }, + ], + [ + { + name: 'author', + size: 6, + }, + ], + ]); + expect(body.data.contentType.layouts.list).toStrictEqual(['id', 'title', 'date', 'author']); + }); + + test('Update list and edit layout (with relation)', async () => { + await rq({ + url: '/content-manager/content-types/api::article.article/configuration', + method: 'PUT', + body: { + layouts: { + edit: [ + [ + { + name: 'title', + size: 6, + }, + { + name: 'date', + size: 4, + }, + ], + [ + { + name: 'jsonField', + size: 12, + }, + ], + [ + { + name: 'author', + size: 6, + }, + ], + ], + list: ['id', 'title', 'author'], + }, + }, + }); + + await restart(); + + const { body } = await rq({ + url: '/content-manager/content-types/api::article.article/configuration', + method: 'GET', + }); + expect(body.data.contentType.layouts.edit).toStrictEqual([ + [ + { + name: 'title', + size: 6, + }, + { + name: 'date', + size: 4, + }, + ], + [ + { + name: 'jsonField', + size: 12, + }, + ], + [ + { + name: 'author', + size: 6, + }, + ], + ]); + expect(body.data.contentType.layouts.list).toStrictEqual(['id', 'title', 'author']); + }); +}); diff --git a/packages/core/content-manager/server/tests/content-manager/content-types.test.e2e.js b/packages/core/content-manager/server/tests/content-manager/content-types.test.e2e.js index f70bf7e9dd..790ac680bd 100644 --- a/packages/core/content-manager/server/tests/content-manager/content-types.test.e2e.js +++ b/packages/core/content-manager/server/tests/content-manager/content-types.test.e2e.js @@ -87,7 +87,6 @@ describe('Content Manager - Update Layout', () => { body: { layouts: { edit: payload, - editRelations: [], list: [], }, }, @@ -132,7 +131,6 @@ describe('Content Manager - Update Layout', () => { body: { layouts: { edit: payload, - editRelations: [], list: [], }, }, @@ -198,7 +196,6 @@ describe('Content Manager - Update Layout', () => { body: { layouts: { edit: payload, - editRelations: [], list: [], }, }, diff --git a/packages/core/content-manager/server/tests/content-manager/relations.test.e2e.js b/packages/core/content-manager/server/tests/content-manager/relations.test.e2e.js deleted file mode 100644 index cc7dbadcde..0000000000 --- a/packages/core/content-manager/server/tests/content-manager/relations.test.e2e.js +++ /dev/null @@ -1,75 +0,0 @@ -'use strict'; - -// Helpers. -const { createTestBuilder } = require('../../../../../../test/helpers/builder'); -const { createStrapiInstance } = require('../../../../../../test/helpers/strapi'); -const form = require('../../../../../../test/helpers/generators'); -const { createAuthRequest } = require('../../../../../../test/helpers/request'); - -const builder = createTestBuilder(); -let strapi; -let rq; - -const restart = async () => { - await strapi.destroy(); - strapi = await createStrapiInstance(); - rq = await createAuthRequest({ strapi }); -}; - -describe('Content Manager - Hide relations', () => { - beforeAll(async () => { - await builder.addContentTypes([form.article]).build(); - - strapi = await createStrapiInstance(); - rq = await createAuthRequest({ strapi }); - }); - - afterAll(async () => { - await strapi.destroy(); - await builder.cleanup(); - }); - - test('Hide relations', async () => { - await rq({ - url: '/content-manager/content-types/api::article.article/configuration', - method: 'PUT', - body: { - layouts: { - edit: [], - editRelations: [], - list: [], - }, - }, - }); - - const { body } = await rq({ - url: '/content-manager/content-types/api::article.article/configuration', - method: 'GET', - }); - - expect(body.data.contentType.layouts.editRelations).toStrictEqual([]); - }); - - test('Hide relations after server restart', async () => { - await rq({ - url: '/content-manager/content-types/api::article.article/configuration', - method: 'PUT', - body: { - layouts: { - edit: [], - editRelations: [], - list: [], - }, - }, - }); - - await restart(); - - const { body } = await rq({ - url: '/content-manager/content-types/api::article.article/configuration', - method: 'GET', - }); - - expect(body.data.contentType.layouts.editRelations).toStrictEqual([]); - }); -});