<commit_before>/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @emails oncall+draft_js
 * @flow strict-local
 * @format
 */

'use strict';

const DraftEntity = require('DraftEntity');

beforeEach(() => {
  jest.resetModules();
});

const createLink = () => {
  return DraftEntity.__create('LINK', 'MUTABLE', {uri: 'zombo.com'});
};

test('must create instances', () => {
  const key = createLink();
  expect(typeof key).toMatchSnapshot();
});

test('must retrieve an instance given a key', () => {
  const key = createLink();
  const retrieved = DraftEntity.__get(key);
  expect(retrieved.getType()).toMatchSnapshot();
  expect(retrieved.getMutability()).toMatchSnapshot();
  expect(retrieved.getData()).toMatchSnapshot();
});

test('must throw when retrieving for an invalid key', () => {
  createLink();
  expect(() => DraftEntity.__get('<KEY>')).toThrow();
});

test('must merge data', () => {
  const key = createLink();

  // Merge new property.
  const newData = {foo: 'bar'};
  DraftEntity.__mergeData(key, newData);
  const newEntity = DraftEntity.__get(key);

  // Replace existing property.
  const withNewURI = {uri: 'homestarrunner.com'};
  DraftEntity.__mergeData(key, withNewURI);
  const entityWithNewURI = DraftEntity.__get(key);

  expect(newEntity.getData()).toMatchSnapshot();
  expect(entityWithNewURI.getData()).toMatchSnapshot();
});<commit_msg>Migrate DraftEntity tests to not use DraftEntity<commit_after>/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @emails oncall+draft_js
 * @flow strict-local
 * @format
 */

'use strict';

const ContentState = require('ContentState');

beforeEach(() => {
  jest.resetModules();
});

const createLink = (contentState: ContentState) => {
  const newContentState = contentState.createEntity('LINK', 'MUTABLE', {
    uri: 'zombo.com',
  });
  return {
    contentState: newContentState,
    key: contentState.getLastCreatedEntityKey(),
  };
};

test('must create instances', () => {
  const {key} = createLink(ContentState.createFromText(''));
  expect(typeof key).toMatchSnapshot();
});

test('must retrieve an instance given a key', () => {
  const {key, contentState} = createLink(ContentState.createFromText(''));
  const retrieved = contentState.getEntity(key);
  expect(retrieved.getType()).toMatchSnapshot();
  expect(retrieved.getMutability()).toMatchSnapshot();
  expect(retrieved.getData()).toMatchSnapshot();
});

test('must throw when retrieving for an invalid key', () => {
  const {contentState} = createLink(ContentState.createFromText(''));
  expect(() => contentState.getEntity('<KEY>')).toThrow();
});

test('must merge data', () => {
  const result = createLink(ContentState.createFromText(''));
  const key = result.key;
  let contentState = result.contentState;

  // Merge new property.
  const newData = {foo: 'bar'};
  contentState = contentState.mergeEntityData(key, newData);
  const newEntity = contentState.getEntity(key);

  // Replace existing property.
  const withNewURI = {uri: 'homestarrunner.com'};
  contentState = contentState.mergeEntityData(key, withNewURI);
  const entityWithNewURI = contentState.getEntity(key);

  expect(newEntity.getData()).toMatchSnapshot();
  expect(entityWithNewURI.getData()).toMatchSnapshot();
});
{'fraction_non_alphanumeric': 0.1564102564102564, 'fraction_numerical': 0.0, 'mean_word_length': 5.053448275862069, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1781461', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1044, 'n_words': 257}