Skip to content

Commit

Permalink
Add tests for fluid utils
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian authored and noisysocks committed Oct 10, 2022
1 parent 7d2e2fb commit 54aa8fc
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* WordPress dependencies
*/
import { logged } from '@wordpress/deprecated';

/**
* Internal dependencies
*/
import { getComputedFluidTypographyValue } from '../fluid-utils';

describe( 'getComputedFluidTypographyValue()', () => {
afterEach( () => {
for ( const key in logged ) {
delete logged[ key ];
}
} );

it( 'should return a fluid font size when given a min and max', () => {
const fluidTypographyValues = getComputedFluidTypographyValue( {
minimumFontSize: '20px',
maximumFontSize: '45px',
} );
expect( fluidTypographyValues ).toBe(
'clamp(20px, 1.25rem + ((1vw - 7.68px) * 3.005), 45px)'
);
} );

it( 'should return a fluid font size when given a font size', () => {
const fluidTypographyValues = getComputedFluidTypographyValue( {
fontSize: '30px',
} );
expect( fluidTypographyValues ).toBe(
'clamp(22.5px, 1.40625rem + ((1vw - 7.68px) * 2.704), 45px)'
);
} );

it( 'should return a fluid font size when given a min and max viewport width', () => {
const fluidTypographyValues = getComputedFluidTypographyValue( {
fontSize: '30px',
minimumViewPortWidth: '500px',
maximumViewPortWidth: '1000px',
} );
expect( fluidTypographyValues ).toBe(
'clamp(22.5px, 1.40625rem + ((1vw - 5px) * 4.5), 45px)'
);
} );

it( 'should return a fluid font size when given a scale factor', () => {
const fluidTypographyValues = getComputedFluidTypographyValue( {
fontSize: '30px',
scaleFactor: '2',
} );
expect( fluidTypographyValues ).toBe(
'clamp(22.5px, 1.40625rem + ((1vw - 7.68px) * 5.408), 45px)'
);
} );

it( 'should return a fluid font size when given a min and max font size factor', () => {
const fluidTypographyValues = getComputedFluidTypographyValue( {
fontSize: '30px',
minimumFontSizeFactor: '0.5',
maximumFontSizeFactor: '2',
} );
expect( fluidTypographyValues ).toBe(
'clamp(15px, 0.9375rem + ((1vw - 7.68px) * 5.409), 60px)'
);
} );
} );

0 comments on commit 54aa8fc

Please sign in to comment.