Skip to content

Commit

Permalink
Add inline file rights variants to storybook
Browse files Browse the repository at this point in the history
REDMINE-20093
  • Loading branch information
tf committed Dec 11, 2023
1 parent da5c9ec commit a8e592f
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 9 deletions.
54 changes: 54 additions & 0 deletions entry_types/scrolled/package/spec/support/__spec__/stories-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ describe('exampleStories', () => {
})
}));
});

it('supports adding story for inline file rights', () => {
stubSeedFixture(normalizeSeed({
imageFiles: [
{id: 10, permaId: 1}
]
}));

const stories = exampleStories({
typeName: 'test',
inlineFileRights: true,
baseConfiguration: {}
});

expect(stories).toContainEqual(expect.objectContaining({
title: 'Inline File Rights - Icon',
seed: expect.objectContaining({
collections: expect.objectContaining({
imageFiles: expect.arrayContaining([
expect.objectContaining({
configuration: expect.objectContaining({rights_display: 'inline'})
})
]),
widgets: [
expect.objectContaining({
role: 'inlineFileRights',
typeName: 'iconInlineFileRights'
})
],
contentElements: expect.arrayContaining([
expect.objectContaining({id: 1000})
])
})
})
}));
});
});

describe('filePermaId', () => {
Expand Down Expand Up @@ -187,4 +223,22 @@ describe('normalizeAndMergeFixture', () => {
widgetPrimaryColor: '#f00'
})
});

it('supports inline file rights', () => {
stubSeedFixture(normalizeSeed({
imageFiles: [
{id: 10, permaId: 1}
]
}));

const seed = normalizeAndMergeFixture({inlineFileRightsFor: ['imageFiles']});

expect(seed.collections.imageFiles[0]).toMatchObject({
rights: 'Jane Doe',
configuration: {
rights_display: 'inline',
source_url: 'https://example.com/jane-doe/image'
}
})
});
})
56 changes: 53 additions & 3 deletions entry_types/scrolled/package/spec/support/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
} from 'pageflow-scrolled/frontend';
import {browser, Consent} from 'pageflow/frontend';

import '../../src/widgets/iconInlineFileRights';
import '../../src/widgets/textInlineFileRights';

import {normalizeSeed} from 'pageflow-scrolled/testHelpers';
import {storiesOf} from '@storybook/react';

Expand Down Expand Up @@ -164,7 +167,8 @@ export function exampleStories(options) {
...variantsExampleStories(options),
...layoutExampleStories(options),
...mobileExampleStories(options),
...consentOptInStories(options)
...consentOptInStories(options),
...inlineFileRightsStories(options)
];
}

Expand Down Expand Up @@ -263,7 +267,35 @@ function consentOptInStories({typeName, consent, baseConfiguration}) {
});
}

function exampleStoryGroup({name, typeName, examples, parameters, consentVendors}) {
function inlineFileRightsStories({typeName, inlineFileRights, baseConfiguration}) {
if (!inlineFileRights) {
return [];
}

return exampleStoryGroup({
typeName,
name: 'Inline File Rights',
inlineFileRightsFor: ['audioFiles', 'imageFiles', 'videoFiles'],
examples: [
['Icon', 'iconInlineFileRights'], ['Text', 'textInlineFileRights']
].map(([name, typeName]) => (
{
name,
widgets: [{
role: 'inlineFileRights',
typeName
}],
contentElementConfiguration: {
...baseConfiguration
}
}
))
});
}

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

const sections = examples.map((example, index) => ({
Expand All @@ -287,8 +319,10 @@ function exampleStoryGroup({name, typeName, examples, parameters, consentVendors
seed: normalizeAndMergeFixture({
sections: [section],
contentElements: contentElements,
widgets: examples[index].widgets,
themeOptions: examples[index].themeOptions,
consentVendors,
inlineFileRightsFor,
contentElementConsentVendors: consentVendors &&
contentElements
.filter(({id}) => id)
Expand Down Expand Up @@ -322,7 +356,7 @@ function dasherize(text) {
);
}

export function normalizeAndMergeFixture(options = {}) {
export function normalizeAndMergeFixture({inlineFileRightsFor = [], ...options} = {}) {
const seed = normalizeSeed(options);

return {
Expand All @@ -339,6 +373,10 @@ export function normalizeAndMergeFixture(options = {}) {
),
collections: {
...seedFixture.collections,
...inlineFileRightsFor.reduce((memo, collectionName) => ({
...memo,
[collectionName]: applyInlineFileRights(seedFixture.collections[collectionName])
}), {}),
chapters: seed.collections.chapters,
sections: seed.collections.sections,
contentElements: seed.collections.contentElements,
Expand All @@ -347,6 +385,18 @@ export function normalizeAndMergeFixture(options = {}) {
};
}

function applyInlineFileRights(files) {
return files.map(file => ({
...file,
rights: 'Jane Doe',
configuration: {
...file.configuration,
rights_display: 'inline',
source_url: 'https://example.com/jane-doe/image'
}
}));
}

export function exampleHeading({sectionId, text, position, width}) {
return {
sectionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ storiesOfContentElement(module, {
image: filePermaId('imageFiles', 'churchAfter')
}
]
}
},
inlineFileRights: true
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ storiesOfContentElement(module, {
caption: 'Some caption'
}
}
]
],
inlineFileRights: true
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ storiesOfContentElement(module, {
caption: 'Some text here'
}
},
]
],
inlineFileRights: true
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ storiesOfContentElement(module, {
name: 'With Caption',
configuration: {caption: 'Some text here'}
}
]
],
inlineFileRights: true
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ storiesOfContentElement(module, {
posterId: filePermaId('imageFiles', 'turtle')
}
}
]
],
inlineFileRights: true
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ storiesOfContentElement(module, {
caption: 'Some text here'
}
},
]
],
inlineFileRights: true
});

0 comments on commit a8e592f

Please sign in to comment.