This repository was archived by the owner on May 20, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from proful/test-bounds
Added tests for bounds components
- Loading branch information
Showing
14 changed files
with
305 additions
and
27 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import * as React from 'react' | ||
import { BoundsBg } from './bounds-bg' | ||
|
||
jest.spyOn(console, 'error').mockImplementation(() => void null) | ||
|
||
describe('BoundsBg', () => { | ||
test('mounts component without crashing', () => { | ||
render( | ||
<BoundsBg | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
rotation={45} | ||
isHidden={false} | ||
/> | ||
) | ||
}) | ||
test('validate attributes for a bounds bg', () => { | ||
render( | ||
<BoundsBg | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
rotation={45} | ||
isHidden={false} | ||
/> | ||
) | ||
const boundsBg = screen.getByLabelText('bounds bg') | ||
expect(boundsBg).toHaveAttribute('height', '100') | ||
expect(boundsBg).toHaveAttribute('width', '100') | ||
expect(boundsBg).toHaveAttribute('opacity', '1') | ||
}) | ||
}) |
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
108 changes: 108 additions & 0 deletions
108
packages/core/src/components/bounds/corner-handle.test.tsx
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,108 @@ | ||
import { renderWithContext } from '~test' | ||
import { screen } from '@testing-library/react' | ||
import * as React from 'react' | ||
import { CornerHandle } from './corner-handle' | ||
import { TLBoundsCorner } from '~types' | ||
|
||
jest.spyOn(console, 'error').mockImplementation(() => void null) | ||
|
||
describe('CenterHandle', () => { | ||
test('mounts component without crashing', () => { | ||
renderWithContext( | ||
<CornerHandle | ||
size={10} | ||
targetSize={20} | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
corner={TLBoundsCorner.TopLeft} | ||
/> | ||
) | ||
}) | ||
test('top left corner > validate attributes', () => { | ||
renderWithContext( | ||
<CornerHandle | ||
size={10} | ||
targetSize={20} | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
corner={TLBoundsCorner.TopLeft} | ||
/> | ||
) | ||
const cornerTransparent = screen.getByLabelText('corner transparent') | ||
const cornerHandle = screen.getByLabelText('corner handle') | ||
|
||
expect(cornerTransparent).toHaveAttribute('height', '40') | ||
expect(cornerTransparent).toHaveAttribute('width', '40') | ||
expect(cornerTransparent).toHaveAttribute('x', '-21') | ||
expect(cornerTransparent).toHaveAttribute('y', '-21') | ||
|
||
expect(cornerHandle).toHaveAttribute('height', '10') | ||
expect(cornerHandle).toHaveAttribute('width', '10') | ||
expect(cornerHandle).toHaveAttribute('x', '-6') | ||
expect(cornerHandle).toHaveAttribute('y', '-6') | ||
}) | ||
test('top right corner > validate attributes', () => { | ||
renderWithContext( | ||
<CornerHandle | ||
size={10} | ||
targetSize={20} | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
corner={TLBoundsCorner.TopRight} | ||
/> | ||
) | ||
const cornerTransparent = screen.getByLabelText('corner transparent') | ||
const cornerHandle = screen.getByLabelText('corner handle') | ||
|
||
expect(cornerTransparent).toHaveAttribute('height', '40') | ||
expect(cornerTransparent).toHaveAttribute('width', '40') | ||
expect(cornerTransparent).toHaveAttribute('x', '81') | ||
expect(cornerTransparent).toHaveAttribute('y', '-21') | ||
|
||
expect(cornerHandle).toHaveAttribute('height', '10') | ||
expect(cornerHandle).toHaveAttribute('width', '10') | ||
expect(cornerHandle).toHaveAttribute('x', '96') | ||
expect(cornerHandle).toHaveAttribute('y', '-6') | ||
}) | ||
test('bottom left corner > validate attributes', () => { | ||
renderWithContext( | ||
<CornerHandle | ||
size={10} | ||
targetSize={20} | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
corner={TLBoundsCorner.BottomLeft} | ||
/> | ||
) | ||
const cornerTransparent = screen.getByLabelText('corner transparent') | ||
const cornerHandle = screen.getByLabelText('corner handle') | ||
|
||
expect(cornerTransparent).toHaveAttribute('height', '40') | ||
expect(cornerTransparent).toHaveAttribute('width', '40') | ||
expect(cornerTransparent).toHaveAttribute('x', '-21') | ||
expect(cornerTransparent).toHaveAttribute('y', '81') | ||
|
||
expect(cornerHandle).toHaveAttribute('height', '10') | ||
expect(cornerHandle).toHaveAttribute('width', '10') | ||
expect(cornerHandle).toHaveAttribute('x', '-6') | ||
expect(cornerHandle).toHaveAttribute('y', '96') | ||
}) | ||
test('bottom right corner > validate attributes', () => { | ||
renderWithContext( | ||
<CornerHandle | ||
size={10} | ||
targetSize={20} | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
corner={TLBoundsCorner.BottomRight} | ||
/> | ||
) | ||
const cornerTransparent = screen.getByLabelText('corner transparent') | ||
const cornerHandle = screen.getByLabelText('corner handle') | ||
|
||
expect(cornerTransparent).toHaveAttribute('height', '40') | ||
expect(cornerTransparent).toHaveAttribute('width', '40') | ||
expect(cornerTransparent).toHaveAttribute('x', '81') | ||
expect(cornerTransparent).toHaveAttribute('y', '81') | ||
|
||
expect(cornerHandle).toHaveAttribute('height', '10') | ||
expect(cornerHandle).toHaveAttribute('width', '10') | ||
expect(cornerHandle).toHaveAttribute('x', '96') | ||
expect(cornerHandle).toHaveAttribute('y', '96') | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import * as React from 'react' | ||
import { renderWithContext } from '~test' | ||
import { screen } from '@testing-library/react' | ||
import { EdgeHandle } from './edge-handle' | ||
import { TLBoundsEdge } from '~types' | ||
|
||
jest.spyOn(console, 'error').mockImplementation(() => void null) | ||
|
||
describe('EdgeHandle', () => { | ||
test('mounts component without crashing', () => { | ||
renderWithContext( | ||
<EdgeHandle | ||
targetSize={20} | ||
size={10} | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
edge={TLBoundsEdge.Top} | ||
isHidden={false} | ||
/> | ||
) | ||
}) | ||
test('top edge > validate attributes', () => { | ||
renderWithContext( | ||
<EdgeHandle | ||
targetSize={20} | ||
size={10} | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
edge={TLBoundsEdge.Top} | ||
isHidden={false} | ||
/> | ||
) | ||
const edgeHandle = screen.getByLabelText('top_edge handle') | ||
|
||
expect(edgeHandle).toHaveAttribute('height', '10') | ||
expect(edgeHandle).toHaveAttribute('width', '91') | ||
expect(edgeHandle).toHaveAttribute('x', '5') | ||
expect(edgeHandle).toHaveAttribute('y', '-6') | ||
}) | ||
test('bottom edge > validate attributes', () => { | ||
renderWithContext( | ||
<EdgeHandle | ||
targetSize={20} | ||
size={10} | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
edge={TLBoundsEdge.Bottom} | ||
isHidden={false} | ||
/> | ||
) | ||
const edgeHandle = screen.getByLabelText('bottom_edge handle') | ||
|
||
expect(edgeHandle).toHaveAttribute('height', '10') | ||
expect(edgeHandle).toHaveAttribute('width', '91') | ||
expect(edgeHandle).toHaveAttribute('x', '5') | ||
expect(edgeHandle).toHaveAttribute('y', '96') | ||
}) | ||
test('left edge > validate attributes', () => { | ||
renderWithContext( | ||
<EdgeHandle | ||
targetSize={20} | ||
size={10} | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
edge={TLBoundsEdge.Left} | ||
isHidden={false} | ||
/> | ||
) | ||
const edgeHandle = screen.getByLabelText('left_edge handle') | ||
|
||
expect(edgeHandle).toHaveAttribute('height', '91') | ||
expect(edgeHandle).toHaveAttribute('width', '10') | ||
expect(edgeHandle).toHaveAttribute('x', '-6') | ||
expect(edgeHandle).toHaveAttribute('y', '5') | ||
}) | ||
test('right edge > validate attributes', () => { | ||
renderWithContext( | ||
<EdgeHandle | ||
targetSize={20} | ||
size={10} | ||
bounds={{ minX: 0, minY: 0, maxX: 100, maxY: 100, width: 100, height: 100 }} | ||
edge={TLBoundsEdge.Right} | ||
isHidden={false} | ||
/> | ||
) | ||
const edgeHandle = screen.getByLabelText('right_edge handle') | ||
|
||
expect(edgeHandle).toHaveAttribute('height', '91') | ||
expect(edgeHandle).toHaveAttribute('width', '10') | ||
expect(edgeHandle).toHaveAttribute('x', '96') | ||
expect(edgeHandle).toHaveAttribute('y', '5') | ||
}) | ||
}) |
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
Oops, something went wrong.
1ae5997
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: