-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
47 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/block-editor/src/components/background-image-control/test/index.js
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,47 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import { backgroundPositionToCoords, coordsToBackgroundPosition } from '../'; | ||
|
||
describe( 'backgroundPositionToCoords', () => { | ||
it( 'should return the correct coordinates for a percentage value using 2-value syntax', () => { | ||
expect( backgroundPositionToCoords( '25% 75%' ) ).toEqual( { | ||
x: 0.25, | ||
y: 0.75, | ||
} ); | ||
} ); | ||
|
||
it( 'should return the correct coordinates for a percentage using 1-value syntax', () => { | ||
expect( backgroundPositionToCoords( '50%' ) ).toEqual( { | ||
x: 0.5, | ||
y: 0.5, | ||
} ); | ||
} ); | ||
|
||
it( 'should return undefined coords in given an empty value', () => { | ||
expect( backgroundPositionToCoords( '' ) ).toEqual( { | ||
x: undefined, | ||
y: undefined, | ||
} ); | ||
} ); | ||
|
||
it( 'should return undefined coords in given a string that cannot be converted', () => { | ||
expect( backgroundPositionToCoords( 'apples' ) ).toEqual( { | ||
x: undefined, | ||
y: undefined, | ||
} ); | ||
} ); | ||
} ); | ||
|
||
describe( 'coordsToBackgroundPosition', () => { | ||
it( 'should return the correct background position for a set of coordinates', () => { | ||
expect( coordsToBackgroundPosition( { x: 0.25, y: 0.75 } ) ).toBe( | ||
'25% 75%' | ||
); | ||
} ); | ||
|
||
it( 'should return undefined if no coordinates are provided', () => { | ||
expect( coordsToBackgroundPosition( {} ) ).toBeUndefined(); | ||
} ); | ||
} ); |
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