{"size": 2807, "ext": "js", "max_stars_repo_path": "cypress/integration/markdown_widget_enter_spec.js", "max_stars_repo_name": "arinjaysaraf/netlify-cms", "max_stars_repo_stars_event_min_datetime": "2015-09-29T08:51:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:08:56.000Z", "max_issues_repo_path": "cypress/integration/markdown_widget_enter_spec.js", "max_issues_repo_name": "arinjaysaraf/netlify-cms", "max_issues_repo_issues_event_min_datetime": "2015-11-03T16:48:20.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T19:44:49.000Z", "max_forks_repo_path": "cypress/integration/markdown_widget_enter_spec.js", "max_forks_repo_name": "arinjaysaraf/netlify-cms", "max_forks_repo_forks_event_min_datetime": "2015-09-29T09:02:52.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T07:36:09.000Z"}
{"max_stars_count": 16109, "max_issues_count": 4280, "max_forks_count": 3681, "avg_line_length": 25.752293578, "max_line_length": 109, "alphanum_fraction": 0.4980406128}
import '../utils/dismiss-local-backup';

describe('Markdown widget breaks', () => {
  before(() => {
    Cypress.config('defaultCommandTimeout', 4000);
    cy.task('setupBackend', { backend: 'test' });
    cy.loginAndNewPost();
  });

  beforeEach(() => {
    cy.clearMarkdownEditorContent();
  });

  after(() => {
    cy.task('teardownBackend', { backend: 'test' });
  });

  describe('pressing enter', () => {
    it('creates new default block from empty block', () => {
      cy.focused()
        .enter()
        .confirmMarkdownEditorContent(`
          <p></p>
          <p></p>
        `);
    });
    it('creates new default block when selection collapsed at end of block', () => {
      cy.focused()
        .type('foo')
        .enter()
        .confirmMarkdownEditorContent(`
          <p>foo</p>
          <p></p>
        `);
    });
    it('creates new default block when selection collapsed at end of non-default block', () => {
      cy.clickHeadingOneButton()
        .type('foo')
        .enter()
        .confirmMarkdownEditorContent(`
          <h1>foo</h1>
          <p></p>
        `);
    });
    it('creates new default block when selection collapsed in empty non-default block', () => {
      cy.clickHeadingOneButton()
        .enter()
        .confirmMarkdownEditorContent(`
          <h1></h1>
          <p></p>
        `);
    });
    it('splits block into two same-type blocks when collapsed selection at block start', () => {
      cy.clickHeadingOneButton()
        .type('foo')
        .setCursorBefore('foo')
        .enter()
        .confirmMarkdownEditorContent(`
          <h1></h1>
          <h1>foo</h1>
        `);
    });
    it('splits block into two same-type blocks when collapsed in middle of selection at block start', () => {
      cy.clickHeadingOneButton()
        .type('foo')
        .setCursorBefore('oo')
        .enter()
        .confirmMarkdownEditorContent(`
          <h1>f</h1>
          <h1>oo</h1>
        `);
    });
    it('deletes selected content and splits to same-type block when selection is expanded', () => {
      cy.clickHeadingOneButton()
        .type('foo bar')
        .setSelection('o b')
        .enter()
        .confirmMarkdownEditorContent(`
          <h1>fo</h1>
          <h1>ar</h1>
        `);
    });
  });

  describe('pressing shift+enter', () => {
    it('creates line break', () => {
      cy.focused()
        .enter({ shift: true })
        .confirmMarkdownEditorContent(`
          <p>
            <br>
          </p>
        `);
    });
    it('creates consecutive line break', () => {
      cy.focused()
        .enter({ shift: true, times: 4 })
        .confirmMarkdownEditorContent(`
          <p>
            <br>
            <br>
            <br>
            <br>
          </p>
        `);
    });
  });
});
