This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/acceptance/composer-uncategorized-test.js
Jarek Radosz a17d54d0bf
DEV: De-arrowify tests (#11068)
Using arrow functions changes `this` context, which is undesired in tests, e.g. it makes it impossible to setup things like pretender (`this.server`) in `beforeEach` hooks.

Ember guides always use classic functions in examples (e.g. https://guides.emberjs.com/release/testing/test-types/), and that's what it uses in its own test suite, as do various addons and ember apps.

It was also already used in Discourse where `this` was required. Moving forward, it will be needed in more places as we migrate toward ember-cli.

(I might later add a custom rule to eslint-discourse-ember to enforce this)
2020-10-30 17:37:32 +01:00

113 lines
3.3 KiB
JavaScript

import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { exists } from "discourse/tests/helpers/qunit-helpers";
import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance(
"Composer disabled, uncategorized not allowed when any topic_template present",
function (needs) {
needs.user();
needs.settings({
enable_whispers: true,
allow_uncategorized_topics: false,
});
test("Disable body until category is selected", async function (assert) {
await visit("/");
await click("#create-topic");
assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.ok(
exists(".title-input .popup-tip.bad.hide"),
"title errors are hidden by default"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.bad.hide"),
"body errors are hidden by default"
);
assert.ok(
exists(".d-editor-textarea-wrapper.disabled"),
"textarea is disabled"
);
const categoryChooser = selectKit(".category-chooser");
await categoryChooser.expand();
await categoryChooser.selectRowByValue(2);
assert.ok(
queryAll(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is enabled"
);
await fillIn(".d-editor-input", "Now I can type stuff");
await categoryChooser.expand();
await categoryChooser.selectRowByIndex(0);
assert.ok(
queryAll(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is still enabled"
);
});
}
);
acceptance(
"Composer enabled, uncategorized not allowed when topic_template not present",
function (needs) {
needs.user();
needs.settings({ allow_uncategorized_topics: false });
needs.site({
categories: [
{
id: 1,
name: "test won",
slug: "test-won",
topic_template: null,
},
{
id: 2,
name: "test too",
slug: "test-too",
topic_template: "",
},
{
id: 3,
name: "test free",
slug: "test-free",
topic_template: null,
},
],
});
test("Enable composer/body if no topic templates present", async function (assert) {
await visit("/");
await click("#create-topic");
assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.ok(
exists(".category-input .popup-tip.bad.hide"),
"category errors are hidden by default"
);
assert.ok(
queryAll(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is enabled"
);
await click("#reply-control button.create");
assert.ok(
exists(".category-input .popup-tip.bad"),
"it shows the choose a category error"
);
const categoryChooser = selectKit(".category-chooser");
await categoryChooser.expand();
await categoryChooser.selectRowByValue(1);
assert.ok(
!exists(".category-input .popup-tip.bad"),
"category error removed after selecting category"
);
});
}
);