# all files / test/unit/base/module/ LinkDialog.spec.js

100% Statements 29/29
100% Branches 0/0
100% Functions 5/5
100% Lines 29/29

    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

    1×
    1×
    1×
    1×
    1×

    1×
    1×
    1×

    1×
    2×
    2×
    2×

    2×

    2×

    2×
    2×

    2×
    2×

    1×
    1×
    1×
    1×

    1×
    1×

    1×
    1×
    1×

    1×
    1×

     /**
     * LinkDialog.spec.js
     * (c) 2015~ Summernote Team
     * summernote may be freely distributed under the MIT license./
     */
    import chai from 'chai';
    import $ from 'jquery';
    import range from '../../../../src/js/base/core/range';
    import Context from '../../../../src/js/base/Context';
    import LinkDialog from '../../../../src/js/base/module/LinkDialog';

    describe('LinkDialog', () => {
      var expect = chai.expect;
      var context, dialog, $editable;

      beforeEach(() => {
        var options = $.extend({}, $.summernote.options);
        options.langInfo = $.extend(true, {}, $.summernote.lang['en-US'], $.summernote.lang[options.lang]);
        options.toolbar = [
          ['insert', ['link']]
        ];
        context = new Context(
          $('<div>' +
            '<p><a href="https://summernote.org/" target="_blank">hello</a></p>' +
            '<p><a href="https://summernote.org/">world</a></p>' +
            '</div>'),
          options
        );
        context.initialize();

        dialog = new LinkDialog(context);
        dialog.initialize();

        $editable = context.layoutInfo.editable;
        $editable.appendTo('body');
      });

      describe('LinkDialog', () => {
        it('should check new window when target=_blank', () => {
          range.createFromNode($editable.find('a')[0]).normalize().select();
          dialog.show();

          var checked = dialog.$dialog.find('#sn-checkbox-open-in-new-window').is(':checked');
          expect(checked).to.be.true;
        });

        it('should uncheck new window without target=_blank', () => {
          range.createFromNode($editable.find('a')[1]).normalize().select();
          dialog.show();

          var checked = dialog.$dialog.find('#sn-checkbox-open-in-new-window').is(':checked');
          expect(checked).to.be.false;
        });
      });
    });