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,16 +9,13 @@ 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) => {
@ -208,7 +205,10 @@ 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(),
@ -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");
@ -291,7 +294,10 @@ test("Can edit a post after starting a reply", 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");
@ -312,7 +318,10 @@ test("Create an enqueued 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", "enqueue this content please");
await click("#reply-control button.create");
@ -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"
);
@ -604,7 +614,10 @@ 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 {
@ -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"
);
@ -811,3 +826,4 @@ test("Image resizing buttons", async (assert) => {
"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,7 +23,23 @@ 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) => {
@ -56,3 +55,4 @@ test("Visit subcategory by slug", async (assert) => {
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,7 +91,6 @@ acceptance("Group logs", {
});
}
});
},
});
test("Browsing group logs", async (assert) => {
@ -107,3 +106,4 @@ test("Browsing group logs", async (assert) => {
"it should display the right number of logs"
);
});
});

View File

@ -6,9 +6,8 @@ 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) => {
updateCurrentUser({ can_create_group: true });
@ -69,7 +68,9 @@ 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");
@ -122,3 +123,4 @@ test("As a group owner", async (assert) => {
"it should disable group allow_membership_request input"
);
});
});

View File

@ -5,7 +5,7 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Managing Group Profile");
acceptance("Managing Group Profile", function () {
test("As an anonymous user", async (assert) => {
await visit("/g/discourse/manage/profile");
@ -14,8 +14,10 @@ test("As an anonymous user", async (assert) => {
"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) => {
await visit("/g/discourse/manage/profile");
@ -53,3 +55,4 @@ test("As a group owner", async (assert) => {
"it should not display group name input"
);
});
});

View File

@ -5,7 +5,7 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Managing Group Tag Notification Defaults");
acceptance("Managing Group Tag Notification Defaults", function () {
test("As an anonymous user", async (assert) => {
await visit("/g/discourse/manage/tags");
@ -14,8 +14,10 @@ test("As an anonymous user", async (assert) => {
"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) => {
await visit("/g/discourse/manage/tags");
@ -36,3 +38,4 @@ test("As a group owner", async (assert) => {
"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,11 +76,10 @@ 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) => {
@ -125,3 +125,4 @@ test("Group Requests", async (assert) => {
["20", undefined],
]);
});
});

View File

@ -3,26 +3,22 @@ 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) {
await visit("/g/discourse");
@ -88,65 +84,25 @@ test("Anonymous Viewing Automatic Group", async (assert) => {
"it does not show group messages navigation link"
);
});
acceptance("Group", Object.assign({ loggedIn: true }, groupArgs));
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",
acceptance("Group - Authenticated", function (needs) {
setupGroupTest(needs);
needs.user();
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']");
@ -286,3 +288,4 @@ test("Moderator Viewing Group", async (assert) => {
I18n.t("groups.members.make_owner")
);
});
});

View File

@ -2,8 +2,7 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Groups");
acceptance("Groups", function () {
test("Browsing Groups", async (assert) => {
await visit("/g?username=eviltrout");
@ -47,3 +46,4 @@ test("Browsing Groups", async (assert) => {
assert.ok(exists(".modal.login-modal"), "it shows the login modal");
});
});

View File

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

View File

@ -5,13 +5,13 @@ 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) => {
updateCurrentUser({ moderator: true, admin: false });
@ -20,3 +20,4 @@ test("As a staff member", async (assert) => {
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,7 +15,6 @@ acceptance("Category and Tag Hashtags", {
},
});
});
},
});
test("hashtags are cooked properly", async (assert) => {
@ -38,3 +37,4 @@ category vs tag: #bug vs #bug::tag`
<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,11 +3,8 @@ 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) => {
PreloadStore.store("invite_info", {
@ -82,3 +79,4 @@ test("Invite Acceptance Page", async (assert) => {
"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,7 +25,6 @@ acceptance("Accept Invite - User Fields", {
required: false,
},
],
},
});
test("accept invite with user fields", async (assert) => {
@ -79,3 +78,4 @@ test("accept invite with user fields", async (assert) => {
"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,7 +18,6 @@ acceptance("Jump to", {
return helper.response(404, null);
});
},
});
test("default", async (assert) => {
@ -52,3 +50,4 @@ test("invalid date", async (assert) => {
"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,7 +2,7 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Login redirect");
acceptance("Login redirect - anonymous", function () {
test("redirects login to default homepage", async function (assert) {
await visit("/login");
assert.equal(
@ -11,11 +11,11 @@ test("redirects login to default homepage", async function (assert) {
"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) {
@ -26,3 +26,4 @@ test("when site setting is categories", async function (assert) {
"it works when categories is the homepage"
);
});
});

View File

@ -2,18 +2,19 @@ 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) => {
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");
@ -21,3 +22,4 @@ test("redirect", async (assert) => {
await click(".modal-header .close");
assert.ok(invisible(".login-modal"), "it closes the login modal");
});
});

View File

@ -2,22 +2,17 @@ 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" });
});
},
needs.pretender((server, helper) => {
server.post("/u/email-login", () => {
return helper.response({ success: "OK" });
});
});
test("with hide_email_address_taken enabled", async (assert) => {
@ -34,3 +29,4 @@ test("with hide_email_address_taken enabled", async (assert) => {
"it should display the success message for any email address"
);
});
});

View File

@ -2,15 +2,11 @@ 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) => {
await visit("/");
await click("header .login-button");
@ -24,3 +20,4 @@ test("with login with email disabled", async (assert) => {
assert.notOk(find(".login-buttons").is(":visible"));
});
});

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("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) => {
@ -23,3 +22,4 @@ test("with email button", async (assert) => {
"it displays the login with email button"
);
});
});

