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

Dsy 4653 - test build-storybook #1832

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0ca0347
feat(natds-react): update teste react to 18
vagnerbarbosant Apr 30, 2024
6b5e7b5
fix(natds-react): fix package.json
vagnerbarbosant Apr 30, 2024
1af4b0d
test(natds-react): fix test useWindowSize
vagnerbarbosant Apr 30, 2024
8c00f6e
feat(natds-react): update setup.sh
vagnerbarbosant May 2, 2024
604f8d2
fix(natds-react): fix setup.sh script
vagnerbarbosant May 2, 2024
63ec37b
fix(natds-react): update setup.sh added --cwd packages
vagnerbarbosant May 2, 2024
6187e74
fix(natds-react): update setups.sh added build
vagnerbarbosant May 2, 2024
079cbef
fix(natds-react): update setup.sh build path react only
vagnerbarbosant May 2, 2024
c5edf67
fix(natds-react): fix remove params stories icon
vagnerbarbosant May 2, 2024
e7b562d
fix(natds-react): fix stories icon
vagnerbarbosant May 2, 2024
3df9dcf
fix(natds-react): update build-storybook,sh and setup.sh
vagnerbarbosant May 2, 2024
d02ad17
fix(natds-react): update test build-storybook.sh
vagnerbarbosant May 2, 2024
a5a0d05
feat(natds-react): update build-storybook and setup.sh
vagnerbarbosant May 2, 2024
b72ff95
feat(natds-react): update setup.sh
vagnerbarbosant May 3, 2024
dcd04d0
feat(natds-react): update setup.sh
vagnerbarbosant May 3, 2024
03df593
feat(natds-react): update setup.sh
vagnerbarbosant May 3, 2024
ca20826
feat(natds-react): update quality-check-sh
vagnerbarbosant May 3, 2024
45f7840
feat(natds-react): update build-storybook and check
vagnerbarbosant May 3, 2024
bc986c0
feat(natds-react): update build-storybook
vagnerbarbosant May 3, 2024
7086df4
feat(natds-react): update build-storybook.sh
vagnerbarbosant May 3, 2024
fd6ce0d
feat(natds-react): update build-Storybook
vagnerbarbosant May 3, 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
28 changes: 14 additions & 14 deletions .cicd/build-storybook.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/bin/bash
set -e

export NODE_OPTIONS=--openssl-legacy-provider

