<commit_before>import { acceptance } from "helpers/qunit-helpers";

acceptance('Spoiler Button', { loggedIn: true, settings: { spoiler_enabled: true }});

function findTextarea() {
  return find(".d-editor-input")[0];
}

test('spoiler button', () => {
  visit("/");

  andThen(() => {
    ok(exists('#create-topic'), 'the create button is visible');
  });

  click('#create-topic');
  click('button.options');
  click(`.popup-menu button:contains(${I18n.t("spoiler.title")})`);

  andThen(() => {
    equal(
      find(".d-editor-input").val(),
      `[spoiler]${I18n.t("composer.spoiler_text")}[/spoiler]`,
      'it should contain the right output'
    );

    const textarea = findTextarea();
    equal(textarea.selectionStart, 9, 'it should start highlighting at the right position');
    equal(textarea.selectionEnd, I18n.t("composer.spoiler_text").length + 9, 'it should end highlighting at the right position');
  });

  fillIn('.d-editor-input', "This is hidden");

  andThen(() => {
    const textarea = findTextarea();
    textarea.selectionStart = 0;
    textarea.selectionEnd = textarea.value.length;
  });

  click('button.options');
  click(`.popup-menu button:contains(${I18n.t("spoiler.title")})`);

  andThen(() => {
    equal(
      find(".d-editor-input").val(),
      `[spoiler]This is hidden[/spoiler]`,
      'it should contain the right output'
    );

    const textarea = findTextarea();
    equal(textarea.selectionStart, 9, 'it should start highlighting at the right position');
    equal(textarea.selectionEnd, 23, 'it should end highlighting at the right position');
  });

  fillIn('.d-editor-input', "Before this is hidden After");

  andThen(() => {
    const textarea = findTextarea();
    textarea.selectionStart = 7;
    textarea.selectionEnd = 21;
  });

  click('button.options');
  click(`.popup-menu button:contains(${I18n.t("spoiler.title")})`);

  andThen(() => {
    equal(
      find(".d-editor-input").val(),
      `Before [spoiler]this is hidden[/spoiler] After`,
      'it should contain the right output'
    );

    const textarea = findTextarea();
    equal(textarea.selectionStart, 16, 'it should start highlighting at the right position');
    equal(textarea.selectionEnd, 30, 'it should end highlighting at the right position');
  });

  fillIn('.d-editor-input', "Before\nthis is hidden\nAfter");

  andThen(() => {
    const textarea = findTextarea();
    textarea.selectionStart = 7;
    textarea.selectionEnd = 21;
  });

  click('button.options');
  click(`.popup-menu button:contains(${I18n.t("spoiler.title")})`);

  andThen(() => {
    equal(
      find(".d-editor-input").val(),
      `Before\n[spoiler]this is hidden[/spoiler]\nAfter`,
      'it should contain the right output'
    );

    const textarea = findTextarea();
    equal(textarea.selectionStart, 16, 'it should start highlighting at the right position');
    equal(textarea.selectionEnd, 30, 'it should end highlighting at the right position');
  });
});<commit_msg>Fix qunit tests using new `assert` syntax<commit_after>import { acceptance } from "helpers/qunit-helpers";

acceptance('Spoiler Button', { loggedIn: true, settings: { spoiler_enabled: true }});

function findTextarea() {
  return find(".d-editor-input")[0];
}

test('spoiler button', assert => {
  visit("/");

  andThen(() => {
    assert.ok(exists('#create-topic'), 'the create button is visible');
  });

  click('#create-topic');
  click('button.options');
  click(`.popup-menu button:contains(${I18n.t("spoiler.title")})`);

  andThen(() => {
    assert.equal(
      find(".d-editor-input").val(),
      `[spoiler]${I18n.t("composer.spoiler_text")}[/spoiler]`,
      'it should contain the right output'
    );

    const textarea = findTextarea();
    assert.equal(textarea.selectionStart, 9, 'it should start highlighting at the right position');
    assert.equal(textarea.selectionEnd, I18n.t("composer.spoiler_text").length + 9, 'it should end highlighting at the right position');
  });

  fillIn('.d-editor-input', "This is hidden");

  andThen(() => {
    const textarea = findTextarea();
    textarea.selectionStart = 0;
    textarea.selectionEnd = textarea.value.length;
  });

  click('button.options');
  click(`.popup-menu button:contains(${I18n.t("spoiler.title")})`);

  andThen(() => {
    assert.equal(
      find(".d-editor-input").val(),
      `[spoiler]This is hidden[/spoiler]`,
      'it should contain the right output'
    );

    const textarea = findTextarea();
    assert.equal(textarea.selectionStart, 9, 'it should start highlighting at the right position');
    assert.equal(textarea.selectionEnd, 23, 'it should end highlighting at the right position');
  });

  fillIn('.d-editor-input', "Before this is hidden After");

  andThen(() => {
    const textarea = findTextarea();
    textarea.selectionStart = 7;
    textarea.selectionEnd = 21;
  });

  click('button.options');
  click(`.popup-menu button:contains(${I18n.t("spoiler.title")})`);

  andThen(() => {
    assert.equal(
      find(".d-editor-input").val(),
      `Before [spoiler]this is hidden[/spoiler] After`,
      'it should contain the right output'
    );

    const textarea = findTextarea();
    assert.equal(textarea.selectionStart, 16, 'it should start highlighting at the right position');
    assert.equal(textarea.selectionEnd, 30, 'it should end highlighting at the right position');
  });

  fillIn('.d-editor-input', "Before\nthis is hidden\nAfter");

  andThen(() => {
    const textarea = findTextarea();
    textarea.selectionStart = 7;
    textarea.selectionEnd = 21;
  });

  click('button.options');
  click(`.popup-menu button:contains(${I18n.t("spoiler.title")})`);

  andThen(() => {
    assert.equal(
      find(".d-editor-input").val(),
      `Before\n[spoiler]this is hidden[/spoiler]\nAfter`,
      'it should contain the right output'
    );

    const textarea = findTextarea();
    assert.equal(textarea.selectionStart, 16, 'it should start highlighting at the right position');
    assert.equal(textarea.selectionEnd, 30, 'it should end highlighting at the right position');
  });
});
{'fraction_non_alphanumeric': 0.16887796887796888, 'fraction_numerical': 0.010810810810810811, 'mean_word_length': 3.8078740157480313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1885296', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1869, 'n_words': 441}