View File

@ -3,18 +3,17 @@ 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) => {
@ -80,3 +79,4 @@ test("with email button", async (assert) => {
userFound = false;
});
});

View File

@ -1,8 +1,9 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic Discovery - Mobile", { mobileView: true });
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");
@ -11,3 +12,4 @@ test("Visit Discovery Pages", async (assert) => {
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 });
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 });
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;
},
});
skip("modal", async function (assert) {
needs.hooks.afterEach(() => {
I18n.translations = _translations;
});
test("modal", async function (assert) {
await visit("/");
assert.ok(
@ -126,8 +125,10 @@ test("modal title", async function (assert) {
"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) {
await visit("/t/internationalization-localization/280");
@ -161,3 +162,4 @@ test("modal-keyboard-events", async function (assert) {
"modal should disappear on hitting Enter"
);
});
});

View File

@ -2,8 +2,7 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("New Message");
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"
@ -11,8 +10,11 @@ test("accessing new-message route when logged out", async (assert) => {
assert.ok(exists(".modal.login-modal"), "it shows the login modal");
});
});
acceptance("New Message - Authenticated", function (needs) {
needs.user();
acceptance("New Message", { loggedIn: true });
test("accessing new-message route when logged in", async (assert) => {
await visit(
"/new-message?username=charlie&title=message%20title&body=message%20body"
@ -35,3 +37,4 @@ test("accessing new-message route when logged in", async (assert) => {
"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");
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 });
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");
await visit(
"/new-topic?title=topic%20title&body=topic%20body&category=bug"
);
assert.ok(exists(".composer-fields"), "it opens composer");
assert.equal(
@ -32,3 +35,4 @@ test("accessing new-topic route when logged in", async (assert) => {
"it selects desired category"
);
});
});

View File

@ -3,9 +3,8 @@ 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) => {
await visit("/u/eviltrout/notifications");
@ -32,3 +31,4 @@ test("Notifications filter unread", async (assert) => {
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,8 +22,8 @@ acceptance("Page Publishing", {
reason: "i don't need a reason",
});
});
},
});
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");
@ -40,3 +40,4 @@ 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,24 +36,23 @@ 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) => {
@ -78,8 +77,9 @@ 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"
);
@ -120,3 +120,4 @@ test("Password Reset Page With Second Factor", async (assert) => {
assert.ok(!exists(".password-reset form"), "form is gone");
});
});

View File

@ -3,9 +3,8 @@ 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) => {
await visit("/t/pm-for-testing/12");
@ -24,3 +23,4 @@ test("suggested messages", async (assert) => {
I18n.t("suggested_topics.pm_title")
);
});
});

View File

