Skip to content

Commit

Permalink
MWPW-150610: implement partial load options in configurator (#3010)
Browse files Browse the repository at this point in the history
* Saving WIP

* Temporarily adding mock endpoint to test e2e

* Making panel for partial load settings toggle

* Removing accidentally commited code

* Fixing linting issue

* Updating config to fix unit tests

* Fixing linting + more test stuff

* Next attempt at fixing linting + tests
  • Loading branch information
sanrai authored Oct 22, 2024
1 parent dccf0b2 commit deae355
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libs/blocks/caas-config/caas-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ const defaultOptions = {
default: 'Default',
grow: 'Grow',
},
partialLoadEnabled: {
true: 'Enabled',
false: 'Disabled',
},
};

const getTagList = (root) => Object.entries(root).reduce((options, [, tag]) => {
Expand Down Expand Up @@ -344,6 +348,9 @@ const BasicsPanel = ({ tagsData }) => {
<${Select} options=${countryTags} prop="country" label="Country" sort />
<${Select} options=${languageTags} prop="language" label="Language" sort />`;

const partialLoadOptions = html`
<${Input} label="Partial Load Count" prop="partialLoadCount" type="number" />`;

return html`
<${Input} label="Collection Name" placeholder="Only used in the author link" prop="collectionName" type="text" />
<${Input} label="Collection Title" prop="collectionTitle" type="text" title="Enter a title, {placeholder}, or leave empty "/>
Expand All @@ -353,7 +360,8 @@ const BasicsPanel = ({ tagsData }) => {
<${Input} label="Total Cards to Show" prop="totalCardsToShow" type="number" />
<${Input} label="Auto detect country & lang" prop="autoCountryLang" type="checkbox" />
${!state.autoCountryLang && countryLangOptions}
<${Input} label="Partial Load Enabled" prop="partialLoadEnabled" options="${defaultOptions.partialLoadEnabled}" type="checkbox" />
${state.partialLoadEnabled && partialLoadOptions}
`;
};

Expand Down
6 changes: 6 additions & 0 deletions libs/blocks/caas/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,10 @@ export const getConfig = async (originalState, strs = {}) => {
setCardBorders: state.setCardBorders,
showFooterDivider: state.showFooterDivider,
useOverlayLinks: state.useOverlayLinks,
partialLoadWithBackgroundFetch: {
enabled: state.partialLoadEnabled,
partialLoadCount: state.partialLoadCount,
},
collectionButtonStyle: state.collectionBtnStyle,
banner: {
register: {
Expand Down Expand Up @@ -819,6 +823,8 @@ export const defaultState = {
paginationQuantityShown: false,
paginationType: 'paginator',
paginationUseTheme3: false,
partialLoadEnabled: false,
partialLoadCount: 100,
placeholderUrl: '',
resultsPerPage: 5,
searchFields: [],
Expand Down
4 changes: 4 additions & 0 deletions test/blocks/caas-config/expectedConfigs/defaultConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const defaultConfig = {
collection: {
mode: 'lightest',
partialLoadWithBackgroundFetch: {
enabled: false,
partialLoadCount: 100,
},
layout: { type: '4up', gutter: '4x', container: '1200MaxWidth' },
button: { style: 'primary' },
collectionButtonStyle: 'primary',
Expand Down
1 change: 1 addition & 0 deletions test/blocks/caas/caas.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
expect(loadStyle.callCount).to.equal(1);
expect(caasEl).to.equal(document.getElementById('caas'));
});

});
});
</script>
Expand Down
27 changes: 27 additions & 0 deletions test/blocks/caas/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ describe('getConfig', () => {
expect(config).to.be.eql({
collection: {
mode: 'lightest',
partialLoadWithBackgroundFetch: {
enabled: false,
partialLoadCount: 100,
},
layout: { type: '4up', gutter: '4x', container: '1200MaxWidth' },
button: { style: 'primary' },
collectionButtonStyle: 'primary',
Expand Down Expand Up @@ -426,6 +430,10 @@ describe('getConfig', () => {
expect(config).to.be.eql({
collection: {
mode: 'lightest',
partialLoadWithBackgroundFetch: {
enabled: false,
partialLoadCount: 100,
},
layout: { type: '4up', gutter: '4x', container: '1200MaxWidth' },
button: { style: 'primary' },
collectionButtonStyle: 'primary',
Expand Down Expand Up @@ -740,6 +748,21 @@ describe('getCountryAndLang', () => {
locales: '',
});
});

it('should include partial load settings in the config', async () => {
const state = {
...defaultState,
partialLoadEnabled: true,
partialLoadCount: 75,
};

const config = await getConfig(state, strings);

expect(config.collection.partialLoadWithBackgroundFetch).to.deep.equal({
enabled: true,
partialLoadCount: 75,
});
});
});

describe('getFloodgateCaasConfig', () => {
Expand All @@ -752,6 +775,10 @@ describe('getFloodgateCaasConfig', () => {
expect(caasFgConfig).to.be.eql({
collection: {
mode: 'lightest',
partialLoadWithBackgroundFetch: {
enabled: false,
partialLoadCount: 100,
},
layout: { type: '4up', gutter: '4x', container: '1200MaxWidth' },
button: { style: 'primary' },
collectionButtonStyle: 'primary',
Expand Down

0 comments on commit deae355

Please sign in to comment.