Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sitecore-jss-react] Fix rendering issue in components using withPlaceholder #1349

Merged
merged 2 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export class PlaceholderCommon<T extends PlaceholderProps> extends React.Compone
}

getSXAParams(rendering: ComponentRendering) {
if (!rendering.params) return {};
return (
rendering.params.FieldNames && {
styles: `${rendering.params.GridParameters || ''} ${rendering.params.Styles || ''}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import React, { ReactElement } from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import { altData, convertedDevData as nonEeDevData } from '../test-data/non-ee-data';
import { convertedDevData as nonEeDevData } from '../test-data/non-ee-data';
import { convertedDevDataWithoutParams as nonEeDevDataWithoutParams } from '../test-data/non-ee-data';
import { convertedDataWithoutParams as eeDataWithoutParams } from '../test-data/ee-data';
import { convertedData as eeData } from '../test-data/ee-data';
import { withPlaceholder } from '../enhancers/withPlaceholder';
import { SitecoreContext } from '../components/SitecoreContext';
Expand Down Expand Up @@ -91,6 +93,11 @@ const testData = [
{ label: 'LayoutService data - EE on', data: eeData },
];

const testDataWithoutParams = [
{ label: 'Dev data without params', data: nonEeDevDataWithoutParams },
{ label: 'LayoutService data - EE on without params', data: eeDataWithoutParams },
];

describe('withPlaceholder HOC', () => {
describe('Error handling', () => {
it('should render default error component on wrapped component error', () => {
Expand Down Expand Up @@ -193,4 +200,29 @@ describe('withPlaceholder HOC', () => {
});
});
});

testDataWithoutParams.forEach((dataSet) => {
describe(`with ${dataSet.label}`, () => {
it('should render a placeholder with given key when params are not passed', () => {
const component = (dataSet.data.sitecore.route.placeholders.main as (
| ComponentRendering
| RouteData
)[]).find((c) => (c as ComponentRendering).componentName);
const phKey = 'page-content';
const props: PlaceholderProps = {
name: phKey,
rendering: component,
params: { test: 'test' },
addy-pathania marked this conversation as resolved.
Show resolved Hide resolved
componentFactory: componentFactory,
};
const Element = withPlaceholder(phKey)(Home);
const renderedComponent = mount(
<SitecoreContext componentFactory={componentFactory}>
<Element {...props} />
</SitecoreContext>
);
expect(renderedComponent.find('.download-callout-mock').length).to.equal(1);
});
});
});
});
Loading