@ -5,13 +5,11 @@ 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) => {
withPluginApi("0.8.38", (api) => {
api.addKeyboardShortcut("]", () => {
@ -29,14 +27,12 @@ test("a plugin can add a keyboard shortcut", async (assert) => {
"the keyboard shortcut callback fires successfully"
);
});
acceptance("Plugin Keyboard Shortcuts - Anonymous", {
loggedIn: false,
beforeEach() {
KeyboardShortcutInitializer.initialize(this.container);
},
});
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) => {
let spy = sandbox.spy(KeyboardShortcuts, "_bindToPath");
withPluginApi("0.8.38", (api) => {
@ -51,3 +47,4 @@ test("a plugin can add a keyboard shortcut with an option", async (assert) => {
"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,13 +58,12 @@ 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) => {
@ -87,3 +87,4 @@ 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,12 +33,11 @@ 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) => {
@ -58,3 +58,4 @@ test("Calls the plugin callback with the rendered outlet", async (assert) => {
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,13 +16,12 @@ 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) => {
@ -46,3 +45,4 @@ test("Renders a template into the outlet", async (assert) => {
"it renders into the outlet"
);
});
});

View File

@ -4,16 +4,16 @@ 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) => {
@ -28,3 +28,4 @@ test("Renders a template into the outlet", async (assert) => {
"it renders into the outlet"
);
});
});

View File

@ -2,8 +2,7 @@ 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 });
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");
@ -18,9 +17,10 @@ test("Enter as a anon user", async (assert) => {
"The wrench button was not rendered"
);
});
});
acceptance("Post - Admin Menu", { loggedIn: true });
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");
@ -32,3 +32,4 @@ test("Enter as a user with group moderator permissions", async (assert) => {
);
assert.ok(exists(".add-notice"), "The add notice button was rendered");
});
});

View File

@ -66,11 +66,9 @@ function preferencesPretender(server, helper) {
});
}
acceptance("User Preferences", {
loggedIn: true,
pretend: preferencesPretender,
});
acceptance("User Preferences", function (needs) {
needs.user();
needs.pretender(preferencesPretender);
test("update some fields", async (assert) => {
await visit("/u/eviltrout/preferences");
@ -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);
@ -240,10 +240,11 @@ test("default avatar selector", async (assert) => {
"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,8 +261,8 @@ acceptance("Second Factor Backups", {
server.get("/u/eviltrout/activity.json", () => {
return helper.response({});
});
},
});
test("second factor backup", async (assert) => {
updateCurrentUser({ second_factor_enabled: true });
await visit("/u/eviltrout/preferences/second-factor");
@ -274,11 +275,14 @@ test("second factor backup", async (assert) => {
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,22 +290,21 @@ acceptance("Avatar selector when selectable avatars is enabled", {
["https://www.discourse.org", "https://meta.discourse.org"],
];
});
},
});
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) => {
await visit("/u/eviltrout/preferences");
@ -352,22 +355,20 @@ test("recently connected devices", async (assert) => {
"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) => {
await visit("/u/eviltrout/preferences/profile");
@ -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");
@ -403,10 +407,12 @@ test("setting featured topic on profile", async (assert) => {
"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,9 +422,8 @@ acceptance("Custom User Fields", {
required: true,
},
],
},
pretend: preferencesPretender,
});
needs.pretender(preferencesPretender);
test("can select an option from a dropdown", async (assert) => {
await visit("/u/eviltrout/preferences/profile");
@ -430,18 +435,21 @@ 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) => {
await visit("/u/eviltrout/preferences/interface");
@ -459,3 +467,5 @@ test("selecting bookmarks as home directs home to bookmarks", async (assert) =>
"it navigates to bookmarks"
);
});
}
);

View File

@ -10,19 +10,17 @@ 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() {
removeRawTemplate(CONNECTOR);
},
});
needs.hooks.afterEach(() => {
removeRawTemplate(CONNECTOR);
});
test("Renders the raw plugin outlet", async (assert) => {
await visit("/");
assert.ok(find(".topic-lala").length > 0, "it renders the outlet");
@ -32,3 +30,4 @@ test("Renders the raw plugin outlet", async (assert) => {
"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,9 +17,8 @@ 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) => {
updateCurrentUser({
@ -31,7 +30,11 @@ 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) => {
@ -59,3 +62,4 @@ test("redirects root to All top", async (assert) => {
await visit("/");
assert.equal(currentPath(), "discovery.topAll", "it works for root");
});
});

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("Reports", {
loggedIn: true,
});
acceptance("Reports", function (needs) {
needs.user();
test("Visit reports page", async (assert) => {
await visit("/admin/reports");
@ -26,3 +25,4 @@ test("Visit report page", async (assert) => {
assert.ok(exists(".export-csv-btn"));
});
});

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("Review", {
loggedIn: true,
});
acceptance("Review", function (needs) {
needs.user();
const user = ".reviewable-item[data-reviewable-id=1234]";
@ -132,3 +131,4 @@ 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,7 +87,6 @@ acceptance("Search - Full Page", {
],
});
});
},
});
test("perform various searches", async (assert) => {
@ -421,3 +420,4 @@ test("validate advanced search when initially empty", async (assert) => {
"does not populate the likes checkbox"
);
});
});

View File

@ -2,7 +2,8 @@ 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) => {
await visit("/");
@ -41,3 +42,4 @@ test("search", async (assert) => {
"it does not reset input when hitting search icon again"
);
});
});

