REFACTOR: Convert many more acceptance tests to the new format

This commit is contained in:
Robin Ward 2020-10-19 16:39:04 -04:00
parent b3b9cf7c5d
commit a65b426b8a
26 changed files with 2413 additions and 2495 deletions

View File

@ -2,7 +2,7 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
function setupPretender(server, helper) {
function pretender(server, helper) {
server.post("/uploads/lookup-urls", () => {
return helper.response([
{
@ -28,35 +28,29 @@ async function writeInComposer(assert) {
await fillIn(".d-editor-input", "[test|attachment](upload://asdsad.png)");
}
acceptance("Composer Attachment", {
loggedIn: true,
pretend(server, helper) {
setupPretender(server, helper);
},
acceptance("Composer Attachment", function (needs) {
needs.user();
needs.pretender(pretender);
test("attachments are cooked properly", async (assert) => {
await writeInComposer(assert);
assert.equal(
find(".d-editor-preview:visible").html().trim(),
'<p><a class="attachment" href="/uploads/short-url/asdsad.png">test</a></p>'
);
});
});
test("attachments are cooked properly", async (assert) => {
await writeInComposer(assert);
assert.equal(
find(".d-editor-preview:visible").html().trim(),
'<p><a class="attachment" href="/uploads/short-url/asdsad.png">test</a></p>'
);
});
acceptance("Composer Attachment - Secure Media Enabled", function (needs) {
needs.user();
needs.settings({ secure_media: true });
needs.pretender(pretender);
acceptance("Composer Attachment - Secure Media Enabled", {
loggedIn: true,
settings: {
secure_media: true,
},
pretend(server, helper) {
setupPretender(server, helper);
},
});
test("attachments are cooked properly when secure media is enabled", async (assert) => {
await writeInComposer(assert);
assert.equal(
find(".d-editor-preview:visible").html().trim(),
'<p><a class="attachment" href="/secure-media-uploads/default/3X/1/asjdiasjdiasida.png">test</a></p>'
);
test("attachments are cooked properly when secure media is enabled", async (assert) => {
await writeInComposer(assert);
assert.equal(
find(".d-editor-preview:visible").html().trim(),
'<p><a class="attachment" href="/secure-media-uploads/default/3X/1/asjdiasjdiasida.png">test</a></p>'
);
});
});

View File

@ -2,72 +2,54 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import I18n from "I18n";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender";
acceptance("Composer - Edit conflict", {
loggedIn: true,
});
acceptance("Composer - Edit conflict", function (needs) {
needs.user();
test("Edit a post that causes an edit conflict", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:eq(0) button.show-more-actions");
await click(".topic-post:eq(0) button.edit");
await fillIn(".d-editor-input", "this will 409");
await click("#reply-control button.create");
assert.equal(
find("#reply-control button.create").text().trim(),
I18n.t("composer.overwrite_edit"),
"it shows the overwrite button"
);
assert.ok(
find("#draft-status .d-icon-user-edit"),
"error icon should be there"
);
await click(".modal .btn-primary");
});
function handleDraftPretender(assert) {
pretender.post("/draft.json", (request) => {
if (
request.requestBody.indexOf("%22reply%22%3A%22%22") === -1 &&
request.requestBody.indexOf("Any+plans+to+support+localization") !== -1
) {
assert.notEqual(request.requestBody.indexOf("originalText"), -1);
}
if (
request.requestBody.indexOf(
"draft_key=topic_280&sequence=4&data=%7B%22reply%22%3A%22hello+world+hello+world+hello+world+hello+world+hello+world%22%2C%22action%22%3A%22reply%22%2C%22categoryId%22%3A2%2C%22archetypeId%22%3A%22regular%22%2C%22metaData"
) !== -1
) {
assert.equal(
request.requestBody.indexOf("originalText"),
-1,
request.requestBody
);
}
return [200, { "Content-Type": "application/json" }, { success: true }];
let lastBody;
needs.pretender((server, helper) => {
server.post("/draft.json", (request) => {
lastBody = request.requestBody;
return helper.response({ success: true });
});
});
}
test("Should not send originalText when posting a new reply", async (assert) => {
handleDraftPretender(assert);
test("Edit a post that causes an edit conflict", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:eq(0) button.show-more-actions");
await click(".topic-post:eq(0) button.edit");
await fillIn(".d-editor-input", "this will 409");
await click("#reply-control button.create");
assert.equal(
find("#reply-control button.create").text().trim(),
I18n.t("composer.overwrite_edit"),
"it shows the overwrite button"
);
assert.ok(
find("#draft-status .d-icon-user-edit"),
"error icon should be there"
);
await click(".modal .btn-primary");
});
await visit("/t/internationalization-localization/280");
await click(".topic-post:eq(0) button.reply");
await fillIn(
".d-editor-input",
"hello world hello world hello world hello world hello world"
);
});
test("Should send originalText when editing a reply", async (assert) => {
handleDraftPretender(assert);
await visit("/t/internationalization-localization/280");
await click(".topic-post:eq(0) button.show-more-actions");
await click(".topic-post:eq(0) button.edit");
await fillIn(
".d-editor-input",
"hello world hello world hello world hello world hello world"
);
test("Should not send originalText when posting a new reply", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:eq(0) button.reply");
await fillIn(
".d-editor-input",
"hello world hello world hello world hello world hello world"
);
assert.ok(lastBody.indexOf("originalText") === -1);
});
test("Should send originalText when editing a reply", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:eq(0) button.show-more-actions");
await click(".topic-post:eq(0) button.edit");
await fillIn(
".d-editor-input",
"hello world hello world hello world hello world hello world"
);
assert.ok(lastBody.indexOf("originalText") > -1);
});
});

View File

@ -2,97 +2,97 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Composer - Hyperlink", {
loggedIn: true,
});
test("add a hyperlink to a reply", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:first-child button.reply");
await fillIn(".d-editor-input", "This is a link to ");
assert.ok(
!exists(".insert-link.modal-body"),
"no hyperlink modal by default"
);
await click(".d-editor button.link");
assert.ok(exists(".insert-link.modal-body"), "hyperlink modal visible");
await fillIn(".modal-body .link-url", "google.com");
await fillIn(".modal-body .link-text", "Google");
await click(".modal-footer button.btn-primary");
assert.equal(
find(".d-editor-input").val(),
"This is a link to [Google](https://google.com)",
"adds link with url and text, prepends 'https://'"
);
assert.ok(
!exists(".insert-link.modal-body"),
"modal dismissed after submitting link"
);
await fillIn(".d-editor-input", "Reset textarea contents.");
await click(".d-editor button.link");
await fillIn(".modal-body .link-url", "google.com");
await fillIn(".modal-body .link-text", "Google");
await click(".modal-footer button.btn-danger");
assert.equal(
find(".d-editor-input").val(),
"Reset textarea contents.",
"doesnt insert anything after cancelling"
);
assert.ok(
!exists(".insert-link.modal-body"),
"modal dismissed after cancelling"
);
const textarea = find("#reply-control .d-editor-input")[0];
textarea.selectionStart = 0;
textarea.selectionEnd = 6;
await click(".d-editor button.link");
await fillIn(".modal-body .link-url", "somelink.com");
await click(".modal-footer button.btn-primary");
assert.equal(
find(".d-editor-input").val(),
"[Reset](https://somelink.com) textarea contents.",
"adds link to a selected text"
);
await fillIn(".d-editor-input", "");
await click(".d-editor button.link");
await fillIn(".modal-body .link-url", "http://google.com");
await keyEvent(".modal-body .link-url", "keyup", 32);
assert.ok(
!exists(".internal-link-results"),
"does not show internal links search dropdown when inputting a url"
);
await fillIn(".modal-body .link-url", "local");
await keyEvent(".modal-body .link-url", "keyup", 32);
assert.ok(
exists(".internal-link-results"),
"shows internal links search dropdown when entering keywords"
);
await keyEvent(".insert-link", "keydown", 40);
await keyEvent(".insert-link", "keydown", 13);
assert.ok(
!exists(".internal-link-results"),
"search dropdown dismissed after selecting an internal link"
);
assert.ok(
find(".link-url").val().includes("http"),
"replaces link url field with internal link"
);
acceptance("Composer - Hyperlink", function (needs) {
needs.user();
test("add a hyperlink to a reply", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:first-child button.reply");
await fillIn(".d-editor-input", "This is a link to ");
assert.ok(
!exists(".insert-link.modal-body"),
"no hyperlink modal by default"
);
await click(".d-editor button.link");
assert.ok(exists(".insert-link.modal-body"), "hyperlink modal visible");
await fillIn(".modal-body .link-url", "google.com");
await fillIn(".modal-body .link-text", "Google");
await click(".modal-footer button.btn-primary");
assert.equal(
find(".d-editor-input").val(),
"This is a link to [Google](https://google.com)",
"adds link with url and text, prepends 'https://'"
);
assert.ok(
!exists(".insert-link.modal-body"),
"modal dismissed after submitting link"
);
await fillIn(".d-editor-input", "Reset textarea contents.");
await click(".d-editor button.link");
await fillIn(".modal-body .link-url", "google.com");
await fillIn(".modal-body .link-text", "Google");
await click(".modal-footer button.btn-danger");
assert.equal(
find(".d-editor-input").val(),
"Reset textarea contents.",
"doesnt insert anything after cancelling"
);
assert.ok(
!exists(".insert-link.modal-body"),
"modal dismissed after cancelling"
);
const textarea = find("#reply-control .d-editor-input")[0];
textarea.selectionStart = 0;
textarea.selectionEnd = 6;
await click(".d-editor button.link");
await fillIn(".modal-body .link-url", "somelink.com");
await click(".modal-footer button.btn-primary");
assert.equal(
find(".d-editor-input").val(),
"[Reset](https://somelink.com) textarea contents.",
"adds link to a selected text"
);
await fillIn(".d-editor-input", "");
await click(".d-editor button.link");
await fillIn(".modal-body .link-url", "http://google.com");
await keyEvent(".modal-body .link-url", "keyup", 32);
assert.ok(
!exists(".internal-link-results"),
"does not show internal links search dropdown when inputting a url"
);
await fillIn(".modal-body .link-url", "local");
await keyEvent(".modal-body .link-url", "keyup", 32);
assert.ok(
exists(".internal-link-results"),
"shows internal links search dropdown when entering keywords"
);
await keyEvent(".insert-link", "keydown", 40);
await keyEvent(".insert-link", "keydown", 13);
assert.ok(
!exists(".internal-link-results"),
"search dropdown dismissed after selecting an internal link"
);
assert.ok(
find(".link-url").val().includes("http"),
"replaces link url field with internal link"
);
});
});

View File

@ -2,21 +2,20 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Composer - Onebox", {
loggedIn: true,
settings: {
acceptance("Composer - Onebox", function (needs) {
needs.user();
needs.settings({
max_oneboxes_per_post: 2,
enable_markdown_linkify: true,
},
});
});
test("Preview update should respect max_oneboxes_per_post site setting", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
test("Preview update should respect max_oneboxes_per_post site setting", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await fillIn(
".d-editor-input",
`
await fillIn(
".d-editor-input",
`
http://www.example.com/has-title.html
This is another test http://www.example.com/has-title.html
@ -26,18 +25,19 @@ This is another test http://www.example.com/no-title.html
This is another test http://www.example.com/has-title.html
http://www.example.com/has-title.html
`
);
`
);
assert.equal(
find(".d-editor-preview:visible").html().trim(),
`
assert.equal(
find(".d-editor-preview:visible").html().trim(),
`
<p><aside class=\"onebox\"><article class=\"onebox-body\"><h3><a href=\"http://www.example.com/article.html\">An interesting article</a></h3></article></aside><br>
This is another test <a href=\"http://www.example.com/has-title.html\" class=\"inline-onebox\">This is a great title</a></p>
<p><a href=\"http://www.example.com/no-title.html\" class=\"onebox\" target=\"_blank\">http://www.example.com/no-title.html</a></p>
<p>This is another test <a href=\"http://www.example.com/no-title.html\" class=\"\">http://www.example.com/no-title.html</a><br>
This is another test <a href=\"http://www.example.com/has-title.html\" class=\"inline-onebox\">This is a great title</a></p>
<p><aside class=\"onebox\"><article class=\"onebox-body\"><h3><a href=\"http://www.example.com/article.html\">An interesting article</a></h3></article></aside></p>
`.trim()
);
`.trim()
);
});
});

View File

@ -7,57 +7,55 @@ import {
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("Composer - Tags", {
loggedIn: true,
pretend(pretenderServer, helper) {
pretenderServer.post("/uploads/lookup-urls", () => {
acceptance("Composer - Tags", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.post("/uploads/lookup-urls", () => {
return helper.response([]);
});
},
site: {
can_tag_topics: true,
},
});
test("staff bypass tag validation rule", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "this is my new topic title");
await fillIn(".d-editor-input", "this is the *content* of a post");
Category.findById(2).set("minimum_required_tags", 1);
const categoryChooser = selectKit(".category-chooser");
await categoryChooser.expand();
await categoryChooser.selectRowByValue(2);
await click("#reply-control button.create");
assert.notEqual(currentURL(), "/");
});
test("users do not bypass tag validation rule", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "this is my new topic title");
await fillIn(".d-editor-input", "this is the *content* of a post");
Category.findById(2).set("minimum_required_tags", 1);
const categoryChooser = selectKit(".category-chooser");
await categoryChooser.expand();
await categoryChooser.selectRowByValue(2);
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await click("#reply-control button.create");
assert.equal(currentURL(), "/");
const tags = selectKit(".mini-tag-chooser");
await tags.expand();
await tags.selectRowByValue("monkey");
await click("#reply-control button.create");
assert.notEqual(currentURL(), "/");
});
needs.site({ can_tag_topics: true });
test("staff bypass tag validation rule", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "this is my new topic title");
await fillIn(".d-editor-input", "this is the *content* of a post");
Category.findById(2).set("minimum_required_tags", 1);
const categoryChooser = selectKit(".category-chooser");
await categoryChooser.expand();
await categoryChooser.selectRowByValue(2);
await click("#reply-control button.create");
assert.notEqual(currentURL(), "/");
});
test("users do not bypass tag validation rule", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "this is my new topic title");
await fillIn(".d-editor-input", "this is the *content* of a post");
Category.findById(2).set("minimum_required_tags", 1);
const categoryChooser = selectKit(".category-chooser");
await categoryChooser.expand();
await categoryChooser.selectRowByValue(2);
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await click("#reply-control button.create");
assert.equal(currentURL(), "/");
const tags = selectKit(".mini-tag-chooser");
await tags.expand();
await tags.selectRowByValue("monkey");
await click("#reply-control button.create");
assert.notEqual(currentURL(), "/");
});
});

View File

@ -1,172 +1,170 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import {
acceptance,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Composer topic featured links", {
loggedIn: true,
settings: {
acceptance("Composer topic featured links", function (needs) {
needs.user();
needs.settings({
topic_featured_link_enabled: true,
max_topic_title_length: 80,
enable_markdown_linkify: true,
},
});
test("onebox with title", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/has-title.html");
assert.ok(
find(".d-editor-preview").html().trim().indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
});
test("onebox result doesn't include a title", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/no-title.html");
assert.ok(
find(".d-editor-preview").html().trim().indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/no-title.html",
"title is unchanged"
);
});
test("no onebox result", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/nope-onebox.html");
assert.ok(
find(".d-editor-preview").html().trim().indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"link is pasted into body"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/nope-onebox.html",
"title is unchanged"
);
});
test("ignore internal links", async (assert) => {
await visit("/");
await click("#create-topic");
const title = "http://" + window.location.hostname + "/internal-page.html";
await fillIn("#reply-title", title);
assert.equal(
find(".d-editor-preview").html().trim().indexOf("onebox"),
-1,
"onebox preview doesn't show"
);
assert.equal(
find(".d-editor-input").val().length,
0,
"link isn't put into the post"
);
assert.equal(find(".title-input input").val(), title, "title is unchanged");
});
test("link is longer than max title length", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn(
"#reply-title",
"http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html"
);
assert.ok(
find(".d-editor-preview").html().trim().indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
});
test("onebox with title but extra words in title field", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/has-title.html test");
assert.equal(
find(".d-editor-preview").html().trim().indexOf("onebox"),
-1,
"onebox preview doesn't show"
);
assert.equal(
find(".d-editor-input").val().length,
0,
"link isn't put into the post"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/has-title.html test",
"title is unchanged"
);
});
});
test("onebox with title", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/has-title.html");
assert.ok(
find(".d-editor-preview").html().trim().indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
});
acceptance(
"Composer topic featured links when uncategorized is not allowed",
function (needs) {
needs.user({ moderator: true, admin: false, trust_level: 1 });
needs.settings({
topic_featured_link_enabled: true,
max_topic_title_length: 80,
enable_markdown_linkify: true,
allow_uncategorized_topics: false,
});
test("onebox result doesn't include a title", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/no-title.html");
assert.ok(
find(".d-editor-preview").html().trim().indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/no-title.html",
"title is unchanged"
);
});
test("no onebox result", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/nope-onebox.html");
assert.ok(
find(".d-editor-preview").html().trim().indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"link is pasted into body"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/nope-onebox.html",
"title is unchanged"
);
});
test("ignore internal links", async (assert) => {
await visit("/");
await click("#create-topic");
const title = "http://" + window.location.hostname + "/internal-page.html";
await fillIn("#reply-title", title);
assert.equal(
find(".d-editor-preview").html().trim().indexOf("onebox"),
-1,
"onebox preview doesn't show"
);
assert.equal(
find(".d-editor-input").val().length,
0,
"link isn't put into the post"
);
assert.equal(find(".title-input input").val(), title, "title is unchanged");
});
test("link is longer than max title length", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn(
"#reply-title",
"http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html"
);
assert.ok(
find(".d-editor-preview").html().trim().indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
});
test("onebox with title but extra words in title field", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "http://www.example.com/has-title.html test");
assert.equal(
find(".d-editor-preview").html().trim().indexOf("onebox"),
-1,
"onebox preview doesn't show"
);
assert.equal(
find(".d-editor-input").val().length,
0,
"link isn't put into the post"
);
assert.equal(
find(".title-input input").val(),
"http://www.example.com/has-title.html test",
"title is unchanged"
);
});
acceptance("Composer topic featured links when uncategorized is not allowed", {
loggedIn: true,
settings: {
topic_featured_link_enabled: true,
max_topic_title_length: 80,
enable_markdown_linkify: true,
allow_uncategorized_topics: false,
},
});
test("Pasting a link enables the text input area", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await visit("/");
await click("#create-topic");
assert.ok(
find(".d-editor-textarea-wrapper.disabled").length,
"textarea is disabled"
);
await fillIn("#reply-title", "http://www.example.com/has-title.html");
assert.ok(
find(".d-editor-preview").html().trim().indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
assert.ok(
find(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is enabled"
);
});
test("Pasting a link enables the text input area", async (assert) => {
await visit("/");
await click("#create-topic");
assert.ok(
find(".d-editor-textarea-wrapper.disabled").length,
"textarea is disabled"
);
await fillIn("#reply-title", "http://www.example.com/has-title.html");
assert.ok(
find(".d-editor-preview").html().trim().indexOf("onebox") > 0,
"it pastes the link into the body and previews it"
);
assert.ok(
exists(".d-editor-textarea-wrapper .popup-tip.good"),
"the body is now good"
);
assert.equal(
find(".title-input input").val(),
"An interesting article",
"title is from the oneboxed article"
);
assert.ok(
find(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is enabled"
);
});
}
);

