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

feat(pie-storybook): DSW-2593 improve logic for conditional rendering of stories #2088

Merged
merged 36 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d715fca
feat(pie-storybook): Improve logic for conditional rendering of stories
Nov 20, 2024
cbaab70
update other stories to show in testing deployment
Nov 21, 2024
09bb13f
fix conflict
Nov 29, 2024
e3d06b8
fix variant story params
Nov 25, 2024
505fc34
add tagging functionality
Nov 25, 2024
4e2db2a
add tagging v2
Nov 25, 2024
cabf076
fix linting
Nov 25, 2024
fae7e36
fix linting
Nov 25, 2024
ac288ae
fix linting
Nov 25, 2024
b6389dd
fix linting
Nov 25, 2024
92e9c16
fix ts warnings
Nov 26, 2024
d044d32
fix ts warnings
Nov 26, 2024
22b3a1e
update jsdoc
Nov 26, 2024
3377b89
chip visual test to use storybook
Nov 26, 2024
3491378
chip visual test to use storybook
Nov 26, 2024
d0aca9c
pr suggestions
Nov 26, 2024
3fcbe89
pr suggestions
Nov 26, 2024
929b6ac
pr suggestions
Nov 26, 2024
b89521d
pr suggestions
Nov 26, 2024
ae48c36
pr suggestions
Nov 26, 2024
5836688
update generator and remove showInTestingDeployment
Nov 27, 2024
546ed92
use correct import for a11y
Nov 27, 2024
ca12d17
correct file name
Nov 27, 2024
3210039
correct import path
Nov 27, 2024
3f47f2d
correct filename
Nov 27, 2024
9cd1d07
correct filename
Nov 27, 2024
d7afb63
correct lint
Nov 27, 2024
51700a2
correct lint
Nov 27, 2024
47c4343
correct test
Nov 27, 2024
9f65529
correct linting
Nov 27, 2024
8462cda
add tests
Nov 27, 2024
5874b3c
fix linting
Nov 27, 2024
6ff9eb6
changeset
Nov 27, 2024
e955c28
update test
Nov 29, 2024
994a406
Merge branch 'main' into wcp-2593-storybook-selective-rendering
siggerzz Nov 29, 2024
ff40cf7
Merge branch 'main' into wcp-2593-storybook-selective-rendering
siggerzz Nov 29, 2024
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
5 changes: 5 additions & 0 deletions .changeset/loud-turkeys-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@justeattakeaway/generator-pie-component": minor
---