View File

@ -2,22 +2,20 @@ 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) => {
await visit("/");
@ -42,7 +40,10 @@ 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) => {
@ -110,17 +111,12 @@ 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");
@ -150,8 +146,10 @@ test("Right filters are shown to anonymous users", async (assert) => {
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) => {
const inSelector = selectKit(".select-kit#in");
@ -175,15 +173,11 @@ test("Right filters are shown to logged-in users", async (assert) => {
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) => {
await visit("/");
@ -199,3 +193,4 @@ test("displays tags", async (assert) => {
assert.equal(tags, "dev slow");
});
});

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("Share and Invite modal - desktop", {
loggedIn: true,
});
acceptance("Share and Invite modal - desktop", function (needs) {
needs.user();
test("Topic footer button", async (assert) => {
await visit("/t/internationalization-localization/280");
@ -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"
);
@ -72,14 +73,11 @@ test("Post date link", async (assert) => {
assert.ok(exists("#share-link"), "it shows the share modal");
});
acceptance("Share url with badges disabled - desktop", {
loggedIn: true,
settings: {
enable_badges: false,
},
});
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");
@ -91,3 +89,4 @@ test("topic footer button - badges disabled - desktop", async (assert) => {
"it doesn't add the username param when badges are disabled"
);
});
});

View File

@ -3,10 +3,9 @@ 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) => {
await visit("/t/internationalization-localization/280");
@ -62,15 +61,14 @@ test("Post date link", async (assert) => {
assert.ok(exists("#share-link"), "it shows the share modal");
});
acceptance("Share url with badges disabled - mobile", {
loggedIn: true,
mobileView: true,
settings: {
enable_badges: false,
},
});
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) => {
await visit("/t/internationalization-localization/280");
@ -85,3 +83,4 @@ test("topic footer button - badges disabled - mobile", async (assert) => {
"it doesn't add the username param when badges are disabled"
);
});
});

View File

@ -3,8 +3,7 @@ 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 });
acceptance("Shared Drafts", function () {
test("Viewing", async (assert) => {
await visit("/t/some-topic/9");
assert.ok(find(".shared-draft-controls").length === 1);
@ -16,3 +15,4 @@ test("Viewing", async (assert) => {
assert.ok(find(".shared-draft-controls").length === 0);
});
});

View File

@ -1,9 +1,8 @@
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");
acceptance("Signing In", function () {
test("sign in", async (assert) => {
await visit("/");
await click("header .login-button");
@ -71,7 +70,7 @@ test("sign in - not activated - edit email", async (assert) => {
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");
@ -104,7 +103,7 @@ skip("second factor", async (assert) => {
);
});
skip("security key", async (assert) => {
test("security key", async (assert) => {
await visit("/");
await click("header .login-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(
@ -197,3 +199,4 @@ test("second factor backup - invalid token", async (assert) => {
"it shows an error when the code is invalid"
);
});
});

View File

@ -1,8 +1,8 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Static");
acceptance("Static", function () {
test("Static Pages", async (assert) => {
await visit("/faq");
assert.ok($("body.static-faq").length, "has the body class");
@ -27,3 +27,4 @@ test("Static Pages", async (assert) => {
"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,7 +32,6 @@ acceptance("Tag Groups", {
},
]);
});
},
});
test("tag groups can be saved and deleted", async (assert) => {
@ -51,9 +50,7 @@ test("tag groups can be saved and deleted", async (assert) => {
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,7 +28,6 @@ acceptance("Tags intersection", {
},
});
});
},
});
test("Populate tags when creating new topic", async (assert) => {
@ -41,3 +41,4 @@ test("Populate tags when creating new topic", async (assert) => {
"populates the tags when clicking 'New topic'"
);
});
});

View File

@ -4,9 +4,9 @@ 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) => {
await visit("/tags");
@ -17,12 +17,70 @@ test("list the tags", async (assert) => {
"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 },
})
);
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) => {
@ -67,67 +125,6 @@ test("list the tags in groups", async (assert) => {
});
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: [],
},
},
]);
updateCurrentUser({ moderator: false, admin: false });
await visit("/tag/regular-tag");
@ -144,13 +141,14 @@ 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,7 +217,10 @@ acceptance("Tag info", {
],
});
});
},
server.delete("/tag/planters/synonyms/containers", () =>
helper.response({ success: true })
);
});
test("tag info can show synonyms", async (assert) => {
@ -248,12 +249,6 @@ test("tag info can show synonyms", async (assert) => {
});
test("admin can manage tags", async (assert) => {
pretender.delete("/tag/planters/synonyms/containers", () => [
200,
{ "Content-Type": "application/json" },
{ success: true },
]);
updateCurrentUser({ moderator: false, admin: true });
await visit("/tag/planters");
@ -280,3 +275,4 @@ test("admin can manage tags", async (assert) => {
"removed a synonym"
);
});
});

View File

@ -5,8 +5,7 @@ import {
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic - Admin Menu Anonymous Users", { loggedIn: false });
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");
@ -15,15 +14,19 @@ test("Enter as a regular user", async (assert) => {
"The admin menu button was not rendered"
);
});
});
acceptance("Topic - Admin Menu", { loggedIn: true });
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) => {
@ -31,7 +34,10 @@ test("Enter as a user with moderator and admin permissions", 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 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) => {
@ -46,3 +52,4 @@ test("Toggle the menu as admin focuses the first item", async (assert) => {
document.querySelector(".topic-admin-multi-select > button")
);
});
});

