mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
119 lines
3.6 KiB
JavaScript
Vendored
119 lines
3.6 KiB
JavaScript
Vendored
import { click, fillIn, visit } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
import Category from "discourse/models/category";
|
|
import { parsePostData } from "discourse/tests/helpers/create-pretender";
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
|
import { i18n } from "discourse-i18n";
|
|
|
|
let createAsPostVotingSetInRequest = false;
|
|
|
|
acceptance("composer (new composer actions)", function (needs) {
|
|
needs.user();
|
|
needs.settings({
|
|
post_voting_enabled: true,
|
|
enable_new_composer_actions: true,
|
|
});
|
|
|
|
needs.hooks.afterEach(function () {
|
|
createAsPostVotingSetInRequest = false;
|
|
});
|
|
|
|
needs.pretender((server, helper) => {
|
|
server.post("/posts", (request) => {
|
|
const data = parsePostData(request.requestBody);
|
|
if (
|
|
String(data.create_as_post_voting) === "true" ||
|
|
String(data.only_post_voting_in_this_category) === "true"
|
|
) {
|
|
createAsPostVotingSetInRequest = true;
|
|
}
|
|
|
|
return helper.response({
|
|
post: {
|
|
topic_id: 280,
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
test("Creating new topic with post voting format", async function (assert) {
|
|
await visit("/");
|
|
await click("#create-topic");
|
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
await categoryChooser.expand();
|
|
await categoryChooser.selectRowByValue(2);
|
|
|
|
await click(".composer-actions-trigger");
|
|
await click("[data-action-id='togglePostVoting']");
|
|
|
|
assert
|
|
.dom(".composer-actions-trigger")
|
|
.includesText(
|
|
i18n("composer.create_post_voting.label"),
|
|
"displays the right composer action title when creating Post Voting topic"
|
|
);
|
|
|
|
assert
|
|
.dom(".create .d-button-label")
|
|
.hasText(
|
|
i18n("composer.create_post_voting.label"),
|
|
"displays the right label for composer create button"
|
|
);
|
|
|
|
await click(".composer-actions-trigger");
|
|
await click("[data-action-id='togglePostVoting']");
|
|
|
|
assert
|
|
.dom(".composer-actions-trigger")
|
|
.doesNotIncludeText(
|
|
i18n("composer.create_post_voting.label"),
|
|
"reverts to original composer title when post voting format is disabled"
|
|
);
|
|
|
|
await click(".composer-actions-trigger");
|
|
await click("[data-action-id='togglePostVoting']");
|
|
|
|
await fillIn("#reply-title", "this is some random topic title");
|
|
await fillIn(".d-editor-input", "this is some random body");
|
|
await click(".create");
|
|
|
|
assert.true(
|
|
createAsPostVotingSetInRequest,
|
|
"submits the right request to create topic as Post Voting formatted"
|
|
);
|
|
});
|
|
|
|
test("Creating new topic in category with Post Voting create default", async function (assert) {
|
|
Category.findById(2).set("create_as_post_voting_default", true);
|
|
|
|
await visit("/");
|
|
await click("#create-topic");
|
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
await categoryChooser.expand();
|
|
await categoryChooser.selectRowByValue(2);
|
|
|
|
assert
|
|
.dom(".composer-actions-trigger")
|
|
.includesText(i18n("composer.create_post_voting.label"));
|
|
});
|
|
|
|
test("Creating new topic in category with only_post_voting_in_this_category enabled", async function (assert) {
|
|
const category = Category.findById(2);
|
|
category.set("only_post_voting_in_this_category", true);
|
|
|
|
await visit("/");
|
|
await click("#create-topic");
|
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
await categoryChooser.expand();
|
|
|
|
await categoryChooser.selectRowByValue(2);
|
|
|
|
assert
|
|
.dom(".composer-actions-trigger")
|
|
.includesText(i18n("composer.create_post_voting.label"));
|
|
});
|
|
});
|