Skip to content

Commit

Permalink
Remove random value in storybook (#2187)
Browse files Browse the repository at this point in the history
<!--
  How to write a good PR title:
- Follow [the Conventional Commits
specification](https://www.conventionalcommits.org/en/v1.0.0/).
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

## Self Checklist

- [x] I wrote a PR title in **English** and added an appropriate
**label** to the PR.
- [x] I wrote the commit message in **English** and to follow [**the
Conventional Commits
specification**](https://www.conventionalcommits.org/en/v1.0.0/).
- [x] I [added the
**changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
about the changes that needed to be released. (or didn't have to)
- [x] I wrote or updated **documentation** related to the changes. (or
didn't have to)
- [x] I wrote or updated **tests** related to the changes. (or didn't
have to)
- [x] I tested the changes in various browsers. (or didn't have to)
  - Windows: Chrome, Edge, (Optional) Firefox
  - macOS: Chrome, Edge, Safari, (Optional) Firefox

## Related Issue

<!-- Please link to issue if one exists -->

<!-- Fixes #0000 -->

- #1000

## Summary

<!-- Please brief explanation of the changes made -->

- 시각회귀테스트가 잘 동작하려면 스토리북에서 랜덤한 이미지나 값을 사용하지 않아야 합니다. 고정된 값을 사용하는 것으로
변경합니다.

## Details

<!-- Please elaborate description of the changes -->

- 생략

### Breaking change? (Yes/No)

<!-- If Yes, please describe the impact and migration path for users -->

- No

## References

<!-- Please list any other resources or points the reviewer should be
aware of -->

- None
  • Loading branch information
yangwooseong authored May 2, 2024
1 parent 27c5cd0 commit 8334164
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const WithCustomComponent: StoryObj<ButtonProps> = {
leftContent: (
<Avatar
name="test"
avatarUrl="https://source.unsplash.com/random"
avatarUrl="https://cf.channel.io/thumb/200x200/pub-file/1/65fc43ee585607b276f6/tmp-3329819395"
/>
),
size: 'm',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { useState } from 'react'
import React from 'react'

import type { Meta, StoryFn, StoryObj } from '@storybook/react'

import { range } from '~/src/utils/number'

import { Button } from '~/src/components/Button'
import { Text } from '~/src/components/Text'

Expand Down Expand Up @@ -65,22 +63,20 @@ const meta: Meta<
}
export default meta

const randomSize = (): number => Math.floor(Math.random() * 240 + 120)

const Item = ({
size,
fixedSize,
direction,
}: {
size: number
fixedSize: boolean
direction: 'horizontal' | 'vertical'
}) => {
const [alignSize] = useState(() => randomSize())

return (
<div
style={{
width: fixedSize && direction === 'vertical' ? alignSize : '100%',
height: fixedSize && direction === 'horizontal' ? alignSize : '100%',
width: fixedSize && direction === 'vertical' ? size : '100%',
height: fixedSize && direction === 'horizontal' ? size : '100%',
backgroundColor: 'var(--bg-black-light)',
borderRadius: '4px',
boxShadow: 'inset 0 0 1px #c0c0c0',
Expand Down Expand Up @@ -142,7 +138,7 @@ const Template: StoryFn<StackPreviewProps> = ({
align={align}
spacing={spacing}
>
{range(4).map((i) => (
{[200, 400, 300, 100].map((size, i) => (
<LegacyStackItem
key={`item-${i}`}
justify={itemJustifies[i]}
Expand All @@ -157,6 +153,7 @@ const Template: StoryFn<StackPreviewProps> = ({
<Item
direction={direction}
fixedSize={(align ?? itemAligns[i]) !== 'stretch'}
size={size}
/>
</LegacyStackItem>
))}
Expand Down

0 comments on commit 8334164

Please sign in to comment.