View File

@ -1,8 +1,8 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic - Anonymous");
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");
@ -35,3 +35,4 @@ test("Enter with 500 errors", async (assert) => {
assert.ok(!exists("#topic"), "The topic was not rendered");
assert.ok(exists(".topic-error"), "An error message is displayed");
});
});

View File

@ -5,10 +5,9 @@ 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) => {
@ -127,3 +126,4 @@ test("Using period chooser when query params are present", async (assert) => {
"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,7 +22,6 @@ acceptance("Topic - Edit timer", {
category_id: null,
})
);
},
});
test("default", async (assert) => {
@ -33,7 +32,10 @@ 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);
});
@ -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();
@ -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,8 +147,14 @@ 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();
@ -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();
@ -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();
@ -238,3 +258,4 @@ test("Inline delete timer", async (assert) => {
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,12 +30,11 @@ acceptance("Topic footer buttons mobile", {
},
});
});
},
});
afterEach() {
needs.hooks.afterEach(() => {
clearTopicFooterButtons();
_test = undefined;
},
});
test("default", async (assert) => {
@ -48,3 +48,4 @@ test("default", async (assert) => {
assert.equal(_test, 2);
});
});

View File

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

View File

@ -2,7 +2,9 @@ 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 });
acceptance("Topic move posts", function (needs) {
needs.user();
test("default", async (assert) => {
await visit("/t/internationalization-localization");
@ -140,3 +142,4 @@ test("group moderator moving posts", async (assert) => {
"it opens move to modal"
);
});
});

View File

@ -3,13 +3,13 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("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) => {
@ -58,3 +58,4 @@ test("Updating topic notification level", async (assert) => {
"it should display the right notification level"
);
});
});

View File