BRANCH_NAME=$(bash ./.cicd/get-branch-name.sh)
FOLDER_NAME=${BRANCH_NAME//[\/]/-}
OUTPUT_PATH=build

mkdir -p build

if [ -z $(./.cicd/skip-commit.sh) ]; then

if [ -z $1 ]; then
if [ -z "$(./.cicd/skip-commit.sh)" ]; then
if [ -z "$1" ]; then
OUTPUT_PATH=build/${FOLDER_NAME}
mkdir -p ${OUTPUT_PATH}
mkdir -p "${OUTPUT_PATH}"
echo "Created ${FOLDER_NAME} folder"
fi

yarn build:storybook
cp -r packages/web/docs/dist/* ${OUTPUT_PATH}

mkdir -p ${OUTPUT_PATH}/react

yarn --cwd packages/react build:storybook

mkdir -p "${OUTPUT_PATH}/react"
cp -r packages/react/docs/dist/* ${OUTPUT_PATH}/react

fi
fi
10 changes: 5 additions & 5 deletions .cicd/quality-check.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -e

if [ -z $(./.cicd/skip-commit.sh) ]; then
echo "Quality Check"

yarn lint
yarn test:ci ${NATDS_CODECOV_WEB}
fi
yarn --cwd packages/react
yarn --cwd packages/react test:ci
fi
8 changes: 4 additions & 4 deletions .cicd/setup.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -e

if [ -z $(./.cicd/skip-commit.sh) ]; then
bash .cicd/configure-git.sh

yarn install
yarn build
yarn --cwd packages/react install
yarn --cwd packages/react build
fi
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@
}
},
"resolutions": {
"react": "^17.0.1",
"react-dom": "^17.0.1",
"@types/react": "17.0.39"
"react": "^18.2.0",
"react-dom": "^18.2.18",
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18"
}
}
10 changes: 5 additions & 5 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
"react-jss": "10.9.0"
},
"devDependencies": {
"@types/react": "17.0.39",
"@types/react-dom": "17.0.13",
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18",
"plop": "3.0.5",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-test-renderer": "17.0.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-test-renderer": "18.2.0",
"storybook-dark-mode": "1.0.9"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export interface AccordionGroupProps {
* Optional ID for testing
*/
testID?: string;

children?: React.ReactNode
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const Middle: Story<DividerProps> = (args) => (
)
FullBleed.args = { ...Playground.args }

const Template: React.FC = ({ children }) => (
const Template = ({ children }: {children: React.ReactNode}) => (
<div style={{ maxWidth: 200, border: '1px solid #00000014', padding: '16px 0' }}>
{children}
</div>
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/components/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
export const Playground: Story<IconProps> = (args) => <Icon {...args} />
export const Icons: Story<IconProps> = (args) => <Icon {...args} />

export const SearchIcon: Story<IconProps> = (args) => {
export const SearchIcon: Story<IconProps> = () => {
const [value, setValue] = useState(iconNames[0])
const [filterOptionsN] = useState<OptionProps[]>(iconNames.map((icon) => ({ value: icon, label: icon })))
const [filterOptions, setFilterOptions] = useState<OptionProps[]>(iconNames.map((icon) => ({ value: icon, label: icon })))
Expand All @@ -47,6 +47,7 @@ export const SearchIcon: Story<IconProps> = (args) => {
setValue(values.label)
handleChange(values.label)
}

const handleChange = (values: string) => {
setValue(values)

Expand Down Expand Up @@ -107,7 +108,7 @@ export const SearchIcon: Story<IconProps> = (args) => {
}
SearchIcon.args = { ...Playground.args }

export const ListIcon: Story<IconProps> = (args) => {
export const ListIcon: Story<IconProps> = () => {
const [filterOptionsN] = useState<OptionProps[]>(iconNames.map((icon) => ({ value: icon, label: icon })))
const [filterOptions] = useState<OptionProps[]>(filterOptionsN)

Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/helpers/StoryContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react'
import { createUseStyles } from 'react-jss'

interface StoryContainerProps {
children: React.ReactNode
}

const styles = createUseStyles({
container: {
display: 'flex',
Expand All @@ -11,7 +15,7 @@ const styles = createUseStyles({
}
})

const StoryContainer: React.FC = ({ children }) => {
const StoryContainer = ({ children }: StoryContainerProps): JSX.Element => {
const classes = styles()

return (
Expand Down
40 changes: 0 additions & 40 deletions packages/react/src/hooks/useWindowSize.test.ts

This file was deleted.

67 changes: 67 additions & 0 deletions packages/react/src/hooks/useWindowSize.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react'
import {
act, fireEvent, render, screen
} from '@testing-library/react'
// import { renderHook } from '@testing-library/react-hooks'
import useWindowSize from './useWindowSize'

const TestSizeComponent = (): JSX.Element => {
const { width, height } = useWindowSize()
return <div>{`Width: ${width}, Height: ${height}`}</div>
}

jest.useFakeTimers('legacy')

describe('hooks/useWindowSize', () => {
beforeEach(() => {
global.innerWidth = 768
global.innerHeight = 664
fireEvent(window, new Event('resize'))
})

it('should read initial innerWidth and innerHeight values from window', () => {
// const { result } = renderHook(() => useWindowSize())

render(<TestSizeComponent />)

expect(screen.getByText(/Width:/)).toHaveTextContent(`Width: ${window.innerWidth}`)
expect(screen.getByText(/Height:/)).toHaveTextContent(`Height: ${window.innerHeight}`)

// Simule a mudança do tamanho da janela

// act(() => {
// window.innerWidth = 500
// window.innerHeight = 300
// window.dispatchEvent(new Event('resize'))
// })
// Verifique se os valores foram atualizados
// expect(screen.getByText(/Width:/)).toHaveTextContent('Width: 500')
// expect(screen.getByText(/Height:/)).toHaveTextContent('Height: 300')

// expect(result.current.width).toEqual(768)
// expect(result.current.height).toEqual(664)
// expect(setTimeout).toHaveBeenCalledTimes(1)
})

it('should update innerWidth and innerHeight values when window resizes', () => {
// const { result } = renderHook(() => useWindowSize())

// expect(result.current.width).toEqual(768)
// expect(result.current.height).toEqual(664)
render(<TestSizeComponent />)
act(() => {
global.innerWidth = 320
global.innerHeight = 664
fireEvent(window, new Event('resize'))
})

jest.advanceTimersByTime(500)

// expect(result.current.width).toBe(320)
// expect(result.current.height).toBe(664)

expect(screen.getByText(/Width:/)).toHaveTextContent(`Width: ${window.innerWidth}`)
expect(screen.getByText(/Height:/)).toHaveTextContent(`Height: ${window.innerHeight}`)
expect(setTimeout).toHaveBeenCalledTimes(1)
})
})
Loading