From c233061f7dd402bbf116a539b37498ecffef1064 Mon Sep 17 00:00:00 2001 From: Maximilian Stoiber Date: Sun, 24 Sep 2017 17:36:42 +0200 Subject: [PATCH] Add failing test for tab indentation completion --- lib/__tests__/handle-tab.test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/__tests__/handle-tab.test.js b/lib/__tests__/handle-tab.test.js index 38bb7c7..b15b8c9 100644 --- a/lib/__tests__/handle-tab.test.js +++ b/lib/__tests__/handle-tab.test.js @@ -61,3 +61,29 @@ it('should replace selected content with the tab', () => { expect(toPlainText(before)).toEqual(initialText); expect(toPlainText(after)).toEqual(tabs(1)); }); + +it('should match the indentation of the previous line', () => { + const evt = { preventDefault: jest.fn() }; + const initialText = `${tabs(2)}const a = 'b';\n`; + + const currentContent = ContentState.createFromText(initialText); + // " const a = 'b' + // " + // ^ cursor here (on second line/in second block) + const cursorOnSecondLine = SelectionState.createEmpty( + currentContent + .getBlockMap() + .last() + .getKey() + ); + const before = EditorState.create({ + allowUndo: true, + currentContent, + // Focus the entire initial word + selection: cursorOnSecondLine + }); + + const after = handleTab(evt, before); + expect(toPlainText(before)).toEqual(initialText); + expect(toPlainText(after)).toEqual(initialText + tabs(2)); +});