diff --git a/blocks/api/test/parser.js b/blocks/api/test/parser.js index 3eb16a2878e59..5ed001bb49940 100644 --- a/blocks/api/test/parser.js +++ b/blocks/api/test/parser.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { noop } from 'lodash'; - /** * Internal dependencies */ @@ -32,6 +27,18 @@ describe( 'block parser', () => { title: 'block title', }; + const unknownBlockSettings = { + category: 'common', + title: 'unknown block', + attributes: { + content: { + type: 'string', + source: 'html', + }, + }, + save: ( { attributes } ) => attributes.content, + }; + afterEach( () => { setUnknownTypeHandlerName( undefined ); getBlockTypes().forEach( ( block ) => { @@ -163,7 +170,7 @@ describe( 'block parser', () => { const block = createBlockWithFallback( 'core/test-block', - 'content', + 'Bananas', { fruit: 'Bananas' } ); expect( block.name ).toEqual( 'core/test-block' ); @@ -173,49 +180,35 @@ describe( 'block parser', () => { it( 'should create the requested block with no attributes if it exists', () => { registerBlockType( 'core/test-block', defaultBlockSettings ); - const block = createBlockWithFallback( 'core/test-block', 'content' ); + const block = createBlockWithFallback( 'core/test-block', '' ); expect( block.name ).toEqual( 'core/test-block' ); expect( block.attributes ).toEqual( {} ); } ); it( 'should fall back to the unknown type handler for unknown blocks if present', () => { - registerBlockType( 'core/unknown-block', { - category: 'common', - title: 'unknown block', - attributes: { - content: { - type: 'string', - source: 'html', - }, - fruit: { - type: 'string', - }, - }, - save: ( { attributes } ) => attributes.content, - } ); + registerBlockType( 'core/unknown-block', unknownBlockSettings ); setUnknownTypeHandlerName( 'core/unknown-block' ); const block = createBlockWithFallback( 'core/test-block', - 'content', + 'Bananas', { fruit: 'Bananas' } ); expect( block.name ).toBe( 'core/unknown-block' ); - expect( block.attributes.fruit ).toBe( 'Bananas' ); expect( block.attributes.content ).toContain( 'wp:test-block' ); } ); it( 'should fall back to the unknown type handler if block type not specified', () => { - registerBlockType( 'core/unknown-block', defaultBlockSettings ); + registerBlockType( 'core/unknown-block', unknownBlockSettings ); setUnknownTypeHandlerName( 'core/unknown-block' ); const block = createBlockWithFallback( null, 'content' ); expect( block.name ).toEqual( 'core/unknown-block' ); - expect( block.attributes ).toEqual( {} ); + expect( block.attributes ).toEqual( { content: 'content' } ); } ); it( 'should not create a block if no unknown type handler', () => { - const block = createBlockWithFallback( 'core/test-block', 'content' ); + const block = createBlockWithFallback( 'core/test-block', '' ); expect( block ).toBeUndefined(); } ); } ); @@ -232,7 +225,7 @@ describe( 'block parser', () => { url: { type: 'string' }, chicken: { type: 'string' }, }, - save: noop, + save: ( { attributes } ) => attributes.content, category: 'common', title: 'test block', } ); @@ -268,7 +261,7 @@ describe( 'block parser', () => { source: 'text', }, }, - save: noop, + save: ( { attributes } ) => attributes.content, category: 'common', title: 'test block', } ); @@ -291,7 +284,7 @@ describe( 'block parser', () => { registerBlockType( 'core/test-block', defaultBlockSettings ); const parsed = parse( - '\nRibs\n' + '\nBananas\n' ); expect( parsed ).toHaveLength( 1 ); @@ -304,7 +297,7 @@ describe( 'block parser', () => { setUnknownTypeHandlerName( 'core/unknown-block' ); const parsed = parse( - 'Ribs' + + '\nBananas\n' + '
Broccoli
' + 'Ribs' ); @@ -314,12 +307,12 @@ describe( 'block parser', () => { it( 'should parse the post content, using unknown block handler', () => { registerBlockType( 'core/test-block', defaultBlockSettings ); - registerBlockType( 'core/unknown-block', defaultBlockSettings ); + registerBlockType( 'core/unknown-block', unknownBlockSettings ); setUnknownTypeHandlerName( 'core/unknown-block' ); const parsed = parse( - 'Ribs' + + '\nBananas\n' + 'Broccoli
' + 'Ribs' ); @@ -334,25 +327,15 @@ describe( 'block parser', () => { it( 'should parse the post content, including raw HTML at each end', () => { registerBlockType( 'core/test-block', defaultBlockSettings ); - registerBlockType( 'core/unknown-block', { - attributes: { - content: { - type: 'string', - source: 'html', - }, - }, - save: noop, - category: 'common', - title: 'unknown block', - } ); + registerBlockType( 'core/unknown-block', unknownBlockSettings ); setUnknownTypeHandlerName( 'core/unknown-block' ); const parsed = parse( 'Cauliflower
' + - 'Ribs' + + '\nBananas\n' + '\nBroccoli
\n' + - 'Ribs' + + '\nBananas\n' + 'Romanesco
' ); diff --git a/blocks/api/test/validation.js b/blocks/api/test/validation.js index f203913491685..6e3aabba82169 100644 --- a/blocks/api/test/validation.js +++ b/blocks/api/test/validation.js @@ -30,6 +30,18 @@ describe( 'validation', () => { title: 'block title', }; + /* eslint-disable no-console */ + function expectError() { + expect( console.error ).toHaveBeenCalled(); + console.error.mockClear(); + } + + function expectWarning() { + expect( console.warn ).toHaveBeenCalled(); + console.warn.mockClear(); + } + /* eslint-enable no-console */ + afterEach( () => { setUnknownTypeHandlerName( undefined ); getBlockTypes().forEach( ( block ) => { @@ -102,6 +114,7 @@ describe( 'validation', () => { { chars: 'a \n c \t b ' }, ); + expectWarning(); expect( isEqual ).toBe( false ); } ); @@ -178,7 +191,7 @@ describe( 'validation', () => { expect( isEqual ).toBe( true ); } ); - it( 'returns true if not same style', () => { + it( 'returns false if not same style', () => { const isEqual = isEqualAttributesOfName.style( 'background-image: url( "https://wordpress.org/img.png" ); color: red;', 'color: red; font-size: 13px; background-image: url(\'https://wordpress.org/img.png\');' @@ -201,6 +214,7 @@ describe( 'validation', () => { ] ); + expectWarning(); expect( isEqual ).toBe( false ); } ); @@ -228,6 +242,7 @@ describe( 'validation', () => { { tagName: 'section' } ); + expectWarning(); expect( isEqual ).toBe( false ); } ); @@ -248,6 +263,7 @@ describe( 'validation', () => { } ); + expectWarning(); expect( isEqual ).toBe( false ); } ); @@ -306,6 +322,7 @@ describe( 'validation', () => { '+diff --git a/blocks/test/fixtures/core__pullquote.json b/blocks/test/fixtures/core__pullquote.json index 83c8ec4ec2acf..e264a2bafd908 100644 --- a/blocks/test/fixtures/core__pullquote.json +++ b/blocks/test/fixtures/core__pullquote.json @@ -2,7 +2,7 @@ { "uid": "_uid_0", "name": "core/pullquote", - "isValid": false, + "isValid": true, "attributes": { "value": [ { @@ -23,6 +23,6 @@ ], "align": "none" }, - "originalContent": "Testing pullquote block...
\n" + "originalContent": "Testing pullquote block...
\n\n" } ] diff --git a/blocks/test/fixtures/core__pullquote.parsed.json b/blocks/test/fixtures/core__pullquote.parsed.json index ff24bfaa0115b..b2f37bebc98be 100644 --- a/blocks/test/fixtures/core__pullquote.parsed.json +++ b/blocks/test/fixtures/core__pullquote.parsed.json @@ -3,7 +3,7 @@ "blockName": "core/pullquote", "attrs": null, "innerBlocks": [], - "innerHTML": "\nTesting pullquote block...
\n\n\n" + "innerHTML": "\nTesting pullquote block...
\n\n\n" }, { "attrs": {}, diff --git a/blocks/test/fixtures/core__pullquote.serialized.html b/blocks/test/fixtures/core__pullquote.serialized.html index 340b4fef74d4c..8dbdbe613ad15 100644 --- a/blocks/test/fixtures/core__pullquote.serialized.html +++ b/blocks/test/fixtures/core__pullquote.serialized.html @@ -1,5 +1,5 @@ -Testing pullquote block...
\n+diff --git a/blocks/test/fixtures/core__table.html b/blocks/test/fixtures/core__table.html index 19099e249e5b7..632c38d213f74 100644 --- a/blocks/test/fixtures/core__table.html +++ b/blocks/test/fixtures/core__table.html @@ -1,4 +1,4 @@ -Testing pullquote block...
+
Version Musician Date .70 No musician chosen. May 27, 2003 1.0 Miles Davis January 3, 2004 Lots of versions skipped, see the full list … … 4.4 Clifford Brown December 8, 2015 4.5 Coleman Hawkins April 12, 2016 4.6 Pepper Adams August 16, 2016 4.7 Sarah Vaughan December 6, 2016 diff --git a/blocks/test/fixtures/core__table.json b/blocks/test/fixtures/core__table.json index ac44c8f471126..2ecdee94dd749 100644 --- a/blocks/test/fixtures/core__table.json +++ b/blocks/test/fixtures/core__table.json @@ -2,7 +2,7 @@ { "uid": "_uid_0", "name": "core/table", - "isValid": false, + "isValid": true, "attributes": { "content": [ { @@ -196,6 +196,6 @@ } ] }, - "originalContent": "
Version Musician Date .70 No musician chosen. May 27, 2003 1.0 Miles Davis January 3, 2004 Lots of versions skipped, see the full list … … 4.4 Clifford Brown December 8, 2015 4.5 Coleman Hawkins April 12, 2016 4.6 Pepper Adams August 16, 2016 4.7 Sarah Vaughan December 6, 2016 " + "originalContent": "
Version Musician Date .70 No musician chosen. May 27, 2003 1.0 Miles Davis January 3, 2004 Lots of versions skipped, see the full list … … 4.4 Clifford Brown December 8, 2015 4.5 Coleman Hawkins April 12, 2016 4.6 Pepper Adams August 16, 2016 4.7 Sarah Vaughan December 6, 2016 " } ] diff --git a/blocks/test/fixtures/core__table.parsed.json b/blocks/test/fixtures/core__table.parsed.json index e5b190a4e983e..0051d503b8d62 100644 --- a/blocks/test/fixtures/core__table.parsed.json +++ b/blocks/test/fixtures/core__table.parsed.json @@ -3,7 +3,7 @@ "blockName": "core/table", "attrs": null, "innerBlocks": [], - "innerHTML": "\n
Version Musician Date .70 No musician chosen. May 27, 2003 1.0 Miles Davis January 3, 2004 Lots of versions skipped, see the full list … … 4.4 Clifford Brown December 8, 2015 4.5 Coleman Hawkins April 12, 2016 4.6 Pepper Adams August 16, 2016 4.7 Sarah Vaughan December 6, 2016 \n" + "innerHTML": "\n
Version Musician Date .70 No musician chosen. May 27, 2003 1.0 Miles Davis January 3, 2004 Lots of versions skipped, see the full list … … 4.4 Clifford Brown December 8, 2015 4.5 Coleman Hawkins April 12, 2016 4.6 Pepper Adams August 16, 2016 4.7 Sarah Vaughan December 6, 2016 \n" }, { "attrs": {}, diff --git a/blocks/test/fixtures/core__table.serialized.html b/blocks/test/fixtures/core__table.serialized.html index 9fe01de807a50..ffa7716b9877d 100644 --- a/blocks/test/fixtures/core__table.serialized.html +++ b/blocks/test/fixtures/core__table.serialized.html @@ -1,5 +1,5 @@ -
Version Musician Date .70 No musician chosen. May 27, 2003 1.0 Miles Davis January 3, 2004 Lots of versions skipped, see the full list … … 4.4 Clifford Brown December 8, 2015 4.5 Coleman Hawkins April 12, 2016 4.6 Pepper Adams August 16, 2016 4.7 Sarah Vaughan December 6, 2016 +
Version @@ -20,8 +20,8 @@Lots of versions skipped, see the full list -… -… +… +… 4.4 diff --git a/package-lock.json b/package-lock.json index ae40fb5c2046b..754e39bd3df77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -248,6 +248,14 @@ "dev": true, "requires": { "sprintf-js": "1.0.3" + }, + "dependencies": { + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true + } } }, "argv": { @@ -9391,9 +9399,9 @@ "integrity": "sha1-yd96NCRZSt5r0RkA1ZZpbcBrrFc=" }, "sprintf-js": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.1.tgz", + "integrity": "sha1-Nr54Mgr+WAH2zqPueLblqrlA6gw=", "dev": true }, "sshpk": { diff --git a/package.json b/package.json index 0a35074bfa902..7fa81079f05b7 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "react-test-renderer": "16.0.0", "sass-loader": "6.0.6", "sass-variables-loader": "0.1.3", + "sprintf-js": "1.1.1", "style-loader": "0.18.2", "tinymce": "4.7.2", "webpack": "3.8.1"