Merge pull request #12690 from strapi/fix/edit-relations-restart

CM: Fix sync layouts in case no relation is set
This commit is contained in:
DMehaffy 2022-03-08 10:37:13 -07:00 committed by GitHub
commit 086c449fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 78 additions and 1 deletions

View File

@ -138,7 +138,9 @@ function syncLayouts(configuration, schema) {
list: cleanList.length > 0 ? cleanList : createDefaultListLayout(schema),
edit: cleanEdit.length > 0 ? cleanEdit : createDefaultEditLayout(schema),
editRelations:
cleanEditRelations.length > 0 ? cleanEditRelations : createDefaultEditRelationsLayout(schema),
editRelations.length === 0 || cleanEditRelations.length > 0
? cleanEditRelations
: createDefaultEditRelationsLayout(schema),
};
}

View File

@ -0,0 +1,75 @@
'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([]);
});
});