discourse/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6
2017-07-11 17:25:53 +01:00

93 lines
2.7 KiB
JavaScript

import { acceptance } from "helpers/qunit-helpers";
acceptance('Details Button', { loggedIn: true });
function findTextarea() {
return find(".d-editor-input")[0];
}
test('details button', (assert) => {
visit("/");
click('#create-topic');
click('button.options');
click('.popup-menu .fa-caret-right');
andThen(() => {
assert.equal(
find(".d-editor-input").val(),
`\n[details=${I18n.t("composer.details_title")}]\n${I18n.t("composer.details_text")}\n[/details]\n`,
'it should contain the right output'
);
});
fillIn('.d-editor-input', "This is my title");
andThen(() => {
const textarea = findTextarea();
textarea.selectionStart = 0;
textarea.selectionEnd = textarea.value.length;
});
click('button.options');
click('.popup-menu .fa-caret-right');
andThen(() => {
assert.equal(
find(".d-editor-input").val(),
`\n[details=${I18n.t("composer.details_title")}]\nThis is my title\n[/details]\n`,
'it should contain the right selected output'
);
const textarea = findTextarea();
assert.equal(textarea.selectionStart, 19, 'it should start highlighting at the right position');
assert.equal(textarea.selectionEnd, 35, 'it should end highlighting at the right position');
});
fillIn('.d-editor-input', "Before some text in between After");
andThen(() => {
const textarea = findTextarea();
textarea.selectionStart = 7;
textarea.selectionEnd = 28;
});
click('button.options');
click('.popup-menu .fa-caret-right');
andThen(() => {
assert.equal(
find(".d-editor-input").val(),
`Before\n[details=${I18n.t("composer.details_title")}]\nsome text in between\n[/details]\nAfter`,
'it should contain the right output'
);
const textarea = findTextarea();
assert.equal(textarea.selectionStart, 26, 'it should start highlighting at the right position');
assert.equal(textarea.selectionEnd, 46, 'it should end highlighting at the right position');
});
fillIn('.d-editor-input', "Before\nsome text in between\nAfter");
andThen(() => {
const textarea = findTextarea();
textarea.selectionStart = 7;
textarea.selectionEnd = 28;
});
click('button.options');
click('.popup-menu .fa-caret-right');
andThen(() => {
assert.equal(
find(".d-editor-input").val(),
`Before\n\n[details=${I18n.t("composer.details_title")}]\nsome text in between\n[/details]\n\nAfter`,
'it should contain the right output'
);
const textarea = findTextarea();
assert.equal(textarea.selectionStart, 26, 'it should start highlighting at the right position');
assert.equal(textarea.selectionEnd, 46, 'it should end highlighting at the right position');
});
});