Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Move blocks raw handling tests to test/integration folder #6731

Merged
merged 2 commits into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 0 additions & 79 deletions blocks/api/raw-handling/test/index.js

This file was deleted.

52 changes: 0 additions & 52 deletions blocks/api/raw-handling/test/integration/index.js

This file was deleted.

112 changes: 112 additions & 0 deletions test/integration/blocks-raw-handling.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* External dependencies
*/
import fs from 'fs';
import path from 'path';

/**
* WordPress dependencies
*/
import {
getBlockContent,
rawHandler,
serialize,
} from '@wordpress/blocks';
import { registerCoreBlocks } from '@wordpress/core-blocks';

describe( 'Blocks raw handling', () => {
beforeAll( () => {
// Load all hooks that modify blocks
require( 'editor/hooks' );
registerCoreBlocks();
} );

it( 'should filter inline content', () => {
const filtered = rawHandler( {
HTML: '<h2><em>test</em></h2>',
mode: 'INLINE',
} );

expect( filtered ).toBe( '<em>test</em>' );
} );

it( 'should parse Markdown', () => {
const filtered = rawHandler( {
HTML: '* one<br>* two<br>* three',
plainText: '* one\n* two\n* three',
mode: 'AUTO',
} ).map( getBlockContent ).join( '' );

expect( filtered ).toBe( '<ul>\n\t<li>one</li>\n\t<li>two</li>\n\t<li>three</li>\n</ul>' );
} );

it( 'should parse inline Markdown', () => {
const filtered = rawHandler( {
HTML: 'Some **bold** text.',
plainText: 'Some **bold** text.',
mode: 'AUTO',
} );

expect( filtered ).toBe( 'Some <strong>bold</strong> text.' );
} );

it( 'should parse HTML in plainText', () => {
const filtered = rawHandler( {
HTML: '&lt;p&gt;Some &lt;strong&gt;bold&lt;/strong&gt; text.&lt;/p&gt;',
plainText: '<p>Some <strong>bold</strong> text.</p>',
mode: 'AUTO',
} ).map( getBlockContent ).join( '' );

expect( filtered ).toBe( '<p>Some <strong>bold</strong> text.</p>' );
} );

it( 'should parse Markdown with HTML', () => {
const filtered = rawHandler( {
HTML: '',
plainText: '# Some <em>heading</em>',
mode: 'AUTO',
} ).map( getBlockContent ).join( '' );

expect( filtered ).toBe( '<h1>Some <em>heading</em></h1>' );
} );

it( 'should break up forced inline content', () => {
const filtered = rawHandler( {
HTML: '<p>test</p><p>test</p>',
mode: 'INLINE',
} );

expect( filtered ).toBe( 'test<br>test' );
} );

describe( 'serialize', () => {
function readFile( filePath ) {
return fs.existsSync( filePath ) ? fs.readFileSync( filePath, 'utf8' ).trim() : '';
}

[
'plain',
'classic',
'apple',
'google-docs',
'ms-word',
'ms-word-online',
'evernote',
'iframe-embed',
'one-image',
'two-images',
'markdown',
'wordpress',
].forEach( ( type ) => {
it( type, () => {
const HTML = readFile( path.join( __dirname, `fixtures/${ type }-in.html` ) );
const plainText = readFile( path.join( __dirname, `fixtures/${ type }-in.txt` ) );
const output = readFile( path.join( __dirname, `fixtures/${ type }-out.html` ) );
const converted = rawHandler( { HTML, plainText, canUserUseUnfilteredHTML: true } );
const serialized = typeof converted === 'string' ? converted : serialize( converted );

expect( serialized ).toBe( output );
} );
} );
} );
} );