mirror of
https://github.com/strapi/strapi.git
synced 2025-07-05 16:12:18 +00:00

* feat: init new homepage with custom greeting (#22269) * feat: init new homepage * fix: e2e test * chore(homepage): move guided tour (#22338) * enhancement: create homepage widget component * enhancement(homepage): create recently edited documents endpoint (#22355) * chore: init recent documents route and controller * enhancement: add recently updated docs endpoint * chore: add endpoint types * chore: add api tests * fix: ts build * enhancement: add generic widget component * enhancement: add homepage recently edited widget * chore: add compound component * fix: unit test * enhancement: add no data state * enhancement: add no data variant * future(homepage): add generic widget component (#22369) * enhancement: create homepage widget component * enhancement: add generic widget component * chore: add compound component * fix: unit test * enhancement: add no data variant * fix: widget height * enhancement(homepage): get recent publish activity (#22377) * chore: tracking and a11y improvements * chore: add e2e tests * fix: more cache invalidation * chore: update api tests * fix: remove cm dependency * fix: broken status * enhancement(home): add recently published widget (#22391) * fix(home): replace title documentId with document title (#22403) * fix(home): make locale defined or null to get the correct status (#22405) * fix(homepage): make back button work when document has a locale (#22450) * release: 5.6.0 * Revert "release: 5.6.0" This reverts commit 77ad0efc79afd9777d140f84e8abc47cda26d1d9. * release: 5.6.0 * fix(homepage): add missing styles for error, loading, and empty states (#22448) * fix(homepage): add missing styles for error, loading, and empty states * fix: always include title and icon * chore: refactor to not rerender static content * chore: reuse table component * fix: single type link --------- Co-authored-by: Rémi de Juvigny <remi.dejuvigny@strapi.io> * fix: minor ui issues * fix: hide doc status when no d&p (#22409) * fix: hide doc status when no d&p * enhancement: show dash instead --------- Co-authored-by: Rémi de Juvigny <remi.dejuvigny@strapi.io> Co-authored-by: Rémi de Juvigny <8087692+remidej@users.noreply.github.com> * v5.7.0-beta.0 * fix: package versions * fix: package version --------- Co-authored-by: Mark Kaylor <mark.kaylor@strapi.io> Co-authored-by: Marc-Roig <marc12info@gmail.com>
259 lines
6.7 KiB
TypeScript
259 lines
6.7 KiB
TypeScript
'use strict';
|
|
|
|
import { createTestBuilder } from 'api-tests/builder';
|
|
import { createAuthRequest } from 'api-tests/request';
|
|
import { createStrapiInstance } from 'api-tests/strapi';
|
|
|
|
const articleUid = 'api::article.article';
|
|
const articleModel = {
|
|
kind: 'collectionType',
|
|
collectionName: 'articles',
|
|
singularName: 'article',
|
|
pluralName: 'articles',
|
|
displayName: 'Article',
|
|
description: '',
|
|
draftAndPublish: true,
|
|
pluginOptions: {
|
|
i18n: {
|
|
localized: true,
|
|
},
|
|
},
|
|
attributes: {
|
|
title: {
|
|
type: 'string',
|
|
pluginOptions: {
|
|
i18n: {
|
|
localized: true,
|
|
},
|
|
},
|
|
},
|
|
content: {
|
|
type: 'blocks',
|
|
pluginOptions: {
|
|
i18n: {
|
|
localized: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const authorUid = 'api::author.author';
|
|
const authorModel = {
|
|
kind: 'collectionType',
|
|
collectionName: 'authors',
|
|
singularName: 'author',
|
|
pluralName: 'authors',
|
|
displayName: 'Author',
|
|
description: '',
|
|
draftAndPublish: false,
|
|
pluginOptions: {
|
|
i18n: {
|
|
localized: true,
|
|
},
|
|
},
|
|
attributes: {
|
|
name: {
|
|
type: 'string',
|
|
pluginOptions: {
|
|
i18n: {
|
|
localized: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const tagUid = 'api::tag.tag';
|
|
const tagModel = {
|
|
kind: 'collectionType',
|
|
collectionName: 'tags',
|
|
singularName: 'tag',
|
|
pluralName: 'tags',
|
|
displayName: 'Tag',
|
|
description: '',
|
|
draftAndPublish: true,
|
|
pluginOptions: {
|
|
i18n: {
|
|
localized: true,
|
|
},
|
|
},
|
|
attributes: {
|
|
slug: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
};
|
|
|
|
const globalUid = 'api::global.global';
|
|
const globalModel = {
|
|
kind: 'singleType',
|
|
collectionName: 'globals',
|
|
singularName: 'global',
|
|
pluralName: 'globals',
|
|
displayName: 'Global',
|
|
description: '',
|
|
draftAndPublish: true,
|
|
attributes: {
|
|
siteName: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
};
|
|
|
|
describe('Homepage API', () => {
|
|
const builder = createTestBuilder();
|
|
let strapi;
|
|
let rq;
|
|
|
|
beforeAll(async () => {
|
|
await builder.addContentTypes([articleModel, globalModel, tagModel, authorModel]).build();
|
|
strapi = await createStrapiInstance();
|
|
rq = await createAuthRequest({ strapi });
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await strapi.destroy();
|
|
await builder.cleanup();
|
|
});
|
|
|
|
it('requires action param', async () => {
|
|
const response = await rq({
|
|
method: 'GET',
|
|
url: '/admin/homepage/recent-documents',
|
|
});
|
|
|
|
expect(response.statusCode).toBe(400);
|
|
expect(response.body).toMatchObject({
|
|
error: {
|
|
message: 'action is a required field',
|
|
},
|
|
});
|
|
});
|
|
|
|
it('finds the most recently updated documents', async () => {
|
|
// Create a global document so we can update it later
|
|
const globalDoc = await strapi.documents(globalUid).create({
|
|
data: {
|
|
siteName: 'a cool site name',
|
|
},
|
|
});
|
|
await strapi.documents(globalUid).publish({
|
|
documentId: globalDoc.documentId,
|
|
});
|
|
|
|
/**
|
|
* Create content in different content types. Use a loop with the modulo operator to alternate
|
|
* actions of different kinds, so we can then make sure that the list of recent documents
|
|
* has them all in the right order.
|
|
**/
|
|
for (let i = 0; i < 9; i++) {
|
|
if (i % 3 === 0) {
|
|
// When index is 0, 3, 6
|
|
await strapi.documents(articleUid).create({
|
|
data: {
|
|
title: `Article ${i}`,
|
|
content: [{ type: 'paragraph', children: [{ type: 'text', text: 'Hello world' }] }],
|
|
},
|
|
});
|
|
} else if (i % 3 === 1) {
|
|
// When index is 1, 4, 7
|
|
await strapi.documents(globalUid).update({
|
|
documentId: globalDoc.documentId,
|
|
status: 'draft',
|
|
data: {
|
|
siteName: `global-${i}`,
|
|
},
|
|
});
|
|
} else {
|
|
// When index is 2, 5, 8
|
|
await strapi.documents(authorUid).create({
|
|
data: {
|
|
name: `author-${i}`,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
const response = await rq({
|
|
method: 'GET',
|
|
url: '/admin/homepage/recent-documents?action=update',
|
|
});
|
|
|
|
// Assert the response
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.data).toHaveLength(4);
|
|
// Assert the document titles
|
|
expect(response.body.data[0].title).toBe('author-8');
|
|
expect(response.body.data[1].title).toBe('global-7');
|
|
expect(response.body.data[2].title).toBe('Article 6');
|
|
expect(response.body.data[3].title).toBe('author-5');
|
|
// Assert the document content type uids
|
|
expect(response.body.data[0].contentTypeUid).toBe('api::author.author');
|
|
expect(response.body.data[1].contentTypeUid).toBe('api::global.global');
|
|
expect(response.body.data[2].contentTypeUid).toBe('api::article.article');
|
|
expect(response.body.data[3].contentTypeUid).toBe('api::author.author');
|
|
// Assert the document statuses
|
|
expect(response.body.data[0].status).toBe(undefined);
|
|
expect(response.body.data[1].status).toBe('modified');
|
|
expect(response.body.data[2].status).toBe('draft');
|
|
expect(response.body.data[3].status).toBe(undefined);
|
|
});
|
|
|
|
it('finds the most recently published documents', async () => {
|
|
// Create draft and publish documents
|
|
const article = await strapi.documents(articleUid).create({
|
|
data: {
|
|
title: 'The Paperback Writer',
|
|
},
|
|
});
|
|
const tag = await strapi.documents(tagUid).create({
|
|
data: {
|
|
slug: 'Tag 1',
|
|
},
|
|
});
|
|
// Create non draft and publish document
|
|
const author = await strapi.documents(authorUid).create({
|
|
data: {
|
|
name: 'Paul McCartney',
|
|
},
|
|
});
|
|
|
|
// Publish the article
|
|
await strapi.documents(articleUid).publish({
|
|
documentId: article.documentId,
|
|
});
|
|
// Update published document to create a 'modified' status
|
|
await strapi.documents(articleUid).update({
|
|
documentId: article.documentId,
|
|
data: {
|
|
title: 'Paperback Writer',
|
|
},
|
|
});
|
|
await strapi.documents(tagUid).publish({
|
|
documentId: tag.documentId,
|
|
});
|
|
// Update the author (won't be included in the response)
|
|
await strapi.documents(authorUid).update({
|
|
documentId: author.documentId,
|
|
data: {
|
|
name: `John Lennon`,
|
|
},
|
|
});
|
|
|
|
const response = await rq({
|
|
method: 'GET',
|
|
url: '/admin/homepage/recent-documents?action=publish',
|
|
});
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.data).toHaveLength(3);
|
|
expect(response.body.data.every((doc) => doc.publishedAt)).not.toBe(null);
|
|
expect(response.body.data[0].title).toBe('Tag 1');
|
|
expect(response.body.data[0].status).toBe('published');
|
|
// Assert the data is the published data, but the status should be modified
|
|
expect(response.body.data[1].title).toBe('The Paperback Writer');
|
|
expect(response.body.data[1].status).toBe('modified');
|
|
});
|
|
});
|