# all files / test/unit/base/editing/ Typing.spec.js

100% Statements 34/34
100% Branches 0/0
100% Functions 13/13
100% Lines 34/34

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72

    1×
    1×
    1×
    1×

    1×

    1×
    1×
    6×

    1×
    1×
    1×
    1×

    1×
    6×

    1×
    6×

    1×
    1×

    1×

    1×
    1×

    1×

    1×
    1×

    1×

    1×
    1×

    1×

    1×
    1×

    1×

    1×
    1×

    1×

     /**
     * Typing.spec.js
     * (c) 2015~ Summernote Team
     * summernote may be freely distributed under the MIT license./
     */
    /* jshint unused: false */
    /* jshint -W101 */
    import chai from 'chai';
    import $ from 'jquery';
    import range from '../../../../src/js/base/core/range';
    import Typing from '../../../../src/js/base/editing/Typing';

    var expect = chai.expect;

    describe('base:editing.Style', () => {
      function typing(level) {
        return new Typing({ options: { blockquoteBreakingLevel: level } });
      }

      describe('base:editing.Typing', () => {
        describe('insertParagraph', () => {
          describe('blockquote breaking support', () => {
            var $editable;

            function check(html) {
              expect($editable.html()).to.equalsIgnoreCase(html);
            }

            beforeEach(() => {
              $editable = $('<div class="note-editable"><blockquote id="1">Part1<blockquote id="2">Part2.1<br>Part2.2</blockquote>Part3</blockquote></div>');
            });

            it('should not break blockquote if blockquoteBreakingLevel=0', () => {
              typing(0).insertParagraph($editable, range.create($('#2', $editable)[0].firstChild, 1));

              check('<blockquote id="1">Part1<blockquote id="2"><p>P</p><p>art2.1<br>Part2.2</p></blockquote>Part3</blockquote>');
            });

            it('should break the first blockquote if blockquoteBreakingLevel=1', () => {
              typing(1).insertParagraph($editable, range.create($('#2', $editable)[0].firstChild, 1));

              check('<blockquote id="1">Part1<blockquote id="2"><p>P</p></blockquote><p><br></p><blockquote id="2"><p>art2.1<br>Part2.2</p></blockquote>Part3</blockquote>');
            });

            it('should break all blockquotes if blockquoteBreakingLevel=2', () => {
              typing(2).insertParagraph($editable, range.create($('#2', $editable)[0].firstChild, 1));

              check('<blockquote id="1">Part1<blockquote id="2"><p>P</p></blockquote></blockquote><p><br></p><blockquote id="1"><blockquote id="2"><p>art2.1<br>Part2.2</p></blockquote>Part3</blockquote>');
            });

            it('should remove leading BR from split, when breaking is on the right edge of a line', () => {
              typing(1).insertParagraph($editable, range.create($('#2', $editable)[0].firstChild, 7));

              check('<blockquote id="1">Part1<blockquote id="2"><p>Part2.1</p></blockquote><p><br></p><blockquote id="2"><p>Part2.2</p></blockquote>Part3</blockquote>');
            });

            it('should insert new paragraph after the blockquote, if break happens at the end of the blockquote', () => {
              typing(2).insertParagraph($editable, range.create($('#1', $editable)[0].lastChild, 5));

              check('<blockquote id="1"><p>Part1<blockquote id="2">Part2.1<br>Part2.2</blockquote>Part3</p></blockquote><p><br></p>');
            });

            it('should insert new paragraph before the blockquote, if break happens at the beginning of the blockquote', () => {
              typing(2).insertParagraph($editable, range.create($('#1', $editable)[0].firstChild, 0));

              check('<p><br></p><blockquote id="1"><p>Part1<blockquote id="2">Part2.1<br>Part2.2</blockquote>Part3</p></blockquote>');
            });
          });
        });
      });
    });