diff --git a/packages/block-editor/src/components/aspect-ratio-dropdown/index.js b/packages/block-editor/src/components/aspect-ratio-dropdown/index.js index c7dbc6da302f23..fc4692b545fda3 100644 --- a/packages/block-editor/src/components/aspect-ratio-dropdown/index.js +++ b/packages/block-editor/src/components/aspect-ratio-dropdown/index.js @@ -39,7 +39,7 @@ function AspectRatioGroup( { ); } -function ratioToNumber( str ) { +export function ratioToNumber( str ) { // TODO: support two-value aspect ratio? // https://css-tricks.com/almanac/properties/a/aspect-ratio/#aa-it-can-take-two-values const [ a, b, ...rest ] = str.split( '/' ).map( Number ); diff --git a/packages/block-editor/src/components/aspect-ratio-dropdown/test/index.js b/packages/block-editor/src/components/aspect-ratio-dropdown/test/index.js new file mode 100644 index 00000000000000..28763a6f66093c --- /dev/null +++ b/packages/block-editor/src/components/aspect-ratio-dropdown/test/index.js @@ -0,0 +1,22 @@ +/** + * Internal dependencies + */ +import { ratioToNumber } from '../'; + +test( 'ratioToNumber', () => { + expect( ratioToNumber( '1/1' ) ).toBe( 1 ); + expect( ratioToNumber( '1' ) ).toBe( 1 ); + expect( ratioToNumber( '11/11' ) ).toBe( 1 ); + expect( ratioToNumber( '16/9' ) ).toBe( 16 / 9 ); + expect( ratioToNumber( '4/3' ) ).toBe( 4 / 3 ); + expect( ratioToNumber( '3/2' ) ).toBe( 3 / 2 ); + expect( ratioToNumber( '2/1' ) ).toBe( 2 ); + expect( ratioToNumber( '1/2' ) ).toBe( 1 / 2 ); + expect( ratioToNumber( '2/3' ) ).toBe( 2 / 3 ); + expect( ratioToNumber( '3/4' ) ).toBe( 3 / 4 ); + expect( ratioToNumber( '9/16' ) ).toBe( 9 / 16 ); + expect( ratioToNumber( '1/16' ) ).toBe( 1 / 16 ); + expect( ratioToNumber( '16/1' ) ).toBe( 16 ); + expect( ratioToNumber( '1/9' ) ).toBe( 1 / 9 ); + expect( ratioToNumber( 'auto' ) ).toBe( NaN ); +} );