View File

@ -1,69 +1,62 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import {
acceptance,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance(
"Composer disabled, uncategorized not allowed when any topic_template present",
{
loggedIn: true,
settings: {
function (needs) {
needs.user();
needs.settings({
enable_whispers: true,
allow_uncategorized_topics: false,
},
});
test("Disable body until category is selected", async (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(
find(".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(
find(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is still enabled"
);
});
}
);
test("Disable body until category is selected", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
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(
find(".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(
find(".d-editor-textarea-wrapper.disabled").length === 0,
"textarea is still enabled"
);
});
acceptance(
"Composer enabled, uncategorized not allowed when topic_template not present",
{
loggedIn: true,
settings: {
allow_uncategorized_topics: false,
},
site: {
function (needs) {
needs.user();
needs.settings({ allow_uncategorized_topics: false });
needs.site({
categories: [
{
id: 1,
@ -84,37 +77,34 @@ acceptance(
topic_template: null,
},
],
},
});
test("Enable composer/body if no topic templates present", async (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(
find(".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"
);
});
}
);
test("Enable composer/body if no topic templates present", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
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(
find(".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"
);
});

View File

@ -2,8 +2,8 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Create Account - external auth", {
beforeEach() {
acceptance("Create Account - external auth", function (needs) {
needs.hooks.beforeEach(() => {
const node = document.createElement("meta");
node.dataset.authenticationData = JSON.stringify({
auth_provider: "test",
@ -13,33 +13,33 @@ acceptance("Create Account - external auth", {
});
node.id = "data-authentication";
document.querySelector("head").appendChild(node);
},
afterEach() {
});
needs.hooks.afterEach(() => {
document
.querySelector("head")
.removeChild(document.getElementById("data-authentication"));
},
});
test("when skip is disabled (default)", async (assert) => {
await visit("/");
assert.ok(
exists("#discourse-modal div.create-account"),
"it shows the registration modal"
);
assert.ok(exists("#new-account-username"), "it shows the fields");
});
test("when skip is enabled", async function (assert) {
this.siteSettings.external_auth_skip_create_confirm = true;
await visit("/");
assert.ok(
exists("#discourse-modal div.create-account"),
"it shows the registration modal"
);
assert.not(exists("#new-account-username"), "it does not show the fields");
});
test("when skip is disabled (default)", async (assert) => {
await visit("/");
assert.ok(
exists("#discourse-modal div.create-account"),
"it shows the registration modal"
);
assert.ok(exists("#new-account-username"), "it shows the fields");
});
test("when skip is enabled", async function (assert) {
this.siteSettings.external_auth_skip_create_confirm = true;
await visit("/");
assert.ok(
exists("#discourse-modal div.create-account"),
"it shows the registration modal"
);
assert.not(exists("#new-account-username"), "it does not show the fields");
});
});

View File

@ -2,8 +2,8 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Create Account - User Fields", {
site: {
acceptance("Create Account - User Fields", function (needs) {
needs.site({
user_fields: [
{
id: 34,
@ -24,43 +24,43 @@ acceptance("Create Account - User Fields", {
required: false,
},
],
},
});
test("create account with user fields", async (assert) => {
await visit("/");
await click("header .sign-up-button");
assert.ok(exists(".create-account"), "it shows the create account modal");
assert.ok(exists(".user-field"), "it has at least one user field");
await click(".modal-footer .btn-primary");
assert.ok(exists("#modal-alert"), "it shows the required field alert");
assert.equal(find("#modal-alert").text(), "Please enter an email address");
await fillIn("#new-account-name", "Dr. Good Tuna");
await fillIn("#new-account-password", "cool password bro");
// without this double fill, field will sometimes being empty
// got consistent repro by having browser search bar focused when starting test
await fillIn("#new-account-email", "good.tuna@test.com");
await fillIn("#new-account-email", "good.tuna@test.com");
await fillIn("#new-account-username", "goodtuna");
assert.ok(
exists("#username-validation.good"),
"the username validation is good"
);
assert.ok(
exists("#account-email-validation.good"),
"the email validation is good"
);
await click(".modal-footer .btn-primary");
assert.equal(find("#modal-alert")[0].style.display, "");
await fillIn(".user-field input[type=text]:first", "Barky");
await click(".user-field input[type=checkbox]");
await click(".modal-footer .btn-primary");
assert.equal(find("#modal-alert")[0].style.display, "none");
});
test("create account with user fields", async (assert) => {
await visit("/");
await click("header .sign-up-button");
assert.ok(exists(".create-account"), "it shows the create account modal");
assert.ok(exists(".user-field"), "it has at least one user field");
await click(".modal-footer .btn-primary");
assert.ok(exists("#modal-alert"), "it shows the required field alert");
assert.equal(find("#modal-alert").text(), "Please enter an email address");
await fillIn("#new-account-name", "Dr. Good Tuna");
await fillIn("#new-account-password", "cool password bro");
// without this double fill, field will sometimes being empty
// got consistent repro by having browser search bar focused when starting test
await fillIn("#new-account-email", "good.tuna@test.com");
await fillIn("#new-account-email", "good.tuna@test.com");
await fillIn("#new-account-username", "goodtuna");
assert.ok(
exists("#username-validation.good"),
"the username validation is good"
);
assert.ok(
exists("#account-email-validation.good"),
"the email validation is good"
);
await click(".modal-footer .btn-primary");
assert.equal(find("#modal-alert")[0].style.display, "");
await fillIn(".user-field input[type=text]:first", "Barky");
await click(".user-field input[type=checkbox]");
await click(".modal-footer .btn-primary");
assert.equal(find("#modal-alert")[0].style.display, "none");
});
});

View File

@ -4,29 +4,33 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { setCustomHTML } from "discourse/helpers/custom-html";
import PreloadStore from "discourse/lib/preload-store";
acceptance("CustomHTML set");
test("has no custom HTML in the top", async (assert) => {
await visit("/static/faq");
assert.ok(!exists("span.custom-html-test"), "it has no markup");
});
test("renders set HTML", async (assert) => {
setCustomHTML("top", '<span class="custom-html-test">HTML</span>');
await visit("/static/faq");
assert.equal(
find("span.custom-html-test").text(),
"HTML",
"it inserted the markup"
);
});
test("renders preloaded HTML", async (assert) => {
PreloadStore.store("customHTML", {
top: "<span class='cookie'>monster</span>",
acceptance("CustomHTML set", function () {
test("has no custom HTML in the top", async (assert) => {
await visit("/static/faq");
assert.ok(!exists("span.custom-html-test"), "it has no markup");
});
await visit("/static/faq");
assert.equal(find("span.cookie").text(), "monster", "it inserted the markup");
test("renders set HTML", async (assert) => {
setCustomHTML("top", '<span class="custom-html-test">HTML</span>');
await visit("/static/faq");
assert.equal(
find("span.custom-html-test").text(),
"HTML",
"it inserted the markup"
);
});
test("renders preloaded HTML", async (assert) => {
PreloadStore.store("customHTML", {
top: "<span class='cookie'>monster</span>",
});
await visit("/static/faq");
assert.equal(
find("span.cookie").text(),
"monster",
"it inserted the markup"
);
});
});

View File

@ -1,20 +1,24 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import Ember from "ember";
acceptance("CustomHTML template", {
beforeEach() {
acceptance("CustomHTML template", function (needs) {
needs.hooks.beforeEach(() => {
Ember.TEMPLATES["top"] = Ember.HTMLBars.compile(
`<span class='top-span'>TOP</span>`
);
},
afterEach() {
});
needs.hooks.afterEach(() => {
delete Ember.TEMPLATES["top"];
},
});
});
test("renders custom template", async (assert) => {
await visit("/static/faq");
assert.equal(find("span.top-span").text(), "TOP", "it inserted the template");
test("renders custom template", async (assert) => {
await visit("/static/faq");
assert.equal(
find("span.top-span").text(),
"TOP",
"it inserted the template"
);
});
});

View File

@ -3,13 +3,13 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Dashboard", {
loggedIn: true,
settings: {
acceptance("Dashboard", function (needs) {
needs.user();
needs.settings({
dashboard_visible_tabs: "moderation|security|reports",
dashboard_general_tab_activity_metrics: "page_view_total_reqs",
},
site: {
});
needs.site({
groups: [
{
id: 88,
@ -20,138 +20,139 @@ acceptance("Dashboard", {
name: "tl2",
},
],
},
});
test("default", async (assert) => {
await visit("/admin");
assert.ok(exists(".dashboard"), "has dashboard-next class");
});
test("tabs", async (assert) => {
await visit("/admin");
assert.ok(exists(".dashboard .navigation-item.general"), "general tab");
assert.ok(
exists(".dashboard .navigation-item.moderation"),
"moderation tab"
);
assert.ok(exists(".dashboard .navigation-item.security"), "security tab");
assert.ok(exists(".dashboard .navigation-item.reports"), "reports tab");
});
test("general tab", async (assert) => {
await visit("/admin");
assert.ok(exists(".admin-report.signups"), "signups report");
assert.ok(exists(".admin-report.posts"), "posts report");
assert.ok(exists(".admin-report.dau-by-mau"), "dau-by-mau report");
assert.ok(
exists(".admin-report.daily-engaged-users"),
"daily-engaged-users report"
);
assert.ok(
exists(".admin-report.new-contributors"),
"new-contributors report"
);
assert.equal(
$(".section.dashboard-problems .problem-messages ul li:first-child")
.html()
.trim(),
"Houston...",
"displays problems"
);
});
test("activity metrics", async (assert) => {
await visit("/admin");
assert.ok(exists(".admin-report.page-view-total-reqs .today-count"));
assert.ok(exists(".admin-report.page-view-total-reqs .yesterday-count"));
assert.ok(exists(".admin-report.page-view-total-reqs .sevendays-count"));
assert.ok(exists(".admin-report.page-view-total-reqs .thirty-days-count"));
});
test("reports tab", async (assert) => {
await visit("/admin");
await click(".dashboard .navigation-item.reports .navigation-link");
assert.equal(
find(".dashboard .reports-index.section .reports-list .report").length,
1
);
await fillIn(".dashboard .filter-reports-input", "flags");
assert.equal(
find(".dashboard .reports-index.section .reports-list .report").length,
0
);
await click(".dashboard .navigation-item.security .navigation-link");
await click(".dashboard .navigation-item.reports .navigation-link");
assert.equal(
find(".dashboard .reports-index.section .reports-list .report").length,
1,
"navigating back and forth resets filter"
);
await fillIn(".dashboard .filter-reports-input", "activities");
assert.equal(
find(".dashboard .reports-index.section .reports-list .report").length,
1,
"filter is case insensitive"
);
});
test("reports filters", async (assert) => {
await visit(
'/admin/reports/signups_with_groups?end_date=2018-07-16&filters=%7B"group"%3A88%7D&start_date=2018-06-16'
);
const groupFilter = selectKit(".group-filter .combo-box");
assert.equal(
groupFilter.header().value(),
88,
"its set the value of the filter from the query params"
);
});
});
test("default", async (assert) => {
await visit("/admin");
acceptance("Dashboard: dashboard_visible_tabs", function (needs) {
needs.user();
needs.settings({ dashboard_visible_tabs: "general|security|reports" });
assert.ok(exists(".dashboard"), "has dashboard-next class");
});
test("tabs", async (assert) => {
await visit("/admin");
assert.ok(exists(".dashboard .navigation-item.general"), "general tab");
assert.ok(exists(".dashboard .navigation-item.moderation"), "moderation tab");
assert.ok(exists(".dashboard .navigation-item.security"), "security tab");
assert.ok(exists(".dashboard .navigation-item.reports"), "reports tab");
});
test("general tab", async (assert) => {
await visit("/admin");
assert.ok(exists(".admin-report.signups"), "signups report");
assert.ok(exists(".admin-report.posts"), "posts report");
assert.ok(exists(".admin-report.dau-by-mau"), "dau-by-mau report");
assert.ok(
exists(".admin-report.daily-engaged-users"),
"daily-engaged-users report"
);
assert.ok(
exists(".admin-report.new-contributors"),
"new-contributors report"
);
assert.equal(
$(".section.dashboard-problems .problem-messages ul li:first-child")
.html()
.trim(),
"Houston...",
"displays problems"
);
});
test("activity metrics", async (assert) => {
await visit("/admin");
assert.ok(exists(".admin-report.page-view-total-reqs .today-count"));
assert.ok(exists(".admin-report.page-view-total-reqs .yesterday-count"));
assert.ok(exists(".admin-report.page-view-total-reqs .sevendays-count"));
assert.ok(exists(".admin-report.page-view-total-reqs .thirty-days-count"));
});
test("reports tab", async (assert) => {
await visit("/admin");
await click(".dashboard .navigation-item.reports .navigation-link");
assert.equal(
find(".dashboard .reports-index.section .reports-list .report").length,
1
);
await fillIn(".dashboard .filter-reports-input", "flags");
assert.equal(
find(".dashboard .reports-index.section .reports-list .report").length,
0
);
await click(".dashboard .navigation-item.security .navigation-link");
await click(".dashboard .navigation-item.reports .navigation-link");
assert.equal(
find(".dashboard .reports-index.section .reports-list .report").length,
1,
"navigating back and forth resets filter"
);
await fillIn(".dashboard .filter-reports-input", "activities");
assert.equal(
find(".dashboard .reports-index.section .reports-list .report").length,
1,
"filter is case insensitive"
);
});
test("reports filters", async (assert) => {
await visit(
'/admin/reports/signups_with_groups?end_date=2018-07-16&filters=%7B"group"%3A88%7D&start_date=2018-06-16'
);
const groupFilter = selectKit(".group-filter .combo-box");
assert.equal(
groupFilter.header().value(),
88,
"its set the value of the filter from the query params"
);
});
acceptance("Dashboard: dashboard_visible_tabs", {
loggedIn: true,
settings: {
dashboard_visible_tabs: "general|security|reports",
},
});
test("visible tabs", async (assert) => {
await visit("/admin");
assert.ok(exists(".dashboard .navigation-item.general"), "general tab");
assert.notOk(
exists(".dashboard .navigation-item.moderation"),
"moderation tab"
);
assert.ok(exists(".dashboard .navigation-item.security"), "security tab");
assert.ok(exists(".dashboard .navigation-item.reports"), "reports tab");
});
acceptance("Dashboard: dashboard_hidden_reports", {
loggedIn: true,
settings: {
dashboard_visible_tabs: "reports",
dashboard_hidden_reports: "posts|dau_by_mau",
},
});
test("hidden reports", async (assert) => {
await visit("/admin");
assert.ok(exists(".admin-report.signups.is-visible"), "signups report");
assert.notOk(exists(".admin-report.is-visible.posts"), "posts report");
assert.notOk(
exists(".admin-report.is-visible.dau-by-mau"),
"dau-by-mau report"
);
test("visible tabs", async (assert) => {
await visit("/admin");
assert.ok(exists(".dashboard .navigation-item.general"), "general tab");
assert.notOk(
exists(".dashboard .navigation-item.moderation"),
"moderation tab"
);
assert.ok(exists(".dashboard .navigation-item.security"), "security tab");
assert.ok(exists(".dashboard .navigation-item.reports"), "reports tab");
});
acceptance("Dashboard: dashboard_hidden_reports", {
loggedIn: true,
settings: {
dashboard_visible_tabs: "reports",
dashboard_hidden_reports: "posts|dau_by_mau",
},
});
test("hidden reports", async (assert) => {
await visit("/admin");
assert.ok(exists(".admin-report.signups.is-visible"), "signups report");
assert.notOk(exists(".admin-report.is-visible.posts"), "posts report");
assert.notOk(
exists(".admin-report.is-visible.dau-by-mau"),
"dau-by-mau report"
);
});
});

View File

@ -5,40 +5,40 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Email Disabled Banner", {
loggedIn: true,
});
acceptance("Email Disabled Banner", function (needs) {
needs.user();
test("when disabled", async function (assert) {
this.siteSettings.disable_emails = "no";
await visit("/");
assert.notOk(
exists(".alert-emails-disabled"),
"alert is not displayed when email enabled"
);
});
test("when disabled", async function (assert) {
this.siteSettings.disable_emails = "no";
await visit("/");
assert.notOk(
exists(".alert-emails-disabled"),
"alert is not displayed when email enabled"
);
});
test("when enabled", async function (assert) {
this.siteSettings.disable_emails = "yes";
await visit("/latest");
assert.ok(
exists(".alert-emails-disabled"),
"alert is displayed when email disabled"
);
});
test("when enabled", async function (assert) {
this.siteSettings.disable_emails = "yes";
await visit("/latest");
assert.ok(
exists(".alert-emails-disabled"),
"alert is displayed when email disabled"
);
});
test("when non-staff", async function (assert) {
this.siteSettings.disable_emails = "non-staff";
await visit("/");
assert.ok(
exists(".alert-emails-disabled"),
"alert is displayed when email disabled for non-staff"
);
test("when non-staff", async function (assert) {
this.siteSettings.disable_emails = "non-staff";
await visit("/");
assert.ok(
exists(".alert-emails-disabled"),
"alert is displayed when email disabled for non-staff"
);
updateCurrentUser({ moderator: true });
await visit("/");
assert.ok(
exists(".alert-emails-disabled"),
"alert is displayed to staff when email disabled for non-staff"
);
updateCurrentUser({ moderator: true });
await visit("/");
assert.ok(
exists(".alert-emails-disabled"),
"alert is displayed to staff when email disabled for non-staff"
);
});
});

View File

@ -2,137 +2,138 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("EmojiPicker", {
loggedIn: true,
beforeEach() {
acceptance("EmojiPicker", function (needs) {
needs.user();
needs.hooks.beforeEach(function () {
this.emojiStore = this.container.lookup("service:emoji-store");
this.emojiStore.reset();
},
afterEach() {
});
needs.hooks.afterEach(function () {
this.emojiStore.reset();
},
});
test("emoji picker can be opened/closed", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
assert.ok(exists(".emoji-picker.opened"), "it opens the picker");
await click("button.emoji.btn");
assert.notOk(exists(".emoji-picker.opened"), "it closes the picker");
});
test("emoji picker triggers event when picking emoji", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
await click(".emoji-picker-emoji-area img.emoji[title='grinning']");
assert.equal(
find(".d-editor-input").val(),
":grinning:",
"it adds the emoji code in the editor when selected"
);
});
test("emoji picker adds leading whitespace before emoji", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
// Whitespace should be added on text
await fillIn(".d-editor-input", "This is a test input");
await click("button.emoji.btn");
await click(".emoji-picker-emoji-area img.emoji[title='grinning']");
assert.equal(
find(".d-editor-input").val(),
"This is a test input :grinning:",
"it adds the emoji code and a leading whitespace when there is text"
);
// Whitespace should not be added on whitespace
await fillIn(".d-editor-input", "This is a test input ");
await click(".emoji-picker-emoji-area img.emoji[title='grinning']");
assert.equal(
find(".d-editor-input").val(),
"This is a test input :grinning:",
"it adds the emoji code and no leading whitespace when user already entered whitespace"
);
});
test("emoji picker has a list of recently used emojis", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
await click(".emoji-picker-emoji-area img.emoji[title='grinning']");
assert.ok(
exists(
".emoji-picker .section.recent .section-group img.emoji[title='grinning']"
),
"it shows recent selected emoji"
);
assert.ok(
exists('.emoji-picker .category-button[data-section="recent"]'),
"it shows recent category icon"
);
await click(".emoji-picker .trash-recent");
assert.notOk(
exists(
".emoji-picker .section.recent .section-group img.emoji[title='grinning']"
),
"it has cleared recent emojis"
);
assert.notOk(
exists('.emoji-picker .section[data-section="recent"]'),
"it hides recent section"
);
assert.notOk(
exists('.emoji-picker .category-button[data-section="recent"]'),
"it hides recent category icon"
);
});
test("emoji picker correctly orders recently used emojis", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
await click(".emoji-picker-emoji-area img.emoji[title='sunglasses']");
await click(".emoji-picker-emoji-area img.emoji[title='grinning']");
assert.equal(
find('.section[data-section="recent"] .section-group img.emoji').length,
2,
"it has multiple recent emojis"
);
assert.equal(
/grinning/.test(
find(".section.recent .section-group img.emoji").first().attr("src")
),
true,
"it puts the last used emoji in first"
);
});
test("emoji picker persists state", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
await click(".emoji-picker button.diversity-scale.medium-dark");
await click("button.emoji.btn");
await click("button.emoji.btn");
assert.ok(
exists(".emoji-picker button.diversity-scale.medium-dark .d-icon"),
true,
"it stores diversity scale"
);
});
test("emoji picker can be opened/closed", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
assert.ok(exists(".emoji-picker.opened"), "it opens the picker");
await click("button.emoji.btn");
assert.notOk(exists(".emoji-picker.opened"), "it closes the picker");
});
test("emoji picker triggers event when picking emoji", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
await click(".emoji-picker-emoji-area img.emoji[title='grinning']");
assert.equal(
find(".d-editor-input").val(),
":grinning:",
"it adds the emoji code in the editor when selected"
);
});
test("emoji picker adds leading whitespace before emoji", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
// Whitespace should be added on text
await fillIn(".d-editor-input", "This is a test input");
await click("button.emoji.btn");
await click(".emoji-picker-emoji-area img.emoji[title='grinning']");
assert.equal(
find(".d-editor-input").val(),
"This is a test input :grinning:",
"it adds the emoji code and a leading whitespace when there is text"
);
// Whitespace should not be added on whitespace
await fillIn(".d-editor-input", "This is a test input ");
await click(".emoji-picker-emoji-area img.emoji[title='grinning']");
assert.equal(
find(".d-editor-input").val(),
"This is a test input :grinning:",
"it adds the emoji code and no leading whitespace when user already entered whitespace"
);
});
test("emoji picker has a list of recently used emojis", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
await click(".emoji-picker-emoji-area img.emoji[title='grinning']");
assert.ok(
exists(
".emoji-picker .section.recent .section-group img.emoji[title='grinning']"
),
"it shows recent selected emoji"
);
assert.ok(
exists('.emoji-picker .category-button[data-section="recent"]'),
"it shows recent category icon"
);
await click(".emoji-picker .trash-recent");
assert.notOk(
exists(
".emoji-picker .section.recent .section-group img.emoji[title='grinning']"
),
"it has cleared recent emojis"
);
assert.notOk(
exists('.emoji-picker .section[data-section="recent"]'),
"it hides recent section"
);
assert.notOk(
exists('.emoji-picker .category-button[data-section="recent"]'),
"it hides recent category icon"
);
});
test("emoji picker correctly orders recently used emojis", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
await click(".emoji-picker-emoji-area img.emoji[title='sunglasses']");
await click(".emoji-picker-emoji-area img.emoji[title='grinning']");
assert.equal(
find('.section[data-section="recent"] .section-group img.emoji').length,
2,
"it has multiple recent emojis"
);
assert.equal(
/grinning/.test(
find(".section.recent .section-group img.emoji").first().attr("src")
),
true,
"it puts the last used emoji in first"
);
});
test("emoji picker persists state", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await click("button.emoji.btn");
await click(".emoji-picker button.diversity-scale.medium-dark");
await click("button.emoji.btn");
await click("button.emoji.btn");
assert.ok(
exists(".emoji-picker button.diversity-scale.medium-dark .d-icon"),
true,
"it stores diversity scale"
);
});
});

View File

@ -3,26 +3,28 @@ import { test } from "qunit";
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Emoji", { loggedIn: true });
acceptance("Emoji", function (needs) {
needs.user();
test("emoji is cooked properly", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
test("emoji is cooked properly", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await fillIn(".d-editor-input", "this is an emoji :blonde_woman:");
assert.equal(
find(".d-editor-preview:visible").html().trim(),
`<p>this is an emoji <img src="/images/emoji/emoji_one/blonde_woman.png?v=${v}" title=":blonde_woman:" class="emoji" alt=":blonde_woman:"></p>`
);
});
test("skin toned emoji is cooked properly", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await fillIn(".d-editor-input", "this is an emoji :blonde_woman:t5:");
assert.equal(
find(".d-editor-preview:visible").html().trim(),
`<p>this is an emoji <img src="/images/emoji/emoji_one/blonde_woman/5.png?v=${v}" title=":blonde_woman:t5:" class="emoji" alt=":blonde_woman:t5:"></p>`
);
await fillIn(".d-editor-input", "this is an emoji :blonde_woman:");
assert.equal(
find(".d-editor-preview:visible").html().trim(),
`<p>this is an emoji <img src="/images/emoji/emoji_one/blonde_woman.png?v=${v}" title=":blonde_woman:" class="emoji" alt=":blonde_woman:"></p>`
);
});
test("skin toned emoji is cooked properly", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await fillIn(".d-editor-input", "this is an emoji :blonde_woman:t5:");
assert.equal(
find(".d-editor-preview:visible").html().trim(),
`<p>this is an emoji <img src="/images/emoji/emoji_one/blonde_woman/5.png?v=${v}" title=":blonde_woman:t5:" class="emoji" alt=":blonde_woman:t5:"></p>`
);
});
});

View File

@ -5,85 +5,85 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Enforce Second Factor", {
loggedIn: true,
pretend(server, helper) {
acceptance("Enforce Second Factor", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.post("/u/second_factors.json", () => {
return helper.response({
success: "OK",
password_required: "true",
});
});
},
});
test("as an admin", async function (assert) {
await visit("/u/eviltrout/preferences/second-factor");
this.siteSettings.enforce_second_factor = "staff";
await visit("/u/eviltrout/summary");
assert.equal(
find(".control-label").text(),
"Password",
"it will not transition from second-factor preferences"
);
await click("#toggle-hamburger-menu");
await click("a.admin-link");
assert.equal(
find(".control-label").text(),
"Password",
"it stays at second-factor preferences"
);
});
test("as a user", async function (assert) {
updateCurrentUser({ moderator: false, admin: false });
await visit("/u/eviltrout/preferences/second-factor");
this.siteSettings.enforce_second_factor = "all";
await visit("/u/eviltrout/summary");
assert.equal(
find(".control-label").text(),
"Password",
"it will not transition from second-factor preferences"
);
await click("#toggle-hamburger-menu");
await click("a.about-link");
assert.equal(
find(".control-label").text(),
"Password",
"it stays at second-factor preferences"
);
});
test("as an anonymous user", async function (assert) {
updateCurrentUser({ moderator: false, admin: false, is_anonymous: true });
await visit("/u/eviltrout/preferences/second-factor");
this.siteSettings.enforce_second_factor = "all";
this.siteSettings.allow_anonymous_posting = true;
await visit("/u/eviltrout/summary");
assert.notEqual(
find(".control-label").text(),
"Password",
"it will transition from second-factor preferences"
);
await click("#toggle-hamburger-menu");
await click("a.about-link");
assert.notEqual(
find(".control-label").text(),
"Password",
"it is possible to navigate to other pages"
);
});
test("as an admin", async function (assert) {
await visit("/u/eviltrout/preferences/second-factor");
this.siteSettings.enforce_second_factor = "staff";
await visit("/u/eviltrout/summary");
assert.equal(
find(".control-label").text(),
"Password",
"it will not transition from second-factor preferences"
);
await click("#toggle-hamburger-menu");
await click("a.admin-link");
assert.equal(
find(".control-label").text(),
"Password",
"it stays at second-factor preferences"
);
});
test("as a user", async function (assert) {
updateCurrentUser({ moderator: false, admin: false });
await visit("/u/eviltrout/preferences/second-factor");
this.siteSettings.enforce_second_factor = "all";
await visit("/u/eviltrout/summary");
assert.equal(
find(".control-label").text(),
"Password",
"it will not transition from second-factor preferences"
);
await click("#toggle-hamburger-menu");
await click("a.about-link");
assert.equal(
find(".control-label").text(),
"Password",
"it stays at second-factor preferences"
);
});
test("as an anonymous user", async function (assert) {
updateCurrentUser({ moderator: false, admin: false, is_anonymous: true });
await visit("/u/eviltrout/preferences/second-factor");
this.siteSettings.enforce_second_factor = "all";
this.siteSettings.allow_anonymous_posting = true;
await visit("/u/eviltrout/summary");
assert.notEqual(
find(".control-label").text(),
"Password",
"it will transition from second-factor preferences"
);
await click("#toggle-hamburger-menu");
await click("a.about-link");
assert.notEqual(
find(".control-label").text(),
"Password",
"it is possible to navigate to other pages"
);
});
});

View File

@ -3,17 +3,21 @@ import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import userFixtures from "discourse/tests/fixtures/user-fixtures";
acceptance("flagging", {
loggedIn: true,
afterEach() {
sandbox.restore();
},
pretend(pretenderServer, helper) {
async function openFlagModal() {
if (exists(".topic-post:first-child button.show-more-actions")) {
await click(".topic-post:first-child button.show-more-actions");
}
await click(".topic-post:first-child button.create-flag");
}
acceptance("flagging", function (needs) {
needs.user();
needs.pretender((server, helper) => {
const userResponse = Object.assign({}, userFixtures["/u/charlie.json"]);
pretenderServer.get("/u/uwe_keim.json", () => {
server.get("/u/uwe_keim.json", () => {
return helper.response(userResponse);
});
pretenderServer.get("/admin/users/255.json", () => {
server.get("/admin/users/255.json", () => {
return helper.response({
id: 255,
automatic: false,
@ -38,7 +42,7 @@ acceptance("flagging", {
full_name: null,
});
});
pretenderServer.get("/admin/users/5.json", () => {
server.get("/admin/users/5.json", () => {
return helper.response({
id: 5,
automatic: false,
@ -63,82 +67,74 @@ acceptance("flagging", {
full_name: null,
});
});
pretenderServer.put("admin/users/5/silence", () => {
server.put("admin/users/5/silence", () => {
return helper.response({
silenced: true,
});
});
pretenderServer.post("post_actions", () => {
server.post("post_actions", () => {
return helper.response({
response: true,
});
});
},
});
async function openFlagModal() {
if (exists(".topic-post:first-child button.show-more-actions")) {
await click(".topic-post:first-child button.show-more-actions");
}
await click(".topic-post:first-child button.create-flag");
}
test("Flag modal opening", async (assert) => {
await visit("/t/internationalization-localization/280");
await openFlagModal();
assert.ok(exists(".flag-modal-body"), "it shows the flag modal");
});
test("Flag take action dropdown exists", async (assert) => {
await visit("/t/internationalization-localization/280");
await openFlagModal();
await click("#radio_inappropriate");
await selectKit(".reviewable-action-dropdown").expand();
assert.ok(
exists("[data-value='agree_and_silence']"),
"it shows the silence action option"
);
await click("[data-value='agree_and_silence']");
assert.ok(exists(".silence-user-modal"), "it shows the silence modal");
});
test("Can silence from take action", async (assert) => {
await visit("/t/internationalization-localization/280");
await openFlagModal();
await click("#radio_inappropriate");
await selectKit(".reviewable-action-dropdown").expand();
await click("[data-value='agree_and_silence']");
const silenceUntilCombobox = selectKit(".silence-until .combobox");
await silenceUntilCombobox.expand();
await silenceUntilCombobox.selectRowByValue("tomorrow");
await fillIn(".silence-reason", "for breaking the rules");
await click(".perform-silence");
assert.equal(find(".bootbox.modal:visible").length, 0);
});
test("Gets dismissable warning from canceling incomplete silence from take action", async (assert) => {
await visit("/t/internationalization-localization/280");
await openFlagModal();
await click("#radio_inappropriate");
await selectKit(".reviewable-action-dropdown").expand();
await click("[data-value='agree_and_silence']");
const silenceUntilCombobox = selectKit(".silence-until .combobox");
await silenceUntilCombobox.expand();
await silenceUntilCombobox.selectRowByValue("tomorrow");
await fillIn(".silence-reason", "for breaking the rules");
await click(".d-modal-cancel");
assert.equal(find(".bootbox.modal:visible").length, 1);
await click(".modal-footer .btn-default");
assert.equal(find(".bootbox.modal:visible").length, 0);
assert.ok(exists(".silence-user-modal"), "it shows the silence modal");
await click(".d-modal-cancel");
assert.equal(find(".bootbox.modal:visible").length, 1);
await click(".modal-footer .btn-primary");
assert.equal(find(".bootbox.modal:visible").length, 0);
});
test("Flag modal opening", async (assert) => {
await visit("/t/internationalization-localization/280");
await openFlagModal();
assert.ok(exists(".flag-modal-body"), "it shows the flag modal");
});
test("Flag take action dropdown exists", async (assert) => {
await visit("/t/internationalization-localization/280");
await openFlagModal();
await click("#radio_inappropriate");
await selectKit(".reviewable-action-dropdown").expand();
assert.ok(
exists("[data-value='agree_and_silence']"),
"it shows the silence action option"
);
await click("[data-value='agree_and_silence']");
assert.ok(exists(".silence-user-modal"), "it shows the silence modal");
});
test("Can silence from take action", async (assert) => {
await visit("/t/internationalization-localization/280");
await openFlagModal();
await click("#radio_inappropriate");
await selectKit(".reviewable-action-dropdown").expand();
await click("[data-value='agree_and_silence']");
const silenceUntilCombobox = selectKit(".silence-until .combobox");
await silenceUntilCombobox.expand();
await silenceUntilCombobox.selectRowByValue("tomorrow");
await fillIn(".silence-reason", "for breaking the rules");
await click(".perform-silence");
assert.equal(find(".bootbox.modal:visible").length, 0);
});
test("Gets dismissable warning from canceling incomplete silence from take action", async (assert) => {
await visit("/t/internationalization-localization/280");
await openFlagModal();
await click("#radio_inappropriate");
await selectKit(".reviewable-action-dropdown").expand();
await click("[data-value='agree_and_silence']");
const silenceUntilCombobox = selectKit(".silence-until .combobox");
await silenceUntilCombobox.expand();
await silenceUntilCombobox.selectRowByValue("tomorrow");
await fillIn(".silence-reason", "for breaking the rules");
await click(".d-modal-cancel");
assert.equal(find(".bootbox.modal:visible").length, 1);
await click(".modal-footer .btn-default");
assert.equal(find(".bootbox.modal:visible").length, 0);
assert.ok(exists(".silence-user-modal"), "it shows the silence modal");
await click(".d-modal-cancel");
assert.equal(find(".bootbox.modal:visible").length, 1);
await click(".modal-footer .btn-primary");
assert.equal(find(".bootbox.modal:visible").length, 0);
});
});

View File

@ -5,79 +5,79 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
let userFound = false;
acceptance("Forgot password", {
pretend(server, helper) {
acceptance("Forgot password", function (needs) {
needs.pretender((server, helper) => {
server.post("/session/forgot_password", () => {
return helper.response({
user_found: userFound,
});
});
},
});
test("requesting password reset", async (assert) => {
await visit("/");
await click("header .login-button");
await click("#forgot-password-link");
assert.equal(
find(".forgot-password-reset").attr("disabled"),
"disabled",
"it should disable the button until the field is filled"
);
await fillIn("#username-or-email", "someuser");
await click(".forgot-password-reset");
assert.equal(
find(".alert-error").html().trim(),
I18n.t("forgot_password.complete_username_not_found", {
username: "someuser",
}),
"it should display an error for an invalid username"
);
await fillIn("#username-or-email", "someuser@gmail.com");
await click(".forgot-password-reset");
assert.equal(
find(".alert-error").html().trim(),
I18n.t("forgot_password.complete_email_not_found", {
email: "someuser@gmail.com",
}),
"it should display an error for an invalid email"
);
await fillIn("#username-or-email", "someuser");
userFound = true;
await click(".forgot-password-reset");
assert.notOk(
exists(find(".alert-error")),
"it should remove the flash error when succeeding"
);
assert.equal(
find(".modal-body").html().trim(),
I18n.t("forgot_password.complete_username_found", {
username: "someuser",
}),
"it should display a success message for a valid username"
);
await visit("/");
await click("header .login-button");
await click("#forgot-password-link");
await fillIn("#username-or-email", "someuser@gmail.com");
await click(".forgot-password-reset");
assert.equal(
find(".modal-body").html().trim(),
I18n.t("forgot_password.complete_email_found", {
email: "someuser@gmail.com",
}),
"it should display a success message for a valid email"
);
});
test("requesting password reset", async (assert) => {
await visit("/");
await click("header .login-button");
await click("#forgot-password-link");
assert.equal(
find(".forgot-password-reset").attr("disabled"),
"disabled",
"it should disable the button until the field is filled"
);
await fillIn("#username-or-email", "someuser");
await click(".forgot-password-reset");
assert.equal(
find(".alert-error").html().trim(),
I18n.t("forgot_password.complete_username_not_found", {
username: "someuser",
}),
"it should display an error for an invalid username"
);
await fillIn("#username-or-email", "someuser@gmail.com");
await click(".forgot-password-reset");
assert.equal(
find(".alert-error").html().trim(),
I18n.t("forgot_password.complete_email_not_found", {
email: "someuser@gmail.com",
}),
"it should display an error for an invalid email"
);
await fillIn("#username-or-email", "someuser");
userFound = true;
await click(".forgot-password-reset");
assert.notOk(
exists(find(".alert-error")),
"it should remove the flash error when succeeding"
);
assert.equal(
find(".modal-body").html().trim(),
I18n.t("forgot_password.complete_username_found", {
username: "someuser",
}),
"it should display a success message for a valid username"
);
await visit("/");
await click("header .login-button");
await click("#forgot-password-link");
await fillIn("#username-or-email", "someuser@gmail.com");
await click(".forgot-password-reset");
assert.equal(
find(".modal-body").html().trim(),
I18n.t("forgot_password.complete_email_found", {
email: "someuser@gmail.com",
}),
"it should display a success message for a valid email"
);
});
});

View File

@ -1,24 +0,0 @@
import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import DiscourseURL from "discourse/lib/url";
acceptance("Group Card - Mobile", { mobileView: true });
skip("group card", async (assert) => {
await visit("/t/-/301/1");
assert.ok(
invisible(".group-card"),
"mobile group card is invisible by default"
);
await click("a.mention-group:first");
assert.ok(visible(".group-card"), "mobile group card should appear");
sandbox.stub(DiscourseURL, "routeTo");
await click(".card-content a.group-page-link");
assert.ok(
DiscourseURL.routeTo.calledWith("/g/discourse"),
"it should navigate to the group page"
);
});

View File

@ -1,21 +0,0 @@
import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import DiscourseURL from "discourse/lib/url";
acceptance("Group Card");
skip("group card", async (assert) => {
await visit("/t/-/301/1");
assert.ok(invisible(".group-card"), "user card is invisible by default");
await click("a.mention-group:first");
assert.ok(visible(".group-card"), "card should appear");
sandbox.stub(DiscourseURL, "routeTo");
await click(".card-content a.group-page-link");
assert.ok(
DiscourseURL.routeTo.calledWith("/g/discourse"),
"it should navigate to the group page"
);
});

View File

@ -6,55 +6,57 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Group Members");
acceptance("Group Members - Anonymous", function () {
test("Viewing Members as anon user", async (assert) => {
await visit("/g/discourse");
test("Viewing Members as anon user", async (assert) => {
await visit("/g/discourse");
assert.ok(
count(".avatar-flair .d-icon-adjust") === 1,
"it displays the group's avatar flair"
);
assert.ok(count(".group-members tr") > 0, "it lists group members");
assert.ok(
count(".avatar-flair .d-icon-adjust") === 1,
"it displays the group's avatar flair"
);
assert.ok(count(".group-members tr") > 0, "it lists group members");
assert.ok(
count(".group-member-dropdown") === 0,
"it does not allow anon user to manage group members"
);
assert.ok(
count(".group-member-dropdown") === 0,
"it does not allow anon user to manage group members"
);
assert.equal(
find(".group-username-filter").attr("placeholder"),
I18n.t("groups.members.filter_placeholder"),
"it should display the right filter placehodler"
);
assert.equal(
find(".group-username-filter").attr("placeholder"),
I18n.t("groups.members.filter_placeholder"),
"it should display the right filter placehodler"
);
});
});
acceptance("Group Members", { loggedIn: true });
acceptance("Group Members", function (needs) {
needs.user();
test("Viewing Members as a group owner", async (assert) => {
updateCurrentUser({ moderator: false, admin: false });
test("Viewing Members as a group owner", async (assert) => {
updateCurrentUser({ moderator: false, admin: false });
await visit("/g/discourse");
await click(".group-members-add");
await visit("/g/discourse");
await click(".group-members-add");
assert.equal(
find("#group-add-members-user-selector").length,
1,
"it should display the add members modal"
);
});
test("Viewing Members as an admin user", async (assert) => {
await visit("/g/discourse");
assert.ok(
count(".group-member-dropdown") > 0,
"it allows admin user to manage group members"
);
assert.equal(
find(".group-username-filter").attr("placeholder"),
I18n.t("groups.members.filter_placeholder_admin"),
"it should display the right filter placehodler"
);
assert.equal(
find("#group-add-members-user-selector").length,
1,
"it should display the add members modal"
);
});
test("Viewing Members as an admin user", async (assert) => {
await visit("/g/discourse");
assert.ok(
count(".group-member-dropdown") > 0,
"it allows admin user to manage group members"
);
assert.equal(
find(".group-username-filter").attr("placeholder"),
I18n.t("groups.members.filter_placeholder_admin"),
"it should display the right filter placehodler"
);
});
});

View File

@ -5,34 +5,36 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Managing Group Category Notification Defaults");
test("As an anonymous user", async (assert) => {
await visit("/g/discourse/manage/categories");
acceptance("Managing Group Category Notification Defaults", function () {
test("As an anonymous user", async (assert) => {
await visit("/g/discourse/manage/categories");
assert.ok(
count(".group-members tr") > 0,
"it should redirect to members page for an anonymous user"
);
assert.ok(
count(".group-members tr") > 0,
"it should redirect to members page for an anonymous user"
);
});
});
acceptance("Managing Group Category Notification Defaults", { loggedIn: true });
acceptance("Managing Group Category Notification Defaults", function (needs) {
needs.user();
test("As an admin", async (assert) => {
await visit("/g/discourse/manage/categories");
test("As an admin", async (assert) => {
await visit("/g/discourse/manage/categories");
assert.ok(
find(".groups-notifications-form .category-selector").length === 5,
"it should display category inputs"
);
});
assert.ok(
find(".groups-notifications-form .category-selector").length === 5,
"it should display category inputs"
);
});
test("As a group owner", async (assert) => {
updateCurrentUser({ moderator: false, admin: false });
await visit("/g/discourse/manage/categories");
assert.ok(
find(".groups-notifications-form .category-selector").length === 5,
"it should display category inputs"
);
test("As a group owner", async (assert) => {
updateCurrentUser({ moderator: false, admin: false });
await visit("/g/discourse/manage/categories");
assert.ok(
find(".groups-notifications-form .category-selector").length === 5,
"it should display category inputs"
);
});
});

View File

@ -5,89 +5,87 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Managing Group Interaction Settings", {
loggedIn: true,
settings: {
email_in: true,
},
});
acceptance("Managing Group Interaction Settings", function (needs) {
needs.user();
needs.settings({ email_in: true });
test("As an admin", async (assert) => {
updateCurrentUser({
moderator: false,
admin: true,
can_create_group: true,
test("As an admin", async (assert) => {
updateCurrentUser({
moderator: false,
admin: true,
can_create_group: true,
});
await visit("/g/alternative-group/manage/interaction");
assert.equal(
find(".groups-form-visibility-level").length,
1,
"it should display visibility level selector"
);
assert.equal(
find(".groups-form-mentionable-level").length,
1,
"it should display mentionable level selector"
);
assert.equal(
find(".groups-form-messageable-level").length,
1,
"it should display messageable level selector"
);
assert.equal(
find(".groups-form-incoming-email").length,
1,
"it should display incoming email input"
);
assert.equal(
find(".groups-form-default-notification-level").length,
1,
"it should display default notification level input"
);
});
await visit("/g/alternative-group/manage/interaction");
test("As a group owner", async (assert) => {
updateCurrentUser({
moderator: false,
admin: false,
can_create_group: false,
});
assert.equal(
find(".groups-form-visibility-level").length,
1,
"it should display visibility level selector"
);
await visit("/g/discourse/manage/interaction");
assert.equal(
find(".groups-form-mentionable-level").length,
1,
"it should display mentionable level selector"
);
assert.equal(
find(".groups-form-visibility-level").length,
0,
"it should not display visibility level selector"
);
assert.equal(
find(".groups-form-messageable-level").length,
1,
"it should display messageable level selector"
);
assert.equal(
find(".groups-form-mentionable-level").length,
1,
"it should display mentionable level selector"
);
assert.equal(
find(".groups-form-incoming-email").length,
1,
"it should display incoming email input"
);
assert.equal(
find(".groups-form-messageable-level").length,
1,
"it should display messageable level selector"
);
assert.equal(
find(".groups-form-default-notification-level").length,
1,
"it should display default notification level input"
);
});
assert.equal(
find(".groups-form-incoming-email").length,
0,
"it should not display incoming email input"
);
test("As a group owner", async (assert) => {
updateCurrentUser({
moderator: false,
admin: false,
can_create_group: false,
assert.equal(
find(".groups-form-default-notification-level").length,
1,
"it should display default notification level input"
);
});
await visit("/g/discourse/manage/interaction");
assert.equal(
find(".groups-form-visibility-level").length,
0,
"it should not display visibility level selector"
);
assert.equal(
find(".groups-form-mentionable-level").length,
1,
"it should display mentionable level selector"
);
assert.equal(
find(".groups-form-messageable-level").length,
1,
"it should display messageable level selector"
);
assert.equal(
find(".groups-form-incoming-email").length,
0,
"it should not display incoming email input"
);
assert.equal(
find(".groups-form-default-notification-level").length,
1,
"it should display default notification level input"
);
});

File diff suppressed because it is too large Load Diff

View File

@ -170,6 +170,7 @@ export function acceptance(name, optionsOrCallback) {
let loggedIn = false;
let siteChanges;
let settingChanges;
let userChanges;
const setup = {
beforeEach() {
@ -185,6 +186,9 @@ export function acceptance(name, optionsOrCallback) {
if (loggedIn) {
logIn();
if (userChanges) {
updateCurrentUser(userChanges);
}
}
if (settingChanges) {
@ -249,8 +253,9 @@ export function acceptance(name, optionsOrCallback) {
};
const needs = {
user() {
user(changes) {
loggedIn = true;
userChanges = changes;
},
pretender(fn) {
addPretenderCallback(name, fn);