@ -13,12 +13,11 @@ 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) => {
@ -48,13 +47,12 @@ test("Shows quote share buttons with the right site settings", async function (a
"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) {
@ -113,3 +111,4 @@ test("Shows nothing when visibility is disabled", async function (assert) {
"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,13 +6,22 @@ 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) => {
@ -200,30 +208,21 @@ test("Suggested topics", async (assert) => {
);
});
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) => {
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: {
topic_featured_link_enabled: true,
max_topic_title_length: 80,
},
});
skip("remove featured link", async (assert) => {
acceptance("Topic featured links", function (needs) {
needs.user();
needs.settings({
topic_featured_link_enabled: true,
max_topic_title_length: 80,
});
test("remove featured link", async (assert) => {
await visit("/t/-/299/1");
assert.ok(
exists(".title-wrapper .topic-featured-link"),
@ -247,7 +246,9 @@ test("Converting to a public topic", async (assert) => {
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);
@ -266,7 +267,10 @@ 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) => {
@ -315,16 +319,6 @@ test("View Hidden Replies", async (assert) => {
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) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
@ -387,18 +381,17 @@ test("Quoting by selecting text can mark the quote as full", async (assert) => {
.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) => {
await visit("/t/internationalization-localization/280");
@ -414,3 +407,4 @@ test("Decorate topic title", async (assert) => {
"it decorates topic list item title"
);
});
});

View File

@ -1,8 +1,30 @@
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");
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");
@ -10,42 +32,12 @@ test("Permalink Unknown URL", async (assert) => {
});
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",
},
];
});
await visit("/viewtopic.php?f=8&t=280");
assert.ok(exists(".topic-post"));
assert.equal(currentURL(), "/t/internationalization-localization/280");
});
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",
},
];
});
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,18 +1,8 @@
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");
}
acceptance("User Anonymous", function () {
test("Root URL", async (assert) => {
await visit("/u/eviltrout");
assert.ok($("body.user-summary-page").length, "has the body class");
@ -22,13 +12,16 @@ test("Root URL", 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");
});
@ -48,3 +41,4 @@ test("Restricted Routes", async (assert) => {
"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;
});
});
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) => {
pretender.get("/u/eviltrout/bookmarks.json", () => [
200,
{
"Content-Type": "application/json",
},
{
bookmarks: [],
no_results_help: "no bookmarks",
},
]);
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)"
);
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));
});
test("user card local time - does not update timezone for another user", async (assert) => {
User.current().changeTimezone("Australia/Brisbane");
let cardResponse = Object.assign({}, userFixtures["/u/charlie/card.json"]);
delete cardResponse.user.timezone;
pretender.get("/u/charlie/card.json", () => [
200,
{ "Content-Type": "application/json" },
cardResponse,
]);
await visit("/t/internationalization-localization/280");
await click("a[data-user-card=charlie]:first");
@ -82,56 +24,4 @@ test("user card local time - does not update timezone for another user", async (
"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,7 +2,8 @@ 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) => {
await visit("/u/eviltrout/activity/drafts");
@ -25,3 +26,4 @@ test("Stream - resume draft", async (assert) => {
"A fun new topic for testing drafts."
);
});
});

View File

@ -6,9 +6,8 @@ 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) => {
removeCookie("text_size");
@ -71,19 +70,19 @@ test("shows light/dark color scheme pickers", async (assert) => {
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) => {
@ -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,
@ -197,3 +199,5 @@ test("light and dark color scheme pickers", async (assert) => {
"resets dark scheme dropdown"
);
});
}
);

View File

@ -2,10 +2,9 @@ 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) => {
pretender.get("/u/eviltrout%2F..%2F..%2F.json", () => {
@ -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");
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,
})
);
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,8 +2,7 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("User Directory");
acceptance("User Directory", function () {
test("Visit Page", async (assert) => {
await visit("/u");
assert.ok($("body.users-page").length, "has the body class");
@ -26,3 +25,4 @@ test("Visit With Group Filter", async (assert) => {
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,12 +3,9 @@ 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) => {
const popupMenu = selectKit(".toolbar-popup-menu-options");
@ -133,3 +130,4 @@ test("details button surrounds all selected text in a single details block", asy
"it should contain the right output"
);
});
});

View File

@ -1,9 +1,8 @@
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) => {
const getAttr = (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",
@ -48,3 +51,4 @@ 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,9 +56,6 @@ acceptance("Poll breakdown", {
})
);
});
});
},
});
test("Displaying the poll breakdown modal", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll");
@ -117,3 +112,4 @@ test("Changing the display mode from percentage to count", async (assert) => {
"displays the percentage again"
);
});
});

View File

@ -1,17 +1,17 @@
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) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 3 });
@ -45,3 +45,4 @@ test("staff", async (assert) => {
"it hides the builder button"
);
});
});

View File

@ -1,18 +1,18 @@
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) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
@ -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,8 +1,10 @@
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) => {
@ -34,3 +36,4 @@ test("Displays the pie chart", async (assert) => {
"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,11 +671,8 @@ acceptance("Poll quote", {
},
},
pending_posts: [],
})
);
});
});
},
});
test("Quoted polls", async (assert) => {
@ -695,3 +680,4 @@ test("Quoted polls", async (assert) => {
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,9 +35,8 @@ acceptance("Rendering polls with bar charts - desktop", {
})),
};
}
return [200, { "Content-Type": "application/json" }, body];
return helper.response(body);
});
},
});
test("Polls", async (assert) => {
@ -110,3 +109,4 @@ test("Public number poll", async (assert) => {
"it should display the right number of voters"
);
});
});

View File

@ -1,28 +1,24 @@
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) => {
@ -52,3 +48,4 @@ test("Public number poll", async (assert) => {
"it should display the right number of voters"
);
});
});