Add transforms to and from core Image block
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { transforms } from '../../src/transforms';
|
||||
|
||||
describe( 'transforms', () => {
|
||||
test( 'exposes a "to" transform targeting core/image', () => {
|
||||
const to = transforms.to;
|
||||
expect( Array.isArray( to ) ? to : [ to ] ).toEqual(
|
||||
expect.arrayContaining( [
|
||||
expect.objectContaining( {
|
||||
type: 'block',
|
||||
blocks: expect.arrayContaining( [ 'core/image' ] ),
|
||||
} ),
|
||||
] )
|
||||
);
|
||||
} );
|
||||
|
||||
test( 'exposes a "from" transform sourced from core/image', () => {
|
||||
const from = transforms.from;
|
||||
expect( Array.isArray( from ) ? from : [ from ] ).toEqual(
|
||||
expect.arrayContaining( [
|
||||
expect.objectContaining( {
|
||||
type: 'block',
|
||||
blocks: expect.arrayContaining( [ 'core/image' ] ),
|
||||
} ),
|
||||
] )
|
||||
);
|
||||
} );
|
||||
|
||||
test( 'to-transform drops filter and intensity', () => {
|
||||
const to = Array.isArray( transforms.to ) ? transforms.to[ 0 ] : transforms.to;
|
||||
const mapped = to.transform( {
|
||||
filter: 'dramatic',
|
||||
intensity: 80,
|
||||
imageId: 12,
|
||||
imageUrl: 'https://example.com/a.jpg',
|
||||
imageAlt: 'A',
|
||||
width: 100,
|
||||
height: 100,
|
||||
linkUrl: '',
|
||||
caption: '',
|
||||
} );
|
||||
expect( mapped ).not.toHaveProperty( 'filter' );
|
||||
expect( mapped ).not.toHaveProperty( 'intensity' );
|
||||
expect( mapped.id ).toBe( 12 );
|
||||
expect( mapped.url ).toBe( 'https://example.com/a.jpg' );
|
||||
} );
|
||||
|
||||
test( 'from-transform normalises filter and intensity to defaults', () => {
|
||||
const from = Array.isArray( transforms.from ) ? transforms.from[ 0 ] : transforms.from;
|
||||
const mapped = from.transform( {
|
||||
id: 12,
|
||||
url: 'https://example.com/a.jpg',
|
||||
alt: 'A',
|
||||
caption: 'cap',
|
||||
width: 100,
|
||||
height: 100,
|
||||
href: 'https://example.com',
|
||||
} );
|
||||
expect( mapped.filter ).toBe( 'normal' );
|
||||
expect( mapped.intensity ).toBe( 100 );
|
||||
expect( mapped.imageId ).toBe( 12 );
|
||||
expect( mapped.imageUrl ).toBe( 'https://example.com/a.jpg' );
|
||||
expect( mapped.imageAlt ).toBe( 'A' );
|
||||
expect( mapped.caption ).toBe( 'cap' );
|
||||
expect( mapped.linkUrl ).toBe( 'https://example.com' );
|
||||
} );
|
||||
} );
|
||||
Reference in New Issue
Block a user