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 4649 - Test quality-check-sh #1828

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .cicd/build-storybook.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/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
Expand All @@ -15,8 +15,8 @@ if [ -z $(./.cicd/skip-commit.sh) ]; then
echo "Created ${FOLDER_NAME} folder"
fi

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

mkdir -p ${OUTPUT_PATH}/react
cp -r packages/react/docs/dist/* ${OUTPUT_PATH}/react
Expand Down
24 changes: 17 additions & 7 deletions .cicd/quality-check.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#!/bin/bash
set -e

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

yarn lint
yarn test:ci ${NATDS_CODECOV_WEB}
set -eo pipefail

if ./cicd/skip-commit.sh; then
echo "Skipping commit as per skip-commit.sh"
exit 0
fi

echo "Quality Check"

yarn --cwd packages/react lint

if [ -n "$NATDS_CODECOV_WEB" ]; then
yarn --cwd packages/react test:ci "$NATDS_CODECOV_WEB"
ls
else
yarn --cwd packages/react test:ci
ls
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