From 9deae784a4be4fdd2922f36590d91f8bc37ea141 Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Wed, 8 May 2019 15:14:56 +1000 Subject: [PATCH 1/7] Add unit test for willTrimSpaces. --- .../test/__mocks__/react-native-aztec.js | 2 ++ .../rich-text/test/__mocks__/react-native.js | 2 ++ .../components/rich-text/test/index.native.js | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 packages/block-editor/src/components/rich-text/test/__mocks__/react-native-aztec.js create mode 100644 packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js create mode 100644 packages/block-editor/src/components/rich-text/test/index.native.js diff --git a/packages/block-editor/src/components/rich-text/test/__mocks__/react-native-aztec.js b/packages/block-editor/src/components/rich-text/test/__mocks__/react-native-aztec.js new file mode 100644 index 00000000000000..680e66a1378ead --- /dev/null +++ b/packages/block-editor/src/components/rich-text/test/__mocks__/react-native-aztec.js @@ -0,0 +1,2 @@ +export default class RCTAztecView { +} diff --git a/packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js b/packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js new file mode 100644 index 00000000000000..0a79209c4ca1c2 --- /dev/null +++ b/packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js @@ -0,0 +1,2 @@ +export class View {}; +export class Platform {}; diff --git a/packages/block-editor/src/components/rich-text/test/index.native.js b/packages/block-editor/src/components/rich-text/test/index.native.js new file mode 100644 index 00000000000000..2da1f1e6ce5866 --- /dev/null +++ b/packages/block-editor/src/components/rich-text/test/index.native.js @@ -0,0 +1,31 @@ +/** + * Internal dependencies + */ +import { RichText } from '../index.native'; + +describe( 'RichText Native', () => { + let richText; + + beforeEach( () => { + richText = new RichText( { multiline: false } ); + } ); + + it ( 'exists', () => { + expect( richText ); + } ); + + describe( 'willTrimSpaces', () => { + it( 'exists', () => { + expect( richText.willTrimSpaces ); + } ); + + it( 'is a function', () => { + expect( typeof richText.willTrimSpaces === 'function' ); + } ); + + it( 'reports false for styled text with no outer spaces', () => { + let html = '

Hello Hello WorldWorld!

'; + expect( richText.willTrimSpaces( html ) ).toBe( false ); + } ); + } ); +} ); From 0731689a0cff89b1896454d9d7349ec8b14c454b Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Wed, 8 May 2019 15:15:55 +1000 Subject: [PATCH 2/7] Fix willTripSpaces to report false for no outer spaces on styled text. --- packages/block-editor/src/components/rich-text/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/rich-text/index.native.js b/packages/block-editor/src/components/rich-text/index.native.js index aca01b3897556f..fd7a88a30013b0 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -652,7 +652,7 @@ export class RichText extends Component { willTrimSpaces( html ) { // regex for detecting spaces around html tags - const trailingSpaces = /(\s+)<.+?>|<.+?>(\s+)/g; + const trailingSpaces = /^(\s+)<.+?>|<.+?>(\s+)$/g; const matches = html.match( trailingSpaces ); if ( matches && matches.length > 0 ) { return true; From 95305c8a9e50d25d843be3388415db3f9c10724c Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Mon, 13 May 2019 16:38:27 +1000 Subject: [PATCH 3/7] Ignore gutenberg-mobile unit tests in gutenberg test pipeline --- test/unit/jest.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/jest.config.js b/test/unit/jest.config.js index 597dd2735c33f1..4b1f0974325e99 100644 --- a/test/unit/jest.config.js +++ b/test/unit/jest.config.js @@ -23,5 +23,6 @@ module.exports = { '/packages/e2e-tests', '/.*/build/', '/.*/build-module/', + '/.+\.native\.js$', ], }; From 2c8e9af8c11948eaaaa8bebedcecb99833b9a6e9 Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Mon, 20 May 2019 19:06:20 +1000 Subject: [PATCH 4/7] Revert "Fix willTripSpaces to report false for no outer spaces on styled text." This reverts commit 0731689a0cff89b1896454d9d7349ec8b14c454b. Upstream changes make this implementation no longer necessary. --- packages/block-editor/src/components/rich-text/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/rich-text/index.native.js b/packages/block-editor/src/components/rich-text/index.native.js index fd7a88a30013b0..aca01b3897556f 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -652,7 +652,7 @@ export class RichText extends Component { willTrimSpaces( html ) { // regex for detecting spaces around html tags - const trailingSpaces = /^(\s+)<.+?>|<.+?>(\s+)$/g; + const trailingSpaces = /(\s+)<.+?>|<.+?>(\s+)/g; const matches = html.match( trailingSpaces ); if ( matches && matches.length > 0 ) { return true; From fc2f7290574bad2d5ad4d923cf9207021bf3370b Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Tue, 21 May 2019 18:17:57 +1000 Subject: [PATCH 5/7] Fix lint issues --- .../rich-text/test/__mocks__/react-native.js | 4 ++-- .../components/rich-text/test/index.native.js | 24 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js b/packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js index 0a79209c4ca1c2..69b197ffde1cc1 100644 --- a/packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js +++ b/packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js @@ -1,2 +1,2 @@ -export class View {}; -export class Platform {}; +export class View {} +export class Platform {} diff --git a/packages/block-editor/src/components/rich-text/test/index.native.js b/packages/block-editor/src/components/rich-text/test/index.native.js index 2da1f1e6ce5866..9957829540e4e1 100644 --- a/packages/block-editor/src/components/rich-text/test/index.native.js +++ b/packages/block-editor/src/components/rich-text/test/index.native.js @@ -4,28 +4,24 @@ import { RichText } from '../index.native'; describe( 'RichText Native', () => { - let richText; + let richText; - beforeEach( () => { - richText = new RichText( { multiline: false } ); - } ); - - it ( 'exists', () => { - expect( richText ); - } ); + beforeEach( () => { + richText = new RichText( { multiline: false } ); + } ); describe( 'willTrimSpaces', () => { it( 'exists', () => { - expect( richText.willTrimSpaces ); + expect( richText ).toHaveProperty( 'willTrimSpaces' ); } ); it( 'is a function', () => { - expect( typeof richText.willTrimSpaces === 'function' ); + expect( richText.willTrimSpaces ).toBeInstanceOf( Function ); } ); - it( 'reports false for styled text with no outer spaces', () => { - let html = '

Hello Hello WorldWorld!

'; - expect( richText.willTrimSpaces( html ) ).toBe( false ); - } ); + it( 'reports false for styled text with no outer spaces', () => { + const html = '

Hello Hello WorldWorld!

'; + expect( richText.willTrimSpaces( html ) ).toBe( false ); + } ); } ); } ); From aca6ffd7fef2eaec52fd4dd1fc26b6d29135537a Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Tue, 21 May 2019 18:18:20 +1000 Subject: [PATCH 6/7] Import RichText without native extension --- .../block-editor/src/components/rich-text/test/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/rich-text/test/index.native.js b/packages/block-editor/src/components/rich-text/test/index.native.js index 9957829540e4e1..22ee6b118bb2d2 100644 --- a/packages/block-editor/src/components/rich-text/test/index.native.js +++ b/packages/block-editor/src/components/rich-text/test/index.native.js @@ -1,7 +1,7 @@ /** * Internal dependencies */ -import { RichText } from '../index.native'; +import { RichText } from '../index'; describe( 'RichText Native', () => { let richText; From 7172601de87190e94b61e277bcdab6a44a86c43e Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Wed, 22 May 2019 00:06:09 +1000 Subject: [PATCH 7/7] Remove stubs from rich-text __mocks__ --- .../components/rich-text/test/__mocks__/react-native-aztec.js | 2 -- .../src/components/rich-text/test/__mocks__/react-native.js | 2 -- 2 files changed, 4 deletions(-) delete mode 100644 packages/block-editor/src/components/rich-text/test/__mocks__/react-native-aztec.js delete mode 100644 packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js diff --git a/packages/block-editor/src/components/rich-text/test/__mocks__/react-native-aztec.js b/packages/block-editor/src/components/rich-text/test/__mocks__/react-native-aztec.js deleted file mode 100644 index 680e66a1378ead..00000000000000 --- a/packages/block-editor/src/components/rich-text/test/__mocks__/react-native-aztec.js +++ /dev/null @@ -1,2 +0,0 @@ -export default class RCTAztecView { -} diff --git a/packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js b/packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js deleted file mode 100644 index 69b197ffde1cc1..00000000000000 --- a/packages/block-editor/src/components/rich-text/test/__mocks__/react-native.js +++ /dev/null @@ -1,2 +0,0 @@ -export class View {} -export class Platform {}