test('when editing is disabled, the selection detection code is disabled', (assert) => {
  let done = assert.async();
  $('#qunit-fixture').append('<p>outside section 1</p>');
  $('#qunit-fixture').append('<p>outside section 2</p>');

  editor = new Editor({mobiledoc: mobileDocWithSection});
  editor.render(editorElement);
  editor.disableEditing();

  const outside1 = $('p:contains(outside section 1)')[0];
  const outside2 = $('p:contains(outside section 2)')[0];

  Helpers.wait(() => {
    Helpers.dom.selectText(editor ,'outside', outside1, 'section 2', outside2);

    Helpers.wait(() => {
      assert.equal(editor.activeSections.length, 0, 'no selection inside the editor');
      const selectedText = Helpers.dom.getSelectedText();
      assert.ok(selectedText.indexOf('outside section 1') !== -1 &&
                selectedText.indexOf('outside section 2') !== -1, 'selects the text');

      done();
    });
  });
});
test('when editing is disabled, the placeholder is not shown', (assert) => {
  editor = new Editor({placeholder: 'the placeholder'});
  editor.disableEditing();
  editor.render(editorElement);

  assert.ok(!$('#editor').data('placeholder'), 'no placeholder when disabled');
  editor.enableEditing();
  assert.equal($('#editor').data('placeholder'), 'the placeholder',
               'placeholder is shown when editable');
});
test('#disableEditing before render is meaningful', (assert) => {
  editor = new Editor();
  editor.disableEditing();
  editor.render(editorElement);

  assert.ok(!editorElement.hasAttribute('contenteditable'),
            'element is not contenteditable');
  editor.enableEditing();
  assert.equal(editorElement.getAttribute('contenteditable'),
               'true',
               'element is contenteditable');
});
test('deleting across 2 sections does nothing if editing is disabled', (assert) => {
  editor = new Editor({mobiledoc: mobileDocWith2Sections});
  editor.render(editorElement);
  editor.disableEditing();
  assert.equal($('#editor p').length, 2, 'precond - has 2 sections to start');

  const p0 = $('#editor p:eq(0)')[0],
        p1 = $('#editor p:eq(1)')[0];

  Helpers.dom.selectText(editor ,'tion', p0, 'sec', p1);
  Helpers.dom.triggerDelete(editor);

  assert.equal($('#editor p').length, 2, 'still has 2 sections');
});
test('failing to delete will not trigger deleting hooks', (assert) => {
  assert.expect(0);
  editor = new Editor({mobiledoc: mobileDocWith2Sections});
  editor.willDelete(() => {
    assert.ok(false, 'willDelete should not be triggered');
  });
  editor.didDelete(() => {
    assert.ok(false, 'didDelete should not be triggered');
  });

  editor.render(editorElement);
  editor.disableEditing();
  Helpers.dom.triggerDelete(editor);
});
test('#disableEditing and #enableEditing toggle contenteditable', (assert) => {
  editor = new Editor();
  editor.render(editorElement);

  assert.equal(editorElement.getAttribute('contenteditable'),
               'true',
               'element is contenteditable');
  editor.disableEditing();
  assert.equal(editorElement.getAttribute('contenteditable'),
               'false',
               'element is not contenteditable');
  editor.enableEditing();
  assert.equal(editorElement.getAttribute('contenteditable'),
               'true',
               'element is contenteditable');
});