Skip to content

Commit

Permalink
Make implicit consent vendor work for consent story
Browse files Browse the repository at this point in the history
Include test consent vendor in seed for consent story that resembles
server rendered data and include content element id in
`contentElementConsentVendors`.

REDMINE-20438
  • Loading branch information
tf committed Sep 21, 2023
1 parent 6b01e4a commit c83f299
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,20 @@ describe('exampleStories', () => {

expect(stories).toContainEqual(expect.objectContaining({
title: 'Consent - Opt-In',
requireConsentOptIn: true
requireConsentOptIn: true,
seed: expect.objectContaining({
config: expect.objectContaining({
consentVendors: [
expect.objectContaining({name: 'test'})
],
contentElementConsentVendors: {1000: 'test'}
}),
collections: expect.objectContaining({
contentElements: expect.arrayContaining([
expect.objectContaining({id: 1000})
])
})
})
}));
});
});
Expand Down
41 changes: 34 additions & 7 deletions entry_types/scrolled/package/spec/support/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,25 @@ function consentOptInStories({typeName, consent, baseConfiguration}) {
return exampleStoryGroup({
typeName,
name: 'Consent',
requireConsentOptIn: true,
consentVendors: [
{
name: 'test',
optInPrompt: 'I agree with being shown this content.'
}
],
examples: [
{
name: 'Opt-In',
contentElementConfiguration: baseConfiguration
contentElementConfiguration: {
...baseConfiguration,
...consent.configuration
}
}
]
});
}

function exampleStoryGroup({name, typeName, examples, parameters, requireConsentOptIn}) {
function exampleStoryGroup({name, typeName, examples, parameters, consentVendors}) {
const defaultSectionConfiguration = {transition: 'scroll', backdrop: {image: '#000'}, fullHeight: false};

const sections = examples.map((example, index) => ({
Expand All @@ -266,17 +274,30 @@ function exampleStoryGroup({name, typeName, examples, parameters, requireConsent
const contentElements = examples.reduce((memo, example, index) => [
...memo,
exampleHeading({sectionId: index, text: `${name} - ${example.name}`}),
{sectionId: index, typeName, configuration: example.contentElementConfiguration}
{
id: 1000 + index,
sectionId: index,
typeName,
configuration: example.contentElementConfiguration
}
], []);

return sections.map((section, index) => ({
title: `${name} - ${examples[index].name}`,
seed: normalizeAndMergeFixture({
sections: [section],
contentElements: contentElements,
themeOptions: examples[index].themeOptions
themeOptions: examples[index].themeOptions,
consentVendors,
contentElementConsentVendors: consentVendors &&
contentElements
.filter(({id}) => id)
.reduce(
(memo, {id}) => ({...memo, [id]: consentVendors[0].name}),
{}
)
}),
requireConsentOptIn,
requireConsentOptIn: !!consentVendors,
parameters,
cssRules: Object.entries(examples[index].themeOptions?.properties || {}).reduce(
(result, [scope, properties]) => {
Expand Down Expand Up @@ -308,7 +329,13 @@ export function normalizeAndMergeFixture(options = {}) {
...seedFixture,
config: mergeDeep(
seedFixture.config,
{theme: {options: options.themeOptions || {}}}
{
theme: {
options: options.themeOptions || {}
},
consentVendors: options.consentVendors || [],
contentElementConsentVendors: options.contentElementConsentVendors || {}
}
),
collections: {
...seedFixture.collections,
Expand Down

0 comments on commit c83f299

Please sign in to comment.