[Updated] - structure to follow new testing best practices via rendering in Storybook
7 changes: 3 additions & 4 deletions apps/pie-storybook/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ const isBrowserTesting = process.env.BROWSER_TESTING === 'true';
const config: StorybookConfig = {
stories: isBrowserTesting
? [
"../stories/**/*.test.mdx",
"../stories/**/*.test.stories.@(js|ts|tsx)"
]
"../stories/testing/**/*.test.stories.ts"
]
: [
"../stories/**/*.mdx",
"../stories/**/!(*.test).stories.@(js|ts|tsx)"
"../stories/*.stories.@(js|ts|tsx)",
],
addons: [
"@storybook/addon-essentials",
Expand Down
6 changes: 6 additions & 0 deletions apps/pie-storybook/.storybook/styles/component-status.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
.c-componentStatus--top {
inset-block-start: var(--dt-spacing-c);
}

@media only percy {
.percyHidden {
display: none;
}
}
2 changes: 1 addition & 1 deletion apps/pie-storybook/decorators/component-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ComponentStatus = (story: () => TemplateResult, storybookContext: S
<div class="pie-sb-status-wrapper">
${story()}

<div class="${`c-componentStatus ${positionClass}`}">
<div class="${`c-componentStatus ${positionClass} percyHidden`}">
siggerzz marked this conversation as resolved.
Show resolved Hide resolved
<pie-tag variant="${tagVariant}">
Status: ${componentStatus}
<a
Expand Down
29 changes: 15 additions & 14 deletions apps/pie-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build": "storybook build --output-dir dist && cp -R ./static ./dist",
"build:testing": "BROWSER_TESTING=true storybook build --output-dir dist && cp -R ./static ./dist",
"lint:scripts": "run -T eslint .",
"lint:scripts:fix": "run -T eslint . --fix"
"lint:scripts:fix": "run -T eslint . --fix",
"test": "run -T vitest run test"
},
"author": "Just Eat Takeaway.com - Design System Team",
"license": "Apache-2.0",
Expand Down Expand Up @@ -45,23 +46,23 @@
"devDependencies": {
"@justeattakeaway/pie-icons-configs": "4.5.1",
"@justeattakeaway/pie-monorepo-utils": "0.2.0",
"@storybook/addon-a11y": "8.3.0",
"@storybook/addon-designs": "8.0.3",
"@storybook/addon-essentials": "8.3.0",
"@storybook/addon-links": "8.3.0",
"@storybook/blocks": "8.3.0",
"@storybook/components": "8.3.0",
"@storybook/manager-api": "8.3.0",
"@storybook/preview-api": "8.3.0",
"@storybook/theming": "8.3.0",
"@storybook/types": "8.3.0",
"@storybook/web-components": "8.3.0",
"@storybook/web-components-vite": "8.3.0",
"@storybook/addon-a11y": "8.4.5",
"@storybook/addon-designs": "8.0.4",
"@storybook/addon-essentials": "8.4.5",
"@storybook/addon-links": "8.4.5",
"@storybook/blocks": "8.4.5",
"@storybook/components": "8.4.5",
"@storybook/manager-api": "8.4.5",
"@storybook/preview-api": "8.4.5",
"@storybook/theming": "8.4.5",
"@storybook/types": "8.4.5",
"@storybook/web-components": "8.4.5",
"@storybook/web-components-vite": "8.4.5",
"@types/dompurify": "3.0.5",
"react": "18.3.1",
"react-dom": "18.3.1",
"serve": "14.2.0",
"storybook": "8.3.0",
"storybook": "8.4.5",
"storybook-dark-mode": "4.0.2"
},
"volta": {
Expand Down
9 changes: 5 additions & 4 deletions apps/pie-storybook/stories/pie-chip.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ const Template: TemplateFunction<ChipProps> = ({
${sanitizeAndRenderHTML(slot)}
</pie-chip>`;

const createCardStory = createStory<ChipProps>(Template, defaultArgs);
const createChipStory = createStory<ChipProps>(Template, defaultArgs);

export const Default = createCardStory();
export const Outline = createCardStory({ variant: 'outline' });
export const Ghost = createCardStory({ variant: 'ghost' });
export const Default = createChipStory();
export const Outline = createChipStory({ variant: 'outline' });

export const Ghost = createChipStory({ variant: 'ghost' });
68 changes: 0 additions & 68 deletions apps/pie-storybook/stories/pie-divider.test.stories.ts

This file was deleted.

148 changes: 148 additions & 0 deletions apps/pie-storybook/stories/testing/pie-chip.test.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { html, nothing } from 'lit';
import { ifDefined } from 'lit/directives/if-defined.js';
import { action } from '@storybook/addon-actions';
import { type Meta } from '@storybook/web-components';

import '@justeattakeaway/pie-chip';
import { type ChipProps as ChipPropsBase, variants, defaultProps } from '@justeattakeaway/pie-chip';
import '@justeattakeaway/pie-icons-webc/dist/IconHeartFilled.js';

import { type SlottedComponentProps } from '../../types';
import {
createStory, createVariantStory, type TemplateFunction, sanitizeAndRenderHTML,
} from '../../utilities';

type ChipProps = SlottedComponentProps<ChipPropsBase> & { showIcon: boolean };
type ChipStoryMeta = Meta<ChipProps>;

const defaultArgs: ChipProps = {
...defaultProps,
aria: {
label: 'Chip Label',
close: 'Chip Close',
},
showIcon: false,
slot: 'String',
};

const chipStoryMeta: ChipStoryMeta = {
title: 'Chip',
component: 'pie-chip',
argTypes: {
aria: {
description: 'The ARIA labels used for various parts of the chip.',
control: 'object',
},
variant: {
description: 'Set the variant of the chip.',
control: 'select',
options: variants,
defaultValue: {
summary: defaultProps.variant,
},
},
disabled: {
description: 'If `true`, disables the chip.',
control: 'boolean',
defaultValue: {
summary: defaultProps.disabled,
},
},
isSelected: {
description: 'If `true`, the chip element will apply the selected styles.',
control: 'boolean',
defaultValue: {
summary: defaultProps.isSelected,
},
},
isLoading: {
description: 'If `true`, displays a loading indicator inside the chip.',
control: 'boolean',
defaultValue: {
summary: defaultProps.isLoading,
},
},
isDismissible: {
description: 'If `true`, displays a close icon to dismiss the chip component. <br /><br /> Can be only used if `isSelected` is set to true',
control: 'boolean',
defaultValue: {
summary: defaultProps.isDismissible,
},
if: { arg: 'isSelected', eq: true },
},
showIcon: {
description: 'Enable to see the example of Chip with icon.',
control: 'boolean',
defaultValue: {
summary: defaultArgs.showIcon,
},
},
slot: {
description: 'Content to place within the chip',
control: 'text',
},
},
args: defaultArgs,
};

export default chipStoryMeta;

const clickAction = action('clicked');
const closeAction = action('pie-chip-close');

const Template: TemplateFunction<ChipProps> = ({
siggerzz marked this conversation as resolved.
Show resolved Hide resolved
aria,
disabled,
isSelected,
isLoading,
isDismissible,
showIcon,
slot,
variant,
}) => html`
<pie-chip
.aria="${aria}"
?disabled="${disabled}"
?isSelected="${isSelected}"
?isLoading="${isLoading}"
?isDismissible="${isDismissible}"
variant="${ifDefined(variant)}"
@pie-chip-close="${closeAction}"
@click="${clickAction}">
${showIcon ? html`<icon-heart-filled slot="icon"></icon-heart-filled>` : nothing}
${sanitizeAndRenderHTML(slot)}
</pie-chip>`;
const createChipStory = createStory<ChipProps>(Template, defaultArgs);

export const Default = createChipStory();
export const Outline = createChipStory({ variant: 'outline' });
export const Ghost = createChipStory({ variant: 'ghost' });

// Define the prop options for the matrix
const sharedPropOptions = {
disabled: [true, false],
isSelected: [true, false],
isLoading: [true, false],
isDismissible: [true, false],
showIcon: [true, false],
slot: ['Hello World'],
};

const defaultPropOptions = {
...sharedPropOptions,
variant: ['default'],
};

const ghostPropOptions = {
...sharedPropOptions,
variant: ['ghost'],
};

const outlinePropOptions = {
...sharedPropOptions,
variant: ['outline'],
};

export const DefaultPropVariations = createVariantStory<Omit<ChipProps, 'aria'> >(Template, defaultPropOptions);
export const GhostPropVariations = createVariantStory<Omit<ChipProps, 'aria'>>(Template, ghostPropOptions);
export const OutlinePropVariations = createVariantStory<Omit<ChipProps, 'aria'>>(Template, outlinePropOptions);
Loading
Loading