{"size": 5318, "ext": "js", "max_stars_repo_path": "public/tinymce/plugins/autolink/src/test/js/browser/AutoLinkPluginTest.js", "max_stars_repo_name": "vohungnghiem/bestkwave", "max_stars_repo_stars_event_min_datetime": "2018-12-26T09:00:52.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-26T09:00:52.000Z", "max_issues_repo_path": "public/tinymce/plugins/autolink/src/test/js/browser/AutoLinkPluginTest.js", "max_issues_repo_name": "vohungnghiem/bestkwave", "max_issues_repo_issues_event_min_datetime": "2020-04-29T23:02:33.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-13T20:41:57.000Z", "max_forks_repo_path": "public/tinymce/plugins/autolink/src/test/js/browser/AutoLinkPluginTest.js", "max_forks_repo_name": "vohungnghiem/bestkwave", "max_forks_repo_forks_event_min_datetime": "2017-12-14T04:04:43.000Z", "max_forks_repo_forks_event_max_datetime": "2017-12-18T07:35:22.000Z"}
{"max_stars_count": 1, "max_issues_count": 2, "max_forks_count": 4, "avg_line_length": 44.3166666667, "max_line_length": 140, "alphanum_fraction": 0.6007897706}
asynctest(
  'browser.tinymce.plugins.autolink.AutoLinkPluginTest',
  [
    'ephox.agar.api.Pipeline',
    'ephox.mcagar.api.LegacyUnit',
    'ephox.mcagar.api.TinyLoader',
    'tinymce.core.Env',
    'tinymce.plugins.autolink.Plugin',
    'tinymce.plugins.autolink.test.KeyUtils',
    'tinymce.themes.modern.Theme'
  ],
  function (Pipeline, LegacyUnit, TinyLoader, Env, Plugin, KeyUtils, Theme) {
    var success = arguments[arguments.length - 2];
    var failure = arguments[arguments.length - 1];
    var suite = LegacyUnit.createSuite();

    Theme();
    Plugin();

    var typeUrl = function (editor, url) {
      editor.setContent('<p>' + url + '</p>');
      LegacyUnit.setSelection(editor, 'p', url.length);
      KeyUtils.type(editor, ' ');
      return editor.getContent();
    };

    var typeAnEclipsedURL = function (editor, url) {
      url = "(" + url;
      editor.setContent('<p>' + url + '</p>');
      LegacyUnit.setSelection(editor, 'p', url.length);
      KeyUtils.type(editor, ')');
      return editor.getContent();
    };

    var typeNewlineURL = function (editor, url) {
      editor.setContent('<p>' + url + '</p>');
      LegacyUnit.setSelection(editor, 'p', url.length);
      KeyUtils.type(editor, '\n');
      return editor.getContent();
    };

    suite.test("Urls ended with space", function (editor) {
      LegacyUnit.equal(typeUrl(editor, 'http://www.domain.com'), '<p><a href="http://www.domain.com">http://www.domain.com</a></p>');
      LegacyUnit.equal(typeUrl(editor, 'https://www.domain.com'), '<p><a href="https://www.domain.com">https://www.domain.com</a></p>');
      LegacyUnit.equal(typeUrl(editor, 'ssh://www.domain.com'), '<p><a href="ssh://www.domain.com">ssh://www.domain.com</a></p>');
      LegacyUnit.equal(typeUrl(editor, 'ftp://www.domain.com'), '<p><a href="ftp://www.domain.com">ftp://www.domain.com</a></p>');
      LegacyUnit.equal(typeUrl(editor, 'www.domain.com'), '<p><a href="http://www.domain.com">www.domain.com</a></p>');
      LegacyUnit.equal(typeUrl(editor, 'www.domain.com.'), '<p><a href="http://www.domain.com">www.domain.com</a>.</p>');
      LegacyUnit.equal(typeUrl(editor, 'user@domain.com'), '<p><a href="mailto:user@domain.com">user@domain.com</a></p>');
      LegacyUnit.equal(typeUrl(editor, 'mailto:user@domain.com'), '<p><a href="mailto:user@domain.com">mailto:user@domain.com</a></p>');
      LegacyUnit.equal(typeUrl(editor, 'first-last@domain.com'), '<p><a href="mailto:first-last@domain.com">first-last@domain.com</a></p>');
    });

    suite.test("Urls ended with )", function (editor) {
      LegacyUnit.equal(
        typeAnEclipsedURL(editor, 'http://www.domain.com'),
        '<p>(<a href="http://www.domain.com">http://www.domain.com</a>)</p>'
      );
      LegacyUnit.equal(
        typeAnEclipsedURL(editor, 'https://www.domain.com'),
        '<p>(<a href="https://www.domain.com">https://www.domain.com</a>)</p>'
      );
      LegacyUnit.equal(
        typeAnEclipsedURL(editor, 'ssh://www.domain.com'),
        '<p>(<a href="ssh://www.domain.com">ssh://www.domain.com</a>)</p>'
      );
      LegacyUnit.equal(
        typeAnEclipsedURL(editor, 'ftp://www.domain.com'),
        '<p>(<a href="ftp://www.domain.com">ftp://www.domain.com</a>)</p>'
      );
      LegacyUnit.equal(typeAnEclipsedURL(editor, 'www.domain.com'), '<p>(<a href="http://www.domain.com">www.domain.com</a>)</p>');
      LegacyUnit.equal(typeAnEclipsedURL(editor, 'www.domain.com.'), '<p>(<a href="http://www.domain.com">www.domain.com</a>.)</p>');
    });

    suite.test("Urls ended with new line", function (editor) {
      LegacyUnit.equal(
        typeNewlineURL(editor, 'http://www.domain.com'),
        '<p><a href="http://www.domain.com">http://www.domain.com</a></p><p>&nbsp;</p>'
      );
      LegacyUnit.equal(
        typeNewlineURL(editor, 'https://www.domain.com'),
        '<p><a href="https://www.domain.com">https://www.domain.com</a></p><p>&nbsp;</p>'
      );
      LegacyUnit.equal(
        typeNewlineURL(editor, 'ssh://www.domain.com'),
        '<p><a href="ssh://www.domain.com">ssh://www.domain.com</a></p><p>&nbsp;</p>'
      );
      LegacyUnit.equal(
        typeNewlineURL(editor, 'ftp://www.domain.com'),
        '<p><a href="ftp://www.domain.com">ftp://www.domain.com</a></p><p>&nbsp;</p>'
      );
      LegacyUnit.equal(
        typeNewlineURL(editor, 'www.domain.com'),
        '<p><a href="http://www.domain.com">www.domain.com</a></p><p>&nbsp;</p>'
      );
      LegacyUnit.equal(
        typeNewlineURL(editor, 'www.domain.com.'),
        '<p><a href="http://www.domain.com">www.domain.com</a>.</p><p>&nbsp;</p>'
      );
    });

    suite.test("default_link_target='_self'", function (editor) {
      editor.settings.default_link_target = '_self';
      LegacyUnit.equal(
        typeUrl(editor, 'http://www.domain.com'),
        '<p><a href="http://www.domain.com" target="_self">http://www.domain.com</a></p>'
      );
      delete editor.settings.default_link_target;
    });

    TinyLoader.setup(function (editor, onSuccess, onFailure) {
      var steps = Env.ie ? [] : suite.toSteps(editor);
      Pipeline.async({}, steps, onSuccess, onFailure);
    }, {
      plugins: 'autolink',
      indent: false,
      skin_url: '/project/src/skins/lightgray/dist/lightgray'
    }, success, failure);
  }
);