Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Add list block onTab test
Browse files Browse the repository at this point in the history
Summary:
**Summary**
This PR adds a unit test for `onTab`(#1674) on list block(ordered-list-item, unordered-list-item).
Closes #1694

Differential Revision: D7294623

fbshipit-source-id: b0a103e402b03484ff929f9b5d6d7500ca23c116
  • Loading branch information
il kwon Sim authored and facebook-github-bot committed Mar 15, 2018
1 parent 22f9c52 commit 102701c
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/model/modifier/__tests__/RichTextEditorUtil-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ const SelectionState = require('SelectionState');
const getSampleStateForTesting = require('getSampleStateForTesting');

const {editorState, selectionState} = getSampleStateForTesting();
const {onBackspace, onDelete, tryToRemoveBlockStyle} = RichTextEditorUtil;
const {
onBackspace,
onDelete,
onTab,
tryToRemoveBlockStyle,
} = RichTextEditorUtil;

const insertAtomicBlock = targetEditorState => {
const entityKey = targetEditorState
Expand Down Expand Up @@ -169,3 +174,49 @@ test('tryToRemoveBlockStyleonDelete breaks out of code block on enter two blank

expect(lastBlock.toJS()).toMatchSnapshot();
});

describe('onTab on list block', () => {
const setListBlock = (contentState, type) =>
DraftModifier.setBlockType(contentState, selectionState, type);
const changeBlockType = setListItem =>
EditorState.push(editorState, setListItem, 'change-block-type');
const getFirstBlockDepth = contentState =>
contentState
.getCurrentContent()
.getFirstBlock()
.getDepth();
const addTab = (contentState, maxDepth = 2) =>
onTab({preventDefault: () => {}}, contentState, maxDepth);

test('increases the depth of unordered-list-item', () => {
const contentState = editorState.getCurrentContent();
const setListItem = setListBlock(contentState, 'unordered-list-item');
const withListItem = changeBlockType(setListItem);

const afterFirstTab = addTab(withListItem);
const depthAfterFirstTab = getFirstBlockDepth(afterFirstTab);

expect(depthAfterFirstTab).toBe(1);

const afterSecondTab = addTab(afterFirstTab);
const depthAfterSecondTab = getFirstBlockDepth(afterSecondTab);

expect(depthAfterSecondTab).toBe(2);
});

test('increases the depth of unordered-list-item', () => {
const contentState = editorState.getCurrentContent();
const setListItem = setListBlock(contentState, 'ordered-list-item');
const withListItem = changeBlockType(setListItem);

const afterFirstTab = addTab(withListItem);
const depthAfterFirstTab = getFirstBlockDepth(afterFirstTab);

expect(depthAfterFirstTab).toBe(1);

const afterSecondTab = addTab(afterFirstTab);
const depthAfterSecondTab = getFirstBlockDepth(afterSecondTab);

expect(depthAfterSecondTab).toBe(2);
});
});

0 comments on commit 102701c

Please sign in to comment.