test fixing

This commit is contained in:
mfrachet 2021-03-18 12:46:11 +01:00
parent 2884b3594b
commit fd00987eff

View File

@ -56,6 +56,7 @@ describe('localeQueryParamsMiddleware', () => {
const nextFn = jest.fn(); const nextFn = jest.fn();
const action = { const action = {
type: 'ContentManager/ListView/SET_LIST_LAYOUT ', type: 'ContentManager/ListView/SET_LIST_LAYOUT ',
displayedHeaders: [],
contentType: { contentType: {
pluginOptions: { pluginOptions: {
i18n: { localized: true }, i18n: { localized: true },
@ -67,11 +68,13 @@ describe('localeQueryParamsMiddleware', () => {
middleware(nextFn)(action); middleware(nextFn)(action);
expect(nextFn).toBeCalledWith(action); expect(nextFn).toBeCalledWith(action);
expect(action).toEqual({ // The anonymous function of cellFormatter creates problem, because it's anonymous
contentType: { pluginOptions: { i18n: { localized: true } } }, // In our scenario, it's even more tricky because we use a closure in order to pass
initialParams: { plugins: { i18n: { locale: null } } }, // the locales.
type: 'ContentManager/ListView/SET_LIST_LAYOUT ', // 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', () => { 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 nextFn = jest.fn();
const action = { const action = {
type: 'ContentManager/ListView/SET_LIST_LAYOUT ', type: 'ContentManager/ListView/SET_LIST_LAYOUT ',
displayedHeaders: [],
contentType: { contentType: {
pluginOptions: { pluginOptions: {
i18n: { localized: true }, i18n: { localized: true },
@ -94,10 +98,8 @@ describe('localeQueryParamsMiddleware', () => {
middleware(nextFn)(action); middleware(nextFn)(action);
expect(nextFn).toBeCalledWith(action); expect(nextFn).toBeCalledWith(action);
expect(action).toEqual({ expect(JSON.stringify(action)).toBe(
contentType: { pluginOptions: { i18n: { localized: true } } }, '{"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}}}}'
initialParams: { plugins: { i18n: { locale: null }, hello: 'world' } }, );
type: 'ContentManager/ListView/SET_LIST_LAYOUT ',
});
}); });
}); });