REFACTOR: All remaining acceptance tests converted to new format

Also contains fixes to leaky state in pretender.
This commit is contained in:
Robin Ward 2020-10-20 13:56:52 -04:00
parent 88c5a37efa
commit 919f488358
87 changed files with 6699 additions and 6806 deletions

View File

@ -356,24 +356,9 @@ acceptance("Composer Actions", function (needs) {
assert.equal(composerActions.rows().length, 1);
assert.equal(composerActions.rowByIndex(0).value(), "reply_to_post");
});
});
acceptance("Composer Actions With New Topic Draft", {
loggedIn: true,
settings: {
enable_whispers: true,
},
site: {
can_tag_topics: true,
},
beforeEach() {
_clearSnapshots();
},
afterEach() {
_clearSnapshots();
},
});
const stubDraftResponse = () => {
function stubDraftResponse() {
sandbox.stub(Draft, "get").returns(
Promise.resolve({
draft:
@ -381,7 +366,18 @@ acceptance("Composer Actions", function (needs) {
draft_sequence: 0,
})
);
};
}
acceptance("Composer Actions With New Topic Draft", function (needs) {
needs.user();
needs.settings({
enable_whispers: true,
});
needs.site({
can_tag_topics: true,
});
needs.hooks.beforeEach(() => _clearSnapshots());
needs.hooks.afterEach(() => _clearSnapshots());
test("shared draft", async (assert) => {
stubDraftResponse();

View File

@ -9,19 +9,16 @@ import { toggleCheckDraftPopup } from "discourse/controllers/composer";
import Draft from "discourse/models/draft";
import { Promise } from "rsvp";
acceptance("Composer", {
loggedIn: true,
pretend(server, helper) {
acceptance("Composer", function (needs) {
needs.user();
needs.settings({ enable_whispers: true });
needs.pretender((server, helper) => {
server.post("/uploads/lookup-urls", () => {
return helper.response([]);
});
},
settings: {
enable_whispers: true,
},
});
});
skip("Tests the Composer controls", async (assert) => {
skip("Tests the Composer controls", async (assert) => {
await visit("/");
assert.ok(exists("#create-topic"), "the create button is visible");
@ -97,9 +94,9 @@ skip("Tests the Composer controls", async (assert) => {
await click(".modal-footer a:eq(1)");
assert.ok(!exists(".bootbox.modal"), "the confirmation can be cancelled");
});
});
test("Composer upload placeholder", async (assert) => {
test("Composer upload placeholder", async (assert) => {
await visit("/");
await click("#create-topic");
@ -190,9 +187,9 @@ test("Composer upload placeholder", async (assert) => {
find(".d-editor-input").val(),
"![test|200x300](/images/avatar.png?1) ![test|100x200](/images/avatar.png?2) [Uploading: ima++ge.png...]() ![image|300x400](/images/avatar.png?3) "
);
});
});
test("Create a topic with server side errors", async (assert) => {
test("Create a topic with server side errors", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "this title triggers an error");
@ -202,22 +199,25 @@ test("Create a topic with server side errors", async (assert) => {
await click(".bootbox.modal a.btn-primary");
assert.ok(!exists(".bootbox.modal"), "it dismisses the error");
assert.ok(exists(".d-editor-input"), "the composer input is visible");
});
});
test("Create a Topic", async (assert) => {
test("Create a Topic", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "Internationalization Localization");
await fillIn(".d-editor-input", "this is the *content* of a new topic post");
await fillIn(
".d-editor-input",
"this is the *content* of a new topic post"
);
await click("#reply-control button.create");
assert.equal(
currentURL(),
"/t/internationalization-localization/280",
"it transitions to the newly created topic URL"
);
});
});
test("Create an enqueued Topic", async (assert) => {
test("Create an enqueued Topic", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "Internationalization Localization");
@ -228,9 +228,9 @@ test("Create an enqueued Topic", async (assert) => {
await click(".modal-footer button");
assert.ok(invisible(".d-modal"), "the modal can be dismissed");
});
});
test("Can display a message and route to a URL", async (assert) => {
test("Can display a message and route to a URL", async (assert) => {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "This title doesn't matter");
@ -248,9 +248,9 @@ test("Can display a message and route to a URL", async (assert) => {
"/faq",
"can navigate to a `route_to` destination"
);
});
});
test("Create a Reply", async (assert) => {
test("Create a Reply", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(
@ -260,7 +260,10 @@ test("Create a Reply", async (assert) => {
await click("#topic-footer-buttons .btn.create");
assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.ok(!exists("#reply-title"), "there is no title since this is a reply");
assert.ok(
!exists("#reply-title"),
"there is no title since this is a reply"
);
await fillIn(".d-editor-input", "this is the content of my reply");
await click("#reply-control button.create");
@ -268,9 +271,9 @@ test("Create a Reply", async (assert) => {
find(".cooked:last p").text(),
"If you use gettext format you could leverage Launchpad 13 translations and the community behind it."
);
});
});
test("Can edit a post after starting a reply", async (assert) => {
test("Can edit a post after starting a reply", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .create");
@ -286,12 +289,15 @@ test("Can edit a post after starting a reply", async (assert) => {
find(".d-editor-input").val(),
"this is the content of my reply"
);
});
});
test("Posting on a different topic", async (assert) => {
test("Posting on a different topic", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
await fillIn(".d-editor-input", "this is the content for a different topic");
await fillIn(
".d-editor-input",
"this is the content for a different topic"
);
await visit("/t/1-3-0beta9-no-rate-limit-popups/28830");
assert.equal(currentURL(), "/t/1-3-0beta9-no-rate-limit-popups/28830");
@ -303,16 +309,19 @@ test("Posting on a different topic", async (assert) => {
find(".cooked:last p").text(),
"If you use gettext format you could leverage Launchpad 13 translations and the community behind it."
);
});
});
test("Create an enqueued Reply", async (assert) => {
test("Create an enqueued Reply", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.notOk(find(".pending-posts .reviewable-item").length);
await click("#topic-footer-buttons .btn.create");
assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.ok(!exists("#reply-title"), "there is no title since this is a reply");
assert.ok(
!exists("#reply-title"),
"there is no title since this is a reply"
);
await fillIn(".d-editor-input", "enqueue this content please");
await click("#reply-control button.create");
@ -327,9 +336,9 @@ test("Create an enqueued Reply", async (assert) => {
assert.ok(invisible(".d-modal"), "the modal can be dismissed");
assert.ok(find(".pending-posts .reviewable-item").length);
});
});
test("Edit the first post", async (assert) => {
test("Edit the first post", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(
@ -365,9 +374,9 @@ test("Edit the first post", async (assert) => {
.indexOf("This is the new text for the post") !== -1,
"it updates the post"
);
});
});
test("Composer can switch between edits", async (assert) => {
test("Composer can switch between edits", async (assert) => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.edit");
@ -382,9 +391,9 @@ test("Composer can switch between edits", async (assert) => {
0,
"it populates the input with the post text"
);
});
});
test("Composer with dirty edit can toggle to another edit", async (assert) => {
test("Composer with dirty edit can toggle to another edit", async (assert) => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.edit");
@ -398,9 +407,9 @@ test("Composer with dirty edit can toggle to another edit", async (assert) => {
0,
"it populates the input with the post text"
);
});
});
test("Composer can toggle between edit and reply", async (assert) => {
test("Composer can toggle between edit and reply", async (assert) => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.edit");
@ -417,9 +426,9 @@ test("Composer can toggle between edit and reply", async (assert) => {
0,
"it populates the input with the post text"
);
});
});
test("Composer can toggle whispers", async (assert) => {
test("Composer can toggle whispers", async (assert) => {
const menu = selectKit(".toolbar-popup-menu-options");
await visit("/t/this-is-a-test-topic/9");
@ -452,9 +461,9 @@ test("Composer can toggle whispers", async (assert) => {
menu.rowByValue("toggleWhisper").exists(),
"whisper toggling is still present when going fullscreen"
);
});
});
test("Composer can toggle layouts (open, fullscreen and draft)", async (assert) => {
test("Composer can toggle layouts (open, fullscreen and draft)", async (assert) => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.reply");
@ -491,9 +500,9 @@ test("Composer can toggle layouts (open, fullscreen and draft)", async (assert)
find("#reply-control.open").length === 1,
"from draft, it expands composer back to open state"
);
});
});
test("Composer can toggle between reply and createTopic", async (assert) => {
test("Composer can toggle between reply and createTopic", async (assert) => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.reply");
@ -522,8 +531,9 @@ test("Composer can toggle between reply and createTopic", async (assert) => {
);
assert.ok(
find(".composer-fields .unlist").text().indexOf(I18n.t("composer.unlist")) >
0,
find(".composer-fields .unlist")
.text()
.indexOf(I18n.t("composer.unlist")) > 0,
"it sets the topic to unlisted"
);
@ -536,9 +546,9 @@ test("Composer can toggle between reply and createTopic", async (assert) => {
.indexOf(I18n.t("composer.unlist")) === -1,
"it should reset the state of the composer's model"
);
});
});
test("Composer with dirty reply can toggle to edit", async (assert) => {
test("Composer with dirty reply can toggle to edit", async (assert) => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.reply");
@ -551,9 +561,9 @@ test("Composer with dirty reply can toggle to edit", async (assert) => {
0,
"it populates the input with the post text"
);
});
});
test("Composer draft with dirty reply can toggle to edit", async (assert) => {
test("Composer draft with dirty reply can toggle to edit", async (assert) => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.reply");
@ -571,9 +581,9 @@ test("Composer draft with dirty reply can toggle to edit", async (assert) => {
0,
"it populates the input with the post text"
);
});
});
test("Composer draft can switch to draft in new context without destroying current draft", async (assert) => {
test("Composer draft can switch to draft in new context without destroying current draft", async (assert) => {
await visit("/t/this-is-a-test-topic/9");
await click(".topic-post:eq(0) button.reply");
@ -593,9 +603,9 @@ test("Composer draft can switch to draft in new context without destroying curre
"",
"it populates the input with the post text"
);
});
});
test("Checks for existing draft", async (assert) => {
test("Checks for existing draft", async (assert) => {
try {
toggleCheckDraftPopup(true);
@ -604,15 +614,18 @@ test("Checks for existing draft", async (assert) => {
await click(".topic-post:eq(0) button.show-more-actions");
await click(".topic-post:eq(0) button.edit");
assert.equal(find(".modal-body").text(), I18n.t("drafts.abandon.confirm"));
assert.equal(
find(".modal-body").text(),
I18n.t("drafts.abandon.confirm")
);
await click(".modal-footer .btn.btn-default");
} finally {
toggleCheckDraftPopup(false);
}
});
});
test("Can switch states without abandon popup", async (assert) => {
test("Can switch states without abandon popup", async (assert) => {
try {
toggleCheckDraftPopup(true);
@ -649,7 +662,9 @@ test("Can switch states without abandon popup", async (assert) => {
);
assert.ok(
find('.action-title a[href="/t/internationalization-localization/280"]'),
find(
'.action-title a[href="/t/internationalization-localization/280"]'
),
"mode should have changed"
);
@ -658,9 +673,9 @@ test("Can switch states without abandon popup", async (assert) => {
toggleCheckDraftPopup(false);
}
sandbox.restore();
});
});
test("Loading draft also replaces the recipients", async (assert) => {
test("Loading draft also replaces the recipients", async (assert) => {
try {
toggleCheckDraftPopup(true);
@ -680,9 +695,9 @@ test("Loading draft also replaces the recipients", async (assert) => {
} finally {
toggleCheckDraftPopup(false);
}
});
});
test("Deleting the text content of the first post in a private message", async (assert) => {
test("Deleting the text content of the first post in a private message", async (assert) => {
await visit("/t/34");
await click("#post_1 .d-icon-ellipsis-h");
@ -696,17 +711,17 @@ test("Deleting the text content of the first post in a private message", async (
I18n.t("composer.reply_placeholder"),
"it should not block because of missing category"
);
});
});
const assertImageResized = (assert, uploads) => {
const assertImageResized = (assert, uploads) => {
assert.equal(
find(".d-editor-input").val(),
uploads.join("\n"),
"it resizes uploaded image"
);
};
};
test("Image resizing buttons", async (assert) => {
test("Image resizing buttons", async (assert) => {
await visit("/");
await click("#create-topic");
@ -810,4 +825,5 @@ test("Image resizing buttons", async (assert) => {
find("script").length === 0,
"it does not unescapes script tags in code blocks"
);
});
});

View File

@ -136,13 +136,13 @@ acceptance("Dashboard: dashboard_visible_tabs", function (needs) {
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: {
acceptance("Dashboard: dashboard_hidden_reports", function (needs) {
needs.user();
needs.settings({
dashboard_visible_tabs: "reports",
dashboard_hidden_reports: "posts|dau_by_mau",
},
});
test("hidden reports", async (assert) => {

View File

@ -3,28 +3,11 @@ import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import DiscoveryFixtures from "discourse/tests/fixtures/discovery-fixtures";
acceptance("Encoded Sub Category Discovery", {
pretend(server, helper) {
server.get(
"/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory/6/l/latest.json",
() => {
return helper.response(
DiscoveryFixtures["/latest_can_create_topic.json"]
);
}
);
server.get(
"/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory/find_by_slug.json",
() => {
//respond with an error here: these tests are to check that ember can route this itself without falling back to rails
return helper.response(500, {});
}
);
},
settings: {
acceptance("Encoded Sub Category Discovery", function (needs) {
needs.settings({
slug_generation_method: "encoded",
},
site: {
});
needs.site({
categories: [
{
id: 5,
@ -40,10 +23,26 @@ acceptance("Encoded Sub Category Discovery", {
parent_category_id: 5,
},
],
},
});
});
needs.pretender((server, helper) => {
server.get(
"/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory/6/l/latest.json",
() => {
return helper.response(
DiscoveryFixtures["/latest_can_create_topic.json"]
);
}
);
server.get(
"/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory/find_by_slug.json",
() => {
//respond with an error here: these tests are to check that ember can route this itself without falling back to rails
return helper.response(500, {});
}
);
});
test("Visit subcategory by slug", async (assert) => {
test("Visit subcategory by slug", async (assert) => {
let bodySelector =
"body.category-\\%E6\\%BC\\%A2\\%E5\\%AD\\%97-parent-\\%E6\\%BC\\%A2\\%E5\\%AD\\%97-subcategory";
await visit("/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory");
@ -55,4 +54,5 @@ test("Visit subcategory by slug", async (assert) => {
assert.ok($(bodySelector).length, "has the default navigation");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
});
});

View File

@ -2,9 +2,9 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Group logs", {
loggedIn: true,
pretend(server, helper) {
acceptance("Group logs", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.get("/groups/snorlax.json", () => {
return helper.response({
group: {
@ -91,10 +91,9 @@ acceptance("Group logs", {
});
}
});
},
});
});
test("Browsing group logs", async (assert) => {
test("Browsing group logs", async (assert) => {
await visit("/g/snorlax/manage/logs");
assert.ok(
find("tr.group-manage-logs-row").length === 2,
@ -106,4 +105,5 @@ test("Browsing group logs", async (assert) => {
find("tr.group-manage-logs-row").length === 1,
"it should display the right number of logs"
);
});
});

View File

@ -6,11 +6,10 @@ import {
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("Managing Group Membership", {
loggedIn: true,
});
acceptance("Managing Group Membership", function (needs) {
needs.user();
test("As an admin", async (assert) => {
test("As an admin", async (assert) => {
updateCurrentUser({ can_create_group: true });
await visit("/g/alternative-group/manage/membership");
@ -69,15 +68,17 @@ test("As an admin", async (assert) => {
"it should display the membership request template field"
);
const emailDomains = selectKit(".group-form-automatic-membership-automatic");
const emailDomains = selectKit(
".group-form-automatic-membership-automatic"
);
await emailDomains.expand();
await emailDomains.fillInFilter("foo.com");
await emailDomains.keyboard("enter");
assert.equal(emailDomains.header().value(), "foo.com");
});
});
test("As a group owner", async (assert) => {
test("As a group owner", async (assert) => {
updateCurrentUser({ moderator: false, admin: false });
await visit("/g/discourse/manage/membership");
@ -121,4 +122,5 @@ test("As a group owner", async (assert) => {
find(".group-form-allow-membership-requests[disabled]").length === 1,
"it should disable group allow_membership_request input"
);
});
});

View File

@ -5,19 +5,21 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Managing Group Profile");
test("As an anonymous user", async (assert) => {
acceptance("Managing Group Profile", function () {
test("As an anonymous user", async (assert) => {
await visit("/g/discourse/manage/profile");
assert.ok(
count(".group-members tr") > 0,
"it should redirect to members page for an anonymous user"
);
});
});
acceptance("Managing Group Profile", { loggedIn: true });
acceptance("Managing Group Profile", function (needs) {
needs.user();
test("As an admin", async (assert) => {
test("As an admin", async (assert) => {
await visit("/g/discourse/manage/profile");
assert.ok(
@ -36,9 +38,9 @@ test("As an admin", async (assert) => {
find(".group-form-full-name").length === 1,
"it should display group full name input"
);
});
});
test("As a group owner", async (assert) => {
test("As a group owner", async (assert) => {
updateCurrentUser({
moderator: false,
admin: false,
@ -52,4 +54,5 @@ test("As a group owner", async (assert) => {
0,
"it should not display group name input"
);
});
});

View File

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

View File

@ -1,13 +1,14 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { parsePostData } from "discourse/tests/helpers/create-pretender";
let requests = [];
acceptance("Group Requests", function (needs) {
let requests;
acceptance("Group Requests", {
loggedIn: true,
pretend(server, helper) {
needs.user();
needs.hooks.beforeEach(() => (requests = []));
needs.pretender((server, helper) => {
server.get("/groups/Macdonald.json", () => {
return helper.response({
group: {
@ -75,14 +76,13 @@ acceptance("Group Requests", {
});
server.put("/groups/42/handle_membership_request.json", (request) => {
const body = parsePostData(request.requestBody);
const body = helper.parsePostData(request.requestBody);
requests.push([body["user_id"], body["accept"]]);
return helper.success();
});
},
});
});
test("Group Requests", async (assert) => {
test("Group Requests", async (assert) => {
await visit("/g/Macdonald/requests");
assert.equal(find(".group-members tr").length, 2);
@ -124,4 +124,5 @@ test("Group Requests", async (assert) => {
["19", "true"],
["20", undefined],
]);
});
});

View File

@ -3,28 +3,24 @@ import { test } from "qunit";
import I18n from "I18n";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender";
let groupArgs = {
settings: {
enable_group_directory: true,
},
pretend(pretenderServer, helper) {
pretenderServer.post("/groups/Macdonald/request_membership", () => {
function setupGroupPretender(server, helper) {
server.post("/groups/Macdonald/request_membership", () => {
return helper.response({
relative_url: "/t/internationalization-localization/280",
});
});
},
};
}
acceptance("Group", groupArgs);
function setupGroupTest(needs) {
needs.settings({ enable_group_directory: true });
}
const response = (object) => {
return [200, { "Content-Type": "application/json" }, object];
};
acceptance("Group - Anonymous", function (needs) {
setupGroupTest(needs);
needs.pretender(setupGroupPretender);
test("Anonymous Viewing Group", async function (assert) {
test("Anonymous Viewing Group", async function (assert) {
await visit("/g/discourse");
assert.equal(
@ -77,9 +73,9 @@ test("Anonymous Viewing Group", async function (assert) {
0,
"it should not display the default header"
);
});
});
test("Anonymous Viewing Automatic Group", async (assert) => {
test("Anonymous Viewing Automatic Group", async (assert) => {
await visit("/g/moderators");
assert.equal(
@ -87,66 +83,26 @@ test("Anonymous Viewing Automatic Group", async (assert) => {
0,
"it does not show group messages navigation link"
);
});
});
acceptance("Group", Object.assign({ loggedIn: true }, groupArgs));
acceptance("Group - Authenticated", function (needs) {
setupGroupTest(needs);
needs.user();
test("User Viewing Group", async (assert) => {
await visit("/g");
await click(".group-index-request");
assert.equal(
find(".modal-header").text().trim(),
I18n.t("groups.membership_request.title", { group_name: "Macdonald" })
);
assert.equal(
find(".request-group-membership-form textarea").val(),
"Please add me"
);
await click(".modal-footer .btn-primary");
assert.equal(
find(".fancy-title").text().trim(),
"Internationalization / localization"
);
await visit("/g/discourse");
await click(".group-message-button");
assert.ok(count("#reply-control") === 1, "it opens the composer");
assert.equal(
find(".ac-wrap .item").text(),
"discourse",
"it prefills the group name"
);
});
test("Admin viewing group messages when there are no messages", async (assert) => {
pretender.get(
"/topics/private-messages-group/eviltrout/discourse.json",
needs.pretender((server, helper) => {
setupGroupPretender(server, helper);
server.get(
"/topics/private-messages-group/eviltrout/alternative-group.json",
() => {
return response({ topic_list: { topics: [] } });
return helper.response({ topic_list: { topics: [] } });
}
);
await visit("/g/discourse");
await click(".nav-pills li a[title='Messages']");
assert.equal(
find(".alert").text().trim(),
I18n.t("choose_topic.none_found"),
"it should display the right alert"
);
});
test("Admin viewing group messages", async (assert) => {
pretender.get(
server.get(
"/topics/private-messages-group/eviltrout/discourse.json",
() => {
return response({
return helper.response({
users: [
{
id: 2,
@ -226,7 +182,53 @@ test("Admin viewing group messages", async (assert) => {
});
}
);
});
test("User Viewing Group", async (assert) => {
await visit("/g");
await click(".group-index-request");
assert.equal(
find(".modal-header").text().trim(),
I18n.t("groups.membership_request.title", { group_name: "Macdonald" })
);
assert.equal(
find(".request-group-membership-form textarea").val(),
"Please add me"
);
await click(".modal-footer .btn-primary");
assert.equal(
find(".fancy-title").text().trim(),
"Internationalization / localization"
);
await visit("/g/discourse");
await click(".group-message-button");
assert.ok(count("#reply-control") === 1, "it opens the composer");
assert.equal(
find(".ac-wrap .item").text(),
"discourse",
"it prefills the group name"
);
});
test("Admin viewing group messages when there are no messages", async (assert) => {
await visit("/g/alternative-group");
await click(".nav-pills li a[title='Messages']");
assert.equal(
find(".alert").text().trim(),
I18n.t("choose_topic.none_found"),
"it should display the right alert"
);
});
test("Admin viewing group messages", async (assert) => {
await visit("/g/discourse");
await click(".nav-pills li a[title='Messages']");
@ -235,9 +237,9 @@ test("Admin viewing group messages", async (assert) => {
"This is a private message 1",
"it should display the list of group topics"
);
});
});
test("Admin Viewing Group", async (assert) => {
test("Admin Viewing Group", async (assert) => {
await visit("/g/discourse");
assert.ok(
@ -255,9 +257,9 @@ test("Admin Viewing Group", async (assert) => {
"Awesome Team",
"it should display the group name"
);
});
});
test("Moderator Viewing Group", async (assert) => {
test("Moderator Viewing Group", async (assert) => {
await visit("/g/alternative-group");
assert.ok(
@ -285,4 +287,5 @@ test("Moderator Viewing Group", async (assert) => {
memberDropdown.rowByIndex(1).name(),
I18n.t("groups.members.make_owner")
);
});
});

View File

@ -2,9 +2,8 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Groups");
test("Browsing Groups", async (assert) => {
acceptance("Groups", function () {
test("Browsing Groups", async (assert) => {
await visit("/g?username=eviltrout");
assert.equal(count(".group-box"), 1, "it displays user's groups");
@ -46,4 +45,5 @@ test("Browsing Groups", async (assert) => {
await click(".group-index-join");
assert.ok(exists(".modal.login-modal"), "it shows the login modal");
});
});

View File

@ -3,9 +3,8 @@ import { test } from "qunit";
import I18n from "I18n";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("New Group");
test("As an anon user", async (assert) => {
acceptance("New Group - Anonymous", function () {
test("As an anon user", async (assert) => {
await visit("/g");
assert.equal(
@ -13,11 +12,12 @@ test("As an anon user", async (assert) => {
0,
"it should not display the button to create a group"
);
});
});
acceptance("New Group", { loggedIn: true });
test("Creating a new group", async (assert) => {
acceptance("New Group - Authenticated", function (needs) {
needs.user();
test("Creating a new group", async (assert) => {
await visit("/g");
await click(".groups-header-new");
@ -74,4 +74,5 @@ test("Creating a new group", async (assert) => {
0,
"it should disable the membership requests checkbox"
);
});
});

View File

@ -5,18 +5,19 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Opening the hamburger menu with some reviewables", {
loggedIn: true,
pretend: (server, helper) => {
acceptance("Opening the hamburger menu with some reviewables", function (
needs
) {
needs.user();
needs.pretender((server, helper) => {
server.get("/review/count.json", () => helper.response({ count: 3 }));
},
});
test("As a staff member", async (assert) => {
});
test("As a staff member", async (assert) => {
updateCurrentUser({ moderator: true, admin: false });
await visit("/");
await click(".hamburger-dropdown");
assert.equal(find(".review .badge-notification.reviewables").text(), "3");
});
});

View File

@ -2,10 +2,10 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Category and Tag Hashtags", {
loggedIn: true,
settings: { tagging_enabled: true },
pretend(server, helper) {
acceptance("Category and Tag Hashtags", function (needs) {
needs.user();
needs.settings({ tagging_enabled: true });
needs.pretender((server, helper) => {
server.get("/hashtags", () => {
return helper.response({
categories: { bug: "/c/bugs" },
@ -15,10 +15,9 @@ acceptance("Category and Tag Hashtags", {
},
});
});
},
});
});
test("hashtags are cooked properly", async (assert) => {
test("hashtags are cooked properly", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create");
@ -37,4 +36,5 @@ category vs tag: #bug vs #bug::tag`
<p>this is a tag hashtag <a href="/tag/monkey" class="hashtag">#<span>monkey</span></a></p>
<p>category vs tag: <a href="/c/bugs" class="hashtag">#<span>bug</span></a> vs <a href="/tag/bug" class="hashtag">#<span>bug</span></a></p>`
);
});
});

View File

@ -3,13 +3,10 @@ import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import PreloadStore from "discourse/lib/preload-store";
acceptance("Invite Accept", {
settings: {
full_name_required: true,
},
});
acceptance("Invite Accept", function (needs) {
needs.settings({ full_name_required: true });
test("Invite Acceptance Page", async (assert) => {
test("Invite Acceptance Page", async (assert) => {
PreloadStore.store("invite_info", {
invited_by: {
id: 123,
@ -81,4 +78,5 @@ test("Invite Acceptance Page", async (assert) => {
exists(".invites-show .btn-primary:disabled"),
"submit is enabled"
);
});
});

View File

@ -3,8 +3,8 @@ import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import PreloadStore from "discourse/lib/preload-store";
acceptance("Accept Invite - User Fields", {
site: {
acceptance("Accept Invite - User Fields", function (needs) {
needs.site({
user_fields: [
{
id: 34,
@ -25,10 +25,9 @@ acceptance("Accept Invite - User Fields", {
required: false,
},
],
},
});
});
test("accept invite with user fields", async (assert) => {
test("accept invite with user fields", async (assert) => {
PreloadStore.store("invite_info", {
invited_by: {
id: 123,
@ -78,4 +77,5 @@ test("accept invite with user fields", async (assert) => {
exists(".invites-show .btn-primary:disabled"),
"unclicking the checkbox disables the submit"
);
});
});

View File

@ -2,12 +2,11 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Jump to", {
loggedIn: true,
acceptance("Jump to", function (needs) {
needs.user();
needs.mobileView();
mobileView: true,
pretend(server, helper) {
needs.pretender((server, helper) => {
server.get("/t/280/excerpts.json", () => helper.response(200, []));
server.get("/t/280/3.json", () => helper.response(200, {}));
server.get("/posts/by-date/280/:date", (req) => {
@ -19,10 +18,9 @@ acceptance("Jump to", {
return helper.response(404, null);
});
},
});
});
test("default", async (assert) => {
test("default", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("nav#topic-progress .nums");
await click("button.jump-to-post");
@ -37,9 +35,9 @@ test("default", async (assert) => {
"/t/internationalization-localization/280/3",
"it jumps to the correct post"
);
});
});
test("invalid date", async (assert) => {
test("invalid date", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("nav#topic-progress .nums");
await click("button.jump-to-post");
@ -51,4 +49,5 @@ test("invalid date", async (assert) => {
"/t/internationalization-localization/280/20",
"it jumps to the last post if no post found"
);
});
});

View File

@ -1,66 +1,43 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender";
acceptance("Keyboard Shortcuts", { loggedIn: true });
acceptance("Keyboard Shortcuts", function (needs) {
needs.pretender((server, helper) => {
server.get("/t/27331/4.json", () => helper.response({}));
server.get("/t/27331.json", () => helper.response({}));
test("go to first suggested topic", async (assert) => {
pretender.get("/t/27331/4.json", () => [
200,
{ "Content-Type": "application/json" },
{},
]);
// No suggested topics exist.
server.get("/t/9/last.json", () => helper.response({}));
pretender.get("/t/27331.json", () => [
200,
{ "Content-Type": "application/json" },
{},
]);
/*
* No suggested topics exist.
*/
pretender.get("/t/9/last.json", () => [
200,
{ "Content-Type": "application/json" },
{},
]);
await visit("/t/this-is-a-test-topic/9");
await keyEvent(document, "keypress", "g".charCodeAt(0));
await keyEvent(document, "keypress", "s".charCodeAt(0));
assert.equal(currentURL(), "/t/this-is-a-test-topic/9");
/*
* Suggested topics elements exist.
*/
await visit("/t/internationalization-localization/280");
await keyEvent(document, "keypress", "g".charCodeAt(0));
await keyEvent(document, "keypress", "s".charCodeAt(0));
assert.equal(currentURL(), "/t/polls-are-still-very-buggy/27331/4");
/*
* Suggested topic is returned by server.
*/
pretender.get("/t/28830/last.json", () => [
200,
{ "Content-Type": "application/json" },
{
// Suggested topic is returned by server.
server.get("/t/28830/last.json", () => {
return helper.response({
suggested_topics: [
{
id: 27331,
slug: "keyboard-shortcuts-are-awesome",
},
],
},
]);
});
});
});
test("go to first suggested topic", async (assert) => {
await visit("/t/this-is-a-test-topic/9");
await keyEvent(document, "keypress", "g".charCodeAt(0));
await keyEvent(document, "keypress", "s".charCodeAt(0));
assert.equal(currentURL(), "/t/this-is-a-test-topic/9");
// Suggested topics elements exist.
await visit("/t/internationalization-localization/280");
await keyEvent(document, "keypress", "g".charCodeAt(0));
await keyEvent(document, "keypress", "s".charCodeAt(0));
assert.equal(currentURL(), "/t/polls-are-still-very-buggy/27331/4");
await visit("/t/1-3-0beta9-no-rate-limit-popups/28830");
await keyEvent(document, "keypress", "g".charCodeAt(0));
await keyEvent(document, "keypress", "s".charCodeAt(0));
assert.equal(currentURL(), "/t/keyboard-shortcuts-are-awesome/27331");
});
});

View File

@ -2,27 +2,28 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Login redirect");
test("redirects login to default homepage", async function (assert) {
acceptance("Login redirect - anonymous", function () {
test("redirects login to default homepage", async function (assert) {
await visit("/login");
assert.equal(
currentPath(),
"discovery.latest",
"it works when latest is the homepage"
);
});
});
acceptance("Login redirect - categories default", {
settings: {
acceptance("Login redirect - categories default", function (needs) {
needs.settings({
top_menu: "categories|latest|top|hot",
},
});
});
test("when site setting is categories", async function (assert) {
test("when site setting is categories", async function (assert) {
await visit("/login");
assert.equal(
currentPath(),
"discovery.categories",
"it works when categories is the homepage"
);
});
});

View File

@ -2,22 +2,24 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Login Required", {
settings: {
login_required: true,
},
});
acceptance("Login Required", function (needs) {
needs.settings({ login_required: true });
test("redirect", async (assert) => {
test("redirect", async (assert) => {
await visit("/latest");
assert.equal(currentPath(), "login", "it redirects them to login");
await click("#site-logo");
assert.equal(currentPath(), "login", "clicking the logo keeps them on login");
assert.equal(
currentPath(),
"login",
"clicking the logo keeps them on login"
);
await click("header .login-button");
assert.ok(exists(".login-modal"), "they can still access the login modal");
await click(".modal-header .close");
assert.ok(invisible(".login-modal"), "it closes the login modal");
});
});

View File

@ -2,25 +2,20 @@ 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("Login with email - hide email address taken", {
settings: {
acceptance("Login with email - hide email address taken", function (needs) {
needs.settings({
enable_local_logins_via_email: true,
hide_email_address_taken: true,
},
beforeEach() {
const response = (object) => {
return [200, { "Content-Type": "application/json" }, object];
};
pretender.post("/u/email-login", () => {
return response({ success: "OK" });
});
},
});
test("with hide_email_address_taken enabled", async (assert) => {
needs.pretender((server, helper) => {
server.post("/u/email-login", () => {
return helper.response({ success: "OK" });
});
});
test("with hide_email_address_taken enabled", async (assert) => {
await visit("/");
await click("header .login-button");
await fillIn("#login-account-name", "someuser@example.com");
@ -33,4 +28,5 @@ test("with hide_email_address_taken enabled", async (assert) => {
}),
"it should display the success message for any email address"
);
});
});

View File

@ -2,25 +2,22 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Login with email - no social logins", {
settings: {
enable_local_logins_via_email: true,
},
pretend(server, helper) {
acceptance("Login with email - no social logins", function (needs) {
needs.settings({ enable_local_logins_via_email: true });
needs.pretender((server, helper) => {
server.post("/u/email-login", () => helper.response({ success: "OK" }));
},
});
test("with login with email enabled", async (assert) => {
});
test("with login with email enabled", async (assert) => {
await visit("/");
await click("header .login-button");
assert.ok(exists(".login-with-email-button"));
});
});
test("with login with email disabled", async (assert) => {
test("with login with email disabled", async (assert) => {
await visit("/");
await click("header .login-button");
assert.notOk(find(".login-buttons").is(":visible"));
});
});

View File

@ -2,14 +2,13 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Login with email disabled", {
settings: {
acceptance("Login with email disabled", function (needs) {
needs.settings({
enable_local_logins_via_email: false,
enable_facebook_logins: true,
},
});
});
test("with email button", async (assert) => {
test("with email button", async (assert) => {
await visit("/");
await click("header .login-button");
@ -22,4 +21,5 @@ test("with email button", async (assert) => {
exists(".login-with-email-button"),
"it displays the login with email button"
);
});
});

View File

@ -3,21 +3,20 @@ import { test } from "qunit";
import I18n from "I18n";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
let userFound = false;
acceptance("Login with email", {
settings: {
acceptance("Login with email", function (needs) {
needs.settings({
enable_local_logins_via_email: true,
enable_facebook_logins: true,
},
pretend(server, helper) {
});
let userFound = false;
needs.pretender((server, helper) => {
server.post("/u/email-login", () =>
helper.response({ success: "OK", user_found: userFound })
);
},
});
});
test("with email button", async (assert) => {
test("with email button", async (assert) => {
await visit("/");
await click("header .login-button");
@ -79,4 +78,5 @@ test("with email button", async (assert) => {
);
userFound = false;
});
});

View File

@ -1,13 +1,15 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic Discovery - Mobile", { mobileView: true });
test("Visit Discovery Pages", async (assert) => {
acceptance("Topic Discovery - Mobile", function (needs) {
needs.mobileView();
test("Visit Discovery Pages", async (assert) => {
await visit("/");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
await visit("/categories");
assert.ok(exists(".category"), "has a list of categories");
});
});

View File

@ -2,10 +2,11 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Signing In - Mobile", { mobileView: true });
test("sign in", async (assert) => {
acceptance("Signing In - Mobile", function (needs) {
needs.mobileView();
test("sign in", async (assert) => {
await visit("/");
await click("header .login-button");
assert.ok(exists("#login-form"), "it shows the login modal");
});
});

View File

@ -2,9 +2,10 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("User Directory - Mobile", { mobileView: true });
test("Visit Page", async (assert) => {
acceptance("User Directory - Mobile", function (needs) {
needs.mobileView();
test("Visit Page", async (assert) => {
await visit("/u");
assert.ok(exists(".directory .user"), "has a list of users");
});
});

View File

@ -1,5 +1,4 @@
import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { test } from "qunit";
import I18n from "I18n";
import { run } from "@ember/runloop";
@ -9,9 +8,10 @@ import {
} from "discourse/tests/helpers/qunit-helpers";
import showModal from "discourse/lib/show-modal";
acceptance("Modal", {
beforeEach() {
this._translations = I18n.translations;
acceptance("Modal", function (needs) {
let _translations;
needs.hooks.beforeEach(() => {
_translations = I18n.translations;
I18n.translations = {
en: {
@ -20,14 +20,13 @@ acceptance("Modal", {
},
},
};
},
});
afterEach() {
I18n.translations = this._translations;
},
});
needs.hooks.afterEach(() => {
I18n.translations = _translations;
});
skip("modal", async function (assert) {
test("modal", async function (assert) {
await visit("/");
assert.ok(
@ -75,9 +74,9 @@ skip("modal", async function (assert) {
find(".d-modal:visible").length === 1,
"ESC should not close the modal"
);
});
});
test("rawTitle in modal panels", async function (assert) {
test("rawTitle in modal panels", async function (assert) {
Ember.TEMPLATES["modal/test-raw-title-panels"] = Ember.HTMLBars.compile("");
const panels = [
{ id: "test1", rawTitle: "Test 1" },
@ -92,9 +91,9 @@ test("rawTitle in modal panels", async function (assert) {
"Test 1",
"it should display the raw title"
);
});
});
test("modal title", async function (assert) {
test("modal title", async function (assert) {
Ember.TEMPLATES["modal/test-title"] = Ember.HTMLBars.compile("");
Ember.TEMPLATES["modal/test-title-with-body"] = Ember.HTMLBars.compile(
"{{#d-modal-body}}test{{/d-modal-body}}"
@ -125,11 +124,13 @@ test("modal title", async function (assert) {
find(".d-modal .title").length === 0,
"it should not re-use the previous title"
);
});
});
acceptance("Modal Keyboard Events", { loggedIn: true });
acceptance("Modal Keyboard Events", function (needs) {
needs.user();
test("modal-keyboard-events", async function (assert) {
test("modal-keyboard-events", async function (assert) {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
@ -160,4 +161,5 @@ test("modal-keyboard-events", async function (assert) {
find(".d-modal:visible").length === 0,
"modal should disappear on hitting Enter"
);
});
});

View File

@ -2,18 +2,20 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("New Message");
test("accessing new-message route when logged out", async (assert) => {
acceptance("New Message - Anonymous", function () {
test("accessing new-message route when logged out", async (assert) => {
await visit(
"/new-message?username=charlie&title=message%20title&body=message%20body"
);
assert.ok(exists(".modal.login-modal"), "it shows the login modal");
});
});
acceptance("New Message", { loggedIn: true });
test("accessing new-message route when logged in", async (assert) => {
acceptance("New Message - Authenticated", function (needs) {
needs.user();
test("accessing new-message route when logged in", async (assert) => {
await visit(
"/new-message?username=charlie&title=message%20title&body=message%20body"
);
@ -34,4 +36,5 @@ test("accessing new-message route when logged in", async (assert) => {
"charlie",
"it selects correct username"
);
});
});

View File

@ -3,17 +3,20 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("New Topic");
test("accessing new-topic route when logged out", async (assert) => {
acceptance("New Topic - Anonymous", function () {
test("accessing new-topic route when logged out", async (assert) => {
await visit("/new-topic?title=topic%20title&body=topic%20body");
assert.ok(exists(".modal.login-modal"), "it shows the login modal");
});
});
acceptance("New Topic", { loggedIn: true });
test("accessing new-topic route when logged in", async (assert) => {
await visit("/new-topic?title=topic%20title&body=topic%20body&category=bug");
acceptance("New Topic - Authenticated", function (needs) {
needs.user();
test("accessing new-topic route when logged in", async (assert) => {
await visit(
"/new-topic?title=topic%20title&body=topic%20body&category=bug"
);
assert.ok(exists(".composer-fields"), "it opens composer");
assert.equal(
@ -31,4 +34,5 @@ test("accessing new-topic route when logged in", async (assert) => {
1,
"it selects desired category"
);
});
});

View File

@ -3,17 +3,16 @@ import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("NotificationsFilter", {
loggedIn: true,
});
acceptance("Notifications filter", function (needs) {
needs.user();
test("Notifications filter true", async (assert) => {
test("Notifications filter true", async (assert) => {
await visit("/u/eviltrout/notifications");
assert.ok(find(".large-notification").length >= 0);
});
});
test("Notifications filter read", async (assert) => {
test("Notifications filter read", async (assert) => {
await visit("/u/eviltrout/notifications");
const dropdown = selectKit(".notifications-filter");
@ -21,9 +20,9 @@ test("Notifications filter read", async (assert) => {
await dropdown.selectRowByValue("read");
assert.ok(find(".large-notification").length >= 0);
});
});
test("Notifications filter unread", async (assert) => {
test("Notifications filter unread", async (assert) => {
await visit("/u/eviltrout/notifications");
const dropdown = selectKit(".notifications-filter");
@ -31,4 +30,5 @@ test("Notifications filter unread", async (assert) => {
await dropdown.selectRowByValue("unread");
assert.ok(find(".large-notification").length >= 0);
});
});

View File

@ -2,9 +2,9 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Page Publishing", {
loggedIn: true,
pretend(server, helper) {
acceptance("Page Publishing", function (needs) {
needs.user();
needs.pretender((server, helper) => {
const validSlug = helper.response({ valid_slug: true });
server.put("/pub/by-topic/280", () => {
@ -22,9 +22,9 @@ acceptance("Page Publishing", {
reason: "i don't need a reason",
});
});
},
});
test("can publish a page via modal", async (assert) => {
});
test("can publish a page via modal", 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.show-post-admin-menu");
@ -39,4 +39,5 @@ test("can publish a page via modal", async (assert) => {
await click(".publish-page");
assert.ok(exists(".current-url"));
});
});

View File

@ -5,25 +5,25 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import PreloadStore from "discourse/lib/preload-store";
import { parsePostData } from "discourse/tests/helpers/create-pretender";
acceptance("Password Reset", {
pretend(server, helper) {
acceptance("Password Reset", function (needs) {
needs.pretender((server, helper) => {
server.get("/u/confirm-email-token/myvalidtoken.json", () =>
helper.response(200, { success: "OK" })
helper.response({ success: "OK" })
);
server.get("/u/confirm-email-token/requiretwofactor.json", () =>
helper.response(200, { success: "OK" })
helper.response({ success: "OK" })
);
server.put("/u/password-reset/myvalidtoken.json", (request) => {
const body = parsePostData(request.requestBody);
if (body.password === "jonesyAlienSlayer") {
return helper.response(200, {
return helper.response({
success: false,
errors: { password: ["is the name of your cat"] },
});
} else {
return helper.response(200, {
return helper.response({
success: "OK",
message: I18n.t("password_reset.success"),
});
@ -36,27 +36,26 @@ acceptance("Password Reset", {
body.password === "perf3ctly5ecur3" &&
body.second_factor_token === "123123"
) {
return helper.response(200, {
return helper.response({
success: "OK",
message: I18n.t("password_reset.success"),
});
} else if (body.second_factor_token === "123123") {
return helper.response(200, {
return helper.response({
success: false,
errors: { password: ["invalid"] },
});
} else {
return helper.response(200, {
return helper.response({
success: false,
message: "invalid token",
errors: { user_second_factors: ["invalid token"] },
});
}
});
},
});
});
test("Password Reset Page", async (assert) => {
test("Password Reset Page", async (assert) => {
PreloadStore.store("password_reset", { is_developer: false });
await visit("/u/password-reset/myvalidtoken");
@ -78,17 +77,18 @@ test("Password Reset Page", async (assert) => {
await click(".password-reset form button");
assert.ok(exists(".password-reset .tip.bad"), "input is not valid");
assert.ok(
find(".password-reset .tip.bad").html().indexOf("is the name of your cat") >
-1,
find(".password-reset .tip.bad")
.html()
.indexOf("is the name of your cat") > -1,
"server validation error message shows"
);
await fillIn(".password-reset input", "perf3ctly5ecur3");
await click(".password-reset form button");
assert.ok(!exists(".password-reset form"), "form is gone");
});
});
test("Password Reset Page With Second Factor", async (assert) => {
test("Password Reset Page With Second Factor", async (assert) => {
PreloadStore.store("password_reset", {
is_developer: false,
second_factor_required: true,
@ -119,4 +119,5 @@ test("Password Reset Page With Second Factor", async (assert) => {
await click(".password-reset form button");
assert.ok(!exists(".password-reset form"), "form is gone");
});
});

View File

@ -3,24 +3,24 @@ import { test } from "qunit";
import I18n from "I18n";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Personal Message", {
loggedIn: true,
});
acceptance("Personal Message", function (needs) {
needs.user();
test("footer edit button", async (assert) => {
test("footer edit button", async (assert) => {
await visit("/t/pm-for-testing/12");
assert.ok(
!exists(".edit-message"),
"does not show edit first post button on footer by default"
);
});
});
test("suggested messages", async (assert) => {
test("suggested messages", async (assert) => {
await visit("/t/pm-for-testing/12");
assert.equal(
find("#suggested-topics .suggested-topics-title").text().trim(),
I18n.t("suggested_topics.pm_title")
);
});
});

View File

@ -5,14 +5,12 @@ import { withPluginApi } from "discourse/lib/plugin-api";
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
import KeyboardShortcutInitializer from "discourse/initializers/keyboard-shortcuts";
acceptance("Plugin Keyboard Shortcuts - Logged In", {
loggedIn: true,
beforeEach() {
acceptance("Plugin Keyboard Shortcuts - Logged In", function (needs) {
needs.user();
needs.hooks.beforeEach(function () {
KeyboardShortcutInitializer.initialize(this.container);
},
});
test("a plugin can add a keyboard shortcut", async (assert) => {
});
test("a plugin can add a keyboard shortcut", async (assert) => {
withPluginApi("0.8.38", (api) => {
api.addKeyboardShortcut("]", () => {
$("#qunit-fixture").html(
@ -28,16 +26,14 @@ test("a plugin can add a keyboard shortcut", async (assert) => {
1,
"the keyboard shortcut callback fires successfully"
);
});
});
acceptance("Plugin Keyboard Shortcuts - Anonymous", {
loggedIn: false,
beforeEach() {
acceptance("Plugin Keyboard Shortcuts - Anonymous", function (needs) {
needs.hooks.beforeEach(function () {
KeyboardShortcutInitializer.initialize(this.container);
},
});
test("a plugin can add a keyboard shortcut with an option", async (assert) => {
});
test("a plugin can add a keyboard shortcut with an option", async (assert) => {
let spy = sandbox.spy(KeyboardShortcuts, "_bindToPath");
withPluginApi("0.8.38", (api) => {
api.addKeyboardShortcut("]", () => {}, {
@ -50,4 +46,5 @@ test("a plugin can add a keyboard shortcut with an option", async (assert) => {
spy.calledWith("test-path", "]"),
"bindToPath is called due to options provided"
);
});
});

View File

@ -5,8 +5,9 @@ import { extraConnectorClass } from "discourse/lib/plugin-connectors";
import { action } from "@ember/object";
const PREFIX = "javascripts/single-test/connectors";
acceptance("Plugin Outlet - Connector Class", {
beforeEach() {
acceptance("Plugin Outlet - Connector Class", function (needs) {
needs.hooks.beforeEach(() => {
extraConnectorClass("user-profile-primary/hello", {
actions: {
sayHello() {
@ -57,16 +58,15 @@ acceptance("Plugin Outlet - Connector Class", {
Ember.TEMPLATES[
`${PREFIX}/user-profile-primary/dont-render`
] = Ember.HTMLBars.compile(`I'm not rendered!`);
},
});
afterEach() {
needs.hooks.afterEach(() => {
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`];
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hi`];
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`];
},
});
});
test("Renders a template into the outlet", async (assert) => {
test("Renders a template into the outlet", async (assert) => {
await visit("/u/eviltrout");
assert.ok(
find(".user-profile-primary-outlet.hello").length === 1,
@ -86,4 +86,5 @@ test("Renders a template into the outlet", async (assert) => {
await click(".say-hi");
assert.equal(find(".hi-result").text(), "hi!", "actions delegate properly");
});
});

View File

@ -4,10 +4,11 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { withPluginApi } from "discourse/lib/plugin-api";
const PREFIX = "javascripts/single-test/connectors";
acceptance("Plugin Outlet - Decorator", {
loggedIn: true,
beforeEach() {
acceptance("Plugin Outlet - Decorator", function (needs) {
needs.user();
needs.hooks.beforeEach(() => {
Ember.TEMPLATES[
`${PREFIX}/discovery-list-container-top/foo`
] = Ember.HTMLBars.compile("FOO");
@ -32,15 +33,14 @@ acceptance("Plugin Outlet - Decorator", {
{ id: "yellow-decorator" }
);
});
},
});
afterEach() {
needs.hooks.afterEach(() => {
delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/foo`];
delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/bar`];
},
});
});
test("Calls the plugin callback with the rendered outlet", async (assert) => {
test("Calls the plugin callback with the rendered outlet", async (assert) => {
await visit("/");
const fooConnector = find(".discovery-list-container-top-outlet.foo ")[0];
@ -57,4 +57,5 @@ test("Calls the plugin callback with the rendered outlet", async (assert) => {
await visit("/");
assert.notOk(fooConnector.classList.contains("in-category"));
});
});

View File

@ -7,8 +7,8 @@ const HELLO = "javascripts/multi-test/connectors/user-profile-primary/hello";
const GOODBYE =
"javascripts/multi-test/connectors/user-profile-primary/goodbye";
acceptance("Plugin Outlet - Multi Template", {
beforeEach() {
acceptance("Plugin Outlet - Multi Template", function (needs) {
needs.hooks.beforeEach(() => {
clearCache();
Ember.TEMPLATES[HELLO] = Ember.HTMLBars.compile(
`<span class='hello-span'>Hello</span>`
@ -16,16 +16,15 @@ acceptance("Plugin Outlet - Multi Template", {
Ember.TEMPLATES[GOODBYE] = Ember.HTMLBars.compile(
`<span class='bye-span'>Goodbye</span>`
);
},
});
afterEach() {
needs.hooks.afterEach(() => {
delete Ember.TEMPLATES[HELLO];
delete Ember.TEMPLATES[GOODBYE];
clearCache();
},
});
});
test("Renders a template into the outlet", async (assert) => {
test("Renders a template into the outlet", async (assert) => {
await visit("/u/eviltrout");
assert.ok(
find(".user-profile-primary-outlet.hello").length === 1,
@ -45,4 +44,5 @@ test("Renders a template into the outlet", async (assert) => {
"Goodbye",
"it renders into the outlet"
);
});
});

View File

@ -4,19 +4,19 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
const CONNECTOR =
"javascripts/single-test/connectors/user-profile-primary/hello";
acceptance("Plugin Outlet - Single Template", {
beforeEach() {
acceptance("Plugin Outlet - Single Template", function (needs) {
needs.hooks.beforeEach(() => {
Ember.TEMPLATES[CONNECTOR] = Ember.HTMLBars.compile(
`<span class='hello-username'>{{model.username}}</span>`
);
},
});
afterEach() {
needs.hooks.afterEach(() => {
delete Ember.TEMPLATES[CONNECTOR];
},
});
});
test("Renders a template into the outlet", async (assert) => {
test("Renders a template into the outlet", async (assert) => {
await visit("/u/eviltrout");
assert.ok(
find(".user-profile-primary-outlet.hello").length === 1,
@ -27,4 +27,5 @@ test("Renders a template into the outlet", async (assert) => {
"eviltrout",
"it renders into the outlet"
);
});
});

View File

@ -2,9 +2,8 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Post - Admin Menu Anonymous Users", { loggedIn: false });
test("Enter as a anon user", async (assert) => {
acceptance("Post - Admin Menu - Anonymous", function () {
test("Enter as a anon user", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".show-more-actions");
@ -17,11 +16,12 @@ test("Enter as a anon user", async (assert) => {
!exists(".show-post-admin-menu"),
"The wrench button was not rendered"
);
});
});
acceptance("Post - Admin Menu", { loggedIn: true });
test("Enter as a user with group moderator permissions", async (assert) => {
acceptance("Post - Admin Menu - Authenticated", function (needs) {
needs.user();
test("Enter as a user with group moderator permissions", async (assert) => {
await visit("/t/topic-for-group-moderators/2480");
await click(".show-more-actions");
await click(".show-post-admin-menu");
@ -31,4 +31,5 @@ test("Enter as a user with group moderator permissions", async (assert) => {
"The edit button was rendered"
);
assert.ok(exists(".add-notice"), "The add notice button was rendered");
});
});

View File

@ -66,12 +66,10 @@ function preferencesPretender(server, helper) {
});
}
acceptance("User Preferences", {
loggedIn: true,
pretend: preferencesPretender,
});
test("update some fields", async (assert) => {
acceptance("User Preferences", function (needs) {
needs.user();
needs.pretender(preferencesPretender);
test("update some fields", async (assert) => {
await visit("/u/eviltrout/preferences");
assert.ok($("body.user-preferences-page").length, "has the body class");
@ -101,7 +99,9 @@ test("update some fields", async (assert) => {
await savePreferences();
click(".preferences-nav .nav-notifications a");
await selectKit(".control-group.notifications .combo-box.duration").expand();
await selectKit(
".control-group.notifications .combo-box.duration"
).expand();
await selectKit(
".control-group.notifications .combo-box.duration"
).selectRowByValue(1440);
@ -124,14 +124,14 @@ test("update some fields", async (assert) => {
!exists(".preferences-nav .nav-apps a"),
"apps tab isn't there when you have no authorized apps"
);
});
});
test("username", async (assert) => {
test("username", async (assert) => {
await visit("/u/eviltrout/preferences/username");
assert.ok(exists("#change_username"), "it has the input element");
});
});
test("email", async (assert) => {
test("email", async (assert) => {
await visit("/u/eviltrout/preferences/email");
assert.ok(exists("#change-email"), "it has the input element");
@ -143,9 +143,9 @@ test("email", async (assert) => {
I18n.t("user.email.invalid"),
"it should display invalid email tip"
);
});
});
test("email field always shows up", async (assert) => {
test("email field always shows up", async (assert) => {
await visit("/u/eviltrout/preferences/email");
assert.ok(exists("#change-email"), "it has the input element");
@ -157,9 +157,9 @@ test("email field always shows up", async (assert) => {
await visit("/u/eviltrout/preferences/email");
assert.ok(exists("#change-email"), "it has the input element");
});
});
test("connected accounts", async (assert) => {
test("connected accounts", async (assert) => {
await visit("/u/eviltrout/preferences/account");
assert.ok(
@ -178,9 +178,9 @@ test("connected accounts", async (assert) => {
find(".pref-associated-accounts table tr:first td:last button")
.html()
.indexOf("Connect") > -1;
});
});
test("second factor totp", async (assert) => {
test("second factor totp", async (assert) => {
await visit("/u/eviltrout/preferences/second-factor");
assert.ok(exists("#password"), "it has a password input");
@ -198,9 +198,9 @@ test("second factor totp", async (assert) => {
find(".alert-error").html().indexOf("provide a name and the code") > -1,
"shows name/token missing error message"
);
});
});
test("second factor security keys", async (assert) => {
test("second factor security keys", async (assert) => {
await visit("/u/eviltrout/preferences/second-factor");
assert.ok(exists("#password"), "it has a password input");
@ -224,9 +224,9 @@ test("second factor security keys", async (assert) => {
"shows name missing error message"
);
}
});
});
test("default avatar selector", async (assert) => {
test("default avatar selector", async (assert) => {
await visit("/u/eviltrout/preferences");
await click(".pref-avatar .btn");
@ -239,11 +239,12 @@ test("default avatar selector", async (assert) => {
6543,
"it should set the gravatar_avatar_upload_id property"
);
});
});
acceptance("Second Factor Backups", {
loggedIn: true,
pretend(server, helper) {
acceptance("Second Factor Backups", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.post("/u/second_factors.json", () => {
return helper.response({
success: "OK",
@ -260,9 +261,9 @@ acceptance("Second Factor Backups", {
server.get("/u/eviltrout/activity.json", () => {
return helper.response({});
});
},
});
test("second factor backup", async (assert) => {
});
test("second factor backup", async (assert) => {
updateCurrentUser({ second_factor_enabled: true });
await visit("/u/eviltrout/preferences/second-factor");
await click(".edit-2fa-backup");
@ -273,12 +274,15 @@ test("second factor backup", async (assert) => {
await click(".second-factor-backup-preferences .btn-primary");
assert.ok(exists(".backup-codes-area"), "shows backup codes");
});
});
acceptance("Avatar selector when selectable avatars is enabled", {
loggedIn: true,
settings: { selectable_avatars_enabled: true },
pretend(server) {
acceptance("Avatar selector when selectable avatars is enabled", function (
needs
) {
needs.user();
needs.settings({ selectable_avatars_enabled: true });
needs.pretender((server) => {
server.get("/site/selectable-avatars.json", () => {
return [
200,
@ -286,24 +290,23 @@ acceptance("Avatar selector when selectable avatars is enabled", {
["https://www.discourse.org", "https://meta.discourse.org"],
];
});
},
});
});
test("selectable avatars", async (assert) => {
test("selectable avatars", async (assert) => {
await visit("/u/eviltrout/preferences");
await click(".pref-avatar .btn");
assert.ok(exists(".selectable-avatars", "opens the avatar selection modal"));
assert.ok(
exists(".selectable-avatars", "opens the avatar selection modal")
);
});
});
acceptance("User Preferences when badges are disabled", {
loggedIn: true,
settings: { enable_badges: false },
pretend: preferencesPretender,
});
acceptance("User Preferences when badges are disabled", function (needs) {
needs.user();
needs.settings({ enable_badges: false });
needs.pretender(preferencesPretender);
test("visit my preferences", async (assert) => {
test("visit my preferences", async (assert) => {
await visit("/u/eviltrout/preferences");
assert.ok($("body.user-preferences-page").length, "has the body class");
assert.equal(
@ -312,9 +315,9 @@ test("visit my preferences", async (assert) => {
"defaults to account tab"
);
assert.ok(exists(".user-preferences"), "it shows the preferences");
});
});
test("recently connected devices", async (assert) => {
test("recently connected devices", async (assert) => {
await visit("/u/eviltrout/preferences");
assert.equal(
@ -351,25 +354,23 @@ test("recently connected devices", async (assert) => {
find(".pref-password.highlighted").length === 1,
"it should highlight password preferences"
);
});
});
acceptance(
"User can select a topic to feature on profile if site setting in enabled",
{
loggedIn: true,
settings: { allow_featured_topic_on_user_profiles: true },
pretend(server, helper) {
function (needs) {
needs.user();
needs.settings({ allow_featured_topic_on_user_profiles: true });
needs.pretender((server, helper) => {
server.put("/u/eviltrout/feature-topic", () => {
return helper.response({
success: true,
});
});
},
}
);
});
test("setting featured topic on profile", async (assert) => {
test("setting featured topic on profile", async (assert) => {
await visit("/u/eviltrout/preferences/profile");
assert.ok(
@ -386,7 +387,10 @@ test("setting featured topic on profile", async (assert) => {
await click(selectTopicBtn);
assert.ok(exists(".feature-topic-on-profile"), "topic picker modal is open");
assert.ok(
exists(".feature-topic-on-profile"),
"topic picker modal is open"
);
const topicRadioBtn = find('input[name="choose_topic_id"]:first');
assert.ok(exists(topicRadioBtn), "Topic options are prefilled");
@ -402,11 +406,13 @@ test("setting featured topic on profile", async (assert) => {
exists(".clear-feature-topic-on-profile-btn"),
"clear button is present"
);
});
});
}
);
acceptance("Custom User Fields", {
loggedIn: true,
site: {
acceptance("Custom User Fields", function (needs) {
needs.user();
needs.site({
user_fields: [
{
id: 30,
@ -416,11 +422,10 @@ acceptance("Custom User Fields", {
required: true,
},
],
},
pretend: preferencesPretender,
});
});
needs.pretender(preferencesPretender);
test("can select an option from a dropdown", async (assert) => {
test("can select an option from a dropdown", async (assert) => {
await visit("/u/eviltrout/preferences/profile");
assert.ok(exists(".user-field"), "it has at least one user field");
await click(".user-field.dropdown");
@ -430,20 +435,23 @@ test("can select an option from a dropdown", async (assert) => {
);
await field.expand();
await field.selectRowByValue("Cat");
assert.equal(field.header().value(), "Cat", "it sets the value of the field");
assert.equal(
field.header().value(),
"Cat",
"it sets the value of the field"
);
});
});
acceptance(
"User Preferences, selecting bookmarks discovery as user's default homepage",
{
loggedIn: true,
settings: {
function (needs) {
needs.user();
needs.settings({
top_menu: "categories|latest|top|bookmarks",
},
}
);
});
test("selecting bookmarks as home directs home to bookmarks", async (assert) => {
test("selecting bookmarks as home directs home to bookmarks", async (assert) => {
await visit("/u/eviltrout/preferences/interface");
assert.ok(exists(".home .combo-box"), "it has a home selector combo-box");
@ -458,4 +466,6 @@ test("selecting bookmarks as home directs home to bookmarks", async (assert) =>
"discovery.bookmarks",
"it navigates to bookmarks"
);
});
});
}
);

View File

@ -10,20 +10,18 @@ import {
const CONNECTOR =
"javascripts/raw-test/connectors/topic-list-before-status/lala";
acceptance("Raw Plugin Outlet", {
beforeEach() {
acceptance("Raw Plugin Outlet", function (needs) {
needs.hooks.beforeEach(() => {
addRawTemplate(
CONNECTOR,
compile(`<span class='topic-lala'>{{context.topic.id}}</span>`)
);
},
});
afterEach() {
needs.hooks.afterEach(() => {
removeRawTemplate(CONNECTOR);
},
});
test("Renders the raw plugin outlet", async (assert) => {
});
test("Renders the raw plugin outlet", async (assert) => {
await visit("/");
assert.ok(find(".topic-lala").length > 0, "it renders the outlet");
assert.equal(
@ -31,4 +29,5 @@ test("Renders the raw plugin outlet", async (assert) => {
"11557",
"it has the topic id"
);
});
});

View File

@ -6,8 +6,8 @@ import {
} from "discourse/tests/helpers/qunit-helpers";
import DiscoveryFixtures from "discourse/tests/fixtures/discovery-fixtures";
acceptance("Redirect to Top", {
pretend(server, helper) {
acceptance("Redirect to Top", function (needs) {
needs.pretender((server, helper) => {
server.get("/top/weekly.json", () => {
return helper.response(DiscoveryFixtures["/latest.json"]);
});
@ -17,11 +17,10 @@ acceptance("Redirect to Top", {
server.get("/top/all.json", () => {
return helper.response(DiscoveryFixtures["/latest.json"]);
});
},
loggedIn: true,
});
});
needs.user();
test("redirects categories to weekly top", async (assert) => {
test("redirects categories to weekly top", async (assert) => {
updateCurrentUser({
should_be_redirected_to_top: true,
redirected_to_top: {
@ -31,10 +30,14 @@ test("redirects categories to weekly top", async (assert) => {
});
await visit("/categories");
assert.equal(currentPath(), "discovery.topWeekly", "it works for categories");
});
assert.equal(
currentPath(),
"discovery.topWeekly",
"it works for categories"
);
});
test("redirects latest to monthly top", async (assert) => {
test("redirects latest to monthly top", async (assert) => {
updateCurrentUser({
should_be_redirected_to_top: true,
redirected_to_top: {
@ -45,9 +48,9 @@ test("redirects latest to monthly top", async (assert) => {
await visit("/latest");
assert.equal(currentPath(), "discovery.topMonthly", "it works for latest");
});
});
test("redirects root to All top", async (assert) => {
test("redirects root to All top", async (assert) => {
updateCurrentUser({
should_be_redirected_to_top: true,
redirected_to_top: {
@ -58,4 +61,5 @@ test("redirects root to All top", async (assert) => {
await visit("/");
assert.equal(currentPath(), "discovery.topAll", "it works for root");
});
});

View File

@ -2,11 +2,10 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Reports", {
loggedIn: true,
});
acceptance("Reports", function (needs) {
needs.user();
test("Visit reports page", async (assert) => {
test("Visit reports page", async (assert) => {
await visit("/admin/reports");
assert.equal($(".reports-list .report").length, 1);
@ -19,10 +18,11 @@ test("Visit reports page", async (assert) => {
$report.find(".report-description").html().trim(),
"List of my activities"
);
});
});
test("Visit report page", async (assert) => {
test("Visit report page", async (assert) => {
await visit("/admin/reports/staff_logins");
assert.ok(exists(".export-csv-btn"));
});
});

View File

@ -3,13 +3,12 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Review", {
loggedIn: true,
});
acceptance("Review", function (needs) {
needs.user();
const user = ".reviewable-item[data-reviewable-id=1234]";
const user = ".reviewable-item[data-reviewable-id=1234]";
test("It returns a list of reviewable items", async (assert) => {
test("It returns a list of reviewable items", async (assert) => {
await visit("/review");
assert.ok(find(".reviewable-item").length, "has a list of items");
@ -26,17 +25,17 @@ test("It returns a list of reviewable items", async (assert) => {
find(`${user} .reviewable-action.reject`).length,
"creates a button for reject"
);
});
});
test("Grouped by topic", async (assert) => {
test("Grouped by topic", async (assert) => {
await visit("/review/topics");
assert.ok(
find(".reviewable-topic").length,
"it has a list of reviewable topics"
);
});
});
test("Settings", async (assert) => {
test("Settings", async (assert) => {
await visit("/review/settings");
assert.ok(find(".reviewable-score-type").length, "has a list of bonuses");
@ -47,9 +46,9 @@ test("Settings", async (assert) => {
await click(".save-settings");
assert.ok(find(".reviewable-settings .saved").length, "it saved");
});
});
test("Flag related", async (assert) => {
test("Flag related", async (assert) => {
await visit("/review");
assert.ok(
@ -63,24 +62,24 @@ test("Flag related", async (assert) => {
);
assert.equal(find(".reviewable-flagged-post .reviewable-score").length, 2);
});
});
test("Flag related", async (assert) => {
test("Flag related", async (assert) => {
await visit("/review/1");
assert.ok(
find(".reviewable-flagged-post").length,
"it shows the flagged post"
);
});
});
test("Clicking the buttons triggers actions", async (assert) => {
test("Clicking the buttons triggers actions", async (assert) => {
await visit("/review");
await click(`${user} .reviewable-action.approve`);
assert.equal(find(user).length, 0, "it removes the reviewable on success");
});
});
test("Editing a reviewable", async (assert) => {
test("Editing a reviewable", async (assert) => {
const topic = ".reviewable-item[data-reviewable-id=4321]";
await visit("/review");
assert.ok(find(`${topic} .reviewable-action.approve`).length);
@ -131,4 +130,5 @@ test("Editing a reviewable", async (assert) => {
assert.equal(find(`${topic} .post-body`).text().trim(), "new raw contents");
assert.equal(find(`${topic} .category-name`).text().trim(), "support");
});
});

View File

@ -8,10 +8,10 @@ import {
waitFor,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Search - Full Page", {
settings: { tagging_enabled: true },
loggedIn: true,
pretend(server, helper) {
acceptance("Search - Full Page", function (needs) {
needs.user();
needs.settings({ tagging_enabled: true });
needs.pretender((server, helper) => {
server.get("/tags/filter/search", () => {
return helper.response({ results: [{ text: "monkey", count: 1 }] });
});
@ -87,10 +87,9 @@ acceptance("Search - Full Page", {
],
});
});
},
});
});
test("perform various searches", async (assert) => {
test("perform various searches", async (assert) => {
await visit("/search");
assert.ok($("body.search-page").length, "has body class");
@ -108,9 +107,9 @@ test("perform various searches", async (assert) => {
await click(".search-cta");
assert.ok(find(".fps-topic").length === 1, "has one post");
});
});
test("escape search term", async (assert) => {
test("escape search term", async (assert) => {
await visit("/search");
await fillIn(".search-query", "@<script>prompt(1337)</script>gmail.com");
@ -120,9 +119,9 @@ test("escape search term", async (assert) => {
),
"it escapes search term"
);
});
});
skip("update username through advanced search ui", async (assert) => {
skip("update username through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await fillIn(".search-advanced-options .user-selector", "admin");
@ -153,9 +152,9 @@ skip("update username through advanced search ui", async (assert) => {
'has updated search term to "none user:admin"'
);
});
});
});
test("update category through advanced search ui", async (assert) => {
test("update category through advanced search ui", async (assert) => {
const categoryChooser = selectKit(
".search-advanced-options .category-chooser"
);
@ -177,9 +176,9 @@ test("update category through advanced search ui", async (assert) => {
"none #faq",
'has updated search term to "none #faq"'
);
});
});
test("update in:title filter through advanced search ui", async (assert) => {
test("update in:title filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-title");
@ -200,9 +199,9 @@ test("update in:title filter through advanced search ui", async (assert) => {
exists(".search-advanced-options .in-title:checked"),
"does not populate title only checkbox"
);
});
});
test("update in:likes filter through advanced search ui", async (assert) => {
test("update in:likes filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-likes");
@ -216,9 +215,9 @@ test("update in:likes filter through advanced search ui", async (assert) => {
"none in:likes",
'has updated search term to "none in:likes"'
);
});
});
test("update in:personal filter through advanced search ui", async (assert) => {
test("update in:personal filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-private");
@ -240,9 +239,9 @@ test("update in:personal filter through advanced search ui", async (assert) => {
exists(".search-advanced-options .in-private:checked"),
"does not populate messages checkbox"
);
});
});
test("update in:seen filter through advanced search ui", async (assert) => {
test("update in:seen filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-seen");
@ -264,9 +263,9 @@ test("update in:seen filter through advanced search ui", async (assert) => {
exists(".search-advanced-options .in-seen:checked"),
"does not populate seen checkbox"
);
});
});
test("update in filter through advanced search ui", async (assert) => {
test("update in filter through advanced search ui", async (assert) => {
const inSelector = selectKit(".search-advanced-options .select-kit#in");
await visit("/search");
@ -285,9 +284,9 @@ test("update in filter through advanced search ui", async (assert) => {
"none in:bookmarks",
'has updated search term to "none in:bookmarks"'
);
});
});
test("update status through advanced search ui", async (assert) => {
test("update status through advanced search ui", async (assert) => {
const statusSelector = selectKit(
".search-advanced-options .select-kit#status"
);
@ -308,9 +307,9 @@ test("update status through advanced search ui", async (assert) => {
"none status:closed",
'has updated search term to "none status:closed"'
);
});
});
test("doesn't update status filter header if wrong value entered through searchbox", async (assert) => {
test("doesn't update status filter header if wrong value entered through searchbox", async (assert) => {
const statusSelector = selectKit(
".search-advanced-options .select-kit#status"
);
@ -320,9 +319,9 @@ test("doesn't update status filter header if wrong value entered through searchb
await fillIn(".search-query", "status:none");
assert.equal(statusSelector.header().label(), "any", 'has "any" populated');
});
});
test("doesn't update in filter header if wrong value entered through searchbox", async (assert) => {
test("doesn't update in filter header if wrong value entered through searchbox", async (assert) => {
const inSelector = selectKit(".search-advanced-options .select-kit#in");
await visit("/search");
@ -330,9 +329,9 @@ test("doesn't update in filter header if wrong value entered through searchbox",
await fillIn(".search-query", "in:none");
assert.equal(inSelector.header().label(), "any", 'has "any" populated');
});
});
test("update post time through advanced search ui", async (assert) => {
test("update post time through advanced search ui", async (assert) => {
await visit("/search?expanded=true&q=after:2018-08-22");
assert.equal(
@ -363,9 +362,9 @@ test("update post time through advanced search ui", async (assert) => {
"none after:2016-10-05",
'has updated search term to "none after:2016-10-05"'
);
});
});
test("update min post count through advanced search ui", async (assert) => {
test("update min post count through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await fillIn("#search-min-post-count", "5");
@ -380,9 +379,9 @@ test("update min post count through advanced search ui", async (assert) => {
"none min_posts:5",
'has updated search term to "none min_posts:5"'
);
});
});
test("update max post count through advanced search ui", async (assert) => {
test("update max post count through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await fillIn("#search-max-post-count", "5");
@ -397,9 +396,9 @@ test("update max post count through advanced search ui", async (assert) => {
"none max_posts:5",
'has updated search term to "none max_posts:5"'
);
});
});
test("validate advanced search when initially empty", async (assert) => {
test("validate advanced search when initially empty", async (assert) => {
await visit("/search?expanded=true");
await click(".search-advanced-options .in-likes");
@ -420,4 +419,5 @@ test("validate advanced search when initially empty", async (assert) => {
exists(".search-advanced-options .in-likes:checked"),
"does not populate the likes checkbox"
);
});
});

View File

@ -2,9 +2,10 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Search - Mobile", { mobileView: true });
acceptance("Search - Mobile", function (needs) {
needs.mobileView();
test("search", async (assert) => {
test("search", async (assert) => {
await visit("/");
await click("#search-button");
@ -40,4 +41,5 @@ test("search", async (assert) => {
"posts",
"it does not reset input when hitting search icon again"
);
});
});

View File

@ -2,24 +2,22 @@ import { 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";
import searchFixtures from "discourse/tests/fixtures/search-fixtures";
const emptySearchContextCallbacks = [];
acceptance("Search - Anonymous", function (needs) {
let calledEmpty = false;
let searchArgs = {
pretend(server) {
server.handledRequest = (verb, path, request) => {
if (request.queryParams["search_context[type]"] === undefined) {
emptySearchContextCallbacks.forEach((callback) => {
callback.call();
});
needs.pretender((server, helper) => {
server.get("/search/query", (request) => {
if (!request.queryParams["search_context[type]"]) {
calledEmpty = true;
}
};
},
};
acceptance("Search", searchArgs);
return helper.response(searchFixtures["search/query"]);
});
});
test("search", async (assert) => {
test("search", async (assert) => {
await visit("/");
await click("#search-button");
@ -42,10 +40,13 @@ test("search", async (assert) => {
"dev",
"it shows the search term"
);
assert.ok(exists(".search-advanced-options"), "advanced search is expanded");
});
assert.ok(
exists(".search-advanced-options"),
"advanced search is expanded"
);
});
test("search for a tag", async (assert) => {
test("search for a tag", async (assert) => {
await visit("/");
await click("#search-button");
@ -53,9 +54,9 @@ test("search for a tag", async (assert) => {
await fillIn("#search-term", "evil");
await keyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results");
});
});
test("search scope checkbox", async (assert) => {
test("search scope checkbox", async (assert) => {
await visit("/tag/important");
await click("#search-button");
assert.ok(
@ -86,9 +87,9 @@ test("search scope checkbox", async (assert) => {
exists(".search-context input:checked"),
"scope to user checkbox is checked"
);
});
});
test("Search with context", async (assert) => {
test("Search with context", async (assert) => {
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
@ -110,25 +111,20 @@ test("Search with context", async (assert) => {
"it should highlight the post with the search terms correctly"
);
let callbackCalled = false;
emptySearchContextCallbacks.push(() => {
callbackCalled = true;
});
calledEmpty = false;
await visit("/");
await click("#search-button");
assert.ok(!exists(".search-context input[type='checkbox']"));
assert.ok(callbackCalled, "it triggers a new search");
assert.ok(calledEmpty, "it triggers a new search");
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
assert.ok(!$(".search-context input[type=checkbox]").is(":checked"));
});
});
test("Right filters are shown to anonymous users", async (assert) => {
test("Right filters are shown to anonymous users", async (assert) => {
const inSelector = selectKit(".select-kit#in");
await visit("/search?expanded=true");
@ -149,11 +145,13 @@ test("Right filters are shown to anonymous users", async (assert) => {
assert.notOk(exists(".search-advanced-options .in-likes"));
assert.notOk(exists(".search-advanced-options .in-private"));
assert.notOk(exists(".search-advanced-options .in-seen"));
});
});
acceptance("Search", Object.assign({ loggedIn: true, searchArgs }));
acceptance("Search - Authenticated", function (needs) {
needs.user();
test("Right filters are shown to logged-in users", async (assert) => {
test("Right filters are shown to logged-in users", async (assert) => {
const inSelector = selectKit(".select-kit#in");
await visit("/search?expanded=true");
@ -174,18 +172,14 @@ test("Right filters are shown to logged-in users", async (assert) => {
assert.ok(exists(".search-advanced-options .in-likes"));
assert.ok(exists(".search-advanced-options .in-private"));
assert.ok(exists(".search-advanced-options .in-seen"));
});
});
acceptance(
"Search - with tagging enabled",
Object.assign({
loggedIn: true,
searchArgs,
settings: { tagging_enabled: true },
})
);
acceptance("Search - with tagging enabled", function (needs) {
needs.user();
needs.settings({ tagging_enabled: true });
test("displays tags", async (assert) => {
test("displays tags", async (assert) => {
await visit("/");
await click("#search-button");
@ -198,4 +192,5 @@ test("displays tags", async (assert) => {
.trim();
assert.equal(tags, "dev slow");
});
});

View File

@ -2,11 +2,10 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Share and Invite modal - desktop", {
loggedIn: true,
});
acceptance("Share and Invite modal - desktop", function (needs) {
needs.user();
test("Topic footer button", async (assert) => {
test("Topic footer button", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(
@ -54,7 +53,9 @@ test("Topic footer button", async (assert) => {
await click(".share-and-invite.modal .modal-tab.invite");
assert.ok(
exists(".share-and-invite.modal .modal-panel.invite .send-invite:disabled"),
exists(
".share-and-invite.modal .modal-panel.invite .send-invite:disabled"
),
"send invite button is disabled"
);
@ -64,23 +65,20 @@ test("Topic footer button", async (assert) => {
),
"generate invite button is disabled"
);
});
});
test("Post date link", async (assert) => {
test("Post date link", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#post_2 .post-info.post-date a");
assert.ok(exists("#share-link"), "it shows the share modal");
});
});
acceptance("Share url with badges disabled - desktop", {
loggedIn: true,
settings: {
enable_badges: false,
},
});
test("topic footer button - badges disabled - desktop", async (assert) => {
acceptance("Share url with badges disabled - desktop", function (needs) {
needs.user();
needs.settings({ enable_badges: false });
test("topic footer button - badges disabled - desktop", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-button-share-and-invite");
@ -90,4 +88,5 @@ test("topic footer button - badges disabled - desktop", async (assert) => {
.includes("?u=eviltrout"),
"it doesn't add the username param when badges are disabled"
);
});
});

View File

@ -3,12 +3,11 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Share and Invite modal - mobile", {
loggedIn: true,
mobileView: true,
});
acceptance("Share and Invite modal - mobile", function (needs) {
needs.user();
needs.mobileView();
test("Topic footer mobile button", async (assert) => {
test("Topic footer mobile button", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(
@ -54,24 +53,23 @@ test("Topic footer mobile button", async (assert) => {
find(".share-and-invite.modal .social-link").length > 1,
"it shows social sources"
);
});
});
test("Post date link", async (assert) => {
test("Post date link", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#post_2 .post-info.post-date a");
assert.ok(exists("#share-link"), "it shows the share modal");
});
});
acceptance("Share url with badges disabled - mobile", {
loggedIn: true,
mobileView: true,
settings: {
acceptance("Share url with badges disabled - mobile", function (needs) {
needs.user();
needs.mobileView();
needs.settings({
enable_badges: false,
},
});
test("topic footer button - badges disabled - mobile", async (assert) => {
});
test("topic footer button - badges disabled - mobile", async (assert) => {
await visit("/t/internationalization-localization/280");
const subject = selectKit(".topic-footer-mobile-dropdown");
@ -84,4 +82,5 @@ test("topic footer button - badges disabled - mobile", async (assert) => {
.includes("?u=eviltrout"),
"it doesn't add the username param when badges are disabled"
);
});
});

View File

@ -3,9 +3,8 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Shared Drafts", { loggedIn: true });
test("Viewing", async (assert) => {
acceptance("Shared Drafts", function () {
test("Viewing", async (assert) => {
await visit("/t/some-topic/9");
assert.ok(find(".shared-draft-controls").length === 1);
let categoryChooser = selectKit(".shared-draft-controls .category-chooser");
@ -15,4 +14,5 @@ test("Viewing", async (assert) => {
await click(".bootbox .btn-primary");
assert.ok(find(".shared-draft-controls").length === 0);
});
});

View File

@ -1,10 +1,9 @@
import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Signing In");
test("sign in", async (assert) => {
acceptance("Signing In", function () {
test("sign in", async (assert) => {
await visit("/");
await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal");
@ -26,9 +25,9 @@ test("sign in", async (assert) => {
exists(".modal-footer .btn-primary:disabled"),
"disables the login button"
);
});
});
test("sign in - not activated", async (assert) => {
test("sign in - not activated", async (assert) => {
await visit("/");
await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal");
@ -48,9 +47,9 @@ test("sign in - not activated", async (assert) => {
"<small>current@example.com</small>"
);
assert.ok(!exists(".modal-body small"), "it escapes the email address");
});
});
test("sign in - not activated - edit email", async (assert) => {
test("sign in - not activated - edit email", async (assert) => {
await visit("/");
await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal");
@ -69,9 +68,9 @@ test("sign in - not activated - edit email", async (assert) => {
assert.equal(find(".modal-footer .btn-primary:disabled").length, 0);
await click(".modal-footer .btn-primary");
assert.equal(find(".modal-body b").text(), "different@example.com");
});
});
skip("second factor", async (assert) => {
test("second factor", async (assert) => {
await visit("/");
await click("header .login-button");
@ -102,9 +101,9 @@ skip("second factor", async (assert) => {
exists(".modal-footer .btn-primary:disabled"),
"disables the login button"
);
});
});
skip("security key", async (assert) => {
test("security key", async (assert) => {
await visit("/");
await click("header .login-button");
@ -128,9 +127,9 @@ skip("security key", async (assert) => {
"it shows the security key prompt"
);
assert.not(exists("#login-button:visible"), "hides the login button");
});
});
test("create account", async (assert) => {
test("create account", async (assert) => {
await visit("/");
await click("header .sign-up-button");
@ -151,7 +150,10 @@ test("create account", async (assert) => {
"the username validation is bad"
);
await click(".modal-footer .btn-primary");
assert.ok(exists("#new-account-username:focus"), "username field is focused");
assert.ok(
exists("#new-account-username:focus"),
"username field is focused"
);
await fillIn("#new-account-username", "goodtuna");
assert.ok(
@ -164,9 +166,9 @@ test("create account", async (assert) => {
exists(".modal-footer .btn-primary:disabled"),
"create account is disabled"
);
});
});
test("second factor backup - valid token", async (assert) => {
test("second factor backup - valid token", async (assert) => {
await visit("/");
await click("header .login-button");
await fillIn("#login-account-name", "eviltrout");
@ -180,9 +182,9 @@ test("second factor backup - valid token", async (assert) => {
exists(".modal-footer .btn-primary:disabled"),
"it closes the modal when the code is valid"
);
});
});
test("second factor backup - invalid token", async (assert) => {
test("second factor backup - invalid token", async (assert) => {
await visit("/");
await click("header .login-button");
await fillIn("#login-account-name", "eviltrout");
@ -196,4 +198,5 @@ test("second factor backup - invalid token", async (assert) => {
exists("#modal-alert:visible"),
"it shows an error when the code is invalid"
);
});
});

View File

@ -1,9 +1,9 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Static");
test("Static Pages", async (assert) => {
acceptance("Static", function () {
test("Static Pages", async (assert) => {
await visit("/faq");
assert.ok($("body.static-faq").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present");
@ -26,4 +26,5 @@ test("Static Pages", async (assert) => {
"discovery.latest",
"it redirects them to latest unless `login_required`"
);
});
});

View File

@ -3,10 +3,10 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Tag Groups", {
loggedIn: true,
settings: { tagging_enabled: true },
pretend(server, helper) {
acceptance("Tag Groups", function (needs) {
needs.user();
needs.settings({ tagging_enabled: true });
needs.pretender((server, helper) => {
server.post("/tag_groups", () => {
return helper.response({
tag_group: {
@ -32,10 +32,9 @@ acceptance("Tag Groups", {
},
]);
});
},
});
});
test("tag groups can be saved and deleted", async (assert) => {
test("tag groups can be saved and deleted", async (assert) => {
const tags = selectKit(".tag-chooser");
await visit("/tag_groups");
@ -49,11 +48,9 @@ test("tag groups can be saved and deleted", async (assert) => {
await click(".tag-chooser .choice:first");
assert.ok(!find(".tag-group-content .btn.btn-danger")[0].disabled);
});
});
QUnit.test(
"tag groups can have multiple groups added to them",
async (assert) => {
test("tag groups can have multiple groups added to them", async (assert) => {
const tags = selectKit(".tag-chooser");
const groups = selectKit(".group-chooser");
@ -71,5 +68,5 @@ QUnit.test(
await groups.selectRowByIndex(1);
await groups.selectRowByIndex(0);
assert.ok(!find(".tag-group-content .btn.btn-default")[0].disabled);
}
);
});
});

View File

@ -2,11 +2,12 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Tags intersection", {
loggedIn: true,
site: { can_tag_topics: true },
settings: { tagging_enabled: true },
pretend(server, helper) {
acceptance("Tags intersection", function (needs) {
needs.user();
needs.site({ can_tag_topics: true });
needs.settings({ tagging_enabled: true });
needs.pretender((server, helper) => {
server.get("/tag/first/notifications", () => {
return helper.response({
tag_notification: { id: "first", notification_level: 1 },
@ -27,10 +28,9 @@ acceptance("Tags intersection", {
},
});
});
},
});
});
test("Populate tags when creating new topic", async (assert) => {
test("Populate tags when creating new topic", async (assert) => {
await visit("/tags/intersection/first/second");
await click("#create-topic");
@ -40,4 +40,5 @@ test("Populate tags when creating new topic", async (assert) => {
"first, second",
"populates the tags when clicking 'New topic'"
);
});
});

View File

@ -4,11 +4,11 @@ import {
updateCurrentUser,
acceptance,
} from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender";
acceptance("Tags", { loggedIn: true });
acceptance("Tags", function (needs) {
needs.user();
test("list the tags", async (assert) => {
test("list the tags", async (assert) => {
await visit("/tags");
assert.ok($("body.tags-page").length, "has the body class");
@ -16,16 +16,74 @@ test("list the tags", async (assert) => {
$('*[data-tag-name="eviltrout"]').length,
"shows the eviltrout tag"
);
});
});
acceptance("Tags listed by group", {
loggedIn: true,
settings: {
acceptance("Tags listed by group", function (needs) {
needs.user();
needs.settings({
tags_listed_by_group: true,
},
});
});
needs.pretender((server, helper) => {
server.get("/tag/regular-tag/notifications", () =>
helper.response({
tag_notification: { id: "regular-tag", notification_level: 1 },
})
);
test("list the tags in groups", async (assert) => {
server.get("/tag/regular-tag/l/latest.json", () =>
helper.response({
users: [],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 1,
per_page: 30,
tags: [
{
id: 1,
name: "regular-tag",
topic_count: 1,
},
],
topics: [],
},
})
);
server.get("/tag/staff-only-tag/notifications", () =>
helper.response({
tag_notification: { id: "staff-only-tag", notification_level: 1 },
})
);
server.get("/tag/staff-only-tag/l/latest.json", () =>
helper.response({
users: [],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 1,
per_page: 30,
tags: [
{
id: 1,
name: "staff-only-tag",
topic_count: 1,
staff: true,
},
],
topics: [],
},
})
);
});
test("list the tags in groups", async (assert) => {
await visit("/tags");
assert.equal(
$(".tag-list").length,
@ -64,70 +122,9 @@ test("list the tags in groups", async (assert) => {
"/u/eviltrout/messages/tags/private",
"links to private messages"
);
});
test("new topic button is not available for staff-only tags", async (assert) => {
pretender.get("/tag/regular-tag/notifications", () => [
200,
{ "Content-Type": "application/json" },
{ tag_notification: { id: "regular-tag", notification_level: 1 } },
]);
pretender.get("/tag/regular-tag/l/latest.json", () => [
200,
{ "Content-Type": "application/json" },
{
users: [],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 1,
per_page: 30,
tags: [
{
id: 1,
name: "regular-tag",
topic_count: 1,
},
],
topics: [],
},
},
]);
pretender.get("/tag/staff-only-tag/notifications", () => [
200,
{ "Content-Type": "application/json" },
{ tag_notification: { id: "staff-only-tag", notification_level: 1 } },
]);
pretender.get("/tag/staff-only-tag/l/latest.json", () => [
200,
{ "Content-Type": "application/json" },
{
users: [],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 1,
per_page: 30,
tags: [
{
id: 1,
name: "staff-only-tag",
topic_count: 1,
staff: true,
},
],
topics: [],
},
},
]);
});
test("new topic button is not available for staff-only tags", async (assert) => {
updateCurrentUser({ moderator: false, admin: false });
await visit("/tag/regular-tag");
@ -143,14 +140,15 @@ test("new topic button is not available for staff-only tags", async (assert) =>
await visit("/tag/staff-only-tag");
assert.ok(find("#create-topic:disabled").length === 0);
});
});
acceptance("Tag info", {
loggedIn: true,
settings: {
acceptance("Tag info", function (needs) {
needs.user();
needs.settings({
tags_listed_by_group: true,
},
pretend(server, helper) {
});
needs.pretender((server, helper) => {
server.get("/tag/planters/notifications", () => {
return helper.response({
tag_notification: { id: "planters", notification_level: 1 },
@ -219,10 +217,13 @@ acceptance("Tag info", {
],
});
});
},
});
test("tag info can show synonyms", async (assert) => {
server.delete("/tag/planters/synonyms/containers", () =>
helper.response({ success: true })
);
});
test("tag info can show synonyms", async (assert) => {
updateCurrentUser({ moderator: false, admin: false });
await visit("/tag/planters");
@ -245,15 +246,9 @@ test("tag info can show synonyms", async (assert) => {
assert.ok(!exists("#rename-tag"), "can't rename tag");
assert.ok(!exists("#edit-synonyms"), "can't edit synonyms");
assert.ok(!exists("#delete-tag"), "can't delete tag");
});
test("admin can manage tags", async (assert) => {
pretender.delete("/tag/planters/synonyms/containers", () => [
200,
{ "Content-Type": "application/json" },
{ success: true },
]);
});
test("admin can manage tags", async (assert) => {
updateCurrentUser({ moderator: false, admin: true });
await visit("/tag/planters");
@ -279,4 +274,5 @@ test("admin can manage tags", async (assert) => {
find(".tag-info .synonyms-list .tag-box").length === 1,
"removed a synonym"
);
});
});

View File

@ -5,36 +5,42 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic - Admin Menu Anonymous Users", { loggedIn: false });
test("Enter as a regular user", async (assert) => {
acceptance("Topic - Admin Menu Anonymous Users", function () {
test("Enter as a regular user", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(
!exists(".toggle-admin-menu"),
"The admin menu button was not rendered"
);
});
});
acceptance("Topic - Admin Menu", { loggedIn: true });
test("Enter as a user with group moderator permissions", async (assert) => {
acceptance("Topic - Admin Menu", function (needs) {
needs.user();
test("Enter as a user with group moderator permissions", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await visit("/t/topic-for-group-moderators/2480");
assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(exists(".toggle-admin-menu"), "The admin menu button was rendered");
});
assert.ok(
exists(".toggle-admin-menu"),
"The admin menu button was rendered"
);
});
test("Enter as a user with moderator and admin permissions", async (assert) => {
test("Enter as a user with moderator and admin permissions", async (assert) => {
updateCurrentUser({ moderator: true, admin: true, trust_level: 4 });
await visit("/t/internationalization-localization/280");
assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(exists(".toggle-admin-menu"), "The admin menu button was rendered");
});
assert.ok(
exists(".toggle-admin-menu"),
"The admin menu button was rendered"
);
});
test("Toggle the menu as admin focuses the first item", async (assert) => {
test("Toggle the menu as admin focuses the first item", async (assert) => {
updateCurrentUser({ admin: true });
await visit("/t/internationalization-localization/280");
@ -45,4 +51,5 @@ test("Toggle the menu as admin focuses the first item", async (assert) => {
document.activeElement,
document.querySelector(".topic-admin-multi-select > button")
);
});
});

View File

@ -1,9 +1,9 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic - Anonymous");
test("Enter a Topic", async (assert) => {
acceptance("Topic - Anonymous", function () {
test("Enter a Topic", async (assert) => {
await visit("/t/internationalization-localization/280/1");
assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(exists("#topic .cooked"), "The topic has cooked posts");
@ -11,27 +11,28 @@ test("Enter a Topic", async (assert) => {
find(".shared-draft-notice").length === 0,
"no shared draft unless there's a dest category id"
);
});
});
test("Enter without an id", async (assert) => {
test("Enter without an id", async (assert) => {
await visit("/t/internationalization-localization");
assert.ok(exists("#topic"), "The topic was rendered");
});
});
test("Enter a 404 topic", async (assert) => {
test("Enter a 404 topic", async (assert) => {
await visit("/t/not-found/404");
assert.ok(!exists("#topic"), "The topic was not rendered");
assert.ok(exists(".topic-error"), "An error message is displayed");
});
});
test("Enter without access", async (assert) => {
test("Enter without access", async (assert) => {
await visit("/t/i-dont-have-access/403");
assert.ok(!exists("#topic"), "The topic was not rendered");
assert.ok(exists(".topic-error"), "An error message is displayed");
});
});
test("Enter with 500 errors", async (assert) => {
test("Enter with 500 errors", async (assert) => {
await visit("/t/throws-error/500");
assert.ok(!exists("#topic"), "The topic was not rendered");
assert.ok(exists(".topic-error"), "An error message is displayed");
});
});

View File

@ -5,13 +5,12 @@ import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import MessageBus from "message-bus-client";
acceptance("Topic Discovery", {
settings: {
acceptance("Topic Discovery", function (needs) {
needs.settings({
show_pinned_excerpt_desktop: true,
},
});
});
test("Visit Discovery Pages", async (assert) => {
test("Visit Discovery Pages", async (assert) => {
await visit("/");
assert.ok($("body.navigation-topics").length, "has the default navigation");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
@ -68,9 +67,9 @@ test("Visit Discovery Pages", async (assert) => {
exists(".category-boxes-with-topics .featured-topics"),
"The featured topics are there too"
);
});
});
test("Clearing state after leaving a category", async (assert) => {
test("Clearing state after leaving a category", async (assert) => {
await visit("/c/dev");
assert.ok(
exists(".topic-list-item[data-topic-id=11994] .topic-excerpt"),
@ -81,9 +80,9 @@ test("Clearing state after leaving a category", async (assert) => {
!exists(".topic-list-item[data-topic-id=11557] .topic-excerpt"),
"it doesn't expand all pinned in the latest category"
);
});
});
test("Live update unread state", async (assert) => {
test("Live update unread state", async (assert) => {
await visit("/");
assert.ok(
exists(".topic-list-item:not(.visited) a[data-topic-id='11995']"),
@ -110,9 +109,9 @@ test("Live update unread state", async (assert) => {
exists(".topic-list-item.visited a[data-topic-id='11995']"),
"shows the topic read"
);
});
});
test("Using period chooser when query params are present", async (assert) => {
test("Using period chooser when query params are present", async (assert) => {
await visit("/top?f=foo&d=bar");
sandbox.stub(DiscourseURL, "routeTo");
@ -126,4 +125,5 @@ test("Using period chooser when query params are present", async (assert) => {
DiscourseURL.routeTo.calledWith("/top/yearly?f=foo&d=bar"),
"it keeps the query params"
);
});
});

View File

@ -7,9 +7,9 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic - Edit timer", {
loggedIn: true,
pretend(server, helper) {
acceptance("Topic - Edit timer", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.post("/t/280/timer", () =>
helper.response({
success: "OK",
@ -22,10 +22,9 @@ acceptance("Topic - Edit timer", {
category_id: null,
})
);
},
});
});
test("default", async (assert) => {
test("default", async (assert) => {
updateCurrentUser({ moderator: true });
const futureDateInputSelector = selectKit(".future-date-input-selector");
@ -33,11 +32,14 @@ test("default", async (assert) => {
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
assert.equal(futureDateInputSelector.header().label(), "Select a timeframe");
assert.equal(
futureDateInputSelector.header().label(),
"Select a timeframe"
);
assert.equal(futureDateInputSelector.header().value(), null);
});
});
test("autoclose - specific time", async (assert) => {
test("autoclose - specific time", async (assert) => {
updateCurrentUser({ moderator: true });
const futureDateInputSelector = selectKit(".future-date-input-selector");
@ -54,9 +56,9 @@ test("autoclose - specific time", async (assert) => {
const regex = /will automatically close in/g;
const html = find(".future-date-input .topic-status-info").html().trim();
assert.ok(regex.test(html));
});
});
skip("autoclose", async (assert) => {
skip("autoclose", async (assert) => {
updateCurrentUser({ moderator: true });
const futureDateInputSelector = selectKit(".future-date-input-selector");
@ -82,7 +84,10 @@ skip("autoclose", async (assert) => {
assert.ok(
futureDateInputSelector.header().label().includes("Pick date and time")
);
assert.equal(futureDateInputSelector.header().value(), "pick_date_and_time");
assert.equal(
futureDateInputSelector.header().value(),
"pick_date_and_time"
);
const regex2 = /will automatically close in/g;
const html2 = find(".future-date-input .topic-status-info").html().trim();
@ -107,9 +112,9 @@ skip("autoclose", async (assert) => {
const regex3 = /This topic will close.*after the last reply/g;
const html3 = find(".future-date-input .topic-status-info").html().trim();
assert.ok(regex3.test(html3));
});
});
test("close temporarily", async (assert) => {
test("close temporarily", async (assert) => {
updateCurrentUser({ moderator: true });
const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector");
@ -121,7 +126,10 @@ test("close temporarily", async (assert) => {
await timerType.expand();
await timerType.selectRowByValue("open");
assert.equal(futureDateInputSelector.header().label(), "Select a timeframe");
assert.equal(
futureDateInputSelector.header().label(),
"Select a timeframe"
);
assert.equal(futureDateInputSelector.header().value(), null);
await futureDateInputSelector.expand();
@ -139,15 +147,21 @@ test("close temporarily", async (assert) => {
await fillIn(".future-date-input .date-picker", "2099-11-24");
assert.equal(futureDateInputSelector.header().label(), "Pick date and time");
assert.equal(futureDateInputSelector.header().value(), "pick_date_and_time");
assert.equal(
futureDateInputSelector.header().label(),
"Pick date and time"
);
assert.equal(
futureDateInputSelector.header().value(),
"pick_date_and_time"
);
const regex2 = /will automatically open in/g;
const html2 = find(".future-date-input .topic-status-info").html().trim();
assert.ok(regex2.test(html2));
});
});
test("schedule", async (assert) => {
test("schedule", async (assert) => {
updateCurrentUser({ moderator: true });
const timerType = selectKit(".select-kit.timer-type");
const categoryChooser = selectKit(".modal-body .category-chooser");
@ -163,7 +177,10 @@ test("schedule", async (assert) => {
assert.equal(categoryChooser.header().label(), "uncategorized");
assert.equal(categoryChooser.header().value(), null);
assert.equal(futureDateInputSelector.header().label(), "Select a timeframe");
assert.equal(
futureDateInputSelector.header().label(),
"Select a timeframe"
);
assert.equal(futureDateInputSelector.header().value(), null);
await categoryChooser.expand();
@ -178,9 +195,9 @@ test("schedule", async (assert) => {
const regex = /will be published to #dev/g;
const text = find(".future-date-input .topic-status-info").text().trim();
assert.ok(regex.test(text));
});
});
test("TL4 can't auto-delete", async (assert) => {
test("TL4 can't auto-delete", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 4 });
await visit("/t/internationalization-localization");
@ -192,9 +209,9 @@ test("TL4 can't auto-delete", async (assert) => {
await timerType.expand();
assert.ok(!timerType.rowByValue("delete").exists());
});
});
test("auto delete", async (assert) => {
test("auto delete", async (assert) => {
updateCurrentUser({ moderator: true });
const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector");
@ -206,7 +223,10 @@ test("auto delete", async (assert) => {
await timerType.expand();
await timerType.selectRowByValue("delete");
assert.equal(futureDateInputSelector.header().label(), "Select a timeframe");
assert.equal(
futureDateInputSelector.header().label(),
"Select a timeframe"
);
assert.equal(futureDateInputSelector.header().value(), null);
await futureDateInputSelector.expand();
@ -218,9 +238,9 @@ test("auto delete", async (assert) => {
const regex = /will be automatically deleted/g;
const html = find(".future-date-input .topic-status-info").html().trim();
assert.ok(regex.test(html));
});
});
test("Inline delete timer", async (assert) => {
test("Inline delete timer", async (assert) => {
updateCurrentUser({ moderator: true });
const futureDateInputSelector = selectKit(".future-date-input-selector");
@ -237,4 +257,5 @@ test("Inline delete timer", async (assert) => {
await click(".topic-status-info .topic-timer-remove");
const topicStatusInfo = find(".topic-status-info .topic-timer-remove");
assert.equal(topicStatusInfo.length, 0);
});
});

View File

@ -8,10 +8,11 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
let _test;
acceptance("Topic footer buttons mobile", {
loggedIn: true,
mobileView: true,
beforeEach() {
acceptance("Topic footer buttons mobile", function (needs) {
needs.user();
needs.mobileView();
needs.hooks.beforeEach(() => {
I18n.translations[I18n.locale].js.test = {
title: "My title",
label: "My Label",
@ -29,15 +30,14 @@ acceptance("Topic footer buttons mobile", {
},
});
});
},
});
afterEach() {
needs.hooks.afterEach(() => {
clearTopicFooterButtons();
_test = undefined;
},
});
});
test("default", async (assert) => {
test("default", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.equal(_test, null);
@ -47,4 +47,5 @@ test("default", async (assert) => {
await subject.selectRowByValue("my-button");
assert.equal(_test, 2);
});
});

View File

@ -6,9 +6,9 @@ import {
previousTopicUrl,
setTopicId,
} from "discourse/lib/topic-list-tracker";
acceptance("Topic list tracking");
test("Navigation", async (assert) => {
acceptance("Topic list tracking", function () {
test("Navigation", async (assert) => {
await visit("/");
let url = await nextTopicUrl();
assert.equal(url, "/t/error-after-upgrade-to-0-9-7-9/11557");
@ -20,4 +20,5 @@ test("Navigation", async (assert) => {
url = await previousTopicUrl();
assert.equal(url, "/t/error-after-upgrade-to-0-9-7-9/11557");
});
});

View File

@ -2,9 +2,11 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import I18n from "I18n";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic move posts", { loggedIn: true });
test("default", async (assert) => {
acceptance("Topic move posts", function (needs) {
needs.user();
test("default", async (assert) => {
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
@ -45,9 +47,9 @@ test("default", async (assert) => {
.includes(I18n.t("topic.move_to_new_message.radio_label")),
"it shows an option to move to new message"
);
});
});
test("moving all posts", async (assert) => {
test("moving all posts", async (assert) => {
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
@ -81,9 +83,9 @@ test("moving all posts", async (assert) => {
.includes(I18n.t("topic.move_to_new_message.radio_label")),
"it does not show an option to move to new message"
);
});
});
test("moving posts from personal message", async (assert) => {
test("moving posts from personal message", async (assert) => {
await visit("/t/pm-for-testing/12");
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
@ -117,9 +119,9 @@ test("moving posts from personal message", async (assert) => {
.includes(I18n.t("topic.move_to_existing_message.radio_label")),
"it shows an option to move to existing message"
);
});
});
test("group moderator moving posts", async (assert) => {
test("group moderator moving posts", async (assert) => {
await visit("/t/topic-for-group-moderators/2480");
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
@ -139,4 +141,5 @@ test("group moderator moving posts", async (assert) => {
.includes(I18n.t("topic.move_to.title")),
"it opens move to modal"
);
});
});

View File

@ -3,16 +3,16 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic Notifications button", {
loggedIn: true,
pretend(server, helper) {
acceptance("Topic Notifications button", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.post("/t/280/notifications", () => {
return helper.response({});
});
},
});
});
test("Updating topic notification level", async (assert) => {
test("Updating topic notification level", async (assert) => {
const notificationOptions = selectKit(
"#topic-footer-buttons .topic-notifications-options"
);
@ -57,4 +57,5 @@ test("Updating topic notification level", async (assert) => {
"Muted",
"it should display the right notification level"
);
});
});

View File

@ -13,15 +13,14 @@ function selectText(selector) {
selection.addRange(range);
}
acceptance("Topic - Quote button - logged in", {
loggedIn: true,
settings: {
acceptance("Topic - Quote button - logged in", function (needs) {
needs.user();
needs.settings({
share_quote_visibility: "anonymous",
share_quote_buttons: "twitter|email",
},
});
});
test("Does not show the quote share buttons by default", async (assert) => {
test("Does not show the quote share buttons by default", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
assert.ok(exists(".insert-quote"), "it shows the quote button");
@ -30,9 +29,9 @@ test("Does not show the quote share buttons by default", async (assert) => {
0,
"it does not show quote sharing"
);
});
});
test("Shows quote share buttons with the right site settings", async function (assert) {
test("Shows quote share buttons with the right site settings", async function (assert) {
this.siteSettings.share_quote_visibility = "all";
await visit("/t/internationalization-localization/280");
@ -47,17 +46,16 @@ test("Shows quote share buttons with the right site settings", async function (a
exists(`.quote-sharing .btn[title='${I18n.t("share.email")}']`),
"it includes the email share button"
);
});
});
acceptance("Topic - Quote button - anonymous", {
loggedIn: false,
settings: {
acceptance("Topic - Quote button - anonymous", function (needs) {
needs.settings({
share_quote_visibility: "anonymous",
share_quote_buttons: "twitter|email",
},
});
});
test("Shows quote share buttons with the right site settings", async function (assert) {
test("Shows quote share buttons with the right site settings", async function (assert) {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
@ -75,9 +73,9 @@ test("Shows quote share buttons with the right site settings", async function (a
0,
"it does not show the quote button"
);
});
});
test("Shows single share button when site setting only has one item", async function (assert) {
test("Shows single share button when site setting only has one item", async function (assert) {
this.siteSettings.share_quote_buttons = "twitter";
await visit("/t/internationalization-localization/280");
@ -93,9 +91,9 @@ test("Shows single share button when site setting only has one item", async func
0,
"it does not show the Share label"
);
});
});
test("Shows nothing when visibility is disabled", async function (assert) {
test("Shows nothing when visibility is disabled", async function (assert) {
this.siteSettings.share_quote_visibility = "none";
await visit("/t/internationalization-localization/280");
@ -112,4 +110,5 @@ test("Shows nothing when visibility is disabled", async function (assert) {
0,
"it does not show the quote button"
);
});
});

View File

@ -1,5 +1,4 @@
import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { test } from "qunit";
import I18n from "I18n";
import { withPluginApi } from "discourse/lib/plugin-api";
@ -7,16 +6,25 @@ import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
acceptance("Topic", {
loggedIn: true,
pretend(server, helper) {
function selectText(selector) {
const range = document.createRange();
const node = document.querySelector(selector);
range.selectNodeContents(node);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
acceptance("Topic", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.put("/posts/398/wiki", () => {
return helper.response({});
});
},
});
});
test("Reply as new topic", async (assert) => {
test("Reply as new topic", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("button.share:eq(0)");
await click(".reply-as-new-topic a");
@ -33,9 +41,9 @@ test("Reply as new topic", async (assert) => {
"2",
"it fills category selector with the right category"
);
});
});
test("Reply as new message", async (assert) => {
test("Reply as new message", async (assert) => {
await visit("/t/pm-for-testing/12");
await click("button.share:eq(0)");
await click(".reply-as-new-topic a");
@ -67,16 +75,16 @@ test("Reply as new message", async (assert) => {
"Group",
"it fills up the composer with the right group to start the PM to"
);
});
});
test("Share Modal", async (assert) => {
test("Share Modal", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:first-child button.share");
assert.ok(exists("#share-link"), "it shows the share modal");
});
});
test("Showing and hiding the edit controls", async (assert) => {
test("Showing and hiding the edit controls", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
@ -90,9 +98,9 @@ test("Showing and hiding the edit controls", async (assert) => {
await fillIn("#edit-title", "this is the new title");
await click("#topic-title .cancel-edit");
assert.ok(!exists("#edit-title"), "it hides the editing controls");
});
});
test("Updating the topic title and category", async (assert) => {
test("Updating the topic title and category", async (assert) => {
const categoryChooser = selectKit(".title-wrapper .category-chooser");
await visit("/t/internationalization-localization/280");
@ -113,9 +121,9 @@ test("Updating the topic title and category", async (assert) => {
"this is the new title",
"it displays the new title"
);
});
});
test("Marking a topic as wiki", async (assert) => {
test("Marking a topic as wiki", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(find("a.wiki").length === 0, "it does not show the wiki icon");
@ -125,9 +133,9 @@ test("Marking a topic as wiki", async (assert) => {
await click(".btn.wiki");
assert.ok(find("a.wiki").length === 1, "it shows the wiki icon");
});
});
test("Visit topic routes", async (assert) => {
test("Visit topic routes", async (assert) => {
await visit("/t/12");
assert.equal(
@ -143,9 +151,9 @@ test("Visit topic routes", async (assert) => {
"Internationalization / localization",
"it routes to the right topic"
);
});
});
test("Updating the topic title with emojis", async (assert) => {
test("Updating the topic title with emojis", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
@ -158,9 +166,9 @@ test("Updating the topic title with emojis", async (assert) => {
`emojis title <img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/bike.png?v=${v}" title="bike" alt="bike" class="emoji"> <img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/blonde_woman/6.png?v=${v}" title="blonde_woman:t6" alt="blonde_woman:t6" class="emoji">`,
"it displays the new title with emojis"
);
});
});
test("Updating the topic title with unicode emojis", async (assert) => {
test("Updating the topic title with unicode emojis", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
@ -173,9 +181,9 @@ test("Updating the topic title with unicode emojis", async (assert) => {
`emojis title <img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/man_farmer.png?v=${v}" title="man_farmer" alt="man_farmer" class="emoji"><img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/pray.png?v=${v}" title="pray" alt="pray" class="emoji">`,
"it displays the new title with escaped unicode emojis"
);
});
});
test("Updating the topic title with unicode emojis without whitespaces", async function (assert) {
test("Updating the topic title with unicode emojis without whitespaces", async function (assert) {
this.siteSettings.enable_inline_emoji_translation = true;
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
@ -189,41 +197,32 @@ test("Updating the topic title with unicode emojis without whitespaces", async f
`Test<img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/slightly_smiling_face.png?v=${v}" title="slightly_smiling_face" alt="slightly_smiling_face" class="emoji">Title`,
"it displays the new title with escaped unicode emojis"
);
});
});
test("Suggested topics", async (assert) => {
test("Suggested topics", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.equal(
find("#suggested-topics .suggested-topics-title").text().trim(),
I18n.t("suggested_topics.title")
);
});
});
skip("Deleting a topic", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:eq(0) button.show-more-actions");
await click(".widget-button.delete");
assert.ok(exists(".widget-button.recover"), "it shows the recover button");
});
test("Group category moderator posts", async (assert) => {
test("Group category moderator posts", async (assert) => {
await visit("/t/topic-for-group-moderators/2480");
assert.ok(exists(".category-moderator"), "it has a class applied");
assert.ok(exists(".d-icon-shield-alt"), "it shows an icon");
});
});
acceptance("Topic featured links", {
loggedIn: true,
settings: {
acceptance("Topic featured links", function (needs) {
needs.user();
needs.settings({
topic_featured_link_enabled: true,
max_topic_title_length: 80,
},
});
skip("remove featured link", async (assert) => {
});
test("remove featured link", async (assert) => {
await visit("/t/-/299/1");
assert.ok(
exists(".title-wrapper .topic-featured-link"),
@ -239,23 +238,25 @@ skip("remove featured link", async (assert) => {
await click(".title-wrapper .remove-featured-link");
await click(".title-wrapper .submit-edit");
assert.ok(!exists(".title-wrapper .topic-featured-link"), "link is gone");
});
});
test("Converting to a public topic", async (assert) => {
test("Converting to a public topic", async (assert) => {
await visit("/t/test-pm/34");
assert.ok(exists(".private_message"));
await click(".toggle-admin-menu");
await click(".topic-admin-convert button");
let categoryChooser = selectKit(".convert-to-public-topic .category-chooser");
let categoryChooser = selectKit(
".convert-to-public-topic .category-chooser"
);
await categoryChooser.expand();
await categoryChooser.selectRowByValue(21);
await click(".convert-to-public-topic .btn-primary");
assert.ok(!exists(".private_message"));
});
});
test("Unpinning unlisted topic", async (assert) => {
test("Unpinning unlisted topic", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
@ -266,10 +267,13 @@ test("Unpinning unlisted topic", async (assert) => {
await click(".topic-admin-visible .btn");
await click(".toggle-admin-menu");
assert.ok(exists(".topic-admin-pin"), "it should show the multi select menu");
});
assert.ok(
exists(".topic-admin-pin"),
"it should show the multi select menu"
);
});
test("selecting posts", async (assert) => {
test("selecting posts", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
@ -283,9 +287,9 @@ test("selecting posts", async (assert) => {
exists(".select-all"),
"it should allow users to select all the posts"
);
});
});
test("select below", async (assert) => {
test("select below", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
@ -306,26 +310,16 @@ test("select below", async (assert) => {
.includes(I18n.t("topic.multi_select.description", { count: 19 })),
"it should select the right number of posts"
);
});
});
test("View Hidden Replies", async (assert) => {
test("View Hidden Replies", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".gap");
assert.equal(find(".gap").length, 0, "it hides gap");
});
});
function selectText(selector) {
const range = document.createRange();
const node = document.querySelector(selector);
range.selectNodeContents(node);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
test("Quoting a quote keeps the original poster name", async (assert) => {
test("Quoting a quote keeps the original poster name", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
await click(".quote-button .insert-quote");
@ -335,9 +329,9 @@ test("Quoting a quote keeps the original poster name", async (assert) => {
.val()
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
);
});
});
test("Quoting a quote of a different topic keeps the original topic title", async (assert) => {
test("Quoting a quote of a different topic keeps the original topic title", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_9 blockquote");
await click(".quote-button .insert-quote");
@ -349,9 +343,9 @@ test("Quoting a quote of a different topic keeps the original topic title", asyn
'quote="A new topic with a link to another topic, post:3, topic:62"'
) !== -1
);
});
});
test("Quoting a quote with the Reply button keeps the original poster name", async (assert) => {
test("Quoting a quote with the Reply button keeps the original poster name", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
await click(".reply");
@ -361,9 +355,9 @@ test("Quoting a quote with the Reply button keeps the original poster name", asy
.val()
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
);
});
});
test("Quoting a quote with replyAsNewTopic keeps the original poster name", async (assert) => {
test("Quoting a quote with replyAsNewTopic keeps the original poster name", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
await keyEvent(document, "keypress", "j".charCodeAt(0));
@ -374,9 +368,9 @@ test("Quoting a quote with replyAsNewTopic keeps the original poster name", asyn
.val()
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
);
});
});
test("Quoting by selecting text can mark the quote as full", async (assert) => {
test("Quoting by selecting text can mark the quote as full", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 .cooked");
await click(".quote-button .insert-quote");
@ -386,20 +380,19 @@ test("Quoting by selecting text can mark the quote as full", async (assert) => {
.val()
.indexOf('quote="pekka, post:5, topic:280, full:true"') !== -1
);
});
});
acceptance("Topic with title decorated", {
loggedIn: true,
beforeEach() {
acceptance("Topic with title decorated", function (needs) {
needs.user();
needs.hooks.beforeEach(() => {
withPluginApi("0.8.40", (api) => {
api.decorateTopicTitle((topic, node, topicTitleType) => {
node.innerText = `${node.innerText}-${topic.id}-${topicTitleType}`;
});
});
},
});
test("Decorate topic title", async (assert) => {
});
test("Decorate topic title", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(
@ -413,4 +406,5 @@ test("Decorate topic title", async (assert) => {
),
"it decorates topic list item title"
);
});
});

View File

@ -1,51 +1,43 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender";
acceptance("Unknown");
test("Permalink Unknown URL", async (assert) => {
acceptance("Unknown", function (needs) {
const urls = {
"viewtopic.php": "/t/internationalization-localization/280",
"not-the-url-for-faq": "/faq",
};
needs.pretender((server, helper) => {
server.get("/permalink-check.json", (request) => {
let url = urls[request.queryParams.path];
if (url) {
return helper.response({
found: true,
internal: true,
target_url: url,
});
} else {
return helper.response({
found: false,
html: "<div class='page-not-found'>not found</div>",
});
}
});
});
test("Permalink Unknown URL", async (assert) => {
await visit("/url-that-doesn't-exist");
assert.ok(exists(".page-not-found"), "The not found content is present");
});
test("Permalink URL to a Topic", async (assert) => {
pretender.get("/permalink-check.json", () => {
return [
200,
{ "Content-Type": "application/json" },
{
found: true,
internal: true,
target_url: "/t/internationalization-localization/280",
},
];
});
test("Permalink URL to a Topic", async (assert) => {
await visit("/viewtopic.php?f=8&t=280");
assert.ok(exists(".topic-post"));
});
test("Permalink URL to a static page", async (assert) => {
pretender.get("/permalink-check.json", () => {
return [
200,
{ "Content-Type": "application/json" },
{
found: true,
internal: true,
target_url: "/faq",
},
];
assert.equal(currentURL(), "/t/internationalization-localization/280");
});
test("Permalink URL to a static page", async (assert) => {
await visit("/not-the-url-for-faq");
// body is outside of #ember-testing-container and needs to be targeted
// through document instead of find
assert.ok(
document.querySelector("body.static-faq"),
"routed to the faq page"
);
assert.ok(exists(".body-page"));
assert.equal(currentURL(), "/faq");
});
});

View File

@ -1,45 +1,38 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("User Anonymous");
function hasStream(assert) {
assert.ok(exists(".user-main .about"), "it has the about section");
assert.ok(count(".user-stream .item") > 0, "it has stream items");
}
function hasTopicList(assert) {
assert.equal(count(".user-stream .item"), 0, "has no stream displayed");
assert.ok(count(".topic-list tr") > 0, "it has a topic list");
}
test("Root URL", async (assert) => {
acceptance("User Anonymous", function () {
test("Root URL", async (assert) => {
await visit("/u/eviltrout");
assert.ok($("body.user-summary-page").length, "has the body class");
assert.equal(currentPath(), "user.summary", "it defaults to summary");
});
});
test("Filters", async (assert) => {
test("Filters", async (assert) => {
await visit("/u/eviltrout/activity");
assert.ok($("body.user-activity-page").length, "has the body class");
hasStream(assert);
assert.ok(exists(".user-main .about"), "it has the about section");
assert.ok(count(".user-stream .item") > 0, "it has stream items");
await visit("/u/eviltrout/activity/topics");
await hasTopicList(assert);
assert.equal(count(".user-stream .item"), 0, "has no stream displayed");
assert.ok(count(".topic-list tr") > 0, "it has a topic list");
await visit("/u/eviltrout/activity/replies");
hasStream(assert);
assert.ok(exists(".user-main .about"), "it has the about section");
assert.ok(count(".user-stream .item") > 0, "it has stream items");
assert.ok(exists(".user-stream.filter-5"), "stream has filter class");
});
});
test("Badges", async (assert) => {
test("Badges", async (assert) => {
await visit("/u/eviltrout/badges");
assert.ok($("body.user-badges-page").length, "has the body class");
assert.ok(exists(".user-badges-list .badge-card"), "shows a badge");
});
});
test("Restricted Routes", async (assert) => {
test("Restricted Routes", async (assert) => {
await visit("/u/eviltrout/preferences");
assert.equal(
@ -47,4 +40,5 @@ test("Restricted Routes", async (assert) => {
"/u/eviltrout/activity",
"it redirects from preferences"
);
});
});

View File

@ -2,38 +2,41 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import pretender from "discourse/tests/helpers/create-pretender";
import userFixtures from "discourse/tests/fixtures/user-fixtures";
import { deepMerge } from "discourse-common/lib/object";
acceptance("User's bookmarks", {
loggedIn: true,
acceptance("User's bookmarks", function (needs) {
needs.user();
beforeEach() {
pretender.delete("/bookmarks/576", () => [
200,
{ "Content-Type": "application/json" },
{},
]);
},
});
test("listing user bookmarks", async (assert) => {
test("removing a bookmark with no reminder does not show a confirmation", async (assert) => {
await visit("/u/eviltrout/activity/bookmarks");
assert.ok(find(".bookmark-list-item").length > 0);
assert.ok(find(".bookmark-list-item").length);
const dropdown = selectKit(".bookmark-actions-dropdown:eq(0)");
await dropdown.expand();
await dropdown.selectRowByValue("remove");
assert.not(exists(".bootbox.modal"), "it should not show the modal");
});
});
test("removing a bookmark with a reminder shows a confirmation", async (assert) => {
let listResponse = Object.assign(
acceptance("User's bookmarks - reminder", function (needs) {
needs.user();
needs.pretender((server, helper) => {
let listResponse = deepMerge(
{},
userFixtures["/u/eviltrout/bookmarks.json"]
);
listResponse.user_bookmark_list.bookmarks[0].reminder_at = "2028-01-01T08:00";
pretender.get("/u/eviltrout/bookmarks.json", () => [
200,
{ "Content-Type": "application/json" },
listResponse,
]);
listResponse.user_bookmark_list.bookmarks[0].reminder_at =
"2028-01-01T08:00";
server.get("/u/eviltrout/bookmarks.json", () =>
helper.response(listResponse)
);
});
test("removing a bookmark with a reminder shows a confirmation", async (assert) => {
await visit("/u/eviltrout/activity/bookmarks");
const dropdown = selectKit(".bookmark-actions-dropdown");
@ -44,32 +47,22 @@ test("removing a bookmark with a reminder shows a confirmation", async (assert)
await click(".bootbox.modal a.btn-primary");
assert.not(exists(".bootbox.modal"));
listResponse.user_bookmark_list.bookmarks[0].reminder_at = null;
});
});
test("listing users bookmarks - no bookmarks", async (assert) => {
pretender.get("/u/eviltrout/bookmarks.json", () => [
200,
{
"Content-Type": "application/json",
},
{
acceptance("User's bookmarks - no bookmarks", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.get("/u/eviltrout/bookmarks.json", () =>
helper.response({
bookmarks: [],
no_results_help: "no bookmarks",
},
]);
})
);
});
test("listing users bookmarks - no bookmarks", async (assert) => {
await visit("/u/eviltrout/activity/bookmarks");
assert.equal(find(".alert.alert-info").text(), "no bookmarks");
});
test("removing a bookmark with no reminder does not show a confirmation", async (assert) => {
await visit("/u/eviltrout/activity/bookmarks");
const dropdown = selectKit(".bookmark-actions-dropdown");
await dropdown.expand();
await dropdown.selectRowByValue("remove");
assert.not(exists(".bootbox.modal"), "it should not show the modal");
});
});

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("User Card - Mobile", { mobileView: true });
skip("user card", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(
invisible(".user-card"),
"mobile user card is invisible by default"
);
await click("a[data-user-card=eviltrout]:first");
assert.ok(visible(".user-card"), "mobile user card should appear");
sandbox.stub(DiscourseURL, "routeTo");
await click(".card-content a.user-profile-link");
assert.ok(
DiscourseURL.routeTo.calledWith("/u/eviltrout"),
"it should navigate to the user profile"
);
});

View File

@ -1,78 +1,20 @@
import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import DiscourseURL from "discourse/lib/url";
import pretender from "discourse/tests/helpers/create-pretender";
import userFixtures from "discourse/tests/fixtures/user-fixtures";
import User from "discourse/models/user";
acceptance("User Card - Show Local Time", {
loggedIn: true,
settings: { display_local_time_in_user_card: true },
});
skip("user card local time", async (assert) => {
User.current().changeTimezone("Australia/Brisbane");
let cardResponse = Object.assign({}, userFixtures["/u/eviltrout/card.json"]);
cardResponse.user.timezone = "Australia/Perth";
pretender.get("/u/eviltrout/card.json", () => [
200,
{ "Content-Type": "application/json" },
cardResponse,
]);
await visit("/t/internationalization-localization/280");
assert.ok(invisible(".user-card"), "user card is invisible by default");
await click("a[data-user-card=eviltrout]:first");
let expectedTime = moment
.tz("Australia/Brisbane")
.add(-2, "hours")
.format("h:mm a");
assert.ok(visible(".user-card"), "card should appear");
assert.equal(
find(".user-card .local-time").text().trim(),
expectedTime,
"user card contains the user's local time"
);
cardResponse = Object.assign({}, userFixtures["/u/charlie/card.json"]);
cardResponse.user.timezone = "America/New_York";
pretender.get("/u/charlie/card.json", () => [
200,
{ "Content-Type": "application/json" },
cardResponse,
]);
await click("a[data-user-card=charlie]:first");
expectedTime = moment
.tz("Australia/Brisbane")
.add(-14, "hours")
.format("h:mm a");
assert.equal(
find(".user-card .local-time").text().trim(),
expectedTime,
"opening another user card updates the local time in the card (no caching)"
);
});
test("user card local time - does not update timezone for another user", async (assert) => {
User.current().changeTimezone("Australia/Brisbane");
acceptance("User Card - Show Local Time", function (needs) {
needs.user();
needs.settings({ display_local_time_in_user_card: true });
needs.pretender((server, helper) => {
let cardResponse = Object.assign({}, userFixtures["/u/charlie/card.json"]);
delete cardResponse.user.timezone;
server.get("/u/charlie/card.json", () => helper.response(cardResponse));
});
pretender.get("/u/charlie/card.json", () => [
200,
{ "Content-Type": "application/json" },
cardResponse,
]);
test("user card local time - does not update timezone for another user", async (assert) => {
User.current().changeTimezone("Australia/Brisbane");
await visit("/t/internationalization-localization/280");
await click("a[data-user-card=charlie]:first");
@ -81,57 +23,5 @@ test("user card local time - does not update timezone for another user", async (
exists(".user-card .local-time"),
"it does not show the local time if the user card returns a null/undefined timezone for another user"
);
});
acceptance("User Card", { loggedIn: true });
skip("user card", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(invisible(".user-card"), "user card is invisible by default");
await click("a[data-user-card=eviltrout]:first");
assert.ok(visible(".user-card"), "card should appear");
assert.equal(
find(".user-card .username").text().trim(),
"eviltrout",
"user card contains the data"
);
sandbox.stub(DiscourseURL, "routeTo");
await click(".card-content a.user-profile-link");
assert.ok(
DiscourseURL.routeTo.calledWith("/u/eviltrout"),
"it should navigate to the user profile"
);
await click("a[data-user-card=charlie]:first");
assert.ok(visible(".user-card"), "card should appear");
assert.equal(
find(".user-card .username").text().trim(),
"charlie",
"user card contains the data"
);
assert.ok(
!visible(".user-card .local-time"),
"local time with zone does not show by default"
);
await click(".card-content .compose-pm button");
assert.ok(
invisible(".user-card"),
"user card dismissed after hitting Message button"
);
const mention = find("a.mention");
const icon = document.createElement("span");
icon.classList.add("icon");
mention.append(icon);
await click("a.mention .icon");
assert.ok(visible(".user-card"), "card should appear");
assert.equal(
find(".user-card .username").text().trim(),
"eviltrout",
"user card contains the data"
);
});
});

View File

@ -2,9 +2,10 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("User Drafts", { loggedIn: true });
acceptance("User Drafts", function (needs) {
needs.user();
test("Stream", async (assert) => {
test("Stream", async (assert) => {
await visit("/u/eviltrout/activity/drafts");
assert.ok(find(".user-stream-item").length === 3, "has drafts");
@ -13,9 +14,9 @@ test("Stream", async (assert) => {
find(".user-stream-item").length === 2,
"draft removed, list length diminished by one"
);
});
});
test("Stream - resume draft", async (assert) => {
test("Stream - resume draft", async (assert) => {
await visit("/u/eviltrout/activity/drafts");
assert.ok(find(".user-stream-item").length > 0, "has drafts");
@ -24,4 +25,5 @@ test("Stream - resume draft", async (assert) => {
find(".d-editor-input").val().trim(),
"A fun new topic for testing drafts."
);
});
});

View File

@ -6,11 +6,10 @@ import Site from "discourse/models/site";
import Session from "discourse/models/session";
import cookie, { removeCookie } from "discourse/lib/cookie";
acceptance("User Preferences - Interface", {
loggedIn: true,
});
acceptance("User Preferences - Interface", function (needs) {
needs.user();
test("font size change", async (assert) => {
test("font size change", async (assert) => {
removeCookie("text_size");
const savePreferences = async () => {
@ -53,14 +52,14 @@ test("font size change", async (assert) => {
assert.equal(cookie("text_size"), null, "cookie is removed");
removeCookie("text_size");
});
});
test("does not show option to disable dark mode by default", async (assert) => {
test("does not show option to disable dark mode by default", async (assert) => {
await visit("/u/eviltrout/preferences/interface");
assert.equal($(".control-group.dark-mode").length, 0);
});
});
test("shows light/dark color scheme pickers", async (assert) => {
test("shows light/dark color scheme pickers", async (assert) => {
let site = Site.current();
site.set("user_color_schemes", [
{ id: 2, name: "Cool Breeze" },
@ -70,40 +69,40 @@ test("shows light/dark color scheme pickers", async (assert) => {
await visit("/u/eviltrout/preferences/interface");
assert.ok($(".light-color-scheme").length, "has regular dropdown");
assert.ok($(".dark-color-scheme").length, "has dark color scheme dropdown");
});
});
function interfacePretender(server, helper) {
acceptance(
"User Preferences Color Schemes (with default dark scheme)",
function (needs) {
needs.user();
needs.settings({ default_dark_mode_color_scheme_id: 1 });
needs.pretender((server, helper) => {
server.get("/color-scheme-stylesheet/2.json", () => {
return helper.response({
success: "OK",
});
});
}
});
acceptance("User Preferences Color Schemes (with default dark scheme)", {
loggedIn: true,
settings: { default_dark_mode_color_scheme_id: 1 },
pretend: interfacePretender,
});
test("show option to disable dark mode", async (assert) => {
test("show option to disable dark mode", async (assert) => {
await visit("/u/eviltrout/preferences/interface");
assert.ok(
$(".control-group.dark-mode").length,
"it has the option to disable dark mode"
);
});
});
test("no color scheme picker by default", async (assert) => {
test("no color scheme picker by default", async (assert) => {
let site = Site.current();
site.set("user_color_schemes", []);
await visit("/u/eviltrout/preferences/interface");
assert.equal($(".control-group.color-scheme").length, 0);
});
});
test("light color scheme picker", async (assert) => {
test("light color scheme picker", async (assert) => {
let site = Site.current();
site.set("user_color_schemes", [{ id: 2, name: "Cool Breeze" }]);
@ -114,9 +113,9 @@ test("light color scheme picker", async (assert) => {
0,
"does not have a dark color scheme picker"
);
});
});
test("light and dark color scheme pickers", async (assert) => {
test("light and dark color scheme pickers", async (assert) => {
let site = Site.current();
let session = Session.current();
session.userDarkSchemeId = 1; // same as default set in site settings
@ -136,7 +135,10 @@ test("light and dark color scheme pickers", async (assert) => {
await visit("/u/eviltrout/preferences/interface");
assert.ok($(".light-color-scheme").length, "has regular dropdown");
assert.ok($(".dark-color-scheme").length, "has dark color scheme dropdown");
assert.ok(
$(".dark-color-scheme").length,
"has dark color scheme dropdown"
);
assert.equal(
$(".dark-color-scheme .selected-name").data("value"),
session.userDarkSchemeId,
@ -196,4 +198,6 @@ test("light and dark color scheme pickers", async (assert) => {
session.userDarkSchemeId,
"resets dark scheme dropdown"
);
});
});
}
);

View File

@ -2,12 +2,11 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender";
import Draft from "discourse/models/draft";
import { Promise } from "rsvp";
acceptance("User", { loggedIn: true });
acceptance("User Routes", function (needs) {
needs.user();
test("Invalid usernames", async (assert) => {
test("Invalid usernames", async (assert) => {
pretender.get("/u/eviltrout%2F..%2F..%2F.json", () => {
return [400, { "Content-Type": "application/json" }, {}];
});
@ -15,25 +14,25 @@ test("Invalid usernames", async (assert) => {
await visit("/u/eviltrout%2F..%2F..%2F/summary");
assert.equal(currentPath(), "exception-unknown");
});
});
test("Unicode usernames", async (assert) => {
test("Unicode usernames", async (assert) => {
await visit("/u/%E3%83%A9%E3%82%A4%E3%82%AA%E3%83%B3/summary");
assert.equal(currentPath(), "user.summary");
});
});
test("Invites", async (assert) => {
test("Invites", async (assert) => {
await visit("/u/eviltrout/invited/pending");
assert.ok($("body.user-invites-page").length, "has the body class");
});
});
test("Messages", async (assert) => {
test("Messages", async (assert) => {
await visit("/u/eviltrout/messages");
assert.ok($("body.user-messages-page").length, "has the body class");
});
});
test("Notifications", async (assert) => {
test("Notifications", async (assert) => {
await visit("/u/eviltrout/notifications");
assert.ok($("body.user-notifications-page").length, "has the body class");
@ -44,9 +43,9 @@ test("Notifications", async (assert) => {
"/u/eviltrout/notifications/likes-received?acting_username=aquaman"
)
);
});
});
test("Root URL - Viewing Self", async (assert) => {
test("Root URL - Viewing Self", async (assert) => {
await visit("/u/eviltrout");
assert.ok($("body.user-activity-page").length, "has the body class");
assert.equal(
@ -55,9 +54,9 @@ test("Root URL - Viewing Self", async (assert) => {
"it defaults to activity"
);
assert.ok(exists(".container.viewing-self"), "has the viewing-self class");
});
});
test("Viewing Summary", async (assert) => {
test("Viewing Summary", async (assert) => {
await visit("/u/eviltrout/summary");
assert.ok(exists(".replies-section li a"), "replies");
@ -67,17 +66,13 @@ test("Viewing Summary", async (assert) => {
assert.ok(exists(".liked-by-section .user-info"), "liked by");
assert.ok(exists(".liked-section .user-info"), "liked");
assert.ok(exists(".badges-section .badge-card"), "badges");
assert.ok(exists(".top-categories-section .category-link"), "top categories");
});
test("Viewing Drafts", async (assert) => {
sandbox.stub(Draft, "get").returns(
Promise.resolve({
draft: null,
draft_sequence: 0,
})
assert.ok(
exists(".top-categories-section .category-link"),
"top categories"
);
});
test("Viewing Drafts", async (assert) => {
await visit("/u/eviltrout/activity/drafts");
assert.ok(exists(".user-stream"), "has drafts stream");
assert.ok(
@ -90,5 +85,5 @@ test("Viewing Drafts", async (assert) => {
exists(".d-editor-input"),
"composer is visible after resuming a draft"
);
sandbox.restore();
});
});

View File

@ -2,27 +2,27 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("User Directory");
test("Visit Page", async (assert) => {
acceptance("User Directory", function () {
test("Visit Page", async (assert) => {
await visit("/u");
assert.ok($("body.users-page").length, "has the body class");
assert.ok(exists(".directory table tr"), "has a list of users");
});
});
test("Visit All Time", async (assert) => {
test("Visit All Time", async (assert) => {
await visit("/u?period=all");
assert.ok(exists(".time-read"), "has time read column");
});
});
test("Visit Without Usernames", async (assert) => {
test("Visit Without Usernames", async (assert) => {
await visit("/u?exclude_usernames=system");
assert.ok($("body.users-page").length, "has the body class");
assert.ok(exists(".directory table tr"), "has a list of users");
});
});
test("Visit With Group Filter", async (assert) => {
test("Visit With Group Filter", async (assert) => {
await visit("/u?group=trust_level_0");
assert.ok($("body.users-page").length, "has the body class");
assert.ok(exists(".directory table tr"), "has a list of users");
});
});

View File

@ -129,6 +129,8 @@ export function applyDefaultHandlers(pretender) {
];
});
pretender.delete("/bookmarks/:id", () => response({}));
pretender.get("/tags/filter/search", () => {
return response({ results: [{ text: "monkey", count: 1 }] });
});
@ -279,12 +281,7 @@ export function applyDefaultHandlers(pretender) {
pretender.put("/t/:id/recover", success);
pretender.put("/t/:id/publish", success);
pretender.get("/permalink-check.json", () => {
return response({
found: false,
html: "<div class='page-not-found'>not found</div>",
});
});
pretender.get("/permalink-check.json", () => response({ found: false }));
pretender.delete("/draft.json", success);
pretender.post("/draft.json", success);

View File

@ -146,6 +146,11 @@ export function discourseModule(name, hooks) {
export function addPretenderCallback(name, fn) {
if (name && fn) {
if (_pretenderCallbacks[name]) {
// eslint-disable-next-line no-console
throw `There is already a pretender callback with module name (${name}).`;
}
_pretenderCallbacks[name] = fn;
}
}
@ -159,7 +164,7 @@ export function acceptance(name, optionsOrCallback) {
callback = optionsOrCallback;
} else if (typeof optionsOrCallback === "object") {
deprecated(
"The second parameter to `acceptance` should be a function that encloses your tests.",
`${name}: The second parameter to \`acceptance\` should be a function that encloses your tests.`,
{ since: "2.6.0" }
);
options = optionsOrCallback;
@ -168,6 +173,7 @@ export function acceptance(name, optionsOrCallback) {
addPretenderCallback(name, options.pretend);
let loggedIn = false;
let mobileView = false;
let siteChanges;
let settingChanges;
let userChanges;
@ -180,7 +186,7 @@ export function acceptance(name, optionsOrCallback) {
HeaderComponent.reopen({ examineDockHeader: function () {} });
resetExtraClasses();
if (options.mobileView) {
if (mobileView) {
forceMobile();
}
@ -266,6 +272,9 @@ export function acceptance(name, optionsOrCallback) {
settings(changes) {
settingChanges = changes;
},
mobileView() {
mobileView = true;
},
};
if (options.loggedIn) {
@ -277,6 +286,9 @@ export function acceptance(name, optionsOrCallback) {
if (options.settings) {
needs.settings(options.settings);
}
if (options.mobileView) {
needs.mobileView();
}
if (callback) {
// New, preferred way

View File

@ -71,8 +71,8 @@ export default function setupTests(app, container) {
QUnit.testStart(function (ctx) {
let settings = resetSettings();
server = createPretender;
applyDefaultHandlers(server);
server.handlers = [];
applyDefaultHandlers(server);
server.prepareBody = function (body) {
if (body && typeof body === "object") {

View File

@ -3,14 +3,11 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("Details Button", {
loggedIn: true,
beforeEach: function () {
clearPopupMenuOptionsCallback();
},
});
acceptance("Details Button", function (needs) {
needs.user();
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
test("details button", async (assert) => {
test("details button", async (assert) => {
const popupMenu = selectKit(".toolbar-popup-menu-options");
await visit("/");
@ -108,9 +105,9 @@ test("details button", async (assert) => {
49,
"it should end highlighting at the right position"
);
});
});
test("details button surrounds all selected text in a single details block", async (assert) => {
test("details button surrounds all selected text in a single details block", async (assert) => {
const multilineInput = "first line\n\nsecond line\n\nthird line";
const popupMenu = selectKit(".toolbar-popup-menu-options");
@ -132,4 +129,5 @@ test("details button surrounds all selected text in a single details block", asy
)}"]\n${multilineInput}\n[/details]\n`,
"it should contain the right output"
);
});
});

View File

@ -1,11 +1,10 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Local Dates - composer", {
loggedIn: true,
settings: { discourse_local_dates_enabled: true },
});
acceptance("Local Dates - composer", function (needs) {
needs.user();
needs.settings({ discourse_local_dates_enabled: true });
test("composer bbcode", async (assert) => {
test("composer bbcode", async (assert) => {
const getAttr = (attr) => {
return find(".d-editor-preview .discourse-local-date.cooked-date").attr(
`data-${attr}`
@ -33,7 +32,11 @@ test("composer bbcode", async (assert) => {
"Europe/Paris|America/Los_Angeles",
"it has the correct timezones"
);
assert.equal(getAttr("recurring"), "1.weeks", "it has the correct recurring");
assert.equal(
getAttr("recurring"),
"1.weeks",
"it has the correct recurring"
);
assert.equal(
getAttr("timezone"),
"Asia/Calcutta",
@ -47,4 +50,5 @@ test("composer bbcode", async (assert) => {
assert.equal(getAttr("date"), "2017-10-24", "it has the correct date");
assert.notOk(getAttr("time"), "it doesnt have time");
});
});

View File

@ -1,17 +1,15 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import { Promise } from "rsvp";
acceptance("Poll breakdown", {
loggedIn: true,
settings: { poll_enabled: true, poll_groupable_user_fields: "something" },
beforeEach() {
clearPopupMenuOptionsCallback();
},
pretend(server, helper) {
server.get("/polls/grouped_poll_results.json", () => {
return new Promise((resolve) => {
resolve(
acceptance("Poll breakdown", function (needs) {
needs.user();
needs.settings({
poll_enabled: true,
poll_groupable_user_fields: "something",
});
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
needs.pretender((server, helper) => {
server.get("/polls/grouped_poll_results.json", () =>
helper.response({
grouped_results: [
{
@ -58,11 +56,8 @@ acceptance("Poll breakdown", {
})
);
});
});
},
});
test("Displaying the poll breakdown modal", async (assert) => {
test("Displaying the poll breakdown modal", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll");
assert.equal(
@ -89,9 +84,9 @@ test("Displaying the poll breakdown modal", async (assert) => {
find(".poll-breakdown-chart-container > canvas")[0].$chartjs,
"$chartjs is defined on the pie charts"
);
});
});
test("Changing the display mode from percentage to count", async (assert) => {
test("Changing the display mode from percentage to count", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll");
await click(".poll-show-breakdown:first");
@ -116,4 +111,5 @@ test("Changing the display mode from percentage to count", async (assert) => {
"20.0%",
"displays the percentage again"
);
});
});

View File

@ -1,19 +1,19 @@
import { acceptance, updateCurrentUser } from "discourse/tests/helpers/qunit-helpers";
import {
acceptance,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Poll Builder - polls are disabled", {
loggedIn: true,
settings: {
acceptance("Poll Builder - polls are disabled", function (needs) {
needs.user();
needs.settings({
poll_enabled: false,
poll_minimum_trust_level_to_create: 2,
},
beforeEach: function () {
clearPopupMenuOptionsCallback();
},
});
});
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
test("regular user - sufficient trust level", async (assert) => {
test("regular user - sufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 3 });
await displayPollBuilderButton();
@ -22,9 +22,9 @@ test("regular user - sufficient trust level", async (assert) => {
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
});
test("regular user - insufficient trust level", async (assert) => {
test("regular user - insufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await displayPollBuilderButton();
@ -33,9 +33,9 @@ test("regular user - insufficient trust level", async (assert) => {
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
});
test("staff", async (assert) => {
test("staff", async (assert) => {
updateCurrentUser({ moderator: true });
await displayPollBuilderButton();
@ -44,4 +44,5 @@ test("staff", async (assert) => {
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
});

View File

@ -1,20 +1,20 @@
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance, updateCurrentUser } from "discourse/tests/helpers/qunit-helpers";
import {
acceptance,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Poll Builder - polls are enabled", {
loggedIn: true,
settings: {
acceptance("Poll Builder - polls are enabled", function (needs) {
needs.user();
needs.settings({
poll_enabled: true,
poll_minimum_trust_level_to_create: 1,
},
beforeEach() {
clearPopupMenuOptionsCallback();
},
});
});
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
test("regular user - sufficient trust level", async (assert) => {
test("regular user - sufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await displayPollBuilderButton();
@ -23,9 +23,9 @@ test("regular user - sufficient trust level", async (assert) => {
exists(".select-kit-row[title='Build Poll']"),
"it shows the builder button"
);
});
});
test("regular user - insufficient trust level", async (assert) => {
test("regular user - insufficient trust level", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 0 });
await displayPollBuilderButton();
@ -34,9 +34,9 @@ test("regular user - insufficient trust level", async (assert) => {
!exists(".select-kit-row[title='Build Poll']"),
"it hides the builder button"
);
});
});
test("staff - with insufficient trust level", async (assert) => {
test("staff - with insufficient trust level", async (assert) => {
updateCurrentUser({ moderator: true, trust_level: 0 });
await displayPollBuilderButton();
@ -45,9 +45,9 @@ test("staff - with insufficient trust level", async (assert) => {
exists(".select-kit-row[title='Build Poll']"),
"it shows the builder button"
);
});
});
test("poll preview", async (assert) => {
test("poll preview", async (assert) => {
await displayPollBuilderButton();
const popupMenu = selectKit(".toolbar-popup-menu-options");
@ -55,6 +55,13 @@ test("poll preview", async (assert) => {
await fillIn(".poll-textarea textarea", "First option\nSecond option");
assert.equal(find(".d-editor-preview li:first-child").text(), "First option");
assert.equal(find(".d-editor-preview li:last-child").text(), "Second option");
assert.equal(
find(".d-editor-preview li:first-child").text(),
"First option"
);
assert.equal(
find(".d-editor-preview li:last-child").text(),
"Second option"
);
});
});

View File

@ -1,11 +1,13 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Rendering polls with pie charts", {
loggedIn: true,
settings: { poll_enabled: true, poll_groupable_user_fields: "something" },
});
acceptance("Rendering polls with pie charts", function (needs) {
needs.user();
needs.settings({
poll_enabled: true,
poll_groupable_user_fields: "something",
});
test("Displays the pie chart", async (assert) => {
test("Displays the pie chart", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll");
const poll = find(".poll")[0];
@ -33,4 +35,5 @@ test("Displays the pie chart", async (assert) => {
1,
"Renders the chart div instead of bar container"
);
});
});

View File

@ -1,18 +1,16 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import { Promise } from "rsvp";
acceptance("Poll quote", {
loggedIn: true,
settings: { poll_enabled: true },
beforeEach() {
acceptance("Poll quote", function (needs) {
needs.user();
needs.settings({ poll_enabled: true });
needs.hooks.beforeEach(() => {
clearPopupMenuOptionsCallback();
},
pretend(server, helper) {
});
needs.pretender((server, helper) => {
server.get("/t/topic_with_two_polls.json", () => {
return new Promise((resolve) => {
resolve(
helper.response({
return helper.response({
post_stream: {
posts: [
{
@ -259,20 +257,15 @@ acceptance("Poll quote", {
},
},
pending_posts: [],
})
);
});
});
server.get("/posts/by_number/130/1", () => {
return new Promise((resolve) => {
resolve(
helper.response({
return helper.response({
id: 133,
name: null,
username: "bianca",
avatar_template:
"/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
avatar_template: "/letter_avatar_proxy/v4/letter/b/3be4f8/{size}.png",
created_at: "2020-08-17T12:05:24.577Z",
cooked:
'<div class="poll" data-poll-status="open" data-poll-name="poll1" data-poll-results="always" data-poll-charttype="bar" data-poll-type="regular">\n<div>\n<div class="poll-container">\n<ul>\n<li data-poll-option-id="bf48cd4958a17180e2a298e246988f94">Alpha</li>\n<li data-poll-option-id="c19aa835729ab0413a84a2c9850c4005">Beta</li>\n</ul>\n</div>\n<div class="poll-info">\n<p>\n<span class="info-number">0</span>\n<span class="info-label">voters</span>\n</p>\n</div>\n</div>\n</div>\n<div class="poll" data-poll-status="open" data-poll-name="poll2" data-poll-results="always" data-poll-charttype="bar" data-poll-type="regular">\n<div>\n<div class="poll-container">\n<ul>\n<li data-poll-option-id="def034c6770c6fd3754c054ef9ec4721">First</li>\n<li data-poll-option-id="e0f55d1a981683789bec2a0b05eb70ef">Second</li>\n</ul>\n</div>\n<div class="poll-info">\n<p>\n<span class="info-number">0</span>\n<span class="info-label">voters</span>\n</p>\n</div>\n</div>\n</div>',
@ -379,15 +372,11 @@ acceptance("Poll quote", {
chart_type: "bar",
},
],
})
);
});
});
server.get("/t/topic_with_two_quoted_polls.json", () => {
return new Promise((resolve) => {
resolve(
helper.response({
return helper.response({
post_stream: {
posts: [
{
@ -424,8 +413,7 @@ acceptance("Poll quote", {
can_wiki: true,
link_counts: [
{
url:
"http://forum.example.com/t/topic-with-two-polls/130",
url: "http://forum.example.com/t/topic-with-two-polls/130",
internal: true,
reflection: false,
title: "Topic with two polls",
@ -683,15 +671,13 @@ acceptance("Poll quote", {
},
},
pending_posts: [],
})
);
});
});
},
});
});
test("Quoted polls", async (assert) => {
test("Quoted polls", async (assert) => {
await visit("/t/-/topic_with_two_quoted_polls");
await click(".quote-controls");
assert.equal(find(".poll").length, 2);
});
});

View File

@ -1,13 +1,13 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Rendering polls with bar charts - desktop", {
loggedIn: true,
settings: { poll_enabled: true },
beforeEach() {
acceptance("Rendering polls with bar charts - desktop", function (needs) {
needs.user();
needs.settings({ poll_enabled: true });
needs.hooks.beforeEach(() => {
clearPopupMenuOptionsCallback();
},
pretend(server) {
});
needs.pretender((server, helper) => {
server.get("/polls/voters.json", (request) => {
let body = {};
if (
@ -35,12 +35,11 @@ acceptance("Rendering polls with bar charts - desktop", {
})),
};
}
return [200, { "Content-Type": "application/json" }, body];
return helper.response(body);
});
});
},
});
test("Polls", async (assert) => {
test("Polls", async (assert) => {
await visit("/t/-/15");
const polls = find(".poll");
@ -58,9 +57,9 @@ test("Polls", async (assert) => {
"3",
"it should display the right number of votes"
);
});
});
test("Public poll", async (assert) => {
test("Public poll", async (assert) => {
await visit("/t/-/14");
const polls = find(".poll");
@ -81,9 +80,9 @@ test("Public poll", async (assert) => {
26,
"it should display the right number of voters"
);
});
});
test("Public number poll", async (assert) => {
test("Public number poll", async (assert) => {
await visit("/t/-/13");
const polls = find(".poll");
@ -109,4 +108,5 @@ test("Public number poll", async (assert) => {
30,
"it should display the right number of voters"
);
});
});

View File

@ -1,31 +1,27 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Rendering polls with bar charts - mobile", {
loggedIn: true,
mobileView: true,
settings: { poll_enabled: true },
beforeEach() {
clearPopupMenuOptionsCallback();
},
pretend(server) {
// eslint-disable-next-line
acceptance("Rendering polls with bar charts - mobile", function (needs) {
needs.user();
needs.mobileView();
needs.settings({ poll_enabled: true });
needs.pretender((server, helper) => {
server.get("/polls/voters.json", () => {
const body = {
return helper.response({
voters: Array.from(new Array(10), (_, i) => ({
id: 500 + i,
username: `bruce${500 + i}`,
avatar_template: "/images/avatar.png",
name: "Bruce Wayne",
})),
};
return [200, { "Content-Type": "application/json" }, body];
});
},
});
});
});
needs.hooks.beforeEach(() => {
clearPopupMenuOptionsCallback();
});
test("Public number poll", async (assert) => {
test("Public number poll", async (assert) => {
await visit("/t/-/13");
const polls = find(".poll");
@ -51,4 +47,5 @@ test("Public number poll", async (assert) => {
35,
"it should display the right number of voters"
);
});
});