Skip to content

Commit

Permalink
ci(pie-cookie-banner): DSW-000 add cookie banner story into test depl…
Browse files Browse the repository at this point in the history
…oy (#2110)
  • Loading branch information
JoshuaNg2332 authored Dec 4, 2024
1 parent 237778a commit 664411b
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions apps/pie-storybook/stories/testing/pie-cookie-banner.test.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { html } from 'lit';
import { action } from '@storybook/addon-actions';
import { type Meta } from '@storybook/web-components';

import '@justeattakeaway/pie-cookie-banner';
import { type CookieBannerProps, defaultProps } from '@justeattakeaway/pie-cookie-banner';
import {
Country,
Language,
} from '@justeattakeaway/pie-cookie-banner/src/defs';
import { createStory } from '../../utilities';

type CookieBannerStoryMeta = Meta<CookieBannerProps>;

const defaultArgs: CookieBannerProps = {
...defaultProps,
cookieTechnologiesLink: `${Language.ENGLISH}/technologies`,
cookieStatementLink: `${Language.ENGLISH}/cookiestatement`,
defaultPreferences: {
functional: true,
personalized: true,
analytical: true,
},
};

const cookieBannerStoryMeta: CookieBannerStoryMeta = {
title: 'Cookie Banner',
component: 'pie-cookie-banner',
argTypes: {
hasPrimaryActionsOnly: {
description: 'When true, sets the variant to "primary" for the button which accepts necessary cookies only.',
control: 'boolean',
},
country: {
options: [...Object.values(Country), 'ru', 'pt', 'ES', 'invalid'], // Expanded to allow for unsupported value tests
control: 'select',
description: 'Assigns the country for the component',
defaultValue: {
summary: defaultProps.country,
},
},
language: {
options: [...Object.values(Language), 'ru', 'pt', 'CA', 'invalid'], // Expanded to allow for unsupported value tests
control: 'select',
description: 'Assigns the language for the component',
defaultValue: {
summary: defaultProps.language,
},
},
defaultPreferences: {
control: 'object',
},
},
args: defaultArgs,
parameters: {
design: {
type: 'figma',
url: '',
},
componentStatusPosition: 'top',
},
};

export default cookieBannerStoryMeta;

const necessaryOnlyAction = action('necessary-only');
const acceptAllAction = action('accept-all');
const managePrefsAction = action('manage-prefs');
const prefsSavedAction = action('prefs-saved');

const BaseStoryTemplate = (props: CookieBannerProps) => {
const {
hasPrimaryActionsOnly,
country,
language,
cookieStatementLink,
cookieTechnologiesLink,
defaultPreferences,
} = props;

return html`
<pie-cookie-banner
country=${country}
language=${language}
.cookieStatementLink=${cookieStatementLink}
.cookieTechnologiesLink=${cookieTechnologiesLink}
?hasPrimaryActionsOnly="${hasPrimaryActionsOnly}"
.defaultPreferences="${defaultPreferences}"
@pie-cookie-banner-necessary-only="${necessaryOnlyAction}"
@pie-cookie-banner-accept-all="${acceptAllAction}"
@pie-cookie-banner-manage-prefs="${managePrefsAction}"
@pie-cookie-banner-prefs-saved="${prefsSavedAction}"></pie-cookie-banner>`;
};

/**
* Creates a 'page' of scrollable HTML. Useful for testing scroll behaviours in a Story.
*/
const createScrollablePageHTML = () => {
const items = [];
for (let i = 0; i < 200; i++) {
items.push(html`<li>Item ${i}</li>`);
}

return html`
<h1>Test Page</h1>
<p>Test copy</p>
<ul>${items}</ul>`;
};

const ScrollablePageStoryTemplate = (props: CookieBannerProps) => html`
${BaseStoryTemplate(props)}
${createScrollablePageHTML()}`;

export const Default = createStory<CookieBannerProps>(BaseStoryTemplate, defaultArgs)();
export const ScrollablePage = createStory<CookieBannerProps>(ScrollablePageStoryTemplate, defaultArgs)();

0 comments on commit 664411b

Please sign in to comment.