/* eslint-disable no-console */

import { toText } from './to-text';

describe('RichTextEditor toText', () => {
  it('can convert very simple models', async () => {
    expect(
      toText({
        kind: 'block',
        type: 'paragraph',
        textContent: 'Hi there!',
      }),
    ).toBe('Hi there!');

    expect(
      toText({
        kind: 'block',
        type: 'paragraph',
        textContent: 'Hi \nthere!',
      }),
    ).toBe('Hi \nthere!');
  });

  it('will trim the start and end new lines of the text', async () => {
    expect(
      toText({
        kind: 'block',
        type: 'paragraph',
        textContent: '\nHi there!\n',
      }),
    ).toBe('Hi there!');
  });

  it('Will preserve line break nodes if told to', async () => {
    expect(
      toText(
        {
          kind: 'block',
          type: 'paragraph',
          children: [
            {
              kind: 'inline',
              textContent: 'Hi ',
            },
            {
              kind: 'inline',
              type: 'line-break',
            },
            {
              kind: 'inline',
              textContent: 'there!',
            },
          ],
        },
        {
          keepLineBreaks: true,
        },
      ),
    ).toBe('Hi \nthere!');

    expect(
      toText({
        kind: 'block',
        type: 'paragraph',
        textContent: 'Hi \nthere!',
      }),
    ).toBe('Hi \nthere!');
  });

  it('Will remove line break nodes if told to', async () => {
    expect(
      toText(
        {
          kind: 'block',
          type: 'paragraph',
          children: [
            {
              kind: 'inline',
              textContent: 'Hi ',
            },
            {
              kind: 'inline',
              type: 'line-break',
            },
            {
              kind: 'inline',
              textContent: 'there!',
            },
          ],
        },
        {
          keepLineBreaks: false,
        },
      ),
    ).toBe('Hi there!');
  });
});
