-
Notifications
You must be signed in to change notification settings - Fork 0
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 #12 from sourcetoad/static-positioning
Static positioning
- Loading branch information
Showing
32 changed files
with
623 additions
and
175 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
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,72 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import BadgeGravity from '../../src/types/BadgeGravity'; | ||
import calculateCircularBadgePosition from '../../src/utils/calculateCircularBadgePosition'; | ||
|
||
describe('calculateManualBadgePosition', () => { | ||
const container = { height: 100, width: 100 }; | ||
const badge = { height: 10, width: 10 }; | ||
const circleRadius = 30; | ||
|
||
it.each([ | ||
[ | ||
'north', | ||
{ | ||
gravity: BadgeGravity.North, | ||
expected: { point: { x: 45, y: 20 }, rotation: 0 }, | ||
}, | ||
], | ||
[ | ||
'northeast', | ||
{ | ||
gravity: BadgeGravity.Northeast, | ||
expected: { point: { x: 60, y: 26 }, rotation: 45 }, | ||
}, | ||
], | ||
[ | ||
'northwest', | ||
{ | ||
gravity: BadgeGravity.Northwest, | ||
expected: { point: { x: 26, y: 26 }, rotation: -45 }, | ||
}, | ||
], | ||
[ | ||
'south', | ||
{ | ||
gravity: BadgeGravity.South, | ||
expected: { point: { x: 45, y: 70 }, rotation: 0 }, | ||
}, | ||
], | ||
[ | ||
'southeast', | ||
{ | ||
gravity: BadgeGravity.Southeast, | ||
expected: { point: { x: 60, y: 60 }, rotation: -45 }, | ||
}, | ||
], | ||
[ | ||
'southwest', | ||
{ | ||
gravity: BadgeGravity.Southwest, | ||
expected: { point: { x: 26, y: 60 }, rotation: 45 }, | ||
}, | ||
], | ||
])('works for %s', (_, { gravity, expected }) => { | ||
const result = calculateCircularBadgePosition( | ||
container, | ||
badge, | ||
circleRadius, | ||
gravity, | ||
); | ||
|
||
expect(result.rotation).toEqual(expected.rotation); | ||
expect( | ||
Math.round(result.point.x), | ||
`Expected x to be ${expected.point.x} but was ${Math.round(result.point.x)}`, | ||
).toEqual(expected.point.x); | ||
expect( | ||
Math.round(result.point.y), | ||
`Expected y to be ${expected.point.y} but was ${Math.round(result.point.y)}`, | ||
).toEqual(expected.point.y); | ||
}); | ||
}); |
Oops, something went wrong.