Skip to content

Commit

Permalink
chore: added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cazala committed Jun 1, 2023
1 parent f493b5f commit 57f9113
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
4 changes: 1 addition & 3 deletions packages/@dcl/inspector/src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const App = () => {
const { height } = useWindowSize()

// Footer's height is 36 pixels, so we need to calculate the percentage of the screen that it takes to pass as the minSize prop for the Panel
const footerMin = (50 / height!) * 100

console.log(footerMin)
const footerMin = (48 / height!) * 100

return (
<div className="App">
Expand Down
40 changes: 40 additions & 0 deletions packages/@dcl/inspector/src/hooks/useWindowSize.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { act, renderHook } from '@testing-library/react'
import { useWindowSize } from './useWindowSize'

const originalWidth = global.innerWidth
const originalHeight = global.innerHeight

describe('useWindowSize', () => {
describe('When the hook is rendered', () => {
beforeEach(() => {
global.innerWidth = 1024
global.innerHeight = 1024
})
afterEach(() => {
global.innerWidth = originalWidth
global.innerHeight = originalHeight
})
it('should return the width and height of the window', () => {
const { result } = renderHook(() => useWindowSize())
const { width, height } = result.current
expect(width).toBe(1024)
expect(height).toBe(1024)
})
describe('and the window is resized', () => {
it('should return the new size of the window', () => {
const { result } = renderHook(() => useWindowSize())
const { width, height } = result.current
expect(width).toBe(1024)
expect(height).toBe(1024)
act(() => {
global.innerWidth = 800
global.innerHeight = 600
global.dispatchEvent(new Event('resize'))
})
const { width: newWidth, height: newHeight } = result.current
expect(newWidth).toBe(800)
expect(newHeight).toBe(600)
})
})
})
})

0 comments on commit 57f9113

Please sign in to comment.