From edbc7e68634a2ad550075fe50bf2f6fc8da056e2 Mon Sep 17 00:00:00 2001 From: Lene Gadewoll Date: Tue, 16 Apr 2024 16:52:01 +0200 Subject: [PATCH] docs(storybook): use faker.seed to generate stable data --- .../resizable_container.stories.tsx | 46 ++++-------- .../resizable_panel.stories.tsx | 8 ++- .../search_bar/search_bar.stories.tsx | 71 +++++-------------- 3 files changed, 37 insertions(+), 88 deletions(-) diff --git a/src/components/resizable_container/resizable_container.stories.tsx b/src/components/resizable_container/resizable_container.stories.tsx index eced7b903a2f..9162db19b464 100644 --- a/src/components/resizable_container/resizable_container.stories.tsx +++ b/src/components/resizable_container/resizable_container.stories.tsx @@ -8,6 +8,7 @@ import React from 'react'; import type { Meta, StoryObj } from '@storybook/react'; +import { faker } from '@faker-js/faker'; import { enableFunctionToggleControls } from '../../../.storybook/utils'; import { EuiText } from '../text'; @@ -16,15 +17,14 @@ import { EuiResizableContainerProps, } from './resizable_container'; -// using static text over '@faker-js/faker' to ensure same output in regards to VRT +faker.seed(42); + const placeholderText = ( -

- Autem vitae quibusdam iure aspernatur nobis. Illo dicta debitis aperiam. - Assumenda dicta saepe corrupti tempora. Nobis nihil ipsum esse eius - perspiciatis velit maiores architecto earum. Minus ipsam dignissimos - voluptatem eos ipsa. Laudantium eius porro autem impedit voluptatibus - accusamus qui adipisci. -

+ <> +

{faker.lorem.sentences(5)}

+

{faker.lorem.sentences(5)}

+

{faker.lorem.sentences(5)}

+ ); const TwoColumns: EuiResizableContainerProps['children'] = ( @@ -33,21 +33,13 @@ const TwoColumns: EuiResizableContainerProps['children'] = ( ) => ( <> - - {placeholderText} - {placeholderText} - {placeholderText} - + {placeholderText} - - {placeholderText} - {placeholderText} - {placeholderText} - + {placeholderText} ); @@ -58,31 +50,19 @@ const ThreeColumns: EuiResizableContainerProps['children'] = ( ) => ( <> - - {placeholderText} - {placeholderText} - {placeholderText} - + {placeholderText} - - {placeholderText} - {placeholderText} - {placeholderText} - + {placeholderText} - - {placeholderText} - {placeholderText} - {placeholderText} - + {placeholderText} ); diff --git a/src/components/resizable_container/resizable_panel.stories.tsx b/src/components/resizable_container/resizable_panel.stories.tsx index d48360f72adb..4a7a8a9778ca 100644 --- a/src/components/resizable_container/resizable_panel.stories.tsx +++ b/src/components/resizable_container/resizable_panel.stories.tsx @@ -8,6 +8,8 @@ import React from 'react'; import type { Meta, StoryObj } from '@storybook/react'; +import { css } from '@emotion/react'; +import { faker } from '@faker-js/faker'; import { disableStorybookControls, @@ -15,7 +17,8 @@ import { } from '../../../.storybook/utils'; import { EuiResizableContainer } from './resizable_container'; import { EuiResizablePanel, EuiResizablePanelProps } from './resizable_panel'; -import { css } from '@emotion/react'; + +faker.seed(42); const meta: Meta = { title: 'Layout/EuiResizableContainer/EuiResizablePanel', @@ -61,8 +64,7 @@ type Story = StoryObj; export const Playground: Story = { args: { - children: - 'Autem vitae quibusdam iure aspernatur nobis. Illo dicta debitis aperiam. Assumenda dicta saepe corrupti tempora.', + children: faker.lorem.sentences(5), initialSize: 100, }, render: ({ mode, children, ...rest }) => { diff --git a/src/components/search_bar/search_bar.stories.tsx b/src/components/search_bar/search_bar.stories.tsx index c7295c31c871..4848ed7165b0 100644 --- a/src/components/search_bar/search_bar.stories.tsx +++ b/src/components/search_bar/search_bar.stories.tsx @@ -8,6 +8,7 @@ import React, { useState } from 'react'; import type { Meta, StoryObj } from '@storybook/react'; +import { faker } from '@faker-js/faker'; import { enableFunctionToggleControls } from '../../../.storybook/utils'; import { EuiBasicTable } from '../basic_table'; @@ -23,6 +24,8 @@ import { QueryType, } from './search_bar'; +faker.seed(42); + const tags = [ { name: 'marketing', color: 'danger' }, { name: 'finance', color: 'success' }, @@ -31,58 +34,22 @@ const tags = [ { name: 'ga', color: 'success' }, ]; -const items = [ - { - type: 'watch', - status: 'open', - active: false, - tag: ['finance'], - owner: 'wanda', - stars: 2, - followers: 10, - comments: 3, - }, - { - type: 'visualization', - status: 'closed', - active: true, - tag: ['ga', 'marketing', 'eng'], - owner: 'carrie', - stars: 2, - followers: 7, - comments: 2, - }, - { - type: 'watch', - open: 'open', - active: true, - tag: [], - owner: 'carrie', - stars: 4, - followers: 2, - comments: 10, - }, - { - type: 'visualization', - open: 'open', - active: false, - tag: ['eng'], - owner: 'dewey', - stars: 5, - followers: 2, - comments: 8, - }, - { - type: 'dashboard', - open: 'closed', - active: false, - tag: ['sales', 'marketing', 'ga'], - owner: 'gabic', - stars: 1, - followers: 13, - comments: 1, - }, -]; +const items = [...Array(5).keys()].map((id) => { + return { + id, + status: faker.helpers.arrayElement(['open', 'closed']), + type: faker.helpers.arrayElement(['dashboard', 'visualization', 'watch']), + tag: faker.helpers.arrayElements( + tags.map((tag) => tag.name), + { min: 0, max: 3 } + ), + active: faker.datatype.boolean(), + owner: faker.helpers.arrayElement(['dewey', 'wanda', 'carrie', 'gabic']), + followers: faker.number.int({ min: 0, max: 20 }), + comments: faker.number.int({ min: 0, max: 10 }), + stars: faker.number.int({ min: 0, max: 5 }), + }; +}); const meta: Meta = { title: 'Forms/EuiSearchBar/EuiSearchBar',