From fd00987effcaeec9176c37c39cf9a8e29017f50d Mon Sep 17 00:00:00 2001 From: mfrachet Date: Thu, 18 Mar 2021 12:46:11 +0100 Subject: [PATCH] test fixing --- .../tests/localeQueryParamsMiddleware.test.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/strapi-plugin-i18n/admin/src/middlewares/tests/localeQueryParamsMiddleware.test.js b/packages/strapi-plugin-i18n/admin/src/middlewares/tests/localeQueryParamsMiddleware.test.js index 20ffddd889..b9f59ac754 100644 --- a/packages/strapi-plugin-i18n/admin/src/middlewares/tests/localeQueryParamsMiddleware.test.js +++ b/packages/strapi-plugin-i18n/admin/src/middlewares/tests/localeQueryParamsMiddleware.test.js @@ -56,6 +56,7 @@ describe('localeQueryParamsMiddleware', () => { const nextFn = jest.fn(); const action = { type: 'ContentManager/ListView/SET_LIST_LAYOUT ', + displayedHeaders: [], contentType: { pluginOptions: { i18n: { localized: true }, @@ -67,11 +68,13 @@ describe('localeQueryParamsMiddleware', () => { middleware(nextFn)(action); expect(nextFn).toBeCalledWith(action); - expect(action).toEqual({ - contentType: { pluginOptions: { i18n: { localized: true } } }, - initialParams: { plugins: { i18n: { locale: null } } }, - type: 'ContentManager/ListView/SET_LIST_LAYOUT ', - }); + // The anonymous function of cellFormatter creates problem, because it's anonymous + // In our scenario, it's even more tricky because we use a closure in order to pass + // the locales. + // Stringifying the action allows us to have a name inside the expectation for the "cellFormatter" key + expect(JSON.stringify(action)).toBe( + '{"type":"ContentManager/ListView/SET_LIST_LAYOUT ","displayedHeaders":[{"key":"__locale_key__","fieldSchema":{"type":"string"},"metadatas":{"label":"Content available in","searchable":false,"sortable":false},"name":"locales"}],"contentType":{"pluginOptions":{"i18n":{"localized":true}}},"initialParams":{"plugins":{"i18n":{"locale":null}}}}' + ); }); it('adds a key to plugins with a locale when initialParams has a plugins key and the field is localized', () => { @@ -79,6 +82,7 @@ describe('localeQueryParamsMiddleware', () => { const nextFn = jest.fn(); const action = { type: 'ContentManager/ListView/SET_LIST_LAYOUT ', + displayedHeaders: [], contentType: { pluginOptions: { i18n: { localized: true }, @@ -94,10 +98,8 @@ describe('localeQueryParamsMiddleware', () => { middleware(nextFn)(action); expect(nextFn).toBeCalledWith(action); - expect(action).toEqual({ - contentType: { pluginOptions: { i18n: { localized: true } } }, - initialParams: { plugins: { i18n: { locale: null }, hello: 'world' } }, - type: 'ContentManager/ListView/SET_LIST_LAYOUT ', - }); + expect(JSON.stringify(action)).toBe( + '{"type":"ContentManager/ListView/SET_LIST_LAYOUT ","displayedHeaders":[{"key":"__locale_key__","fieldSchema":{"type":"string"},"metadatas":{"label":"Content available in","searchable":false,"sortable":false},"name":"locales"}],"contentType":{"pluginOptions":{"i18n":{"localized":true}}},"initialParams":{"plugins":{"hello":"world","i18n":{"locale":null}}}}' + ); }); });