import { GeneralSteps, Keys, Logger, Pipeline } from '@ephox/agar'; import { TinyActions, TinyApis, TinyLoader } from '@ephox/mcagar'; import Theme from 'tinymce/themes/modern/Theme'; import { UnitTest } from '@ephox/bedrock'; UnitTest.asynctest('browser.tinymce.core.keyboard.SpaceKeyTest', (success, failure) => { Theme(); TinyLoader.setup(function (editor, onSuccess, onFailure) { const tinyApis = TinyApis(editor); const tinyActions = TinyActions(editor); const img = ''; Pipeline.async({}, [ Logger.t('Space key around inline boundary elements', GeneralSteps.sequence([ Logger.t('Press space at beginning of inline boundary inserting nbsp', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a b c

'), tinyApis.sSetCursor([0, 1, 0], 0), tinyApis.sNodeChanged, tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 1, 0], 1, [0, 1, 0], 1), tinyApis.sAssertContent('

a  b c

') ])), Logger.t('Press space at end of inline boundary inserting nbsp', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a b c

'), tinyApis.sSetCursor([0, 1, 0], 1), tinyApis.sNodeChanged, tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 1, 0], 2, [0, 1, 0], 2), tinyApis.sAssertContent('

a c

') ])), Logger.t('Press space at beginning of inline boundary inserting space', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

abc

'), tinyApis.sSetCursor([0, 1, 0], 0), tinyApis.sNodeChanged, tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 1, 0], 1, [0, 1, 0], 1), tinyApis.sAssertContent('

a bc

') ])), Logger.t('Press space at end of inline boundary inserting space', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

abc

'), tinyApis.sSetCursor([0, 1, 0], 1), tinyApis.sNodeChanged, tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 1, 0], 2, [0, 1, 0], 2), tinyApis.sAssertContent('

ab c

') ])), Logger.t('Press space at start of inline boundary with leading space inserting nbsp', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a bc

'), tinyApis.sSetCursor([0, 1, 0], 0), tinyApis.sNodeChanged, tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 1, 0], 1, [0, 1, 0], 1), tinyApis.sAssertContent('

a  bc

') ])), Logger.t('Press space at end of inline boundary with trailing space inserting nbsp', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

ab c

'), tinyApis.sSetCursor([0, 1, 0], 2), tinyApis.sNodeChanged, tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 1, 0], 3, [0, 1, 0], 3), tinyApis.sAssertContent('

ab  c

') ])) ])), Logger.t('Space key in block elements', GeneralSteps.sequence([ Logger.t('Press space at beginning of block', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a

'), tinyApis.sSetCursor([0, 0], 0), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 1, [0, 0], 1), tinyApis.sAssertContent('

 a

') ])), Logger.t('Press space at end of block', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a

'), tinyApis.sSetCursor([0, 0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 2, [0, 0], 2), tinyApis.sAssertContent('

') ])) ])), Logger.t('Space key in text', GeneralSteps.sequence([ Logger.t('Press space in middle of text', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

ab

'), tinyApis.sSetCursor([0, 0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 2, [0, 0], 2), tinyApis.sAssertContent('

a b

') ])), Logger.t('Press space after letter preceded by space', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a bc

'), tinyApis.sSetCursor([0, 0], 3), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 4, [0, 0], 4), tinyApis.sAssertContent('

a b c

') ])), Logger.t('Press space before letter followed by space', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

ab c

'), tinyApis.sSetCursor([0, 0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 2, [0, 0], 2), tinyApis.sAssertContent('

a b c

') ])), Logger.t('Press space after letter followed by space in inline element', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a c

'), tinyApis.sSetCursor([0, 0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 2, [0, 0], 2), tinyApis.sAssertContent('

c

') ])), Logger.t('Press space before letter preceded by space in inline element', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

ab c

'), tinyApis.sSetCursor([0, 2], 0), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 2], 1, [0, 2], 1), tinyApis.sAssertContent('

ab  c

') ])), Logger.t('Press space after letter followed by nbsp in inline element', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a c

'), tinyApis.sSetCursor([0, 0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 2, [0, 0], 2), tinyApis.sAssertContent('

a  c

') ])), Logger.t('Press space before letter preceded by nbsp in inline element', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

ac

'), tinyApis.sSetCursor([0, 2], 0), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 2], 1, [0, 2], 1), tinyApis.sAssertContent('

a c

') ])), Logger.t('Press space before nbsp in text', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a b

'), tinyApis.sSetCursor([0, 0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 2, [0, 0], 2), tinyApis.sAssertContent('

a  b

') ])), Logger.t('Press space after nbsp in text', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a b

'), tinyApis.sSetCursor([0, 0], 2), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 3, [0, 0], 3), tinyApis.sAssertContent('

a  b

') ])), Logger.t('Press space between two nbsp in text', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a  b

'), tinyApis.sSetCursor([0, 0], 2), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 3, [0, 0], 3), tinyApis.sAssertContent('

a   b

') ])), Logger.t('Press space before two nbsp in text', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a  b

'), tinyApis.sSetCursor([0, 0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 2, [0, 0], 2), tinyApis.sAssertContent('

a   b

') ])), Logger.t('Press space after two nbsp in text', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

a  b

'), tinyApis.sSetCursor([0, 0], 3), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 4, [0, 0], 4), tinyApis.sAssertContent('

a   b

') ])), Logger.t('Press space before letter followed by space in inline element', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

ab c

'), tinyApis.sSetCursor([0, 0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 2, [0, 0], 2), tinyApis.sAssertContent('

a b c

') ])), Logger.t('Press space after letter preceded by space in inline element', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('

ab cd

'), tinyApis.sSetCursor([0, 2], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 2], 2, [0, 2], 2), tinyApis.sAssertContent('

ab c d

') ])) ])), Logger.t('Space key in preformatted text', GeneralSteps.sequence([ Logger.t('Press space at start of pre', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('
ab
'), tinyApis.sSetCursor([0, 0], 0), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 1, [0, 0], 1), tinyApis.sAssertContent('
 ab
') ])), Logger.t('Press space in middle of text', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('
ab
'), tinyApis.sSetCursor([0, 0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 2, [0, 0], 2), tinyApis.sAssertContent('
a b
') ])), Logger.t('Press space at end of pre', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('
ab
'), tinyApis.sSetCursor([0, 0], 2), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 3, [0, 0], 3), tinyApis.sAssertContent('
ab 
') ])), Logger.t('Press space in after space', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('
a b
'), tinyApis.sSetCursor([0, 0], 2), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 3, [0, 0], 3), tinyApis.sAssertContent('
a  b
') ])), Logger.t('Press space in before space', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetContent('
a b
'), tinyApis.sSetCursor([0, 0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 2, [0, 0], 2), tinyApis.sAssertContent('
a  b
') ])) ])), Logger.t('Space key at br', GeneralSteps.sequence([ Logger.t('Press space between two br:s in block', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetRawContent('



'), tinyApis.sSetCursor([0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 1], 1, [0, 1], 1), tinyApis.sAssertContent('


 

') ])), Logger.t('Press space after br in beginning of text node', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetRawContent('

a
b

'), tinyApis.sSetCursor([0, 2], 0), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 2], 1, [0, 2], 1), tinyApis.sAssertContent('

a
 b

') ])), Logger.t('Press space before br in beginning of text node', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetRawContent('


b

'), tinyApis.sSetCursor([0], 0), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 1, [0, 0], 1), tinyApis.sAssertContent('

 
b

') ])) ])), Logger.t('Space key at node indexes', GeneralSteps.sequence([ Logger.t('Press space before image element in block', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetRawContent(`

${img}

`), tinyApis.sSetCursor([0], 0), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 0], 1, [0, 0], 1), tinyApis.sAssertContent(`

 ${img}

`) ])), Logger.t('Press space between two image elements in block', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetRawContent(`

${img}${img}

`), tinyApis.sSetCursor([0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 1], 1, [0, 1], 1), tinyApis.sAssertContent(`

${img} ${img}

`) ])), Logger.t('Press space after image element in block', GeneralSteps.sequence([ tinyApis.sFocus, tinyApis.sSetRawContent(`

${img}

`), tinyApis.sSetCursor([0], 1), tinyActions.sContentKeystroke(Keys.space(), {}), tinyApis.sAssertSelection([0, 1], 1, [0, 1], 1), tinyApis.sAssertContent(`

${img} 

`) ])) ])) ], onSuccess, onFailure); }, { indent: false, skin_url: '/project/js/tinymce/skins/lightgray' }, success, failure); });