-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: fixed NaN warning * fix: added empty changeset * bug-fix: fixed different warnings from tests * bug-fix: updated code style with prettier * fix: updated change set * fix: removed commented code * fix: remove empty changeset * fix console warnings * fix console warnings * fix console warnings * run prettier --------- Co-authored-by: Daniel Yoachim <daniel.yoachim@project44.com>
- Loading branch information
1 parent
1785777
commit 747eef4
Showing
8 changed files
with
92 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@project44-manifest/react': minor | ||
--- | ||
|
||
fix: fixed warnings in tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,49 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { Button } from '../src'; | ||
|
||
const mockProps = { | ||
'aria-label': 'Mock aria', | ||
children: 'Click me', | ||
onPress: jest.fn(), | ||
}; | ||
|
||
describe('react-button - Button', () => { | ||
beforeEach(jest.resetAllMocks); | ||
|
||
it('should render', () => { | ||
render(<Button>Click Me</Button>); | ||
render(<Button {...mockProps} />); | ||
|
||
const button = screen.getByRole('button'); | ||
|
||
expect(button).toBeVisible(); | ||
expect(button).toHaveAttribute('type', 'button'); | ||
}); | ||
|
||
it('should render icons', () => { | ||
render( | ||
<Button endIcon={<span data-testid="end" />} startIcon={<span data-testid="start" />}> | ||
Click Me | ||
</Button>, | ||
<Button | ||
{...mockProps} | ||
endIcon={<span data-testid="end" />} | ||
startIcon={<span data-testid="start" />} | ||
/>, | ||
); | ||
|
||
expect(screen.getByTestId('end')).toBeVisible(); | ||
expect(screen.getByTestId('start')).toBeVisible(); | ||
}); | ||
|
||
it('should handle click events', () => { | ||
const onClick = jest.fn(); | ||
|
||
render(<Button onClick={onClick}>Click Me</Button>); | ||
|
||
const button = screen.getByRole('button'); | ||
|
||
fireEvent.click(button); | ||
|
||
expect(onClick).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should handle press events', () => { | ||
const onPress = jest.fn(); | ||
|
||
render(<Button onPress={onPress}>Click Me</Button>); | ||
render(<Button {...mockProps} />); | ||
|
||
const button = screen.getByRole('button'); | ||
|
||
fireEvent.click(button); | ||
|
||
expect(onPress).toHaveBeenCalled(); | ||
expect(mockProps.onPress).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should handle disabled button', () => { | ||
const clickSpy = jest.fn(); | ||
|
||
render( | ||
<Button isDisabled onClick={clickSpy}> | ||
Click Me | ||
</Button>, | ||
); | ||
render(<Button {...mockProps} isDisabled />); | ||
|
||
const button = screen.getByRole('button'); | ||
|
||
fireEvent.click(button); | ||
|
||
expect(clickSpy).not.toHaveBeenCalled(); | ||
expect(mockProps.onPress).not.toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,63 @@ | ||
import '@testing-library/jest-dom/extend-expect'; | ||
let windowSpy: jest.SpyInstance; | ||
|
||
// global.window functions may be unavailable and | ||
// must be mocked in jest envirionment | ||
|
||
if (global.window) { | ||
const { getComputedStyle } = window; | ||
window.getComputedStyle = (elt) => getComputedStyle(elt); | ||
global.DOMRect = { | ||
fromRect: () => ({ | ||
bottom: 0, | ||
height: 0, | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
width: 0, | ||
}), | ||
}; | ||
|
||
global.ResizeObserver = class ResizeObserver { | ||
constructor(cb) { | ||
this.cb = cb; | ||
} | ||
observe() { | ||
this.cb([{ borderBoxSize: { blockSize: 0, inlineSize: 0 } }]); | ||
} | ||
unobserve() {} | ||
}; | ||
|
||
window.HTMLElement.prototype.scrollTo = () => {}; | ||
|
||
window.HTMLElement.prototype.getBoundingClientRect = () => ({ | ||
height: 1000, | ||
width: 1600, | ||
left: 0, | ||
top: 0, | ||
right: 0, | ||
bottom: 0, | ||
}); | ||
|
||
window.open = jest.fn(); | ||
|
||
const originalGetComputedStyle = window.getComputedStyle; | ||
|
||
const getComputedStyle = (...args: any[]) => { | ||
const cssStyleDeclaration = originalGetComputedStyle(args[0], args[1]); | ||
cssStyleDeclaration.setProperty('padding-left', '0'); | ||
cssStyleDeclaration.setProperty('padding-right', '0'); | ||
cssStyleDeclaration.setProperty('padding-top', '0'); | ||
cssStyleDeclaration.setProperty('padding-bottom', '0'); | ||
cssStyleDeclaration.setProperty('margin-left', '0'); | ||
cssStyleDeclaration.setProperty('margin-right', '0'); | ||
cssStyleDeclaration.setProperty('margin-top', '0'); | ||
cssStyleDeclaration.setProperty('margin-bottom', '0'); | ||
cssStyleDeclaration.setProperty('border-left-width', '0'); | ||
cssStyleDeclaration.setProperty('border-right-width', '0'); | ||
cssStyleDeclaration.setProperty('border-top-width', '0'); | ||
cssStyleDeclaration.setProperty('border-bottom-width', '0'); | ||
return cssStyleDeclaration; | ||
}; | ||
|
||
windowSpy = jest.spyOn(window, 'getComputedStyle'); | ||
windowSpy.mockImplementation(getComputedStyle); | ||
} |