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,32 +356,28 @@ acceptance("Composer Actions", function (needs) {
assert.equal(composerActions.rows().length, 1); assert.equal(composerActions.rows().length, 1);
assert.equal(composerActions.rowByIndex(0).value(), "reply_to_post"); assert.equal(composerActions.rowByIndex(0).value(), "reply_to_post");
}); });
});
acceptance("Composer Actions With New Topic Draft", { function stubDraftResponse() {
loggedIn: true, sandbox.stub(Draft, "get").returns(
settings: { Promise.resolve({
enable_whispers: true, draft:
}, '{"reply":"dum de dum da ba.","action":"createTopic","title":"dum da ba dum dum","categoryId":null,"archetypeId":"regular","metaData":null,"composerTime":540879,"typingTime":3400}',
site: { draft_sequence: 0,
can_tag_topics: true, })
}, );
beforeEach() { }
_clearSnapshots();
}, acceptance("Composer Actions With New Topic Draft", function (needs) {
afterEach() { needs.user();
_clearSnapshots(); needs.settings({
}, enable_whispers: true,
}); });
needs.site({
const stubDraftResponse = () => { can_tag_topics: true,
sandbox.stub(Draft, "get").returns( });
Promise.resolve({ needs.hooks.beforeEach(() => _clearSnapshots());
draft: needs.hooks.afterEach(() => _clearSnapshots());
'{"reply":"dum de dum da ba.","action":"createTopic","title":"dum da ba dum dum","categoryId":null,"archetypeId":"regular","metaData":null,"composerTime":540879,"typingTime":3400}',
draft_sequence: 0,
})
);
};
test("shared draft", async (assert) => { test("shared draft", async (assert) => {
stubDraftResponse(); stubDraftResponse();

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.security"), "security tab");
assert.ok(exists(".dashboard .navigation-item.reports"), "reports tab"); assert.ok(exists(".dashboard .navigation-item.reports"), "reports tab");
}); });
});
acceptance("Dashboard: dashboard_hidden_reports", { acceptance("Dashboard: dashboard_hidden_reports", function (needs) {
loggedIn: true, needs.user();
settings: { needs.settings({
dashboard_visible_tabs: "reports", dashboard_visible_tabs: "reports",
dashboard_hidden_reports: "posts|dau_by_mau", dashboard_hidden_reports: "posts|dau_by_mau",
},
}); });
test("hidden reports", async (assert) => { test("hidden reports", async (assert) => {

View File

@ -3,28 +3,11 @@ import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import DiscoveryFixtures from "discourse/tests/fixtures/discovery-fixtures"; import DiscoveryFixtures from "discourse/tests/fixtures/discovery-fixtures";
acceptance("Encoded Sub Category Discovery", { acceptance("Encoded Sub Category Discovery", function (needs) {
pretend(server, helper) { needs.settings({
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: {
slug_generation_method: "encoded", slug_generation_method: "encoded",
}, });
site: { needs.site({
categories: [ categories: [
{ {
id: 5, id: 5,
@ -40,19 +23,36 @@ acceptance("Encoded Sub Category Discovery", {
parent_category_id: 5, parent_category_id: 5,
}, },
], ],
}, });
}); needs.pretender((server, helper) => {
server.get(
"/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory/6/l/latest.json",
() => {
return helper.response(
DiscoveryFixtures["/latest_can_create_topic.json"]
);
}
);
server.get(
"/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory/find_by_slug.json",
() => {
//respond with an error here: these tests are to check that ember can route this itself without falling back to rails
return helper.response(500, {});
}
);
});
test("Visit subcategory by slug", async (assert) => { test("Visit subcategory by slug", async (assert) => {
let bodySelector = let bodySelector =
"body.category-\\%E6\\%BC\\%A2\\%E5\\%AD\\%97-parent-\\%E6\\%BC\\%A2\\%E5\\%AD\\%97-subcategory"; "body.category-\\%E6\\%BC\\%A2\\%E5\\%AD\\%97-parent-\\%E6\\%BC\\%A2\\%E5\\%AD\\%97-subcategory";
await visit("/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory"); await visit("/c/%E6%BC%A2%E5%AD%97-parent/%E6%BC%A2%E5%AD%97-subcategory");
assert.ok($(bodySelector).length, "has the default navigation"); assert.ok($(bodySelector).length, "has the default navigation");
assert.ok(exists(".topic-list"), "The list of topics was rendered"); assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics"); assert.ok(exists(".topic-list .topic-list-item"), "has topics");
await visit("/c/漢字-parent/漢字-subcategory"); await visit("/c/漢字-parent/漢字-subcategory");
assert.ok($(bodySelector).length, "has the default navigation"); assert.ok($(bodySelector).length, "has the default navigation");
assert.ok(exists(".topic-list"), "The list of topics was rendered"); assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics"); 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 { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Group logs", { acceptance("Group logs", function (needs) {
loggedIn: true, needs.user();
pretend(server, helper) { needs.pretender((server, helper) => {
server.get("/groups/snorlax.json", () => { server.get("/groups/snorlax.json", () => {
return helper.response({ return helper.response({
group: { group: {
@ -91,19 +91,19 @@ acceptance("Group logs", {
}); });
} }
}); });
}, });
});
test("Browsing group logs", async (assert) => { test("Browsing group logs", async (assert) => {
await visit("/g/snorlax/manage/logs"); await visit("/g/snorlax/manage/logs");
assert.ok( assert.ok(
find("tr.group-manage-logs-row").length === 2, find("tr.group-manage-logs-row").length === 2,
"it should display the right number of logs" "it should display the right number of logs"
); );
await click(find(".group-manage-logs-row button")[0]); await click(find(".group-manage-logs-row button")[0]);
assert.ok( assert.ok(
find("tr.group-manage-logs-row").length === 1, find("tr.group-manage-logs-row").length === 1,
"it should display the right number of logs" "it should display the right number of logs"
); );
});
}); });

View File

@ -6,119 +6,121 @@ import {
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("Managing Group Membership", { acceptance("Managing Group Membership", function (needs) {
loggedIn: true, needs.user();
});
test("As an admin", async (assert) => {
test("As an admin", async (assert) => { updateCurrentUser({ can_create_group: true });
updateCurrentUser({ can_create_group: true });
await visit("/g/alternative-group/manage/membership");
await visit("/g/alternative-group/manage/membership");
assert.ok(
assert.ok( find('label[for="automatic_membership"]').length === 1,
find('label[for="automatic_membership"]').length === 1, "it should display automatic membership label"
"it should display automatic membership label" );
);
assert.ok(
assert.ok( find(".groups-form-primary-group").length === 1,
find(".groups-form-primary-group").length === 1, "it should display set as primary group checkbox"
"it should display set as primary group checkbox" );
);
assert.ok(
assert.ok( find(".groups-form-grant-trust-level").length === 1,
find(".groups-form-grant-trust-level").length === 1, "it should display grant trust level selector"
"it should display grant trust level selector" );
);
assert.ok(
assert.ok( find(".group-form-public-admission").length === 1,
find(".group-form-public-admission").length === 1, "it should display group public admission input"
"it should display group public admission input" );
);
assert.ok(
assert.ok( find(".group-form-public-exit").length === 1,
find(".group-form-public-exit").length === 1, "it should display group public exit input"
"it should display group public exit input" );
);
assert.ok(
assert.ok( find(".group-form-allow-membership-requests").length === 1,
find(".group-form-allow-membership-requests").length === 1, "it should display group allow_membership_request input"
"it should display group allow_membership_request input" );
);
assert.ok(
assert.ok( find(".group-form-allow-membership-requests[disabled]").length === 1,
find(".group-form-allow-membership-requests[disabled]").length === 1, "it should disable group allow_membership_request input"
"it should disable group allow_membership_request input" );
);
await click(".group-form-public-admission");
await click(".group-form-public-admission"); await click(".group-form-allow-membership-requests");
await click(".group-form-allow-membership-requests");
assert.ok(
assert.ok( find(".group-form-public-admission[disabled]").length === 1,
find(".group-form-public-admission[disabled]").length === 1, "it should disable group public admission input"
"it should disable group public admission input" );
);
assert.ok(
assert.ok( find(".group-form-public-exit[disabled]").length === 0,
find(".group-form-public-exit[disabled]").length === 0, "it should not disable group public exit input"
"it should not disable group public exit input" );
);
assert.equal(
assert.equal( find(".group-form-membership-request-template").length,
find(".group-form-membership-request-template").length, 1,
1, "it should display the membership request template field"
"it should display the membership request template field" );
);
const emailDomains = selectKit(
const emailDomains = selectKit(".group-form-automatic-membership-automatic"); ".group-form-automatic-membership-automatic"
await emailDomains.expand(); );
await emailDomains.fillInFilter("foo.com"); await emailDomains.expand();
await emailDomains.keyboard("enter"); await emailDomains.fillInFilter("foo.com");
await emailDomains.keyboard("enter");
assert.equal(emailDomains.header().value(), "foo.com");
}); assert.equal(emailDomains.header().value(), "foo.com");
});
test("As a group owner", async (assert) => {
updateCurrentUser({ moderator: false, admin: false }); test("As a group owner", async (assert) => {
updateCurrentUser({ moderator: false, admin: false });
await visit("/g/discourse/manage/membership");
await visit("/g/discourse/manage/membership");
assert.ok(
find('label[for="automatic_membership"]').length === 0, assert.ok(
"it should not display automatic membership label" find('label[for="automatic_membership"]').length === 0,
); "it should not display automatic membership label"
);
assert.ok(
find(".groups-form-automatic-membership-retroactive").length === 0, assert.ok(
"it should not display automatic membership retroactive checkbox" find(".groups-form-automatic-membership-retroactive").length === 0,
); "it should not display automatic membership retroactive checkbox"
);
assert.ok(
find(".groups-form-primary-group").length === 0, assert.ok(
"it should not display set as primary group checkbox" find(".groups-form-primary-group").length === 0,
); "it should not display set as primary group checkbox"
);
assert.ok(
find(".groups-form-grant-trust-level").length === 0, assert.ok(
"it should not display grant trust level selector" find(".groups-form-grant-trust-level").length === 0,
); "it should not display grant trust level selector"
);
assert.ok(
find(".group-form-public-admission").length === 1, assert.ok(
"it should display group public admission input" find(".group-form-public-admission").length === 1,
); "it should display group public admission input"
);
assert.ok(
find(".group-form-public-exit").length === 1, assert.ok(
"it should display group public exit input" find(".group-form-public-exit").length === 1,
); "it should display group public exit input"
);
assert.ok(
find(".group-form-allow-membership-requests").length === 1, assert.ok(
"it should display group allow_membership_request input" find(".group-form-allow-membership-requests").length === 1,
); "it should display group allow_membership_request input"
);
assert.ok(
find(".group-form-allow-membership-requests[disabled]").length === 1, assert.ok(
"it should disable group allow_membership_request input" find(".group-form-allow-membership-requests[disabled]").length === 1,
); "it should disable group allow_membership_request input"
);
});
}); });

View File

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

View File

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

View File

@ -1,13 +1,14 @@
import { visit } from "@ember/test-helpers"; import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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", { needs.user();
loggedIn: true, needs.hooks.beforeEach(() => (requests = []));
pretend(server, helper) {
needs.pretender((server, helper) => {
server.get("/groups/Macdonald.json", () => { server.get("/groups/Macdonald.json", () => {
return helper.response({ return helper.response({
group: { group: {
@ -75,53 +76,53 @@ acceptance("Group Requests", {
}); });
server.put("/groups/42/handle_membership_request.json", (request) => { 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"]]); requests.push([body["user_id"], body["accept"]]);
return helper.success(); return helper.success();
}); });
}, });
});
test("Group Requests", async (assert) => {
test("Group Requests", async (assert) => { await visit("/g/Macdonald/requests");
await visit("/g/Macdonald/requests");
assert.equal(find(".group-members tr").length, 2);
assert.equal(find(".group-members tr").length, 2); assert.equal(
assert.equal( find(".group-members tr:first-child td:nth-child(1)")
find(".group-members tr:first-child td:nth-child(1)") .text()
.text() .trim()
.trim() .replace(/\s+/g, " "),
.replace(/\s+/g, " "), "eviltrout Robin Ward"
"eviltrout Robin Ward" );
); assert.equal(
assert.equal( find(".group-members tr:first-child td:nth-child(3)").text().trim(),
find(".group-members tr:first-child td:nth-child(3)").text().trim(), "Please accept my membership request."
"Please accept my membership request." );
); assert.equal(
assert.equal( find(".group-members tr:first-child .btn-primary").text().trim(),
find(".group-members tr:first-child .btn-primary").text().trim(), "Accept"
"Accept" );
); assert.equal(
assert.equal( find(".group-members tr:first-child .btn-danger").text().trim(),
find(".group-members tr:first-child .btn-danger").text().trim(), "Deny"
"Deny" );
);
await click(".group-members tr:first-child .btn-primary");
await click(".group-members tr:first-child .btn-primary"); assert.ok(
assert.ok( find(".group-members tr:first-child td:nth-child(4)")
find(".group-members tr:first-child td:nth-child(4)") .text()
.text() .trim()
.trim() .indexOf("accepted") === 0
.indexOf("accepted") === 0 );
); assert.deepEqual(requests, [["19", "true"]]);
assert.deepEqual(requests, [["19", "true"]]);
await click(".group-members tr:last-child .btn-danger");
await click(".group-members tr:last-child .btn-danger"); assert.equal(
assert.equal( find(".group-members tr:last-child td:nth-child(4)").text().trim(),
find(".group-members tr:last-child td:nth-child(4)").text().trim(), "denied"
"denied" );
); assert.deepEqual(requests, [
assert.deepEqual(requests, [ ["19", "true"],
["19", "true"], ["20", undefined],
["20", undefined], ]);
]); });
}); });

View File

@ -3,286 +3,289 @@ import { test } from "qunit";
import I18n from "I18n"; import I18n from "I18n";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender";
let groupArgs = { function setupGroupPretender(server, helper) {
settings: { server.post("/groups/Macdonald/request_membership", () => {
enable_group_directory: true, return helper.response({
}, relative_url: "/t/internationalization-localization/280",
pretend(pretenderServer, helper) {
pretenderServer.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) => { acceptance("Group - Anonymous", function (needs) {
return [200, { "Content-Type": "application/json" }, object]; setupGroupTest(needs);
}; needs.pretender(setupGroupPretender);
test("Anonymous Viewing Group", async function (assert) { test("Anonymous Viewing Group", async function (assert) {
await visit("/g/discourse"); await visit("/g/discourse");
assert.equal( assert.equal(
count(".nav-pills li a[title='Messages']"), count(".nav-pills li a[title='Messages']"),
0, 0,
"it does not show group messages navigation link" "it does not show group messages navigation link"
); );
await click(".nav-pills li a[title='Activity']"); await click(".nav-pills li a[title='Activity']");
assert.ok(count(".user-stream-item") > 0, "it lists stream items"); assert.ok(count(".user-stream-item") > 0, "it lists stream items");
await click(".activity-nav li a[href='/g/discourse/activity/topics']"); await click(".activity-nav li a[href='/g/discourse/activity/topics']");
assert.ok(find(".topic-list"), "it shows the topic list"); assert.ok(find(".topic-list"), "it shows the topic list");
assert.equal(count(".topic-list-item"), 2, "it lists stream items"); assert.equal(count(".topic-list-item"), 2, "it lists stream items");
await click(".activity-nav li a[href='/g/discourse/activity/mentions']"); await click(".activity-nav li a[href='/g/discourse/activity/mentions']");
assert.ok(count(".user-stream-item") > 0, "it lists stream items"); assert.ok(count(".user-stream-item") > 0, "it lists stream items");
assert.ok( assert.ok(
find(".nav-pills li a[title='Edit Group']").length === 0, find(".nav-pills li a[title='Edit Group']").length === 0,
"it should not show messages tab if user is not admin" "it should not show messages tab if user is not admin"
); );
assert.ok( assert.ok(
find(".nav-pills li a[title='Logs']").length === 0, find(".nav-pills li a[title='Logs']").length === 0,
"it should not show Logs tab if user is not admin" "it should not show Logs tab if user is not admin"
); );
assert.ok(count(".user-stream-item") > 0, "it lists stream items"); assert.ok(count(".user-stream-item") > 0, "it lists stream items");
const groupDropdown = selectKit(".group-dropdown"); const groupDropdown = selectKit(".group-dropdown");
await groupDropdown.expand(); await groupDropdown.expand();
assert.equal(groupDropdown.rowByIndex(1).name(), "discourse"); assert.equal(groupDropdown.rowByIndex(1).name(), "discourse");
assert.equal( assert.equal(
groupDropdown.rowByIndex(0).name(), groupDropdown.rowByIndex(0).name(),
I18n.t("groups.index.all").toLowerCase() I18n.t("groups.index.all").toLowerCase()
); );
this.siteSettings.enable_group_directory = false; this.siteSettings.enable_group_directory = false;
await visit("/g"); await visit("/g");
await visit("/g/discourse"); await visit("/g/discourse");
await groupDropdown.expand(); await groupDropdown.expand();
assert.equal( assert.equal(
find(".group-dropdown-filter").length, find(".group-dropdown-filter").length,
0, 0,
"it should not display the default header" "it should not display the default header"
); );
});
test("Anonymous Viewing Automatic Group", async (assert) => {
await visit("/g/moderators");
assert.equal(
count(".nav-pills li a[title='Manage']"),
0,
"it does not show group messages navigation link"
);
});
}); });
test("Anonymous Viewing Automatic Group", async (assert) => { acceptance("Group - Authenticated", function (needs) {
await visit("/g/moderators"); setupGroupTest(needs);
needs.user();
assert.equal( needs.pretender((server, helper) => {
count(".nav-pills li a[title='Manage']"), setupGroupPretender(server, helper);
0, server.get(
"it does not show group messages navigation link" "/topics/private-messages-group/eviltrout/alternative-group.json",
); () => {
}); return helper.response({ topic_list: { topics: [] } });
}
);
acceptance("Group", Object.assign({ loggedIn: true }, groupArgs)); server.get(
"/topics/private-messages-group/eviltrout/discourse.json",
test("User Viewing Group", async (assert) => { () => {
await visit("/g"); return helper.response({
await click(".group-index-request"); users: [
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",
() => {
return 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(
"/topics/private-messages-group/eviltrout/discourse.json",
() => {
return response({
users: [
{
id: 2,
username: "bruce1",
avatar_template:
"/user_avatar/meta.discourse.org/bruce1/{size}/5245.png",
},
{
id: 3,
username: "CodingHorror",
avatar_template:
"/user_avatar/meta.discourse.org/codinghorror/{size}/5245.png",
},
],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 0,
per_page: 30,
topics: [
{ {
id: 12199, id: 2,
title: "This is a private message 1", username: "bruce1",
fancy_title: "This is a private message 1", avatar_template:
slug: "this-is-a-private-message-1", "/user_avatar/meta.discourse.org/bruce1/{size}/5245.png",
posts_count: 0, },
reply_count: 0, {
highest_post_number: 0, id: 3,
image_url: null, username: "CodingHorror",
created_at: "2018-03-16T03:38:45.583Z", avatar_template:
last_posted_at: null, "/user_avatar/meta.discourse.org/codinghorror/{size}/5245.png",
bumped: true,
bumped_at: "2018-03-16T03:38:45.583Z",
unseen: false,
pinned: false,
unpinned: null,
visible: true,
closed: false,
archived: false,
bookmarked: null,
liked: null,
views: 0,
like_count: 0,
has_summary: false,
archetype: "private_message",
last_poster_username: "bruce1",
category_id: null,
pinned_globally: false,
featured_link: null,
posters: [
{
extras: "latest single",
description: "Original Poster, Most Recent Poster",
user_id: 2,
primary_group_id: null,
},
],
participants: [
{
extras: "latest",
description: null,
user_id: 2,
primary_group_id: null,
},
{
extras: null,
description: null,
user_id: 3,
primary_group_id: null,
},
],
}, },
], ],
}, primary_groups: [],
}); topic_list: {
} can_create_topic: true,
); draft: null,
draft_key: "new_topic",
draft_sequence: 0,
per_page: 30,
topics: [
{
id: 12199,
title: "This is a private message 1",
fancy_title: "This is a private message 1",
slug: "this-is-a-private-message-1",
posts_count: 0,
reply_count: 0,
highest_post_number: 0,
image_url: null,
created_at: "2018-03-16T03:38:45.583Z",
last_posted_at: null,
bumped: true,
bumped_at: "2018-03-16T03:38:45.583Z",
unseen: false,
pinned: false,
unpinned: null,
visible: true,
closed: false,
archived: false,
bookmarked: null,
liked: null,
views: 0,
like_count: 0,
has_summary: false,
archetype: "private_message",
last_poster_username: "bruce1",
category_id: null,
pinned_globally: false,
featured_link: null,
posters: [
{
extras: "latest single",
description: "Original Poster, Most Recent Poster",
user_id: 2,
primary_group_id: null,
},
],
participants: [
{
extras: "latest",
description: null,
user_id: 2,
primary_group_id: null,
},
{
extras: null,
description: null,
user_id: 3,
primary_group_id: null,
},
],
},
],
},
});
}
);
});
await visit("/g/discourse"); test("User Viewing Group", async (assert) => {
await click(".nav-pills li a[title='Messages']"); await visit("/g");
await click(".group-index-request");
assert.equal( assert.equal(
find(".topic-list-item .link-top-line").text().trim(), find(".modal-header").text().trim(),
"This is a private message 1", I18n.t("groups.membership_request.title", { group_name: "Macdonald" })
"it should display the list of group topics" );
);
}); assert.equal(
find(".request-group-membership-form textarea").val(),
test("Admin Viewing Group", async (assert) => { "Please add me"
await visit("/g/discourse"); );
assert.ok( await click(".modal-footer .btn-primary");
find(".nav-pills li a[title='Manage']").length === 1,
"it should show manage group tab if user is admin" assert.equal(
); find(".fancy-title").text().trim(),
"Internationalization / localization"
assert.equal( );
count(".group-message-button"),
1, await visit("/g/discourse");
"it displays show group message button"
); await click(".group-message-button");
assert.equal(
find(".group-info-name").text(), assert.ok(count("#reply-control") === 1, "it opens the composer");
"Awesome Team", assert.equal(
"it should display the group name" find(".ac-wrap .item").text(),
); "discourse",
}); "it prefills the group name"
);
test("Moderator Viewing Group", async (assert) => { });
await visit("/g/alternative-group");
test("Admin viewing group messages when there are no messages", async (assert) => {
assert.ok( await visit("/g/alternative-group");
find(".nav-pills li a[title='Manage']").length === 1, await click(".nav-pills li a[title='Messages']");
"it should show manage group tab if user can_admin_group"
); assert.equal(
find(".alert").text().trim(),
await click(".group-members-add.btn"); I18n.t("choose_topic.none_found"),
"it should display the right alert"
assert.ok( );
find(".group-add-members-modal .group-add-members-make-owner"), });
"it allows moderators to set group owners"
); test("Admin viewing group messages", async (assert) => {
await visit("/g/discourse");
await click(".group-add-members-modal .modal-close"); await click(".nav-pills li a[title='Messages']");
const memberDropdown = selectKit(".group-member-dropdown:first"); assert.equal(
await memberDropdown.expand(); find(".topic-list-item .link-top-line").text().trim(),
"This is a private message 1",
assert.equal( "it should display the list of group topics"
memberDropdown.rowByIndex(0).name(), );
I18n.t("groups.members.remove_member") });
);
assert.equal( test("Admin Viewing Group", async (assert) => {
memberDropdown.rowByIndex(1).name(), await visit("/g/discourse");
I18n.t("groups.members.make_owner")
); assert.ok(
find(".nav-pills li a[title='Manage']").length === 1,
"it should show manage group tab if user is admin"
);
assert.equal(
count(".group-message-button"),
1,
"it displays show group message button"
);
assert.equal(
find(".group-info-name").text(),
"Awesome Team",
"it should display the group name"
);
});
test("Moderator Viewing Group", async (assert) => {
await visit("/g/alternative-group");
assert.ok(
find(".nav-pills li a[title='Manage']").length === 1,
"it should show manage group tab if user can_admin_group"
);
await click(".group-members-add.btn");
assert.ok(
find(".group-add-members-modal .group-add-members-make-owner"),
"it allows moderators to set group owners"
);
await click(".group-add-members-modal .modal-close");
const memberDropdown = selectKit(".group-member-dropdown:first");
await memberDropdown.expand();
assert.equal(
memberDropdown.rowByIndex(0).name(),
I18n.t("groups.members.remove_member")
);
assert.equal(
memberDropdown.rowByIndex(1).name(),
I18n.t("groups.members.make_owner")
);
});
}); });

View File

@ -2,48 +2,48 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Groups"); acceptance("Groups", function () {
test("Browsing Groups", async (assert) => {
await visit("/g?username=eviltrout");
test("Browsing Groups", async (assert) => { assert.equal(count(".group-box"), 1, "it displays user's groups");
await visit("/g?username=eviltrout");
assert.equal(count(".group-box"), 1, "it displays user's groups"); await visit("/g");
await visit("/g"); assert.equal(count(".group-box"), 2, "it displays visible groups");
assert.equal(
find(".group-index-join").length,
1,
"it shows button to join group"
);
assert.equal(
find(".group-index-request").length,
1,
"it shows button to request for group membership"
);
assert.equal(count(".group-box"), 2, "it displays visible groups"); await click(".group-index-join");
assert.equal(
find(".group-index-join").length,
1,
"it shows button to join group"
);
assert.equal(
find(".group-index-request").length,
1,
"it shows button to request for group membership"
);
await click(".group-index-join"); assert.ok(exists(".modal.login-modal"), "it shows the login modal");
assert.ok(exists(".modal.login-modal"), "it shows the login modal"); await click(".login-modal .close");
await click(".login-modal .close"); assert.ok(invisible(".modal.login-modal"), "it closes the login modal");
assert.ok(invisible(".modal.login-modal"), "it closes the login modal"); await click(".group-index-request");
await click(".group-index-request"); assert.ok(exists(".modal.login-modal"), "it shows the login modal");
assert.ok(exists(".modal.login-modal"), "it shows the login modal"); await click("a[href='/g/discourse/members']");
await click("a[href='/g/discourse/members']"); assert.equal(
find(".group-info-name").text().trim(),
"Awesome Team",
"it displays the group page"
);
assert.equal( await click(".group-index-join");
find(".group-info-name").text().trim(),
"Awesome Team",
"it displays the group page"
);
await click(".group-index-join"); assert.ok(exists(".modal.login-modal"), "it shows the login modal");
});
assert.ok(exists(".modal.login-modal"), "it shows the login modal");
}); });

View File

@ -3,75 +3,76 @@ import { test } from "qunit";
import I18n from "I18n"; import I18n from "I18n";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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");
test("As an anon user", async (assert) => { assert.equal(
await visit("/g"); find(".groups-header-new").length,
0,
assert.equal( "it should not display the button to create a group"
find(".groups-header-new").length, );
0, });
"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");
test("Creating a new group", async (assert) => { assert.equal(
await visit("/g"); find(".group-form-save[disabled]").length,
await click(".groups-header-new"); 1,
"save button should be disabled"
);
assert.equal( await fillIn("input[name='name']", "1");
find(".group-form-save[disabled]").length,
1,
"save button should be disabled"
);
await fillIn("input[name='name']", "1"); assert.equal(
find(".tip.bad").text().trim(),
I18n.t("admin.groups.new.name.too_short"),
"it should show the right validation tooltip"
);
assert.equal( assert.ok(
find(".tip.bad").text().trim(), find(".group-form-save:disabled").length === 1,
I18n.t("admin.groups.new.name.too_short"), "it should disable the save button"
"it should show the right validation tooltip" );
);
assert.ok( await fillIn(
find(".group-form-save:disabled").length === 1, "input[name='name']",
"it should disable the save button" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
); );
await fillIn( assert.equal(
"input[name='name']", find(".tip.bad").text().trim(),
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" I18n.t("admin.groups.new.name.too_long"),
); "it should show the right validation tooltip"
);
assert.equal( await fillIn("input[name='name']", "");
find(".tip.bad").text().trim(),
I18n.t("admin.groups.new.name.too_long"),
"it should show the right validation tooltip"
);
await fillIn("input[name='name']", ""); assert.equal(
find(".tip.bad").text().trim(),
I18n.t("admin.groups.new.name.blank"),
"it should show the right validation tooltip"
);
assert.equal( await fillIn("input[name='name']", "goodusername");
find(".tip.bad").text().trim(),
I18n.t("admin.groups.new.name.blank"),
"it should show the right validation tooltip"
);
await fillIn("input[name='name']", "goodusername"); assert.equal(
find(".tip.good").text().trim(),
I18n.t("admin.groups.new.name.available"),
"it should show the right validation tooltip"
);
assert.equal( await click(".group-form-public-admission");
find(".tip.good").text().trim(),
I18n.t("admin.groups.new.name.available"),
"it should show the right validation tooltip"
);
await click(".group-form-public-admission"); assert.equal(
find("groups-new-allow-membership-requests").length,
assert.equal( 0,
find("groups-new-allow-membership-requests").length, "it should disable the membership requests checkbox"
0, );
"it should disable the membership requests checkbox" });
);
}); });

View File

@ -5,18 +5,19 @@ import {
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
acceptance("Opening the hamburger menu with some reviewables", { acceptance("Opening the hamburger menu with some reviewables", function (
loggedIn: true, needs
pretend: (server, helper) => { ) {
needs.user();
needs.pretender((server, helper) => {
server.get("/review/count.json", () => helper.response({ count: 3 })); server.get("/review/count.json", () => helper.response({ count: 3 }));
}, });
}); test("As a staff member", async (assert) => {
updateCurrentUser({ moderator: true, admin: false });
test("As a staff member", async (assert) => {
updateCurrentUser({ moderator: true, admin: false }); await visit("/");
await click(".hamburger-dropdown");
await visit("/");
await click(".hamburger-dropdown"); assert.equal(find(".review .badge-notification.reviewables").text(), "3");
});
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 { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Category and Tag Hashtags", { acceptance("Category and Tag Hashtags", function (needs) {
loggedIn: true, needs.user();
settings: { tagging_enabled: true }, needs.settings({ tagging_enabled: true });
pretend(server, helper) { needs.pretender((server, helper) => {
server.get("/hashtags", () => { server.get("/hashtags", () => {
return helper.response({ return helper.response({
categories: { bug: "/c/bugs" }, categories: { bug: "/c/bugs" },
@ -15,26 +15,26 @@ acceptance("Category and Tag Hashtags", {
}, },
}); });
}); });
}, });
});
test("hashtags are cooked properly", async (assert) => { test("hashtags are cooked properly", async (assert) => {
await visit("/t/internationalization-localization/280"); await visit("/t/internationalization-localization/280");
await click("#topic-footer-buttons .btn.create"); await click("#topic-footer-buttons .btn.create");
await fillIn( await fillIn(
".d-editor-input", ".d-editor-input",
`this is a category hashtag #bug `this is a category hashtag #bug
this is a tag hashtag #monkey this is a tag hashtag #monkey
category vs tag: #bug vs #bug::tag` category vs tag: #bug vs #bug::tag`
); );
assert.equal( assert.equal(
find(".d-editor-preview:visible").html().trim(), find(".d-editor-preview:visible").html().trim(),
`<p>this is a category hashtag <a href="/c/bugs" class="hashtag">#<span>bug</span></a></p> `<p>this is a category hashtag <a href="/c/bugs" class="hashtag">#<span>bug</span></a></p>
<p>this is a tag hashtag <a href="/tag/monkey" class="hashtag">#<span>monkey</span></a></p> <p>this is a tag hashtag <a href="/tag/monkey" class="hashtag">#<span>monkey</span></a></p>
<p>category vs tag: <a href="/c/bugs" class="hashtag">#<span>bug</span></a> vs <a href="/tag/bug" class="hashtag">#<span>bug</span></a></p>` <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,82 +3,80 @@ import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import PreloadStore from "discourse/lib/preload-store"; import PreloadStore from "discourse/lib/preload-store";
acceptance("Invite Accept", { acceptance("Invite Accept", function (needs) {
settings: { needs.settings({ full_name_required: true });
full_name_required: true,
},
});
test("Invite Acceptance Page", async (assert) => { test("Invite Acceptance Page", async (assert) => {
PreloadStore.store("invite_info", { PreloadStore.store("invite_info", {
invited_by: { invited_by: {
id: 123, id: 123,
username: "neil", username: "neil",
avatar_template: "/user_avatar/localhost/neil/{size}/25_1.png", avatar_template: "/user_avatar/localhost/neil/{size}/25_1.png",
name: "Neil Lalonde", name: "Neil Lalonde",
title: "team", title: "team",
}, },
email: null, email: null,
username: "invited", username: "invited",
is_invite_link: true, is_invite_link: true,
});
await visit("/invites/myvalidinvitetoken");
assert.ok(exists("#new-account-email"), "shows the email input");
assert.ok(exists("#new-account-username"), "shows the username input");
assert.equal(
find("#new-account-username").val(),
"invited",
"username is prefilled"
);
assert.ok(exists("#new-account-name"), "shows the name input");
assert.ok(exists("#new-account-password"), "shows the password input");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled because name and email is not filled"
);
await fillIn("#new-account-name", "John Doe");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled because email is not filled"
);
await fillIn("#new-account-email", "john.doe@example.com");
assert.not(
exists(".invites-show .btn-primary:disabled"),
"submit is enabled"
);
await fillIn("#new-account-username", "a");
assert.ok(exists(".username-input .bad"), "username is not valid");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled"
);
await fillIn("#new-account-password", "aaa");
assert.ok(exists(".password-input .bad"), "password is not valid");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled"
);
await fillIn("#new-account-email", "john.doe@example");
assert.ok(exists(".email-input .bad"), "email is not valid");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled"
);
await fillIn("#new-account-username", "validname");
await fillIn("#new-account-password", "secur3ty4Y0uAndMe");
await fillIn("#new-account-email", "john.doe@example.com");
assert.ok(exists(".username-input .good"), "username is valid");
assert.ok(exists(".password-input .good"), "password is valid");
assert.ok(exists(".email-input .good"), "email is valid");
assert.not(
exists(".invites-show .btn-primary:disabled"),
"submit is enabled"
);
}); });
await visit("/invites/myvalidinvitetoken");
assert.ok(exists("#new-account-email"), "shows the email input");
assert.ok(exists("#new-account-username"), "shows the username input");
assert.equal(
find("#new-account-username").val(),
"invited",
"username is prefilled"
);
assert.ok(exists("#new-account-name"), "shows the name input");
assert.ok(exists("#new-account-password"), "shows the password input");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled because name and email is not filled"
);
await fillIn("#new-account-name", "John Doe");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled because email is not filled"
);
await fillIn("#new-account-email", "john.doe@example.com");
assert.not(
exists(".invites-show .btn-primary:disabled"),
"submit is enabled"
);
await fillIn("#new-account-username", "a");
assert.ok(exists(".username-input .bad"), "username is not valid");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled"
);
await fillIn("#new-account-password", "aaa");
assert.ok(exists(".password-input .bad"), "password is not valid");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled"
);
await fillIn("#new-account-email", "john.doe@example");
assert.ok(exists(".email-input .bad"), "email is not valid");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled"
);
await fillIn("#new-account-username", "validname");
await fillIn("#new-account-password", "secur3ty4Y0uAndMe");
await fillIn("#new-account-email", "john.doe@example.com");
assert.ok(exists(".username-input .good"), "username is valid");
assert.ok(exists(".password-input .good"), "password is valid");
assert.ok(exists(".email-input .good"), "email is valid");
assert.not(
exists(".invites-show .btn-primary:disabled"),
"submit is enabled"
);
}); });

View File

@ -3,8 +3,8 @@ import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import PreloadStore from "discourse/lib/preload-store"; import PreloadStore from "discourse/lib/preload-store";
acceptance("Accept Invite - User Fields", { acceptance("Accept Invite - User Fields", function (needs) {
site: { needs.site({
user_fields: [ user_fields: [
{ {
id: 34, id: 34,
@ -25,57 +25,57 @@ acceptance("Accept Invite - User Fields", {
required: false, required: false,
}, },
], ],
},
});
test("accept invite with user fields", async (assert) => {
PreloadStore.store("invite_info", {
invited_by: {
id: 123,
username: "neil",
avatar_template: "/user_avatar/localhost/neil/{size}/25_1.png",
name: "Neil Lalonde",
title: "team",
},
email: "invited@asdf.com",
username: "invited",
is_invite_link: false,
}); });
await visit("/invites/myvalidinvitetoken"); test("accept invite with user fields", async (assert) => {
assert.ok(exists(".invites-show"), "shows the accept invite page"); PreloadStore.store("invite_info", {
assert.ok(exists(".user-field"), "it has at least one user field"); invited_by: {
assert.ok( id: 123,
exists(".invites-show .btn-primary:disabled"), username: "neil",
"submit is disabled" avatar_template: "/user_avatar/localhost/neil/{size}/25_1.png",
); name: "Neil Lalonde",
title: "team",
},
email: "invited@asdf.com",
username: "invited",
is_invite_link: false,
});
await fillIn("#new-account-name", "John Doe"); await visit("/invites/myvalidinvitetoken");
await fillIn("#new-account-username", "validname"); assert.ok(exists(".invites-show"), "shows the accept invite page");
await fillIn("#new-account-password", "secur3ty4Y0uAndMe"); assert.ok(exists(".user-field"), "it has at least one user field");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is disabled"
);
assert.ok(exists(".username-input .good"), "username is valid"); await fillIn("#new-account-name", "John Doe");
assert.ok( await fillIn("#new-account-username", "validname");
exists(".invites-show .btn-primary:disabled"), await fillIn("#new-account-password", "secur3ty4Y0uAndMe");
"submit is still disabled due to lack of user fields"
);
await fillIn(".user-field input[type=text]:first", "Barky"); assert.ok(exists(".username-input .good"), "username is valid");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"submit is still disabled due to lack of user fields"
);
assert.ok( await fillIn(".user-field input[type=text]:first", "Barky");
exists(".invites-show .btn-primary:disabled"),
"submit is disabled because field is not checked"
);
await click(".user-field input[type=checkbox]"); assert.ok(
assert.not( exists(".invites-show .btn-primary:disabled"),
exists(".invites-show .btn-primary:disabled"), "submit is disabled because field is not checked"
"submit is enabled because field is checked" );
);
await click(".user-field input[type=checkbox]"); await click(".user-field input[type=checkbox]");
assert.ok( assert.not(
exists(".invites-show .btn-primary:disabled"), exists(".invites-show .btn-primary:disabled"),
"unclicking the checkbox disables the submit" "submit is enabled because field is checked"
); );
await click(".user-field input[type=checkbox]");
assert.ok(
exists(".invites-show .btn-primary:disabled"),
"unclicking the checkbox disables the submit"
);
});
}); });

View File

@ -2,12 +2,11 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Jump to", { acceptance("Jump to", function (needs) {
loggedIn: true, needs.user();
needs.mobileView();
mobileView: true, needs.pretender((server, helper) => {
pretend(server, helper) {
server.get("/t/280/excerpts.json", () => helper.response(200, [])); server.get("/t/280/excerpts.json", () => helper.response(200, []));
server.get("/t/280/3.json", () => helper.response(200, {})); server.get("/t/280/3.json", () => helper.response(200, {}));
server.get("/posts/by-date/280/:date", (req) => { server.get("/posts/by-date/280/:date", (req) => {
@ -19,36 +18,36 @@ acceptance("Jump to", {
return helper.response(404, null); return helper.response(404, null);
}); });
}, });
});
test("default", async (assert) => {
test("default", async (assert) => { await visit("/t/internationalization-localization/280");
await visit("/t/internationalization-localization/280"); await click("nav#topic-progress .nums");
await click("nav#topic-progress .nums"); await click("button.jump-to-post");
await click("button.jump-to-post");
assert.ok(exists(".jump-to-post-modal"), "it shows the modal");
assert.ok(exists(".jump-to-post-modal"), "it shows the modal");
await fillIn("input.date-picker", "2014-02-24");
await fillIn("input.date-picker", "2014-02-24"); await click(".jump-to-post-modal .btn-primary");
await click(".jump-to-post-modal .btn-primary");
assert.equal(
assert.equal( currentURL(),
currentURL(), "/t/internationalization-localization/280/3",
"/t/internationalization-localization/280/3", "it jumps to the correct post"
"it jumps to the correct post" );
); });
});
test("invalid date", async (assert) => {
test("invalid date", async (assert) => { await visit("/t/internationalization-localization/280");
await visit("/t/internationalization-localization/280"); await click("nav#topic-progress .nums");
await click("nav#topic-progress .nums"); await click("button.jump-to-post");
await click("button.jump-to-post"); await fillIn("input.date-picker", "2094-02-24");
await fillIn("input.date-picker", "2094-02-24"); await click(".jump-to-post-modal .btn-primary");
await click(".jump-to-post-modal .btn-primary");
assert.equal(
assert.equal( currentURL(),
currentURL(), "/t/internationalization-localization/280/20",
"/t/internationalization-localization/280/20", "it jumps to the last post if no post found"
"it jumps to the last post if no post found" );
); });
}); });

View File

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

View File

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

View File

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

View File

@ -2,35 +2,31 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import I18n from "I18n"; import I18n from "I18n";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender";
acceptance("Login with email - hide email address taken", { acceptance("Login with email - hide email address taken", function (needs) {
settings: { needs.settings({
enable_local_logins_via_email: true, enable_local_logins_via_email: true,
hide_email_address_taken: true, hide_email_address_taken: true,
}, });
beforeEach() {
const response = (object) => {
return [200, { "Content-Type": "application/json" }, object];
};
pretender.post("/u/email-login", () => { needs.pretender((server, helper) => {
return response({ success: "OK" }); server.post("/u/email-login", () => {
return helper.response({ success: "OK" });
}); });
}, });
});
test("with hide_email_address_taken enabled", async (assert) => { test("with hide_email_address_taken enabled", async (assert) => {
await visit("/"); await visit("/");
await click("header .login-button"); await click("header .login-button");
await fillIn("#login-account-name", "someuser@example.com"); await fillIn("#login-account-name", "someuser@example.com");
await click(".login-with-email-button"); await click(".login-with-email-button");
assert.equal( assert.equal(
find(".alert-success").html().trim(), find(".alert-success").html().trim(),
I18n.t("email_login.complete_email_found", { I18n.t("email_login.complete_email_found", {
email: "someuser@example.com", email: "someuser@example.com",
}), }),
"it should display the success message for any email address" "it should display the success message for any email address"
); );
});
}); });

View File

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

View File

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

View File

@ -3,80 +3,80 @@ import { test } from "qunit";
import I18n from "I18n"; import I18n from "I18n";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
let userFound = false; acceptance("Login with email", function (needs) {
needs.settings({
acceptance("Login with email", {
settings: {
enable_local_logins_via_email: true, enable_local_logins_via_email: true,
enable_facebook_logins: true, enable_facebook_logins: true,
}, });
pretend(server, helper) {
let userFound = false;
needs.pretender((server, helper) => {
server.post("/u/email-login", () => server.post("/u/email-login", () =>
helper.response({ success: "OK", user_found: userFound }) helper.response({ success: "OK", user_found: userFound })
); );
}, });
});
test("with email button", async (assert) => {
test("with email button", async (assert) => { await visit("/");
await visit("/"); await click("header .login-button");
await click("header .login-button");
assert.ok(
assert.ok( exists(".btn-social.facebook"),
exists(".btn-social.facebook"), "it displays the facebook login button"
"it displays the facebook login button" );
);
assert.ok(
assert.ok( exists(".login-with-email-button"),
exists(".login-with-email-button"), "it displays the login with email button"
"it displays the login with email button" );
);
await fillIn("#login-account-name", "someuser");
await fillIn("#login-account-name", "someuser"); await click(".login-with-email-button");
await click(".login-with-email-button");
assert.equal(
assert.equal( find(".alert-error").html(),
find(".alert-error").html(), I18n.t("email_login.complete_username_not_found", {
I18n.t("email_login.complete_username_not_found", { username: "someuser",
username: "someuser", }),
}), "it should display an error for an invalid username"
"it should display an error for an invalid username" );
);
await fillIn("#login-account-name", "someuser@gmail.com");
await fillIn("#login-account-name", "someuser@gmail.com"); await click(".login-with-email-button");
await click(".login-with-email-button");
assert.equal(
assert.equal( find(".alert-error").html(),
find(".alert-error").html(), I18n.t("email_login.complete_email_not_found", {
I18n.t("email_login.complete_email_not_found", { email: "someuser@gmail.com",
email: "someuser@gmail.com", }),
}), "it should display an error for an invalid email"
"it should display an error for an invalid email" );
);
await fillIn("#login-account-name", "someuser");
await fillIn("#login-account-name", "someuser");
userFound = true;
userFound = true;
await click(".login-with-email-button");
await click(".login-with-email-button");
assert.equal(
assert.equal( find(".alert-success").html().trim(),
find(".alert-success").html().trim(), I18n.t("email_login.complete_username_found", { username: "someuser" }),
I18n.t("email_login.complete_username_found", { username: "someuser" }), "it should display a success message for a valid username"
"it should display a success message for a valid username" );
);
await visit("/");
await visit("/"); await click("header .login-button");
await click("header .login-button"); await fillIn("#login-account-name", "someuser@gmail.com");
await fillIn("#login-account-name", "someuser@gmail.com"); await click(".login-with-email-button");
await click(".login-with-email-button");
assert.equal(
assert.equal( find(".alert-success").html().trim(),
find(".alert-success").html().trim(), I18n.t("email_login.complete_email_found", {
I18n.t("email_login.complete_email_found", { email: "someuser@gmail.com",
email: "someuser@gmail.com", }),
}), "it should display a success message for a valid email"
"it should display a success message for a valid email" );
);
userFound = false;
userFound = false; });
}); });

View File

@ -1,13 +1,15 @@
import { visit } from "@ember/test-helpers"; import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic Discovery - Mobile", { mobileView: true });
test("Visit Discovery Pages", async (assert) => { acceptance("Topic Discovery - Mobile", function (needs) {
await visit("/"); needs.mobileView();
assert.ok(exists(".topic-list"), "The list of topics was rendered"); test("Visit Discovery Pages", async (assert) => {
assert.ok(exists(".topic-list .topic-list-item"), "has topics"); await visit("/");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics");
await visit("/categories"); await visit("/categories");
assert.ok(exists(".category"), "has a list of 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 { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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) => { test("sign in", async (assert) => {
await visit("/"); await visit("/");
await click("header .login-button"); await click("header .login-button");
assert.ok(exists("#login-form"), "it shows the login modal"); 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 { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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) => { test("Visit Page", async (assert) => {
await visit("/u"); await visit("/u");
assert.ok(exists(".directory .user"), "has a list of users"); assert.ok(exists(".directory .user"), "has a list of users");
});
}); });

View File

@ -1,5 +1,4 @@
import { visit } from "@ember/test-helpers"; import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { test } from "qunit"; import { test } from "qunit";
import I18n from "I18n"; import I18n from "I18n";
import { run } from "@ember/runloop"; import { run } from "@ember/runloop";
@ -9,9 +8,10 @@ import {
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import showModal from "discourse/lib/show-modal"; import showModal from "discourse/lib/show-modal";
acceptance("Modal", { acceptance("Modal", function (needs) {
beforeEach() { let _translations;
this._translations = I18n.translations; needs.hooks.beforeEach(() => {
_translations = I18n.translations;
I18n.translations = { I18n.translations = {
en: { en: {
@ -20,144 +20,146 @@ acceptance("Modal", {
}, },
}, },
}; };
}, });
afterEach() { needs.hooks.afterEach(() => {
I18n.translations = this._translations; I18n.translations = _translations;
}, });
test("modal", async function (assert) {
await visit("/");
assert.ok(
find(".d-modal:visible").length === 0,
"there is no modal at first"
);
await click(".login-button");
assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
let controller = controllerFor("modal");
assert.equal(controller.name, "login");
await click(".modal-outer-container");
assert.ok(
find(".d-modal:visible").length === 0,
"modal should disappear when you click outside"
);
assert.equal(controller.name, null);
await click(".login-button");
assert.ok(find(".d-modal:visible").length === 1, "modal should reappear");
await keyEvent("#main-outlet", "keyup", 27);
assert.ok(
find(".d-modal:visible").length === 0,
"ESC should close the modal"
);
Ember.TEMPLATES["modal/not-dismissable"] = Ember.HTMLBars.compile(
'{{#d-modal-body title="" class="" dismissable=false}}test{{/d-modal-body}}'
);
run(() => showModal("not-dismissable", {}));
assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
await click(".modal-outer-container");
assert.ok(
find(".d-modal:visible").length === 1,
"modal should not disappear when you click outside"
);
await keyEvent("#main-outlet", "keyup", 27);
assert.ok(
find(".d-modal:visible").length === 1,
"ESC should not close the modal"
);
});
test("rawTitle in modal panels", async function (assert) {
Ember.TEMPLATES["modal/test-raw-title-panels"] = Ember.HTMLBars.compile("");
const panels = [
{ id: "test1", rawTitle: "Test 1" },
{ id: "test2", rawTitle: "Test 2" },
];
await visit("/");
run(() => showModal("test-raw-title-panels", { panels }));
assert.equal(
find(".d-modal .modal-tab:first-child").text().trim(),
"Test 1",
"it should display the raw title"
);
});
test("modal title", async function (assert) {
Ember.TEMPLATES["modal/test-title"] = Ember.HTMLBars.compile("");
Ember.TEMPLATES["modal/test-title-with-body"] = Ember.HTMLBars.compile(
"{{#d-modal-body}}test{{/d-modal-body}}"
);
await visit("/");
run(() => showModal("test-title", { title: "test_title" }));
assert.equal(
find(".d-modal .title").text().trim(),
"Test title",
"it should display the title"
);
await click(".d-modal .close");
run(() => showModal("test-title-with-body", { title: "test_title" }));
assert.equal(
find(".d-modal .title").text().trim(),
"Test title",
"it should display the title when used with d-modal-body"
);
await click(".d-modal .close");
run(() => showModal("test-title"));
assert.ok(
find(".d-modal .title").length === 0,
"it should not re-use the previous title"
);
});
}); });
skip("modal", async function (assert) { acceptance("Modal Keyboard Events", function (needs) {
await visit("/"); needs.user();
assert.ok( test("modal-keyboard-events", async function (assert) {
find(".d-modal:visible").length === 0, await visit("/t/internationalization-localization/280");
"there is no modal at first"
);
await click(".login-button"); await click(".toggle-admin-menu");
assert.ok(find(".d-modal:visible").length === 1, "modal should appear"); await click(".topic-admin-status-update button");
await keyEvent(".d-modal", "keyup", 13);
let controller = controllerFor("modal"); assert.ok(
assert.equal(controller.name, "login"); find("#modal-alert:visible").length === 1,
"hitting Enter triggers modal action"
);
assert.ok(
find(".d-modal:visible").length === 1,
"hitting Enter does not dismiss modal due to alert error"
);
await click(".modal-outer-container"); await keyEvent("#main-outlet", "keyup", 27);
assert.ok( assert.ok(
find(".d-modal:visible").length === 0, find(".d-modal:visible").length === 0,
"modal should disappear when you click outside" "ESC should close the modal"
); );
assert.equal(controller.name, null);
await click(".login-button"); await click(".topic-body button.reply");
assert.ok(find(".d-modal:visible").length === 1, "modal should reappear");
await keyEvent("#main-outlet", "keyup", 27); await click(".d-editor-button-bar .btn.link");
assert.ok(
find(".d-modal:visible").length === 0,
"ESC should close the modal"
);
Ember.TEMPLATES["modal/not-dismissable"] = Ember.HTMLBars.compile( await keyEvent(".d-modal", "keyup", 13);
'{{#d-modal-body title="" class="" dismissable=false}}test{{/d-modal-body}}' assert.ok(
); find(".d-modal:visible").length === 0,
"modal should disappear on hitting Enter"
run(() => showModal("not-dismissable", {})); );
});
assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
await click(".modal-outer-container");
assert.ok(
find(".d-modal:visible").length === 1,
"modal should not disappear when you click outside"
);
await keyEvent("#main-outlet", "keyup", 27);
assert.ok(
find(".d-modal:visible").length === 1,
"ESC should not close the modal"
);
});
test("rawTitle in modal panels", async function (assert) {
Ember.TEMPLATES["modal/test-raw-title-panels"] = Ember.HTMLBars.compile("");
const panels = [
{ id: "test1", rawTitle: "Test 1" },
{ id: "test2", rawTitle: "Test 2" },
];
await visit("/");
run(() => showModal("test-raw-title-panels", { panels }));
assert.equal(
find(".d-modal .modal-tab:first-child").text().trim(),
"Test 1",
"it should display the raw title"
);
});
test("modal title", async function (assert) {
Ember.TEMPLATES["modal/test-title"] = Ember.HTMLBars.compile("");
Ember.TEMPLATES["modal/test-title-with-body"] = Ember.HTMLBars.compile(
"{{#d-modal-body}}test{{/d-modal-body}}"
);
await visit("/");
run(() => showModal("test-title", { title: "test_title" }));
assert.equal(
find(".d-modal .title").text().trim(),
"Test title",
"it should display the title"
);
await click(".d-modal .close");
run(() => showModal("test-title-with-body", { title: "test_title" }));
assert.equal(
find(".d-modal .title").text().trim(),
"Test title",
"it should display the title when used with d-modal-body"
);
await click(".d-modal .close");
run(() => showModal("test-title"));
assert.ok(
find(".d-modal .title").length === 0,
"it should not re-use the previous title"
);
});
acceptance("Modal Keyboard Events", { loggedIn: true });
test("modal-keyboard-events", async function (assert) {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await keyEvent(".d-modal", "keyup", 13);
assert.ok(
find("#modal-alert:visible").length === 1,
"hitting Enter triggers modal action"
);
assert.ok(
find(".d-modal:visible").length === 1,
"hitting Enter does not dismiss modal due to alert error"
);
await keyEvent("#main-outlet", "keyup", 27);
assert.ok(
find(".d-modal:visible").length === 0,
"ESC should close the modal"
);
await click(".topic-body button.reply");
await click(".d-editor-button-bar .btn.link");
await keyEvent(".d-modal", "keyup", 13);
assert.ok(
find(".d-modal:visible").length === 0,
"modal should disappear on hitting Enter"
);
}); });

View File

@ -2,36 +2,39 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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"
);
test("accessing new-message route when logged out", async (assert) => { assert.ok(exists(".modal.login-modal"), "it shows the login modal");
await visit( });
"/new-message?username=charlie&title=message%20title&body=message%20body"
);
assert.ok(exists(".modal.login-modal"), "it shows the login modal");
}); });
acceptance("New Message", { loggedIn: true }); acceptance("New Message - Authenticated", function (needs) {
test("accessing new-message route when logged in", async (assert) => { needs.user();
await visit(
"/new-message?username=charlie&title=message%20title&body=message%20body"
);
assert.ok(exists(".composer-fields"), "it opens composer"); test("accessing new-message route when logged in", async (assert) => {
assert.equal( await visit(
find("#reply-title").val().trim(), "/new-message?username=charlie&title=message%20title&body=message%20body"
"message title", );
"it pre-fills message title"
); assert.ok(exists(".composer-fields"), "it opens composer");
assert.equal( assert.equal(
find(".d-editor-input").val().trim(), find("#reply-title").val().trim(),
"message body", "message title",
"it pre-fills message body" "it pre-fills message title"
); );
assert.equal( assert.equal(
find(".users-input .item:eq(0)").text().trim(), find(".d-editor-input").val().trim(),
"charlie", "message body",
"it selects correct username" "it pre-fills message body"
); );
assert.equal(
find(".users-input .item:eq(0)").text().trim(),
"charlie",
"it selects correct username"
);
});
}); });

View File

@ -3,32 +3,36 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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");
test("accessing new-topic route when logged out", async (assert) => { assert.ok(exists(".modal.login-modal"), "it shows the login modal");
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) {
test("accessing new-topic route when logged in", async (assert) => { needs.user();
await visit("/new-topic?title=topic%20title&body=topic%20body&category=bug"); test("accessing new-topic route when logged in", async (assert) => {
await visit(
"/new-topic?title=topic%20title&body=topic%20body&category=bug"
);
assert.ok(exists(".composer-fields"), "it opens composer"); assert.ok(exists(".composer-fields"), "it opens composer");
assert.equal( assert.equal(
find("#reply-title").val().trim(), find("#reply-title").val().trim(),
"topic title", "topic title",
"it pre-fills topic title" "it pre-fills topic title"
); );
assert.equal( assert.equal(
find(".d-editor-input").val().trim(), find(".d-editor-input").val().trim(),
"topic body", "topic body",
"it pre-fills topic body" "it pre-fills topic body"
); );
assert.equal( assert.equal(
selectKit(".category-chooser").header().value(), selectKit(".category-chooser").header().value(),
1, 1,
"it selects desired category" "it selects desired category"
); );
});
}); });

View File

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

View File

@ -2,9 +2,9 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Page Publishing", { acceptance("Page Publishing", function (needs) {
loggedIn: true, needs.user();
pretend(server, helper) { needs.pretender((server, helper) => {
const validSlug = helper.response({ valid_slug: true }); const validSlug = helper.response({ valid_slug: true });
server.put("/pub/by-topic/280", () => { server.put("/pub/by-topic/280", () => {
@ -22,21 +22,22 @@ acceptance("Page Publishing", {
reason: "i don't need a reason", 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");
await click(".topic-post:eq(0) button.show-post-admin-menu");
await click(".topic-post:eq(0) .publish-page");
await fillIn(".publish-slug", "bad-slug"); test("can publish a page via modal", async (assert) => {
assert.ok(!exists(".valid-slug")); await visit("/t/internationalization-localization/280");
assert.ok(exists(".invalid-slug")); await click(".topic-post:eq(0) button.show-more-actions");
await fillIn(".publish-slug", "internationalization-localization"); await click(".topic-post:eq(0) button.show-post-admin-menu");
assert.ok(exists(".valid-slug")); await click(".topic-post:eq(0) .publish-page");
assert.ok(!exists(".invalid-slug"));
await click(".publish-page"); await fillIn(".publish-slug", "bad-slug");
assert.ok(exists(".current-url")); assert.ok(!exists(".valid-slug"));
assert.ok(exists(".invalid-slug"));
await fillIn(".publish-slug", "internationalization-localization");
assert.ok(exists(".valid-slug"));
assert.ok(!exists(".invalid-slug"));
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 PreloadStore from "discourse/lib/preload-store";
import { parsePostData } from "discourse/tests/helpers/create-pretender"; import { parsePostData } from "discourse/tests/helpers/create-pretender";
acceptance("Password Reset", { acceptance("Password Reset", function (needs) {
pretend(server, helper) { needs.pretender((server, helper) => {
server.get("/u/confirm-email-token/myvalidtoken.json", () => 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", () => 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) => { server.put("/u/password-reset/myvalidtoken.json", (request) => {
const body = parsePostData(request.requestBody); const body = parsePostData(request.requestBody);
if (body.password === "jonesyAlienSlayer") { if (body.password === "jonesyAlienSlayer") {
return helper.response(200, { return helper.response({
success: false, success: false,
errors: { password: ["is the name of your cat"] }, errors: { password: ["is the name of your cat"] },
}); });
} else { } else {
return helper.response(200, { return helper.response({
success: "OK", success: "OK",
message: I18n.t("password_reset.success"), message: I18n.t("password_reset.success"),
}); });
@ -36,87 +36,88 @@ acceptance("Password Reset", {
body.password === "perf3ctly5ecur3" && body.password === "perf3ctly5ecur3" &&
body.second_factor_token === "123123" body.second_factor_token === "123123"
) { ) {
return helper.response(200, { return helper.response({
success: "OK", success: "OK",
message: I18n.t("password_reset.success"), message: I18n.t("password_reset.success"),
}); });
} else if (body.second_factor_token === "123123") { } else if (body.second_factor_token === "123123") {
return helper.response(200, { return helper.response({
success: false, success: false,
errors: { password: ["invalid"] }, errors: { password: ["invalid"] },
}); });
} else { } else {
return helper.response(200, { return helper.response({
success: false, success: false,
message: "invalid token", message: "invalid token",
errors: { user_second_factors: ["invalid token"] }, errors: { user_second_factors: ["invalid token"] },
}); });
} }
}); });
},
});
test("Password Reset Page", async (assert) => {
PreloadStore.store("password_reset", { is_developer: false });
await visit("/u/password-reset/myvalidtoken");
assert.ok(exists(".password-reset input"), "shows the input");
await fillIn(".password-reset input", "perf3ctly5ecur3");
assert.ok(exists(".password-reset .tip.good"), "input looks good");
await fillIn(".password-reset input", "123");
assert.ok(exists(".password-reset .tip.bad"), "input is not valid");
assert.ok(
find(".password-reset .tip.bad")
.html()
.indexOf(I18n.t("user.password.too_short")) > -1,
"password too short"
);
await fillIn(".password-reset input", "jonesyAlienSlayer");
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,
"server validation error message shows"
);
await fillIn(".password-reset input", "perf3ctly5ecur3");
await click(".password-reset form button");
assert.ok(!exists(".password-reset form"), "form is gone");
});
test("Password Reset Page With Second Factor", async (assert) => {
PreloadStore.store("password_reset", {
is_developer: false,
second_factor_required: true,
}); });
await visit("/u/password-reset/requiretwofactor"); test("Password Reset Page", async (assert) => {
PreloadStore.store("password_reset", { is_developer: false });
assert.notOk(exists("#new-account-password"), "does not show the input"); await visit("/u/password-reset/myvalidtoken");
assert.ok(exists("#second-factor"), "shows the second factor prompt"); assert.ok(exists(".password-reset input"), "shows the input");
await fillIn("input#second-factor", "0000"); await fillIn(".password-reset input", "perf3ctly5ecur3");
await click(".password-reset form button"); assert.ok(exists(".password-reset .tip.good"), "input looks good");
assert.ok(exists(".alert-error"), "shows 2 factor error"); await fillIn(".password-reset input", "123");
assert.ok(exists(".password-reset .tip.bad"), "input is not valid");
assert.ok(
find(".password-reset .tip.bad")
.html()
.indexOf(I18n.t("user.password.too_short")) > -1,
"password too short"
);
assert.ok( await fillIn(".password-reset input", "jonesyAlienSlayer");
find(".alert-error").html().indexOf("invalid token") > -1, await click(".password-reset form button");
"shows server validation error message" 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,
"server validation error message shows"
);
await fillIn("input#second-factor", "123123"); await fillIn(".password-reset input", "perf3ctly5ecur3");
await click(".password-reset form button"); await click(".password-reset form button");
assert.ok(!exists(".password-reset form"), "form is gone");
});
assert.notOk(exists(".alert-error"), "hides error"); test("Password Reset Page With Second Factor", async (assert) => {
assert.ok(exists("#new-account-password"), "shows the input"); PreloadStore.store("password_reset", {
is_developer: false,
second_factor_required: true,
});
await fillIn(".password-reset input", "perf3ctly5ecur3"); await visit("/u/password-reset/requiretwofactor");
await click(".password-reset form button");
assert.ok(!exists(".password-reset form"), "form is gone"); assert.notOk(exists("#new-account-password"), "does not show the input");
assert.ok(exists("#second-factor"), "shows the second factor prompt");
await fillIn("input#second-factor", "0000");
await click(".password-reset form button");
assert.ok(exists(".alert-error"), "shows 2 factor error");
assert.ok(
find(".alert-error").html().indexOf("invalid token") > -1,
"shows server validation error message"
);
await fillIn("input#second-factor", "123123");
await click(".password-reset form button");
assert.notOk(exists(".alert-error"), "hides error");
assert.ok(exists("#new-account-password"), "shows the input");
await fillIn(".password-reset input", "perf3ctly5ecur3");
await click(".password-reset form button");
assert.ok(!exists(".password-reset form"), "form is gone");
});
}); });

View File

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

View File

@ -5,49 +5,46 @@ import { withPluginApi } from "discourse/lib/plugin-api";
import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts"; import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
import KeyboardShortcutInitializer from "discourse/initializers/keyboard-shortcuts"; import KeyboardShortcutInitializer from "discourse/initializers/keyboard-shortcuts";
acceptance("Plugin Keyboard Shortcuts - Logged In", { acceptance("Plugin Keyboard Shortcuts - Logged In", function (needs) {
loggedIn: true, needs.user();
beforeEach() { needs.hooks.beforeEach(function () {
KeyboardShortcutInitializer.initialize(this.container); KeyboardShortcutInitializer.initialize(this.container);
},
});
test("a plugin can add a keyboard shortcut", async (assert) => {
withPluginApi("0.8.38", (api) => {
api.addKeyboardShortcut("]", () => {
$("#qunit-fixture").html(
"<div id='added-element'>Test adding plugin shortcut</div>"
);
});
}); });
test("a plugin can add a keyboard shortcut", async (assert) => {
withPluginApi("0.8.38", (api) => {
api.addKeyboardShortcut("]", () => {
$("#qunit-fixture").html(
"<div id='added-element'>Test adding plugin shortcut</div>"
);
});
});
await visit("/t/this-is-a-test-topic/9"); await visit("/t/this-is-a-test-topic/9");
await keyEvent(document, "keypress", "]".charCodeAt(0)); await keyEvent(document, "keypress", "]".charCodeAt(0));
assert.equal( assert.equal(
$("#added-element").length, $("#added-element").length,
1, 1,
"the keyboard shortcut callback fires successfully" "the keyboard shortcut callback fires successfully"
); );
});
}); });
acceptance("Plugin Keyboard Shortcuts - Anonymous", { acceptance("Plugin Keyboard Shortcuts - Anonymous", function (needs) {
loggedIn: false, needs.hooks.beforeEach(function () {
beforeEach() {
KeyboardShortcutInitializer.initialize(this.container); 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) => {
api.addKeyboardShortcut("]", () => {}, {
anonymous: true,
path: "test-path",
});
}); });
test("a plugin can add a keyboard shortcut with an option", async (assert) => {
let spy = sandbox.spy(KeyboardShortcuts, "_bindToPath");
withPluginApi("0.8.38", (api) => {
api.addKeyboardShortcut("]", () => {}, {
anonymous: true,
path: "test-path",
});
});
assert.ok( assert.ok(
spy.calledWith("test-path", "]"), spy.calledWith("test-path", "]"),
"bindToPath is called due to options provided" "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"; import { action } from "@ember/object";
const PREFIX = "javascripts/single-test/connectors"; 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", { extraConnectorClass("user-profile-primary/hello", {
actions: { actions: {
sayHello() { sayHello() {
@ -57,33 +58,33 @@ acceptance("Plugin Outlet - Connector Class", {
Ember.TEMPLATES[ Ember.TEMPLATES[
`${PREFIX}/user-profile-primary/dont-render` `${PREFIX}/user-profile-primary/dont-render`
] = Ember.HTMLBars.compile(`I'm not rendered!`); ] = 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/hello`];
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hi`]; delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hi`];
delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`]; delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`];
}, });
});
test("Renders a template into the outlet", async (assert) => {
test("Renders a template into the outlet", async (assert) => { await visit("/u/eviltrout");
await visit("/u/eviltrout"); assert.ok(
assert.ok( find(".user-profile-primary-outlet.hello").length === 1,
find(".user-profile-primary-outlet.hello").length === 1, "it has class names"
"it has class names" );
); assert.ok(
assert.ok( !find(".user-profile-primary-outlet.dont-render").length,
!find(".user-profile-primary-outlet.dont-render").length, "doesn't render"
"doesn't render" );
);
await click(".say-hello");
await click(".say-hello"); assert.equal(
assert.equal( find(".hello-result").text(),
find(".hello-result").text(), "hello!",
"hello!", "actions delegate properly"
"actions delegate properly" );
);
await click(".say-hi");
await click(".say-hi"); assert.equal(find(".hi-result").text(), "hi!", "actions delegate properly");
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"; import { withPluginApi } from "discourse/lib/plugin-api";
const PREFIX = "javascripts/single-test/connectors"; 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[ Ember.TEMPLATES[
`${PREFIX}/discovery-list-container-top/foo` `${PREFIX}/discovery-list-container-top/foo`
] = Ember.HTMLBars.compile("FOO"); ] = Ember.HTMLBars.compile("FOO");
@ -32,29 +33,29 @@ acceptance("Plugin Outlet - Decorator", {
{ id: "yellow-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/foo`];
delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/bar`]; delete Ember.TEMPLATES[`${PREFIX}/discovery-list-container-top/bar`];
}, });
});
test("Calls the plugin callback with the rendered outlet", async (assert) => {
test("Calls the plugin callback with the rendered outlet", async (assert) => { await visit("/");
await visit("/");
const fooConnector = find(".discovery-list-container-top-outlet.foo ")[0];
const fooConnector = find(".discovery-list-container-top-outlet.foo ")[0]; const barConnector = find(".discovery-list-container-top-outlet.bar ")[0];
const barConnector = find(".discovery-list-container-top-outlet.bar ")[0];
assert.ok(exists(fooConnector));
assert.ok(exists(fooConnector)); assert.equal(fooConnector.style.backgroundColor, "yellow");
assert.equal(fooConnector.style.backgroundColor, "yellow"); assert.equal(barConnector.style.backgroundColor, "");
assert.equal(barConnector.style.backgroundColor, "");
await visit("/c/bug");
await visit("/c/bug");
assert.ok(fooConnector.classList.contains("in-category"));
assert.ok(fooConnector.classList.contains("in-category"));
await visit("/");
await visit("/");
assert.notOk(fooConnector.classList.contains("in-category"));
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 = const GOODBYE =
"javascripts/multi-test/connectors/user-profile-primary/goodbye"; "javascripts/multi-test/connectors/user-profile-primary/goodbye";
acceptance("Plugin Outlet - Multi Template", { acceptance("Plugin Outlet - Multi Template", function (needs) {
beforeEach() { needs.hooks.beforeEach(() => {
clearCache(); clearCache();
Ember.TEMPLATES[HELLO] = Ember.HTMLBars.compile( Ember.TEMPLATES[HELLO] = Ember.HTMLBars.compile(
`<span class='hello-span'>Hello</span>` `<span class='hello-span'>Hello</span>`
@ -16,33 +16,33 @@ acceptance("Plugin Outlet - Multi Template", {
Ember.TEMPLATES[GOODBYE] = Ember.HTMLBars.compile( Ember.TEMPLATES[GOODBYE] = Ember.HTMLBars.compile(
`<span class='bye-span'>Goodbye</span>` `<span class='bye-span'>Goodbye</span>`
); );
}, });
afterEach() { needs.hooks.afterEach(() => {
delete Ember.TEMPLATES[HELLO]; delete Ember.TEMPLATES[HELLO];
delete Ember.TEMPLATES[GOODBYE]; delete Ember.TEMPLATES[GOODBYE];
clearCache(); clearCache();
}, });
});
test("Renders a template into the outlet", async (assert) => { test("Renders a template into the outlet", async (assert) => {
await visit("/u/eviltrout"); await visit("/u/eviltrout");
assert.ok( assert.ok(
find(".user-profile-primary-outlet.hello").length === 1, find(".user-profile-primary-outlet.hello").length === 1,
"it has class names" "it has class names"
); );
assert.ok( assert.ok(
find(".user-profile-primary-outlet.goodbye").length === 1, find(".user-profile-primary-outlet.goodbye").length === 1,
"it has class names" "it has class names"
); );
assert.equal( assert.equal(
find(".hello-span").text(), find(".hello-span").text(),
"Hello", "Hello",
"it renders into the outlet" "it renders into the outlet"
); );
assert.equal( assert.equal(
find(".bye-span").text(), find(".bye-span").text(),
"Goodbye", "Goodbye",
"it renders into the outlet" "it renders into the outlet"
); );
});
}); });

View File

@ -4,27 +4,28 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
const CONNECTOR = const CONNECTOR =
"javascripts/single-test/connectors/user-profile-primary/hello"; "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( Ember.TEMPLATES[CONNECTOR] = Ember.HTMLBars.compile(
`<span class='hello-username'>{{model.username}}</span>` `<span class='hello-username'>{{model.username}}</span>`
); );
}, });
afterEach() { needs.hooks.afterEach(() => {
delete Ember.TEMPLATES[CONNECTOR]; delete Ember.TEMPLATES[CONNECTOR];
}, });
});
test("Renders a template into the outlet", async (assert) => { test("Renders a template into the outlet", async (assert) => {
await visit("/u/eviltrout"); await visit("/u/eviltrout");
assert.ok( assert.ok(
find(".user-profile-primary-outlet.hello").length === 1, find(".user-profile-primary-outlet.hello").length === 1,
"it has class names" "it has class names"
); );
assert.equal( assert.equal(
find(".hello-username").text(), find(".hello-username").text(),
"eviltrout", "eviltrout",
"it renders into the outlet" "it renders into the outlet"
); );
});
}); });

View File

@ -2,33 +2,34 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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");
test("Enter as a anon user", async (assert) => { assert.ok(exists("#topic"), "The topic was rendered");
await visit("/t/internationalization-localization/280"); assert.ok(
await click(".show-more-actions"); exists("#post_1 .post-controls .edit"),
"The edit button was not rendered"
assert.ok(exists("#topic"), "The topic was rendered"); );
assert.ok( assert.ok(
exists("#post_1 .post-controls .edit"), !exists(".show-post-admin-menu"),
"The edit button was not rendered" "The wrench button was not rendered"
); );
assert.ok( });
!exists(".show-post-admin-menu"),
"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");
await click(".show-post-admin-menu");
test("Enter as a user with group moderator permissions", async (assert) => { assert.ok(
await visit("/t/topic-for-group-moderators/2480"); exists("#post_1 .post-controls .edit"),
await click(".show-more-actions"); "The edit button was rendered"
await click(".show-post-admin-menu"); );
assert.ok(exists(".add-notice"), "The add notice button was rendered");
assert.ok( });
exists("#post_1 .post-controls .edit"),
"The edit button was rendered"
);
assert.ok(exists(".add-notice"), "The add notice button was rendered");
}); });

View File

@ -66,184 +66,185 @@ function preferencesPretender(server, helper) {
}); });
} }
acceptance("User Preferences", { acceptance("User Preferences", function (needs) {
loggedIn: true, needs.user();
pretend: preferencesPretender, needs.pretender(preferencesPretender);
}); test("update some fields", async (assert) => {
await visit("/u/eviltrout/preferences");
test("update some fields", async (assert) => { assert.ok($("body.user-preferences-page").length, "has the body class");
await visit("/u/eviltrout/preferences"); assert.equal(
currentURL(),
"/u/eviltrout/preferences/account",
"defaults to account tab"
);
assert.ok(exists(".user-preferences"), "it shows the preferences");
assert.ok($("body.user-preferences-page").length, "has the body class"); const savePreferences = async () => {
assert.equal( assert.ok(!exists(".saved"), "it hasn't been saved yet");
currentURL(), await click(".save-changes");
"/u/eviltrout/preferences/account", assert.ok(exists(".saved"), "it displays the saved message");
"defaults to account tab" find(".saved").remove();
); };
assert.ok(exists(".user-preferences"), "it shows the preferences");
const savePreferences = async () => { fillIn(".pref-name input[type=text]", "Jon Snow");
assert.ok(!exists(".saved"), "it hasn't been saved yet"); await savePreferences();
await click(".save-changes");
assert.ok(exists(".saved"), "it displays the saved message");
find(".saved").remove();
};
fillIn(".pref-name input[type=text]", "Jon Snow"); click(".preferences-nav .nav-profile a");
await savePreferences(); fillIn("#edit-location", "Westeros");
await savePreferences();
click(".preferences-nav .nav-profile a"); click(".preferences-nav .nav-emails a");
fillIn("#edit-location", "Westeros"); click(".pref-activity-summary input[type=checkbox]");
await savePreferences(); await savePreferences();
click(".preferences-nav .nav-emails a"); click(".preferences-nav .nav-notifications a");
click(".pref-activity-summary input[type=checkbox]"); await selectKit(
await savePreferences(); ".control-group.notifications .combo-box.duration"
).expand();
await selectKit(
".control-group.notifications .combo-box.duration"
).selectRowByValue(1440);
await savePreferences();
click(".preferences-nav .nav-notifications a"); click(".preferences-nav .nav-categories a");
await selectKit(".control-group.notifications .combo-box.duration").expand(); fillIn(".tracking-controls .category-selector", "faq");
await selectKit( await savePreferences();
".control-group.notifications .combo-box.duration"
).selectRowByValue(1440);
await savePreferences();
click(".preferences-nav .nav-categories a");
fillIn(".tracking-controls .category-selector", "faq");
await savePreferences();
assert.ok(
!exists(".preferences-nav .nav-tags a"),
"tags tab isn't there when tags are disabled"
);
click(".preferences-nav .nav-interface a");
click(".control-group.other input[type=checkbox]:first");
savePreferences();
assert.ok(
!exists(".preferences-nav .nav-apps a"),
"apps tab isn't there when you have no authorized apps"
);
});
test("username", async (assert) => {
await visit("/u/eviltrout/preferences/username");
assert.ok(exists("#change_username"), "it has the input element");
});
test("email", async (assert) => {
await visit("/u/eviltrout/preferences/email");
assert.ok(exists("#change-email"), "it has the input element");
await fillIn("#change-email", "invalidemail");
assert.equal(
find(".tip.bad").text().trim(),
I18n.t("user.email.invalid"),
"it should display invalid email tip"
);
});
test("email field always shows up", async (assert) => {
await visit("/u/eviltrout/preferences/email");
assert.ok(exists("#change-email"), "it has the input element");
await fillIn("#change-email", "eviltrout@discourse.org");
await click(".user-preferences button.btn-primary");
await visit("/u/eviltrout/preferences");
await visit("/u/eviltrout/preferences/email");
assert.ok(exists("#change-email"), "it has the input element");
});
test("connected accounts", async (assert) => {
await visit("/u/eviltrout/preferences/account");
assert.ok(
exists(".pref-associated-accounts"),
"it has the connected accounts section"
);
assert.ok(
find(".pref-associated-accounts table tr:first td:first")
.html()
.indexOf("Facebook") > -1,
"it lists facebook"
);
await click(".pref-associated-accounts table tr:first td:last button");
find(".pref-associated-accounts table tr:first td:last button")
.html()
.indexOf("Connect") > -1;
});
test("second factor totp", async (assert) => {
await visit("/u/eviltrout/preferences/second-factor");
assert.ok(exists("#password"), "it has a password input");
await fillIn("#password", "secrets");
await click(".user-preferences .btn-primary");
assert.notOk(exists("#password"), "it hides the password input");
await click(".new-totp");
assert.ok(exists("#test-qr"), "shows qr code");
await click(".add-totp");
assert.ok(
find(".alert-error").html().indexOf("provide a name and the code") > -1,
"shows name/token missing error message"
);
});
test("second factor security keys", async (assert) => {
await visit("/u/eviltrout/preferences/second-factor");
assert.ok(exists("#password"), "it has a password input");
await fillIn("#password", "secrets");
await click(".user-preferences .btn-primary");
assert.notOk(exists("#password"), "it hides the password input");
await click(".new-security-key");
assert.ok(exists("#security-key-name"), "shows security key name input");
fillIn("#security-key-name", "");
// The following tests can only run when Webauthn is enabled. This is not
// always the case, for example on a browser running on a non-standard port
if (typeof PublicKeyCredential !== "undefined") {
await click(".add-security-key");
assert.ok( assert.ok(
find(".alert-error").html().indexOf("provide a name") > -1, !exists(".preferences-nav .nav-tags a"),
"shows name missing error message" "tags tab isn't there when tags are disabled"
); );
}
click(".preferences-nav .nav-interface a");
click(".control-group.other input[type=checkbox]:first");
savePreferences();
assert.ok(
!exists(".preferences-nav .nav-apps a"),
"apps tab isn't there when you have no authorized apps"
);
});
test("username", async (assert) => {
await visit("/u/eviltrout/preferences/username");
assert.ok(exists("#change_username"), "it has the input element");
});
test("email", async (assert) => {
await visit("/u/eviltrout/preferences/email");
assert.ok(exists("#change-email"), "it has the input element");
await fillIn("#change-email", "invalidemail");
assert.equal(
find(".tip.bad").text().trim(),
I18n.t("user.email.invalid"),
"it should display invalid email tip"
);
});
test("email field always shows up", async (assert) => {
await visit("/u/eviltrout/preferences/email");
assert.ok(exists("#change-email"), "it has the input element");
await fillIn("#change-email", "eviltrout@discourse.org");
await click(".user-preferences button.btn-primary");
await visit("/u/eviltrout/preferences");
await visit("/u/eviltrout/preferences/email");
assert.ok(exists("#change-email"), "it has the input element");
});
test("connected accounts", async (assert) => {
await visit("/u/eviltrout/preferences/account");
assert.ok(
exists(".pref-associated-accounts"),
"it has the connected accounts section"
);
assert.ok(
find(".pref-associated-accounts table tr:first td:first")
.html()
.indexOf("Facebook") > -1,
"it lists facebook"
);
await click(".pref-associated-accounts table tr:first td:last button");
find(".pref-associated-accounts table tr:first td:last button")
.html()
.indexOf("Connect") > -1;
});
test("second factor totp", async (assert) => {
await visit("/u/eviltrout/preferences/second-factor");
assert.ok(exists("#password"), "it has a password input");
await fillIn("#password", "secrets");
await click(".user-preferences .btn-primary");
assert.notOk(exists("#password"), "it hides the password input");
await click(".new-totp");
assert.ok(exists("#test-qr"), "shows qr code");
await click(".add-totp");
assert.ok(
find(".alert-error").html().indexOf("provide a name and the code") > -1,
"shows name/token missing error message"
);
});
test("second factor security keys", async (assert) => {
await visit("/u/eviltrout/preferences/second-factor");
assert.ok(exists("#password"), "it has a password input");
await fillIn("#password", "secrets");
await click(".user-preferences .btn-primary");
assert.notOk(exists("#password"), "it hides the password input");
await click(".new-security-key");
assert.ok(exists("#security-key-name"), "shows security key name input");
fillIn("#security-key-name", "");
// The following tests can only run when Webauthn is enabled. This is not
// always the case, for example on a browser running on a non-standard port
if (typeof PublicKeyCredential !== "undefined") {
await click(".add-security-key");
assert.ok(
find(".alert-error").html().indexOf("provide a name") > -1,
"shows name missing error message"
);
}
});
test("default avatar selector", async (assert) => {
await visit("/u/eviltrout/preferences");
await click(".pref-avatar .btn");
assert.ok(exists(".avatar-choice", "opens the avatar selection modal"));
await click(".avatar-selector-refresh-gravatar");
assert.equal(
User.currentProp("gravatar_avatar_upload_id"),
6543,
"it should set the gravatar_avatar_upload_id property"
);
});
}); });
test("default avatar selector", async (assert) => { acceptance("Second Factor Backups", function (needs) {
await visit("/u/eviltrout/preferences"); needs.user();
needs.pretender((server, helper) => {
await click(".pref-avatar .btn");
assert.ok(exists(".avatar-choice", "opens the avatar selection modal"));
await click(".avatar-selector-refresh-gravatar");
assert.equal(
User.currentProp("gravatar_avatar_upload_id"),
6543,
"it should set the gravatar_avatar_upload_id property"
);
});
acceptance("Second Factor Backups", {
loggedIn: true,
pretend(server, helper) {
server.post("/u/second_factors.json", () => { server.post("/u/second_factors.json", () => {
return helper.response({ return helper.response({
success: "OK", success: "OK",
@ -260,25 +261,28 @@ acceptance("Second Factor Backups", {
server.get("/u/eviltrout/activity.json", () => { server.get("/u/eviltrout/activity.json", () => {
return helper.response({}); return helper.response({});
}); });
}, });
});
test("second factor backup", async (assert) => {
updateCurrentUser({ second_factor_enabled: true });
await visit("/u/eviltrout/preferences/second-factor");
await click(".edit-2fa-backup");
assert.ok(
exists(".second-factor-backup-preferences"),
"shows the 2fa backup panel"
);
await click(".second-factor-backup-preferences .btn-primary");
assert.ok(exists(".backup-codes-area"), "shows backup codes"); test("second factor backup", async (assert) => {
updateCurrentUser({ second_factor_enabled: true });
await visit("/u/eviltrout/preferences/second-factor");
await click(".edit-2fa-backup");
assert.ok(
exists(".second-factor-backup-preferences"),
"shows the 2fa backup panel"
);
await click(".second-factor-backup-preferences .btn-primary");
assert.ok(exists(".backup-codes-area"), "shows backup codes");
});
}); });
acceptance("Avatar selector when selectable avatars is enabled", { acceptance("Avatar selector when selectable avatars is enabled", function (
loggedIn: true, needs
settings: { selectable_avatars_enabled: true }, ) {
pretend(server) { needs.user();
needs.settings({ selectable_avatars_enabled: true });
needs.pretender((server) => {
server.get("/site/selectable-avatars.json", () => { server.get("/site/selectable-avatars.json", () => {
return [ return [
200, 200,
@ -286,127 +290,129 @@ acceptance("Avatar selector when selectable avatars is enabled", {
["https://www.discourse.org", "https://meta.discourse.org"], ["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")
);
});
}); });
test("selectable avatars", async (assert) => { acceptance("User Preferences when badges are disabled", function (needs) {
await visit("/u/eviltrout/preferences"); needs.user();
needs.settings({ enable_badges: false });
needs.pretender(preferencesPretender);
await click(".pref-avatar .btn"); test("visit my preferences", async (assert) => {
await visit("/u/eviltrout/preferences");
assert.ok($("body.user-preferences-page").length, "has the body class");
assert.equal(
currentURL(),
"/u/eviltrout/preferences/account",
"defaults to account tab"
);
assert.ok(exists(".user-preferences"), "it shows the preferences");
});
assert.ok(exists(".selectable-avatars", "opens the avatar selection modal")); test("recently connected devices", async (assert) => {
}); await visit("/u/eviltrout/preferences");
acceptance("User Preferences when badges are disabled", { assert.equal(
loggedIn: true, find(".auth-tokens > .auth-token:first .auth-token-device").text().trim(),
settings: { enable_badges: false }, "Linux Computer",
pretend: preferencesPretender, "it should display active token first"
}); );
test("visit my preferences", async (assert) => { assert.equal(
await visit("/u/eviltrout/preferences"); find(".pref-auth-tokens > a:first").text().trim(),
assert.ok($("body.user-preferences-page").length, "has the body class"); I18n.t("user.auth_tokens.show_all", { count: 3 }),
assert.equal( "it should display two tokens"
currentURL(), );
"/u/eviltrout/preferences/account", assert.ok(
"defaults to account tab" find(".pref-auth-tokens .auth-token").length === 2,
); "it should display two tokens"
assert.ok(exists(".user-preferences"), "it shows the preferences"); );
});
test("recently connected devices", async (assert) => { await click(".pref-auth-tokens > a:first");
await visit("/u/eviltrout/preferences");
assert.equal( assert.ok(
find(".auth-tokens > .auth-token:first .auth-token-device").text().trim(), find(".pref-auth-tokens .auth-token").length === 3,
"Linux Computer", "it should display three tokens"
"it should display active token first" );
);
assert.equal( await click(".auth-token-dropdown:first button");
find(".pref-auth-tokens > a:first").text().trim(), await click("li[data-value='notYou']");
I18n.t("user.auth_tokens.show_all", { count: 3 }),
"it should display two tokens"
);
assert.ok(
find(".pref-auth-tokens .auth-token").length === 2,
"it should display two tokens"
);
await click(".pref-auth-tokens > a:first"); assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
assert.ok( await click(".modal-footer .btn-primary");
find(".pref-auth-tokens .auth-token").length === 3,
"it should display three tokens"
);
await click(".auth-token-dropdown:first button"); assert.ok(
await click("li[data-value='notYou']"); find(".pref-password.highlighted").length === 1,
"it should highlight password preferences"
assert.ok(find(".d-modal:visible").length === 1, "modal should appear"); );
});
await click(".modal-footer .btn-primary");
assert.ok(
find(".pref-password.highlighted").length === 1,
"it should highlight password preferences"
);
}); });
acceptance( acceptance(
"User can select a topic to feature on profile if site setting in enabled", "User can select a topic to feature on profile if site setting in enabled",
{ function (needs) {
loggedIn: true, needs.user();
settings: { allow_featured_topic_on_user_profiles: true }, needs.settings({ allow_featured_topic_on_user_profiles: true });
needs.pretender((server, helper) => {
pretend(server, helper) {
server.put("/u/eviltrout/feature-topic", () => { server.put("/u/eviltrout/feature-topic", () => {
return helper.response({ return helper.response({
success: true, success: true,
}); });
}); });
}, });
test("setting featured topic on profile", async (assert) => {
await visit("/u/eviltrout/preferences/profile");
assert.ok(
!exists(".featured-topic-link"),
"no featured topic link to present"
);
assert.ok(
!exists(".clear-feature-topic-on-profile-btn"),
"clear button not present"
);
const selectTopicBtn = find(".feature-topic-on-profile-btn:first");
assert.ok(exists(selectTopicBtn), "feature topic button is present");
await click(selectTopicBtn);
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");
await click(topicRadioBtn);
await click(".save-featured-topic-on-profile");
assert.ok(
exists(".featured-topic-link"),
"link to featured topic is present"
);
assert.ok(
exists(".clear-feature-topic-on-profile-btn"),
"clear button is present"
);
});
} }
); );
test("setting featured topic on profile", async (assert) => { acceptance("Custom User Fields", function (needs) {
await visit("/u/eviltrout/preferences/profile"); needs.user();
needs.site({
assert.ok(
!exists(".featured-topic-link"),
"no featured topic link to present"
);
assert.ok(
!exists(".clear-feature-topic-on-profile-btn"),
"clear button not present"
);
const selectTopicBtn = find(".feature-topic-on-profile-btn:first");
assert.ok(exists(selectTopicBtn), "feature topic button is present");
await click(selectTopicBtn);
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");
await click(topicRadioBtn);
await click(".save-featured-topic-on-profile");
assert.ok(
exists(".featured-topic-link"),
"link to featured topic is present"
);
assert.ok(
exists(".clear-feature-topic-on-profile-btn"),
"clear button is present"
);
});
acceptance("Custom User Fields", {
loggedIn: true,
site: {
user_fields: [ user_fields: [
{ {
id: 30, id: 30,
@ -416,46 +422,50 @@ acceptance("Custom User Fields", {
required: true, required: true,
}, },
], ],
}, });
pretend: preferencesPretender, needs.pretender(preferencesPretender);
});
test("can select an option from a dropdown", async (assert) => { test("can select an option from a dropdown", async (assert) => {
await visit("/u/eviltrout/preferences/profile"); await visit("/u/eviltrout/preferences/profile");
assert.ok(exists(".user-field"), "it has at least one user field"); assert.ok(exists(".user-field"), "it has at least one user field");
await click(".user-field.dropdown"); await click(".user-field.dropdown");
const field = selectKit( const field = selectKit(
".user-field-what-kind-of-pet-do-you-have .combo-box" ".user-field-what-kind-of-pet-do-you-have .combo-box"
); );
await field.expand(); await field.expand();
await field.selectRowByValue("Cat"); 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( acceptance(
"User Preferences, selecting bookmarks discovery as user's default homepage", "User Preferences, selecting bookmarks discovery as user's default homepage",
{ function (needs) {
loggedIn: true, needs.user();
settings: { needs.settings({
top_menu: "categories|latest|top|bookmarks", top_menu: "categories|latest|top|bookmarks",
}, });
test("selecting bookmarks as home directs home to bookmarks", async (assert) => {
await visit("/u/eviltrout/preferences/interface");
assert.ok(exists(".home .combo-box"), "it has a home selector combo-box");
const field = selectKit(".home .combo-box");
await field.expand();
await field.selectRowByValue("6");
await click(".save-changes");
await visit("/");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.equal(
currentPath(),
"discovery.bookmarks",
"it navigates to bookmarks"
);
});
} }
); );
test("selecting bookmarks as home directs home to bookmarks", async (assert) => {
await visit("/u/eviltrout/preferences/interface");
assert.ok(exists(".home .combo-box"), "it has a home selector combo-box");
const field = selectKit(".home .combo-box");
await field.expand();
await field.selectRowByValue("6");
await click(".save-changes");
await visit("/");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.equal(
currentPath(),
"discovery.bookmarks",
"it navigates to bookmarks"
);
});

View File

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

View File

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

View File

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

View File

@ -3,132 +3,132 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Review", { acceptance("Review", function (needs) {
loggedIn: true, needs.user();
});
const user = ".reviewable-item[data-reviewable-id=1234]";
const user = ".reviewable-item[data-reviewable-id=1234]";
test("It returns a list of reviewable items", async (assert) => {
test("It returns a list of reviewable items", async (assert) => { await visit("/review");
await visit("/review");
assert.ok(find(".reviewable-item").length, "has a list of items");
assert.ok(find(".reviewable-item").length, "has a list of items"); assert.ok(find(user).length);
assert.ok(find(user).length); assert.ok(
assert.ok( find(`${user}.reviewable-user`).length,
find(`${user}.reviewable-user`).length, "applies a class for the type"
"applies a class for the type" );
); assert.ok(
assert.ok( find(`${user} .reviewable-action.approve`).length,
find(`${user} .reviewable-action.approve`).length, "creates a button for approve"
"creates a button for approve" );
); assert.ok(
assert.ok( find(`${user} .reviewable-action.reject`).length,
find(`${user} .reviewable-action.reject`).length, "creates a button for reject"
"creates a button for reject" );
); });
});
test("Grouped by topic", async (assert) => {
test("Grouped by topic", async (assert) => { await visit("/review/topics");
await visit("/review/topics"); assert.ok(
assert.ok( find(".reviewable-topic").length,
find(".reviewable-topic").length, "it has a list of reviewable topics"
"it has a list of reviewable topics" );
); });
});
test("Settings", async (assert) => {
test("Settings", async (assert) => { await visit("/review/settings");
await visit("/review/settings");
assert.ok(find(".reviewable-score-type").length, "has a list of bonuses");
assert.ok(find(".reviewable-score-type").length, "has a list of bonuses");
const field = selectKit(".reviewable-score-type:eq(0) .field .combo-box");
const field = selectKit(".reviewable-score-type:eq(0) .field .combo-box"); await field.expand();
await field.expand(); await field.selectRowByValue("5");
await field.selectRowByValue("5"); await click(".save-settings");
await click(".save-settings");
assert.ok(find(".reviewable-settings .saved").length, "it saved");
assert.ok(find(".reviewable-settings .saved").length, "it saved"); });
});
test("Flag related", async (assert) => {
test("Flag related", async (assert) => { await visit("/review");
await visit("/review");
assert.ok(
assert.ok( find(".reviewable-flagged-post .post-contents .username a[href]").length,
find(".reviewable-flagged-post .post-contents .username a[href]").length, "it has a link to the user"
"it has a link to the user" );
);
assert.equal(
assert.equal( find(".reviewable-flagged-post .post-body").html().trim(),
find(".reviewable-flagged-post .post-body").html().trim(), "<b>cooked content</b>"
"<b>cooked content</b>" );
);
assert.equal(find(".reviewable-flagged-post .reviewable-score").length, 2);
assert.equal(find(".reviewable-flagged-post .reviewable-score").length, 2); });
});
test("Flag related", async (assert) => {
test("Flag related", async (assert) => { await visit("/review/1");
await visit("/review/1");
assert.ok(
assert.ok( find(".reviewable-flagged-post").length,
find(".reviewable-flagged-post").length, "it shows the flagged post"
"it shows the flagged post" );
); });
});
test("Clicking the buttons triggers actions", async (assert) => {
test("Clicking the buttons triggers actions", async (assert) => { await visit("/review");
await visit("/review"); await click(`${user} .reviewable-action.approve`);
await click(`${user} .reviewable-action.approve`); assert.equal(find(user).length, 0, "it removes the reviewable on success");
assert.equal(find(user).length, 0, "it removes the reviewable on success"); });
});
test("Editing a reviewable", async (assert) => {
test("Editing a reviewable", async (assert) => { const topic = ".reviewable-item[data-reviewable-id=4321]";
const topic = ".reviewable-item[data-reviewable-id=4321]"; await visit("/review");
await visit("/review"); assert.ok(find(`${topic} .reviewable-action.approve`).length);
assert.ok(find(`${topic} .reviewable-action.approve`).length); assert.ok(!find(`${topic} .category-name`).length);
assert.ok(!find(`${topic} .category-name`).length); assert.equal(find(`${topic} .discourse-tag:eq(0)`).text(), "hello");
assert.equal(find(`${topic} .discourse-tag:eq(0)`).text(), "hello"); assert.equal(find(`${topic} .discourse-tag:eq(1)`).text(), "world");
assert.equal(find(`${topic} .discourse-tag:eq(1)`).text(), "world");
assert.equal(find(`${topic} .post-body`).text().trim(), "existing body");
assert.equal(find(`${topic} .post-body`).text().trim(), "existing body");
await click(`${topic} .reviewable-action.edit`);
await click(`${topic} .reviewable-action.edit`); await click(`${topic} .reviewable-action.save-edit`);
await click(`${topic} .reviewable-action.save-edit`); assert.ok(
assert.ok( find(`${topic} .reviewable-action.approve`).length,
find(`${topic} .reviewable-action.approve`).length, "saving without changes is a cancel"
"saving without changes is a cancel" );
); await click(`${topic} .reviewable-action.edit`);
await click(`${topic} .reviewable-action.edit`);
assert.equal(
assert.equal( find(`${topic} .reviewable-action.approve`).length,
find(`${topic} .reviewable-action.approve`).length, 0,
0, "when editing actions are disabled"
"when editing actions are disabled" );
);
await fillIn(".editable-field.payload-raw textarea", "new raw contents");
await fillIn(".editable-field.payload-raw textarea", "new raw contents"); await click(`${topic} .reviewable-action.cancel-edit`);
await click(`${topic} .reviewable-action.cancel-edit`); assert.equal(
assert.equal( find(`${topic} .post-body`).text().trim(),
find(`${topic} .post-body`).text().trim(), "existing body",
"existing body", "cancelling does not update the value"
"cancelling does not update the value" );
);
await click(`${topic} .reviewable-action.edit`);
await click(`${topic} .reviewable-action.edit`); let category = selectKit(`${topic} .category-id .select-kit`);
let category = selectKit(`${topic} .category-id .select-kit`); await category.expand();
await category.expand(); await category.selectRowByValue("6");
await category.selectRowByValue("6");
let tags = selectKit(`${topic} .payload-tags .mini-tag-chooser`);
let tags = selectKit(`${topic} .payload-tags .mini-tag-chooser`); await tags.expand();
await tags.expand(); await tags.fillInFilter("monkey");
await tags.fillInFilter("monkey"); await tags.selectRowByValue("monkey");
await tags.selectRowByValue("monkey");
await fillIn(".editable-field.payload-raw textarea", "new raw contents");
await fillIn(".editable-field.payload-raw textarea", "new raw contents"); await click(`${topic} .reviewable-action.save-edit`);
await click(`${topic} .reviewable-action.save-edit`);
assert.equal(find(`${topic} .discourse-tag:eq(0)`).text(), "hello");
assert.equal(find(`${topic} .discourse-tag:eq(0)`).text(), "hello"); assert.equal(find(`${topic} .discourse-tag:eq(1)`).text(), "world");
assert.equal(find(`${topic} .discourse-tag:eq(1)`).text(), "world"); assert.equal(find(`${topic} .discourse-tag:eq(2)`).text(), "monkey");
assert.equal(find(`${topic} .discourse-tag:eq(2)`).text(), "monkey");
assert.equal(find(`${topic} .post-body`).text().trim(), "new raw contents");
assert.equal(find(`${topic} .post-body`).text().trim(), "new raw contents"); assert.equal(find(`${topic} .category-name`).text().trim(), "support");
assert.equal(find(`${topic} .category-name`).text().trim(), "support"); });
}); });

View File

@ -8,10 +8,10 @@ import {
waitFor, waitFor,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
acceptance("Search - Full Page", { acceptance("Search - Full Page", function (needs) {
settings: { tagging_enabled: true }, needs.user();
loggedIn: true, needs.settings({ tagging_enabled: true });
pretend(server, helper) { needs.pretender((server, helper) => {
server.get("/tags/filter/search", () => { server.get("/tags/filter/search", () => {
return helper.response({ results: [{ text: "monkey", count: 1 }] }); return helper.response({ results: [{ text: "monkey", count: 1 }] });
}); });
@ -87,337 +87,337 @@ acceptance("Search - Full Page", {
], ],
}); });
}); });
}, });
});
test("perform various searches", async (assert) => { test("perform various searches", async (assert) => {
await visit("/search"); await visit("/search");
assert.ok($("body.search-page").length, "has body class"); assert.ok($("body.search-page").length, "has body class");
assert.ok(exists(".search-container"), "has container class"); assert.ok(exists(".search-container"), "has container class");
assert.ok(find(".search-query").length > 0); assert.ok(find(".search-query").length > 0);
assert.ok(find(".fps-topic").length === 0); assert.ok(find(".fps-topic").length === 0);
await fillIn(".search-query", "none"); await fillIn(".search-query", "none");
await click(".search-cta"); await click(".search-cta");
assert.ok(find(".fps-topic").length === 0, "has no results"); assert.ok(find(".fps-topic").length === 0, "has no results");
assert.ok(find(".no-results-suggestion .google-search-form")); assert.ok(find(".no-results-suggestion .google-search-form"));
await fillIn(".search-query", "posts"); await fillIn(".search-query", "posts");
await click(".search-cta"); await click(".search-cta");
assert.ok(find(".fps-topic").length === 1, "has one post"); assert.ok(find(".fps-topic").length === 1, "has one post");
}); });
test("escape search term", async (assert) => { test("escape search term", async (assert) => {
await visit("/search"); await visit("/search");
await fillIn(".search-query", "@<script>prompt(1337)</script>gmail.com"); await fillIn(".search-query", "@<script>prompt(1337)</script>gmail.com");
assert.ok(
exists(
'.search-advanced-options span:contains("&lt;script&gt;prompt(1337)&lt;/script&gt;gmail.com")'
),
"it escapes search term"
);
});
skip("update username through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await fillIn(".search-advanced-options .user-selector", "admin");
await click(".search-advanced-options .user-selector");
await keyEvent(".search-advanced-options .user-selector", "keydown", 8);
waitFor(assert, async () => {
assert.ok(
visible(".search-advanced-options .autocomplete"),
'"autocomplete" popup is visible'
);
assert.ok( assert.ok(
exists( exists(
'.search-advanced-options .autocomplete ul li a span.username:contains("admin")' '.search-advanced-options span:contains("&lt;script&gt;prompt(1337)&lt;/script&gt;gmail.com")'
), ),
'"autocomplete" popup has an entry for "admin"' "it escapes search term"
);
});
skip("update username through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await fillIn(".search-advanced-options .user-selector", "admin");
await click(".search-advanced-options .user-selector");
await keyEvent(".search-advanced-options .user-selector", "keydown", 8);
waitFor(assert, async () => {
assert.ok(
visible(".search-advanced-options .autocomplete"),
'"autocomplete" popup is visible'
);
assert.ok(
exists(
'.search-advanced-options .autocomplete ul li a span.username:contains("admin")'
),
'"autocomplete" popup has an entry for "admin"'
);
await click(".search-advanced-options .autocomplete ul li a:first");
assert.ok(
exists('.search-advanced-options span:contains("admin")'),
'has "admin" pre-populated'
);
assert.equal(
find(".search-query").val(),
"none @admin",
'has updated search term to "none user:admin"'
);
});
});
test("update category through advanced search ui", async (assert) => {
const categoryChooser = selectKit(
".search-advanced-options .category-chooser"
); );
await click(".search-advanced-options .autocomplete ul li a:first"); await visit("/search");
await fillIn(".search-query", "none");
await categoryChooser.expand();
await categoryChooser.fillInFilter("faq");
await categoryChooser.selectRowByValue(4);
assert.ok( assert.ok(
exists('.search-advanced-options span:contains("admin")'), exists('.search-advanced-options .badge-category:contains("faq")'),
'has "admin" pre-populated' 'has "faq" populated'
); );
assert.equal( assert.equal(
find(".search-query").val(), find(".search-query").val(),
"none @admin", "none #faq",
'has updated search term to "none user:admin"' 'has updated search term to "none #faq"'
);
});
test("update in:title filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-title");
assert.ok(
exists(".search-advanced-options .in-title:checked"),
'has "in title" populated'
);
assert.equal(
find(".search-query").val(),
"none in:title",
'has updated search term to "none in:title"'
);
await fillIn(".search-query", "none in:titleasd");
assert.not(
exists(".search-advanced-options .in-title:checked"),
"does not populate title only checkbox"
);
});
test("update in:likes filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-likes");
assert.ok(
exists(".search-advanced-options .in-likes:checked"),
'has "I liked" populated'
);
assert.equal(
find(".search-query").val(),
"none in:likes",
'has updated search term to "none in:likes"'
);
});
test("update in:personal filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-private");
assert.ok(
exists(".search-advanced-options .in-private:checked"),
'has "are in my messages" populated'
);
assert.equal(
find(".search-query").val(),
"none in:personal",
'has updated search term to "none in:personal"'
);
await fillIn(".search-query", "none in:personal-direct");
assert.not(
exists(".search-advanced-options .in-private:checked"),
"does not populate messages checkbox"
);
});
test("update in:seen filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-seen");
assert.ok(
exists(".search-advanced-options .in-seen:checked"),
"it should check the right checkbox"
);
assert.equal(
find(".search-query").val(),
"none in:seen",
"it should update the search term"
);
await fillIn(".search-query", "none in:seenasdan");
assert.not(
exists(".search-advanced-options .in-seen:checked"),
"does not populate seen checkbox"
);
});
test("update in filter through advanced search ui", async (assert) => {
const inSelector = selectKit(".search-advanced-options .select-kit#in");
await visit("/search");
await fillIn(".search-query", "none");
await inSelector.expand();
await inSelector.selectRowByValue("bookmarks");
assert.equal(
inSelector.header().label(),
"I bookmarked",
'has "I bookmarked" populated'
);
assert.equal(
find(".search-query").val(),
"none in:bookmarks",
'has updated search term to "none in:bookmarks"'
);
});
test("update status through advanced search ui", async (assert) => {
const statusSelector = selectKit(
".search-advanced-options .select-kit#status"
);
await visit("/search");
await fillIn(".search-query", "none");
await statusSelector.expand();
await statusSelector.selectRowByValue("closed");
assert.equal(
statusSelector.header().label(),
"are closed",
'has "are closed" populated'
);
assert.equal(
find(".search-query").val(),
"none status:closed",
'has updated search term to "none status:closed"'
);
});
test("doesn't update status filter header if wrong value entered through searchbox", async (assert) => {
const statusSelector = selectKit(
".search-advanced-options .select-kit#status"
);
await visit("/search");
await fillIn(".search-query", "status:none");
assert.equal(statusSelector.header().label(), "any", 'has "any" populated');
});
test("doesn't update in filter header if wrong value entered through searchbox", async (assert) => {
const inSelector = selectKit(".search-advanced-options .select-kit#in");
await visit("/search");
await fillIn(".search-query", "in:none");
assert.equal(inSelector.header().label(), "any", 'has "any" populated');
});
test("update post time through advanced search ui", async (assert) => {
await visit("/search?expanded=true&q=after:2018-08-22");
assert.equal(
find(".search-query").val(),
"after:2018-08-22",
"it should update the search term correctly"
);
await visit("/search");
await fillIn(".search-query", "none");
await selectDate("#search-post-date .date-picker", "2016-10-05");
const postTimeSelector = selectKit(
".search-advanced-options .select-kit#postTime"
);
await postTimeSelector.expand();
await postTimeSelector.selectRowByValue("after");
assert.equal(
postTimeSelector.header().label(),
"after",
'has "after" populated'
);
assert.equal(
find(".search-query").val(),
"none after:2016-10-05",
'has updated search term to "none after:2016-10-05"'
);
});
test("update min post count through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await fillIn("#search-min-post-count", "5");
assert.equal(
find(".search-advanced-options #search-min-post-count").val(),
"5",
'has "5" populated'
);
assert.equal(
find(".search-query").val(),
"none min_posts:5",
'has updated search term to "none min_posts:5"'
);
});
test("update max post count through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await fillIn("#search-max-post-count", "5");
assert.equal(
find(".search-advanced-options #search-max-post-count").val(),
"5",
'has "5" populated'
);
assert.equal(
find(".search-query").val(),
"none max_posts:5",
'has updated search term to "none max_posts:5"'
);
});
test("validate advanced search when initially empty", async (assert) => {
await visit("/search?expanded=true");
await click(".search-advanced-options .in-likes");
assert.ok(
selectKit(".search-advanced-options .in-likes:checked"),
'has "I liked" populated'
);
assert.equal(
find(".search-query").val(),
"in:likes",
'has updated search term to "in:likes"'
);
await fillIn(".search-query", "in:likesasdas");
assert.not(
exists(".search-advanced-options .in-likes:checked"),
"does not populate the likes checkbox"
); );
}); });
}); });
test("update category through advanced search ui", async (assert) => {
const categoryChooser = selectKit(
".search-advanced-options .category-chooser"
);
await visit("/search");
await fillIn(".search-query", "none");
await categoryChooser.expand();
await categoryChooser.fillInFilter("faq");
await categoryChooser.selectRowByValue(4);
assert.ok(
exists('.search-advanced-options .badge-category:contains("faq")'),
'has "faq" populated'
);
assert.equal(
find(".search-query").val(),
"none #faq",
'has updated search term to "none #faq"'
);
});
test("update in:title filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-title");
assert.ok(
exists(".search-advanced-options .in-title:checked"),
'has "in title" populated'
);
assert.equal(
find(".search-query").val(),
"none in:title",
'has updated search term to "none in:title"'
);
await fillIn(".search-query", "none in:titleasd");
assert.not(
exists(".search-advanced-options .in-title:checked"),
"does not populate title only checkbox"
);
});
test("update in:likes filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-likes");
assert.ok(
exists(".search-advanced-options .in-likes:checked"),
'has "I liked" populated'
);
assert.equal(
find(".search-query").val(),
"none in:likes",
'has updated search term to "none in:likes"'
);
});
test("update in:personal filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-private");
assert.ok(
exists(".search-advanced-options .in-private:checked"),
'has "are in my messages" populated'
);
assert.equal(
find(".search-query").val(),
"none in:personal",
'has updated search term to "none in:personal"'
);
await fillIn(".search-query", "none in:personal-direct");
assert.not(
exists(".search-advanced-options .in-private:checked"),
"does not populate messages checkbox"
);
});
test("update in:seen filter through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await click(".search-advanced-options .in-seen");
assert.ok(
exists(".search-advanced-options .in-seen:checked"),
"it should check the right checkbox"
);
assert.equal(
find(".search-query").val(),
"none in:seen",
"it should update the search term"
);
await fillIn(".search-query", "none in:seenasdan");
assert.not(
exists(".search-advanced-options .in-seen:checked"),
"does not populate seen checkbox"
);
});
test("update in filter through advanced search ui", async (assert) => {
const inSelector = selectKit(".search-advanced-options .select-kit#in");
await visit("/search");
await fillIn(".search-query", "none");
await inSelector.expand();
await inSelector.selectRowByValue("bookmarks");
assert.equal(
inSelector.header().label(),
"I bookmarked",
'has "I bookmarked" populated'
);
assert.equal(
find(".search-query").val(),
"none in:bookmarks",
'has updated search term to "none in:bookmarks"'
);
});
test("update status through advanced search ui", async (assert) => {
const statusSelector = selectKit(
".search-advanced-options .select-kit#status"
);
await visit("/search");
await fillIn(".search-query", "none");
await statusSelector.expand();
await statusSelector.selectRowByValue("closed");
assert.equal(
statusSelector.header().label(),
"are closed",
'has "are closed" populated'
);
assert.equal(
find(".search-query").val(),
"none status:closed",
'has updated search term to "none status:closed"'
);
});
test("doesn't update status filter header if wrong value entered through searchbox", async (assert) => {
const statusSelector = selectKit(
".search-advanced-options .select-kit#status"
);
await visit("/search");
await fillIn(".search-query", "status:none");
assert.equal(statusSelector.header().label(), "any", 'has "any" populated');
});
test("doesn't update in filter header if wrong value entered through searchbox", async (assert) => {
const inSelector = selectKit(".search-advanced-options .select-kit#in");
await visit("/search");
await fillIn(".search-query", "in:none");
assert.equal(inSelector.header().label(), "any", 'has "any" populated');
});
test("update post time through advanced search ui", async (assert) => {
await visit("/search?expanded=true&q=after:2018-08-22");
assert.equal(
find(".search-query").val(),
"after:2018-08-22",
"it should update the search term correctly"
);
await visit("/search");
await fillIn(".search-query", "none");
await selectDate("#search-post-date .date-picker", "2016-10-05");
const postTimeSelector = selectKit(
".search-advanced-options .select-kit#postTime"
);
await postTimeSelector.expand();
await postTimeSelector.selectRowByValue("after");
assert.equal(
postTimeSelector.header().label(),
"after",
'has "after" populated'
);
assert.equal(
find(".search-query").val(),
"none after:2016-10-05",
'has updated search term to "none after:2016-10-05"'
);
});
test("update min post count through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await fillIn("#search-min-post-count", "5");
assert.equal(
find(".search-advanced-options #search-min-post-count").val(),
"5",
'has "5" populated'
);
assert.equal(
find(".search-query").val(),
"none min_posts:5",
'has updated search term to "none min_posts:5"'
);
});
test("update max post count through advanced search ui", async (assert) => {
await visit("/search");
await fillIn(".search-query", "none");
await fillIn("#search-max-post-count", "5");
assert.equal(
find(".search-advanced-options #search-max-post-count").val(),
"5",
'has "5" populated'
);
assert.equal(
find(".search-query").val(),
"none max_posts:5",
'has updated search term to "none max_posts:5"'
);
});
test("validate advanced search when initially empty", async (assert) => {
await visit("/search?expanded=true");
await click(".search-advanced-options .in-likes");
assert.ok(
selectKit(".search-advanced-options .in-likes:checked"),
'has "I liked" populated'
);
assert.equal(
find(".search-query").val(),
"in:likes",
'has updated search term to "in:likes"'
);
await fillIn(".search-query", "in:likesasdas");
assert.not(
exists(".search-advanced-options .in-likes:checked"),
"does not populate the likes checkbox"
);
});

View File

@ -2,42 +2,44 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Search - Mobile", { mobileView: true }); acceptance("Search - Mobile", function (needs) {
needs.mobileView();
test("search", async (assert) => { test("search", async (assert) => {
await visit("/"); await visit("/");
await click("#search-button"); await click("#search-button");
assert.ok( assert.ok(
exists("input.full-page-search"), exists("input.full-page-search"),
"it shows the full page search form" "it shows the full page search form"
); );
assert.ok(!exists(".search-results .fps-topic"), "no results by default"); assert.ok(!exists(".search-results .fps-topic"), "no results by default");
await click(".search-advanced-title"); await click(".search-advanced-title");
assert.ok( assert.ok(
find(".search-advanced-filters").length === 1, find(".search-advanced-filters").length === 1,
"it should expand advanced search filters" "it should expand advanced search filters"
); );
await fillIn(".search-query", "posts"); await fillIn(".search-query", "posts");
await click(".search-cta"); await click(".search-cta");
assert.ok(find(".fps-topic").length === 1, "has one post"); assert.ok(find(".fps-topic").length === 1, "has one post");
assert.ok( assert.ok(
find(".search-advanced-filters").length === 0, find(".search-advanced-filters").length === 0,
"it should collapse advanced search filters" "it should collapse advanced search filters"
); );
await click("#search-button"); await click("#search-button");
assert.equal( assert.equal(
find("input.full-page-search").val(), find("input.full-page-search").val(),
"posts", "posts",
"it does not reset input when hitting search icon again" "it does not reset input when hitting search icon again"
); );
});
}); });

View File

@ -2,200 +2,195 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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 = { needs.pretender((server, helper) => {
pretend(server) { server.get("/search/query", (request) => {
server.handledRequest = (verb, path, request) => { if (!request.queryParams["search_context[type]"]) {
if (request.queryParams["search_context[type]"] === undefined) { calledEmpty = true;
emptySearchContextCallbacks.forEach((callback) => {
callback.call();
});
} }
};
},
};
acceptance("Search", searchArgs); return helper.response(searchFixtures["search/query"]);
});
test("search", async (assert) => {
await visit("/");
await click("#search-button");
assert.ok(exists("#search-term"), "it shows the search bar");
assert.ok(!exists(".search-menu .results ul li"), "no results by default");
await fillIn("#search-term", "dev");
await keyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results");
assert.ok(
exists(".search-menu .results ul li .topic-title[data-topic-id]"),
"topic has data-topic-id"
);
await click(".show-help");
assert.equal(
find(".full-page-search").val(),
"dev",
"it shows the search term"
);
assert.ok(exists(".search-advanced-options"), "advanced search is expanded");
});
test("search for a tag", async (assert) => {
await visit("/");
await click("#search-button");
await fillIn("#search-term", "evil");
await keyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results");
});
test("search scope checkbox", async (assert) => {
await visit("/tag/important");
await click("#search-button");
assert.ok(
exists(".search-context input:checked"),
"scope to tag checkbox is checked"
);
await click("#search-button");
await visit("/c/bug");
await click("#search-button");
assert.ok(
exists(".search-context input:checked"),
"scope to category checkbox is checked"
);
await click("#search-button");
await visit("/t/internationalization-localization/280");
await click("#search-button");
assert.not(
exists(".search-context input:checked"),
"scope to topic checkbox is not checked"
);
await click("#search-button");
await visit("/u/eviltrout");
await click("#search-button");
assert.ok(
exists(".search-context input:checked"),
"scope to user checkbox is checked"
);
});
test("Search with context", async (assert) => {
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
await fillIn("#search-term", "a proper");
await click(".search-context input[type='checkbox']");
await keyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results");
const highlighted = [];
find("#post_7 span.highlighted").map((_, span) => {
highlighted.push(span.innerText);
}); });
assert.deepEqual( test("search", async (assert) => {
highlighted, await visit("/");
["a proper"],
"it should highlight the post with the search terms correctly"
);
let callbackCalled = false; await click("#search-button");
emptySearchContextCallbacks.push(() => { assert.ok(exists("#search-term"), "it shows the search bar");
callbackCalled = true; assert.ok(!exists(".search-menu .results ul li"), "no results by default");
await fillIn("#search-term", "dev");
await keyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results");
assert.ok(
exists(".search-menu .results ul li .topic-title[data-topic-id]"),
"topic has data-topic-id"
);
await click(".show-help");
assert.equal(
find(".full-page-search").val(),
"dev",
"it shows the search term"
);
assert.ok(
exists(".search-advanced-options"),
"advanced search is expanded"
);
}); });
await visit("/"); test("search for a tag", async (assert) => {
await click("#search-button"); await visit("/");
assert.ok(!exists(".search-context input[type='checkbox']")); await click("#search-button");
assert.ok(callbackCalled, "it triggers a new search");
await visit("/t/internationalization-localization/280/1"); await fillIn("#search-term", "evil");
await click("#search-button"); await keyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results");
});
assert.ok(!$(".search-context input[type=checkbox]").is(":checked")); test("search scope checkbox", async (assert) => {
await visit("/tag/important");
await click("#search-button");
assert.ok(
exists(".search-context input:checked"),
"scope to tag checkbox is checked"
);
await click("#search-button");
await visit("/c/bug");
await click("#search-button");
assert.ok(
exists(".search-context input:checked"),
"scope to category checkbox is checked"
);
await click("#search-button");
await visit("/t/internationalization-localization/280");
await click("#search-button");
assert.not(
exists(".search-context input:checked"),
"scope to topic checkbox is not checked"
);
await click("#search-button");
await visit("/u/eviltrout");
await click("#search-button");
assert.ok(
exists(".search-context input:checked"),
"scope to user checkbox is checked"
);
});
test("Search with context", async (assert) => {
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
await fillIn("#search-term", "a proper");
await click(".search-context input[type='checkbox']");
await keyEvent("#search-term", "keyup", 16);
assert.ok(exists(".search-menu .results ul li"), "it shows results");
const highlighted = [];
find("#post_7 span.highlighted").map((_, span) => {
highlighted.push(span.innerText);
});
assert.deepEqual(
highlighted,
["a proper"],
"it should highlight the post with the search terms correctly"
);
calledEmpty = false;
await visit("/");
await click("#search-button");
assert.ok(!exists(".search-context input[type='checkbox']"));
assert.ok(calledEmpty, "it triggers a new search");
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
assert.ok(!$(".search-context input[type=checkbox]").is(":checked"));
});
test("Right filters are shown to anonymous users", async (assert) => {
const inSelector = selectKit(".select-kit#in");
await visit("/search?expanded=true");
await inSelector.expand();
assert.ok(inSelector.rowByValue("first").exists());
assert.ok(inSelector.rowByValue("pinned").exists());
assert.ok(inSelector.rowByValue("wiki").exists());
assert.ok(inSelector.rowByValue("images").exists());
assert.notOk(inSelector.rowByValue("unseen").exists());
assert.notOk(inSelector.rowByValue("posted").exists());
assert.notOk(inSelector.rowByValue("watching").exists());
assert.notOk(inSelector.rowByValue("tracking").exists());
assert.notOk(inSelector.rowByValue("bookmarks").exists());
assert.notOk(exists(".search-advanced-options .in-likes"));
assert.notOk(exists(".search-advanced-options .in-private"));
assert.notOk(exists(".search-advanced-options .in-seen"));
});
}); });
test("Right filters are shown to anonymous users", async (assert) => { acceptance("Search - Authenticated", function (needs) {
const inSelector = selectKit(".select-kit#in"); needs.user();
await visit("/search?expanded=true"); test("Right filters are shown to logged-in users", async (assert) => {
const inSelector = selectKit(".select-kit#in");
await inSelector.expand(); await visit("/search?expanded=true");
assert.ok(inSelector.rowByValue("first").exists()); await inSelector.expand();
assert.ok(inSelector.rowByValue("pinned").exists());
assert.ok(inSelector.rowByValue("wiki").exists());
assert.ok(inSelector.rowByValue("images").exists());
assert.notOk(inSelector.rowByValue("unseen").exists()); assert.ok(inSelector.rowByValue("first").exists());
assert.notOk(inSelector.rowByValue("posted").exists()); assert.ok(inSelector.rowByValue("pinned").exists());
assert.notOk(inSelector.rowByValue("watching").exists()); assert.ok(inSelector.rowByValue("wiki").exists());
assert.notOk(inSelector.rowByValue("tracking").exists()); assert.ok(inSelector.rowByValue("images").exists());
assert.notOk(inSelector.rowByValue("bookmarks").exists());
assert.notOk(exists(".search-advanced-options .in-likes")); assert.ok(inSelector.rowByValue("unseen").exists());
assert.notOk(exists(".search-advanced-options .in-private")); assert.ok(inSelector.rowByValue("posted").exists());
assert.notOk(exists(".search-advanced-options .in-seen")); assert.ok(inSelector.rowByValue("watching").exists());
assert.ok(inSelector.rowByValue("tracking").exists());
assert.ok(inSelector.rowByValue("bookmarks").exists());
assert.ok(exists(".search-advanced-options .in-likes"));
assert.ok(exists(".search-advanced-options .in-private"));
assert.ok(exists(".search-advanced-options .in-seen"));
});
}); });
acceptance("Search", Object.assign({ loggedIn: true, searchArgs })); acceptance("Search - with tagging enabled", function (needs) {
needs.user();
needs.settings({ tagging_enabled: true });
test("Right filters are shown to logged-in users", async (assert) => { test("displays tags", async (assert) => {
const inSelector = selectKit(".select-kit#in"); await visit("/");
await visit("/search?expanded=true"); await click("#search-button");
await inSelector.expand(); await fillIn("#search-term", "dev");
await keyEvent("#search-term", "keyup", 16);
assert.ok(inSelector.rowByValue("first").exists()); const tags = find(".search-menu .results ul li:eq(0) .discourse-tags")
assert.ok(inSelector.rowByValue("pinned").exists()); .text()
assert.ok(inSelector.rowByValue("wiki").exists()); .trim();
assert.ok(inSelector.rowByValue("images").exists());
assert.ok(inSelector.rowByValue("unseen").exists()); assert.equal(tags, "dev slow");
assert.ok(inSelector.rowByValue("posted").exists()); });
assert.ok(inSelector.rowByValue("watching").exists());
assert.ok(inSelector.rowByValue("tracking").exists());
assert.ok(inSelector.rowByValue("bookmarks").exists());
assert.ok(exists(".search-advanced-options .in-likes"));
assert.ok(exists(".search-advanced-options .in-private"));
assert.ok(exists(".search-advanced-options .in-seen"));
});
acceptance(
"Search - with tagging enabled",
Object.assign({
loggedIn: true,
searchArgs,
settings: { tagging_enabled: true },
})
);
test("displays tags", async (assert) => {
await visit("/");
await click("#search-button");
await fillIn("#search-term", "dev");
await keyEvent("#search-term", "keyup", 16);
const tags = find(".search-menu .results ul li:eq(0) .discourse-tags")
.text()
.trim();
assert.equal(tags, "dev slow");
}); });

View File

@ -2,92 +2,91 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Share and Invite modal - desktop", { acceptance("Share and Invite modal - desktop", function (needs) {
loggedIn: true, needs.user();
test("Topic footer button", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(
exists("#topic-footer-button-share-and-invite"),
"the button exists"
);
await click("#topic-footer-button-share-and-invite");
assert.ok(exists(".share-and-invite.modal"), "it shows the modal");
assert.ok(
exists(".share-and-invite.modal .modal-tab.share"),
"it shows the share tab"
);
assert.ok(
exists(".share-and-invite.modal .modal-tab.share.is-active"),
"it activates the share tab by default"
);
assert.ok(
exists(".share-and-invite.modal .modal-tab.invite"),
"it shows the invite tab"
);
assert.equal(
find(".share-and-invite.modal .modal-panel.share .title").text(),
"Topic: Internationalization / localization",
"it shows the topic title"
);
assert.ok(
find(".share-and-invite.modal .modal-panel.share .topic-share-url")
.val()
.includes("/t/internationalization-localization/280?u=eviltrout"),
"it shows the topic sharing url"
);
assert.ok(
find(".share-and-invite.modal .social-link").length > 1,
"it shows social sources"
);
await click(".share-and-invite.modal .modal-tab.invite");
assert.ok(
exists(
".share-and-invite.modal .modal-panel.invite .send-invite:disabled"
),
"send invite button is disabled"
);
assert.ok(
exists(
".share-and-invite.modal .modal-panel.invite .generate-invite-link:disabled"
),
"generate invite button is disabled"
);
});
test("Post date link", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#post_2 .post-info.post-date a");
assert.ok(exists("#share-link"), "it shows the share modal");
});
}); });
test("Topic footer button", async (assert) => { acceptance("Share url with badges disabled - desktop", function (needs) {
await visit("/t/internationalization-localization/280"); 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");
assert.ok( assert.notOk(
exists("#topic-footer-button-share-and-invite"), find(".share-and-invite.modal .modal-panel.share .topic-share-url")
"the button exists" .val()
); .includes("?u=eviltrout"),
"it doesn't add the username param when badges are disabled"
await click("#topic-footer-button-share-and-invite"); );
});
assert.ok(exists(".share-and-invite.modal"), "it shows the modal");
assert.ok(
exists(".share-and-invite.modal .modal-tab.share"),
"it shows the share tab"
);
assert.ok(
exists(".share-and-invite.modal .modal-tab.share.is-active"),
"it activates the share tab by default"
);
assert.ok(
exists(".share-and-invite.modal .modal-tab.invite"),
"it shows the invite tab"
);
assert.equal(
find(".share-and-invite.modal .modal-panel.share .title").text(),
"Topic: Internationalization / localization",
"it shows the topic title"
);
assert.ok(
find(".share-and-invite.modal .modal-panel.share .topic-share-url")
.val()
.includes("/t/internationalization-localization/280?u=eviltrout"),
"it shows the topic sharing url"
);
assert.ok(
find(".share-and-invite.modal .social-link").length > 1,
"it shows social sources"
);
await click(".share-and-invite.modal .modal-tab.invite");
assert.ok(
exists(".share-and-invite.modal .modal-panel.invite .send-invite:disabled"),
"send invite button is disabled"
);
assert.ok(
exists(
".share-and-invite.modal .modal-panel.invite .generate-invite-link:disabled"
),
"generate invite button is disabled"
);
});
test("Post date link", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#post_2 .post-info.post-date a");
assert.ok(exists("#share-link"), "it shows the share modal");
});
acceptance("Share url with badges disabled - desktop", {
loggedIn: true,
settings: {
enable_badges: false,
},
});
test("topic footer button - badges disabled - desktop", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-button-share-and-invite");
assert.notOk(
find(".share-and-invite.modal .modal-panel.share .topic-share-url")
.val()
.includes("?u=eviltrout"),
"it doesn't add the username param when badges are disabled"
);
}); });

View File

@ -3,85 +3,84 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Share and Invite modal - mobile", { acceptance("Share and Invite modal - mobile", function (needs) {
loggedIn: true, needs.user();
mobileView: true, needs.mobileView();
test("Topic footer mobile button", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(
!exists("#topic-footer-button-share-and-invite"),
"the button doesnt exist"
);
const subject = selectKit(".topic-footer-mobile-dropdown");
await subject.expand();
await subject.selectRowByValue("share-and-invite");
assert.ok(exists(".share-and-invite.modal"), "it shows the modal");
assert.ok(
exists(".share-and-invite.modal .modal-tab.share"),
"it shows the share tab"
);
assert.ok(
exists(".share-and-invite.modal .modal-tab.share.is-active"),
"it activates the share tab by default"
);
assert.ok(
exists(".share-and-invite.modal .modal-tab.invite"),
"it shows the invite tab"
);
assert.equal(
find(".share-and-invite.modal .modal-panel.share .title").text(),
"Topic: Internationalization / localization",
"it shows the topic title"
);
assert.ok(
find(".share-and-invite.modal .modal-panel.share .topic-share-url")
.val()
.includes("/t/internationalization-localization/280?u=eviltrout"),
"it shows the topic sharing url"
);
assert.ok(
find(".share-and-invite.modal .social-link").length > 1,
"it shows social sources"
);
});
test("Post date link", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#post_2 .post-info.post-date a");
assert.ok(exists("#share-link"), "it shows the share modal");
});
}); });
test("Topic footer mobile button", async (assert) => { acceptance("Share url with badges disabled - mobile", function (needs) {
await visit("/t/internationalization-localization/280"); needs.user();
needs.mobileView();
assert.ok( needs.settings({
!exists("#topic-footer-button-share-and-invite"),
"the button doesnt exist"
);
const subject = selectKit(".topic-footer-mobile-dropdown");
await subject.expand();
await subject.selectRowByValue("share-and-invite");
assert.ok(exists(".share-and-invite.modal"), "it shows the modal");
assert.ok(
exists(".share-and-invite.modal .modal-tab.share"),
"it shows the share tab"
);
assert.ok(
exists(".share-and-invite.modal .modal-tab.share.is-active"),
"it activates the share tab by default"
);
assert.ok(
exists(".share-and-invite.modal .modal-tab.invite"),
"it shows the invite tab"
);
assert.equal(
find(".share-and-invite.modal .modal-panel.share .title").text(),
"Topic: Internationalization / localization",
"it shows the topic title"
);
assert.ok(
find(".share-and-invite.modal .modal-panel.share .topic-share-url")
.val()
.includes("/t/internationalization-localization/280?u=eviltrout"),
"it shows the topic sharing url"
);
assert.ok(
find(".share-and-invite.modal .social-link").length > 1,
"it shows social sources"
);
});
test("Post date link", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#post_2 .post-info.post-date a");
assert.ok(exists("#share-link"), "it shows the share modal");
});
acceptance("Share url with badges disabled - mobile", {
loggedIn: true,
mobileView: true,
settings: {
enable_badges: false, enable_badges: false,
}, });
}); test("topic footer button - badges disabled - mobile", async (assert) => {
await visit("/t/internationalization-localization/280");
test("topic footer button - badges disabled - mobile", async (assert) => {
await visit("/t/internationalization-localization/280"); const subject = selectKit(".topic-footer-mobile-dropdown");
await subject.expand();
const subject = selectKit(".topic-footer-mobile-dropdown"); await subject.selectRowByValue("share-and-invite");
await subject.expand();
await subject.selectRowByValue("share-and-invite"); assert.notOk(
find(".share-and-invite.modal .modal-panel.share .topic-share-url")
assert.notOk( .val()
find(".share-and-invite.modal .modal-panel.share .topic-share-url") .includes("?u=eviltrout"),
.val() "it doesn't add the username param when badges are disabled"
.includes("?u=eviltrout"), );
"it doesn't add the username param when badges are disabled" });
);
}); });

View File

@ -3,16 +3,16 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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);
let categoryChooser = selectKit(".shared-draft-controls .category-chooser");
assert.equal(categoryChooser.header().value(), "3");
test("Viewing", async (assert) => { await click(".publish-shared-draft");
await visit("/t/some-topic/9"); await click(".bootbox .btn-primary");
assert.ok(find(".shared-draft-controls").length === 1);
let categoryChooser = selectKit(".shared-draft-controls .category-chooser");
assert.equal(categoryChooser.header().value(), "3");
await click(".publish-shared-draft"); assert.ok(find(".shared-draft-controls").length === 0);
await click(".bootbox .btn-primary"); });
assert.ok(find(".shared-draft-controls").length === 0);
}); });

View File

@ -1,199 +1,202 @@
import { visit } from "@ember/test-helpers"; import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Signing In");
test("sign in", async (assert) => { acceptance("Signing In", function () {
await visit("/"); test("sign in", async (assert) => {
await click("header .login-button"); await visit("/");
assert.ok(exists(".login-modal"), "it shows the login modal"); await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal");
// Test invalid password first // Test invalid password first
await fillIn("#login-account-name", "eviltrout"); await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "incorrect"); await fillIn("#login-account-password", "incorrect");
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
assert.ok(exists("#modal-alert:visible"), "it displays the login error"); assert.ok(exists("#modal-alert:visible"), "it displays the login error");
assert.not( assert.not(
exists(".modal-footer .btn-primary:disabled"), exists(".modal-footer .btn-primary:disabled"),
"enables the login button" "enables the login button"
); );
// Use the correct password // Use the correct password
await fillIn("#login-account-password", "correct"); await fillIn("#login-account-password", "correct");
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
assert.ok( assert.ok(
exists(".modal-footer .btn-primary:disabled"), exists(".modal-footer .btn-primary:disabled"),
"disables the login button" "disables the login button"
); );
}); });
test("sign in - not activated", async (assert) => { test("sign in - not activated", async (assert) => {
await visit("/"); await visit("/");
await click("header .login-button"); await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal"); assert.ok(exists(".login-modal"), "it shows the login modal");
await fillIn("#login-account-name", "eviltrout"); await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "not-activated"); await fillIn("#login-account-password", "not-activated");
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
assert.equal( assert.equal(
find(".modal-body b").text(), find(".modal-body b").text(),
"<small>eviltrout@example.com</small>" "<small>eviltrout@example.com</small>"
); );
assert.ok(!exists(".modal-body small"), "it escapes the email address"); assert.ok(!exists(".modal-body small"), "it escapes the email address");
await click(".modal-footer button.resend"); await click(".modal-footer button.resend");
assert.equal( assert.equal(
find(".modal-body b").text(), find(".modal-body b").text(),
"<small>current@example.com</small>" "<small>current@example.com</small>"
); );
assert.ok(!exists(".modal-body small"), "it escapes the email address"); assert.ok(!exists(".modal-body small"), "it escapes the email address");
}); });
test("sign in - not activated - edit email", async (assert) => { test("sign in - not activated - edit email", async (assert) => {
await visit("/"); await visit("/");
await click("header .login-button"); await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal"); assert.ok(exists(".login-modal"), "it shows the login modal");
await fillIn("#login-account-name", "eviltrout"); await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "not-activated-edit"); await fillIn("#login-account-password", "not-activated-edit");
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
await click(".modal-footer button.edit-email"); await click(".modal-footer button.edit-email");
assert.equal(find(".activate-new-email").val(), "current@example.com"); assert.equal(find(".activate-new-email").val(), "current@example.com");
assert.equal( assert.equal(
find(".modal-footer .btn-primary:disabled").length, find(".modal-footer .btn-primary:disabled").length,
1, 1,
"must change email" "must change email"
); );
await fillIn(".activate-new-email", "different@example.com"); await fillIn(".activate-new-email", "different@example.com");
assert.equal(find(".modal-footer .btn-primary:disabled").length, 0); assert.equal(find(".modal-footer .btn-primary:disabled").length, 0);
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
assert.equal(find(".modal-body b").text(), "different@example.com"); assert.equal(find(".modal-body b").text(), "different@example.com");
}); });
skip("second factor", async (assert) => { test("second factor", async (assert) => {
await visit("/"); await visit("/");
await click("header .login-button"); await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal"); assert.ok(exists(".login-modal"), "it shows the login modal");
await fillIn("#login-account-name", "eviltrout"); await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "need-second-factor"); await fillIn("#login-account-password", "need-second-factor");
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
assert.not(exists("#modal-alert:visible"), "it hides the login error"); assert.not(exists("#modal-alert:visible"), "it hides the login error");
assert.not( assert.not(
exists("#credentials:visible"), exists("#credentials:visible"),
"it hides the username and password prompt" "it hides the username and password prompt"
); );
assert.ok( assert.ok(
exists("#second-factor:visible"), exists("#second-factor:visible"),
"it displays the second factor prompt" "it displays the second factor prompt"
); );
assert.not( assert.not(
exists(".modal-footer .btn-primary:disabled"), exists(".modal-footer .btn-primary:disabled"),
"enables the login button" "enables the login button"
); );
await fillIn("#login-second-factor", "123456"); await fillIn("#login-second-factor", "123456");
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
assert.ok( assert.ok(
exists(".modal-footer .btn-primary:disabled"), exists(".modal-footer .btn-primary:disabled"),
"disables the login button" "disables the login button"
); );
}); });
skip("security key", async (assert) => { test("security key", async (assert) => {
await visit("/"); await visit("/");
await click("header .login-button"); await click("header .login-button");
assert.ok(exists(".login-modal"), "it shows the login modal"); assert.ok(exists(".login-modal"), "it shows the login modal");
await fillIn("#login-account-name", "eviltrout"); await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-account-password", "need-security-key"); await fillIn("#login-account-password", "need-security-key");
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
assert.not(exists("#modal-alert:visible"), "it hides the login error"); assert.not(exists("#modal-alert:visible"), "it hides the login error");
assert.not( assert.not(
exists("#credentials:visible"), exists("#credentials:visible"),
"it hides the username and password prompt" "it hides the username and password prompt"
); );
assert.not( assert.not(
exists("#login-second-factor:visible"), exists("#login-second-factor:visible"),
"it does not display the second factor prompt" "it does not display the second factor prompt"
); );
assert.ok( assert.ok(
exists("#security-key:visible"), exists("#security-key:visible"),
"it shows the security key prompt" "it shows the security key prompt"
); );
assert.not(exists("#login-button:visible"), "hides the login button"); assert.not(exists("#login-button:visible"), "hides the login button");
}); });
test("create account", async (assert) => { test("create account", async (assert) => {
await visit("/"); await visit("/");
await click("header .sign-up-button"); await click("header .sign-up-button");
assert.ok(exists(".create-account"), "it shows the create account modal"); assert.ok(exists(".create-account"), "it shows the create account modal");
await fillIn("#new-account-name", "Dr. Good Tuna"); await fillIn("#new-account-name", "Dr. Good Tuna");
await fillIn("#new-account-password", "cool password bro"); await fillIn("#new-account-password", "cool password bro");
// without this double fill, field will sometimes being empty // without this double fill, field will sometimes being empty
// got consistent repro by having browser search bar focused when starting test // got consistent repro by having browser search bar focused when starting test
await fillIn("#new-account-email", "good.tuna@test.com"); await fillIn("#new-account-email", "good.tuna@test.com");
await fillIn("#new-account-email", "good.tuna@test.com"); await fillIn("#new-account-email", "good.tuna@test.com");
// Check username // Check username
await fillIn("#new-account-username", "taken"); await fillIn("#new-account-username", "taken");
assert.ok( assert.ok(
exists("#username-validation.bad"), exists("#username-validation.bad"),
"the username validation is bad" "the username validation is bad"
); );
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
assert.ok(exists("#new-account-username:focus"), "username field is focused"); assert.ok(
exists("#new-account-username:focus"),
await fillIn("#new-account-username", "goodtuna"); "username field is focused"
assert.ok( );
exists("#username-validation.good"),
"the username validation is good" await fillIn("#new-account-username", "goodtuna");
); assert.ok(
exists("#username-validation.good"),
await click(".modal-footer .btn-primary"); "the username validation is good"
assert.ok( );
exists(".modal-footer .btn-primary:disabled"),
"create account is disabled" await click(".modal-footer .btn-primary");
); assert.ok(
}); exists(".modal-footer .btn-primary:disabled"),
"create account is disabled"
test("second factor backup - valid token", async (assert) => { );
await visit("/"); });
await click("header .login-button");
await fillIn("#login-account-name", "eviltrout"); test("second factor backup - valid token", async (assert) => {
await fillIn("#login-account-password", "need-second-factor"); await visit("/");
await click(".modal-footer .btn-primary"); await click("header .login-button");
await click(".login-modal .toggle-second-factor-method"); await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-second-factor", "123456"); await fillIn("#login-account-password", "need-second-factor");
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
await click(".login-modal .toggle-second-factor-method");
assert.ok( await fillIn("#login-second-factor", "123456");
exists(".modal-footer .btn-primary:disabled"), await click(".modal-footer .btn-primary");
"it closes the modal when the code is valid"
); assert.ok(
}); exists(".modal-footer .btn-primary:disabled"),
"it closes the modal when the code is valid"
test("second factor backup - invalid token", async (assert) => { );
await visit("/"); });
await click("header .login-button");
await fillIn("#login-account-name", "eviltrout"); test("second factor backup - invalid token", async (assert) => {
await fillIn("#login-account-password", "need-second-factor"); await visit("/");
await click(".modal-footer .btn-primary"); await click("header .login-button");
await click(".login-modal .toggle-second-factor-method"); await fillIn("#login-account-name", "eviltrout");
await fillIn("#login-second-factor", "something"); await fillIn("#login-account-password", "need-second-factor");
await click(".modal-footer .btn-primary"); await click(".modal-footer .btn-primary");
await click(".login-modal .toggle-second-factor-method");
assert.ok( await fillIn("#login-second-factor", "something");
exists("#modal-alert:visible"), await click(".modal-footer .btn-primary");
"it shows an error when the code is invalid"
); assert.ok(
exists("#modal-alert:visible"),
"it shows an error when the code is invalid"
);
});
}); });

View File

@ -1,29 +1,30 @@
import { visit } from "@ember/test-helpers"; import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Static");
test("Static Pages", async (assert) => { acceptance("Static", function () {
await visit("/faq"); test("Static Pages", async (assert) => {
assert.ok($("body.static-faq").length, "has the body class"); await visit("/faq");
assert.ok(exists(".body-page"), "The content is present"); assert.ok($("body.static-faq").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present");
await visit("/guidelines"); await visit("/guidelines");
assert.ok($("body.static-guidelines").length, "has the body class"); assert.ok($("body.static-guidelines").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present"); assert.ok(exists(".body-page"), "The content is present");
await visit("/tos"); await visit("/tos");
assert.ok($("body.static-tos").length, "has the body class"); assert.ok($("body.static-tos").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present"); assert.ok(exists(".body-page"), "The content is present");
await visit("/privacy"); await visit("/privacy");
assert.ok($("body.static-privacy").length, "has the body class"); assert.ok($("body.static-privacy").length, "has the body class");
assert.ok(exists(".body-page"), "The content is present"); assert.ok(exists(".body-page"), "The content is present");
await visit("/login"); await visit("/login");
assert.equal( assert.equal(
currentPath(), currentPath(),
"discovery.latest", "discovery.latest",
"it redirects them to latest unless `login_required`" "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 selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Tag Groups", { acceptance("Tag Groups", function (needs) {
loggedIn: true, needs.user();
settings: { tagging_enabled: true }, needs.settings({ tagging_enabled: true });
pretend(server, helper) { needs.pretender((server, helper) => {
server.post("/tag_groups", () => { server.post("/tag_groups", () => {
return helper.response({ return helper.response({
tag_group: { tag_group: {
@ -32,28 +32,25 @@ acceptance("Tag Groups", {
}, },
]); ]);
}); });
}, });
});
test("tag groups can be saved and deleted", async (assert) => { test("tag groups can be saved and deleted", async (assert) => {
const tags = selectKit(".tag-chooser"); const tags = selectKit(".tag-chooser");
await visit("/tag_groups"); await visit("/tag_groups");
await click(".content-list .btn"); await click(".content-list .btn");
await fillIn(".tag-group-content h1 input", "test tag group"); await fillIn(".tag-group-content h1 input", "test tag group");
await tags.expand(); await tags.expand();
await tags.selectRowByValue("monkey"); await tags.selectRowByValue("monkey");
await click(".tag-group-content .btn.btn-default"); await click(".tag-group-content .btn.btn-default");
await click(".tag-chooser .choice:first"); await click(".tag-chooser .choice:first");
assert.ok(!find(".tag-group-content .btn.btn-danger")[0].disabled); assert.ok(!find(".tag-group-content .btn.btn-danger")[0].disabled);
}); });
QUnit.test( test("tag groups can have multiple groups added to them", async (assert) => {
"tag groups can have multiple groups added to them",
async (assert) => {
const tags = selectKit(".tag-chooser"); const tags = selectKit(".tag-chooser");
const groups = selectKit(".group-chooser"); const groups = selectKit(".group-chooser");
@ -71,5 +68,5 @@ QUnit.test(
await groups.selectRowByIndex(1); await groups.selectRowByIndex(1);
await groups.selectRowByIndex(0); await groups.selectRowByIndex(0);
assert.ok(!find(".tag-group-content .btn.btn-default")[0].disabled); 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 { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Tags intersection", { acceptance("Tags intersection", function (needs) {
loggedIn: true, needs.user();
site: { can_tag_topics: true }, needs.site({ can_tag_topics: true });
settings: { tagging_enabled: true }, needs.settings({ tagging_enabled: true });
pretend(server, helper) {
needs.pretender((server, helper) => {
server.get("/tag/first/notifications", () => { server.get("/tag/first/notifications", () => {
return helper.response({ return helper.response({
tag_notification: { id: "first", notification_level: 1 }, tag_notification: { id: "first", notification_level: 1 },
@ -27,17 +28,17 @@ acceptance("Tags intersection", {
}, },
}); });
}); });
}, });
});
test("Populate tags when creating new topic", async (assert) => { test("Populate tags when creating new topic", async (assert) => {
await visit("/tags/intersection/first/second"); await visit("/tags/intersection/first/second");
await click("#create-topic"); await click("#create-topic");
assert.ok(exists(".mini-tag-chooser"), "The tag selector appears"); assert.ok(exists(".mini-tag-chooser"), "The tag selector appears");
assert.equal( assert.equal(
$(".mini-tag-chooser").text().trim(), $(".mini-tag-chooser").text().trim(),
"first, second", "first, second",
"populates the tags when clicking 'New topic'" "populates the tags when clicking 'New topic'"
); );
});
}); });

View File

@ -4,153 +4,151 @@ import {
updateCurrentUser, updateCurrentUser,
acceptance, acceptance,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender";
acceptance("Tags", { loggedIn: true }); acceptance("Tags", function (needs) {
needs.user();
test("list the tags", async (assert) => { test("list the tags", async (assert) => {
await visit("/tags"); await visit("/tags");
assert.ok($("body.tags-page").length, "has the body class"); assert.ok($("body.tags-page").length, "has the body class");
assert.ok( assert.ok(
$('*[data-tag-name="eviltrout"]').length, $('*[data-tag-name="eviltrout"]').length,
"shows the eviltrout tag" "shows the eviltrout tag"
); );
});
}); });
acceptance("Tags listed by group", { acceptance("Tags listed by group", function (needs) {
loggedIn: true, needs.user();
settings: { needs.settings({
tags_listed_by_group: true, 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) => {
await visit("/tags");
assert.equal(
$(".tag-list").length,
4,
"shows separate lists for the 3 groups and the ungrouped tags"
);
assert.deepEqual(
$(".tag-list h3")
.toArray()
.map((i) => {
return $(i).text();
}),
["Ford Cars", "Honda Cars", "Makes", "Other Tags"],
"shown in given order and with tags that are not in a group"
);
assert.deepEqual(
$(".tag-list:first .discourse-tag")
.toArray()
.map((i) => {
return $(i).text();
}),
["focus", "Escort"],
"shows the tags in default sort (by count)"
);
assert.deepEqual(
$(".tag-list:first .discourse-tag")
.toArray()
.map((i) => {
return $(i).attr("href");
}),
["/tag/focus", "/tag/escort"],
"always uses lowercase URLs for mixed case tags"
);
assert.equal(
$("a[data-tag-name='private']").attr("href"),
"/u/eviltrout/messages/tags/private",
"links to private messages"
);
});
test("new topic button is not available for staff-only tags", async (assert) => {
updateCurrentUser({ moderator: false, admin: false });
await visit("/tag/regular-tag");
assert.ok(find("#create-topic:disabled").length === 0);
await visit("/tag/staff-only-tag");
assert.ok(find("#create-topic:disabled").length === 1);
updateCurrentUser({ moderator: true });
await visit("/tag/regular-tag");
assert.ok(find("#create-topic:disabled").length === 0);
await visit("/tag/staff-only-tag");
assert.ok(find("#create-topic:disabled").length === 0);
});
}); });
test("list the tags in groups", async (assert) => { acceptance("Tag info", function (needs) {
await visit("/tags"); needs.user();
assert.equal( needs.settings({
$(".tag-list").length,
4,
"shows separate lists for the 3 groups and the ungrouped tags"
);
assert.deepEqual(
$(".tag-list h3")
.toArray()
.map((i) => {
return $(i).text();
}),
["Ford Cars", "Honda Cars", "Makes", "Other Tags"],
"shown in given order and with tags that are not in a group"
);
assert.deepEqual(
$(".tag-list:first .discourse-tag")
.toArray()
.map((i) => {
return $(i).text();
}),
["focus", "Escort"],
"shows the tags in default sort (by count)"
);
assert.deepEqual(
$(".tag-list:first .discourse-tag")
.toArray()
.map((i) => {
return $(i).attr("href");
}),
["/tag/focus", "/tag/escort"],
"always uses lowercase URLs for mixed case tags"
);
assert.equal(
$("a[data-tag-name='private']").attr("href"),
"/u/eviltrout/messages/tags/private",
"links to private messages"
);
});
test("new topic button is not available for staff-only tags", async (assert) => {
pretender.get("/tag/regular-tag/notifications", () => [
200,
{ "Content-Type": "application/json" },
{ tag_notification: { id: "regular-tag", notification_level: 1 } },
]);
pretender.get("/tag/regular-tag/l/latest.json", () => [
200,
{ "Content-Type": "application/json" },
{
users: [],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 1,
per_page: 30,
tags: [
{
id: 1,
name: "regular-tag",
topic_count: 1,
},
],
topics: [],
},
},
]);
pretender.get("/tag/staff-only-tag/notifications", () => [
200,
{ "Content-Type": "application/json" },
{ tag_notification: { id: "staff-only-tag", notification_level: 1 } },
]);
pretender.get("/tag/staff-only-tag/l/latest.json", () => [
200,
{ "Content-Type": "application/json" },
{
users: [],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 1,
per_page: 30,
tags: [
{
id: 1,
name: "staff-only-tag",
topic_count: 1,
staff: true,
},
],
topics: [],
},
},
]);
updateCurrentUser({ moderator: false, admin: false });
await visit("/tag/regular-tag");
assert.ok(find("#create-topic:disabled").length === 0);
await visit("/tag/staff-only-tag");
assert.ok(find("#create-topic:disabled").length === 1);
updateCurrentUser({ moderator: true });
await visit("/tag/regular-tag");
assert.ok(find("#create-topic:disabled").length === 0);
await visit("/tag/staff-only-tag");
assert.ok(find("#create-topic:disabled").length === 0);
});
acceptance("Tag info", {
loggedIn: true,
settings: {
tags_listed_by_group: true, tags_listed_by_group: true,
}, });
pretend(server, helper) { needs.pretender((server, helper) => {
server.get("/tag/planters/notifications", () => { server.get("/tag/planters/notifications", () => {
return helper.response({ return helper.response({
tag_notification: { id: "planters", notification_level: 1 }, tag_notification: { id: "planters", notification_level: 1 },
@ -219,64 +217,62 @@ acceptance("Tag info", {
], ],
}); });
}); });
},
}); server.delete("/tag/planters/synonyms/containers", () =>
helper.response({ success: true })
test("tag info can show synonyms", async (assert) => { );
updateCurrentUser({ moderator: false, admin: false }); });
await visit("/tag/planters"); test("tag info can show synonyms", async (assert) => {
assert.ok(find("#show-tag-info").length === 1); updateCurrentUser({ moderator: false, admin: false });
await click("#show-tag-info"); await visit("/tag/planters");
assert.ok(exists(".tag-info .tag-name"), "show tag"); assert.ok(find("#show-tag-info").length === 1);
assert.ok(
find(".tag-info .tag-associations").text().indexOf("Gardening") >= 0, await click("#show-tag-info");
"show tag group names" assert.ok(exists(".tag-info .tag-name"), "show tag");
); assert.ok(
assert.ok( find(".tag-info .tag-associations").text().indexOf("Gardening") >= 0,
find(".tag-info .synonyms-list .tag-box").length === 2, "show tag group names"
"shows the synonyms" );
); assert.ok(
assert.ok( find(".tag-info .synonyms-list .tag-box").length === 2,
find(".tag-info .badge-category").length === 1, "shows the synonyms"
"show the category" );
); assert.ok(
assert.ok(!exists("#rename-tag"), "can't rename tag"); find(".tag-info .badge-category").length === 1,
assert.ok(!exists("#edit-synonyms"), "can't edit synonyms"); "show the category"
assert.ok(!exists("#delete-tag"), "can't delete tag"); );
}); assert.ok(!exists("#rename-tag"), "can't rename tag");
assert.ok(!exists("#edit-synonyms"), "can't edit synonyms");
test("admin can manage tags", async (assert) => { assert.ok(!exists("#delete-tag"), "can't delete tag");
pretender.delete("/tag/planters/synonyms/containers", () => [ });
200,
{ "Content-Type": "application/json" }, test("admin can manage tags", async (assert) => {
{ success: true }, updateCurrentUser({ moderator: false, admin: true });
]);
await visit("/tag/planters");
updateCurrentUser({ moderator: false, admin: true }); assert.ok(find("#show-tag-info").length === 1);
await visit("/tag/planters"); await click("#show-tag-info");
assert.ok(find("#show-tag-info").length === 1); assert.ok(exists("#rename-tag"), "can rename tag");
assert.ok(exists("#edit-synonyms"), "can edit synonyms");
await click("#show-tag-info"); assert.ok(exists("#delete-tag"), "can delete tag");
assert.ok(exists("#rename-tag"), "can rename tag");
assert.ok(exists("#edit-synonyms"), "can edit synonyms"); await click("#edit-synonyms");
assert.ok(exists("#delete-tag"), "can delete tag"); assert.ok(
find(".unlink-synonym:visible").length === 2,
await click("#edit-synonyms"); "unlink UI is visible"
assert.ok( );
find(".unlink-synonym:visible").length === 2, assert.ok(
"unlink UI is visible" find(".delete-synonym:visible").length === 2,
); "delete UI is visible"
assert.ok( );
find(".delete-synonym:visible").length === 2,
"delete UI is visible" await click(".unlink-synonym:first");
); assert.ok(
find(".tag-info .synonyms-list .tag-box").length === 1,
await click(".unlink-synonym:first"); "removed a synonym"
assert.ok( );
find(".tag-info .synonyms-list .tag-box").length === 1, });
"removed a synonym"
);
}); });

View File

@ -5,44 +5,51 @@ import {
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } 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) => {
test("Enter as a regular user", async (assert) => { await visit("/t/internationalization-localization/280");
await visit("/t/internationalization-localization/280"); assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(exists("#topic"), "The topic was rendered"); assert.ok(
assert.ok( !exists(".toggle-admin-menu"),
!exists(".toggle-admin-menu"), "The admin menu button was not rendered"
"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 });
test("Enter as a user with group moderator permissions", async (assert) => { await visit("/t/topic-for-group-moderators/2480");
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 }); assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(
exists(".toggle-admin-menu"),
"The admin menu button was rendered"
);
});
await visit("/t/topic-for-group-moderators/2480"); test("Enter as a user with moderator and admin permissions", async (assert) => {
assert.ok(exists("#topic"), "The topic was rendered"); updateCurrentUser({ moderator: true, admin: true, trust_level: 4 });
assert.ok(exists(".toggle-admin-menu"), "The admin menu button was rendered");
}); await visit("/t/internationalization-localization/280");
assert.ok(exists("#topic"), "The topic was rendered");
test("Enter as a user with moderator and admin permissions", async (assert) => { assert.ok(
updateCurrentUser({ moderator: true, admin: true, trust_level: 4 }); exists(".toggle-admin-menu"),
"The admin menu button was rendered"
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");
}); test("Toggle the menu as admin focuses the first item", async (assert) => {
updateCurrentUser({ admin: true });
test("Toggle the menu as admin focuses the first item", async (assert) => {
updateCurrentUser({ admin: true }); await visit("/t/internationalization-localization/280");
assert.ok(exists("#topic"), "The topic was rendered");
await visit("/t/internationalization-localization/280"); await click(".toggle-admin-menu");
assert.ok(exists("#topic"), "The topic was rendered");
await click(".toggle-admin-menu"); assert.equal(
document.activeElement,
assert.equal( document.querySelector(".topic-admin-multi-select > button")
document.activeElement, );
document.querySelector(".topic-admin-multi-select > button") });
);
}); });

View File

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

View File

@ -5,125 +5,125 @@ import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import MessageBus from "message-bus-client"; import MessageBus from "message-bus-client";
acceptance("Topic Discovery", { acceptance("Topic Discovery", function (needs) {
settings: { needs.settings({
show_pinned_excerpt_desktop: true, show_pinned_excerpt_desktop: true,
}, });
});
test("Visit Discovery Pages", async (assert) => { test("Visit Discovery Pages", async (assert) => {
await visit("/"); await visit("/");
assert.ok($("body.navigation-topics").length, "has the default navigation"); assert.ok($("body.navigation-topics").length, "has the default navigation");
assert.ok(exists(".topic-list"), "The list of topics was rendered"); assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics"); assert.ok(exists(".topic-list .topic-list-item"), "has topics");
assert.equal( assert.equal(
find("a[data-user-card=eviltrout]:first img.avatar").attr("title"), find("a[data-user-card=eviltrout]:first img.avatar").attr("title"),
"Evil Trout - Most Posts", "Evil Trout - Most Posts",
"it shows user's full name in avatar title" "it shows user's full name in avatar title"
); );
await visit("/c/bug"); await visit("/c/bug");
assert.ok(exists(".topic-list"), "The list of topics was rendered"); assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(exists(".topic-list .topic-list-item"), "has topics"); assert.ok(exists(".topic-list .topic-list-item"), "has topics");
assert.ok(!exists(".category-list"), "doesn't render subcategories"); assert.ok(!exists(".category-list"), "doesn't render subcategories");
assert.ok( assert.ok(
$("body.category-bug").length, $("body.category-bug").length,
"has a custom css class for the category id on the body" "has a custom css class for the category id on the body"
); );
await visit("/categories"); await visit("/categories");
assert.ok($("body.navigation-categories").length, "has the body class"); assert.ok($("body.navigation-categories").length, "has the body class");
assert.ok( assert.ok(
$("body.category-bug").length === 0, $("body.category-bug").length === 0,
"removes the custom category class" "removes the custom category class"
); );
assert.ok(exists(".category"), "has a list of categories"); assert.ok(exists(".category"), "has a list of categories");
assert.ok( assert.ok(
$("body.categories-list").length, $("body.categories-list").length,
"has a custom class to indicate categories" "has a custom class to indicate categories"
); );
await visit("/top"); await visit("/top");
assert.ok( assert.ok(
$("body.categories-list").length === 0, $("body.categories-list").length === 0,
"removes the `categories-list` class" "removes the `categories-list` class"
); );
assert.ok(exists(".topic-list .topic-list-item"), "has topics"); assert.ok(exists(".topic-list .topic-list-item"), "has topics");
await visit("/c/feature"); await visit("/c/feature");
assert.ok(exists(".topic-list"), "The list of topics was rendered"); assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok( assert.ok(
exists(".category-boxes"), exists(".category-boxes"),
"The list of subcategories were rendered with box style" "The list of subcategories were rendered with box style"
); );
await visit("/c/dev"); await visit("/c/dev");
assert.ok(exists(".topic-list"), "The list of topics was rendered"); assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok( assert.ok(
exists(".category-boxes-with-topics"), exists(".category-boxes-with-topics"),
"The list of subcategories were rendered with box-with-featured-topics style" "The list of subcategories were rendered with box-with-featured-topics style"
); );
assert.ok( assert.ok(
exists(".category-boxes-with-topics .featured-topics"), exists(".category-boxes-with-topics .featured-topics"),
"The featured topics are there too" "The featured topics are there too"
); );
}); });
test("Clearing state after leaving a category", async (assert) => { test("Clearing state after leaving a category", async (assert) => {
await visit("/c/dev"); await visit("/c/dev");
assert.ok( assert.ok(
exists(".topic-list-item[data-topic-id=11994] .topic-excerpt"), exists(".topic-list-item[data-topic-id=11994] .topic-excerpt"),
"it expands pinned topics in a subcategory" "it expands pinned topics in a subcategory"
); );
await visit("/"); await visit("/");
assert.ok( assert.ok(
!exists(".topic-list-item[data-topic-id=11557] .topic-excerpt"), !exists(".topic-list-item[data-topic-id=11557] .topic-excerpt"),
"it doesn't expand all pinned in the latest category" "it doesn't expand all pinned in the latest category"
); );
}); });
test("Live update unread state", async (assert) => { test("Live update unread state", async (assert) => {
await visit("/"); await visit("/");
assert.ok( assert.ok(
exists(".topic-list-item:not(.visited) a[data-topic-id='11995']"), exists(".topic-list-item:not(.visited) a[data-topic-id='11995']"),
"shows the topic unread" "shows the topic unread"
); );
// Mimic a messagebus message // Mimic a messagebus message
MessageBus.callbacks.filterBy("channel", "/latest").map((c) => MessageBus.callbacks.filterBy("channel", "/latest").map((c) =>
c.func({ c.func({
message_type: "read", message_type: "read",
topic_id: 11995,
payload: {
highest_post_number: 1,
last_read_post_number: 2,
notification_level: 1,
topic_id: 11995, topic_id: 11995,
}, payload: {
}) highest_post_number: 1,
); last_read_post_number: 2,
notification_level: 1,
topic_id: 11995,
},
})
);
await visit("/"); // We're already there, but use this to wait for re-render await visit("/"); // We're already there, but use this to wait for re-render
assert.ok( assert.ok(
exists(".topic-list-item.visited a[data-topic-id='11995']"), exists(".topic-list-item.visited a[data-topic-id='11995']"),
"shows the topic read" "shows the topic read"
); );
}); });
test("Using period chooser when query params are present", async (assert) => { test("Using period chooser when query params are present", async (assert) => {
await visit("/top?f=foo&d=bar"); await visit("/top?f=foo&d=bar");
sandbox.stub(DiscourseURL, "routeTo"); sandbox.stub(DiscourseURL, "routeTo");
const periodChooser = selectKit(".period-chooser"); const periodChooser = selectKit(".period-chooser");
await periodChooser.expand(); await periodChooser.expand();
await periodChooser.selectRowByValue("yearly"); await periodChooser.selectRowByValue("yearly");
assert.ok( assert.ok(
DiscourseURL.routeTo.calledWith("/top/yearly?f=foo&d=bar"), DiscourseURL.routeTo.calledWith("/top/yearly?f=foo&d=bar"),
"it keeps the query params" "it keeps the query params"
); );
});
}); });

View File

@ -7,9 +7,9 @@ import {
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic - Edit timer", { acceptance("Topic - Edit timer", function (needs) {
loggedIn: true, needs.user();
pretend(server, helper) { needs.pretender((server, helper) => {
server.post("/t/280/timer", () => server.post("/t/280/timer", () =>
helper.response({ helper.response({
success: "OK", success: "OK",
@ -22,219 +22,240 @@ acceptance("Topic - Edit timer", {
category_id: null, category_id: null,
}) })
); );
}, });
});
test("default", async (assert) => {
test("default", async (assert) => { updateCurrentUser({ moderator: true });
updateCurrentUser({ moderator: true }); const futureDateInputSelector = selectKit(".future-date-input-selector");
const futureDateInputSelector = selectKit(".future-date-input-selector");
await visit("/t/internationalization-localization");
await visit("/t/internationalization-localization"); await click(".toggle-admin-menu");
await click(".toggle-admin-menu"); await click(".topic-admin-status-update button");
await click(".topic-admin-status-update button");
assert.equal(
assert.equal(futureDateInputSelector.header().label(), "Select a timeframe"); futureDateInputSelector.header().label(),
assert.equal(futureDateInputSelector.header().value(), null); "Select a timeframe"
}); );
assert.equal(futureDateInputSelector.header().value(), null);
test("autoclose - specific time", async (assert) => { });
updateCurrentUser({ moderator: true });
const futureDateInputSelector = selectKit(".future-date-input-selector"); test("autoclose - specific time", async (assert) => {
updateCurrentUser({ moderator: true });
await visit("/t/internationalization-localization"); const futureDateInputSelector = selectKit(".future-date-input-selector");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button"); await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await futureDateInputSelector.expand(); await click(".topic-admin-status-update button");
await futureDateInputSelector.selectRowByValue("next_week");
await futureDateInputSelector.expand();
assert.ok(futureDateInputSelector.header().label().includes("Next week")); await futureDateInputSelector.selectRowByValue("next_week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
assert.ok(futureDateInputSelector.header().label().includes("Next week"));
const regex = /will automatically close in/g; assert.equal(futureDateInputSelector.header().value(), "next_week");
const html = find(".future-date-input .topic-status-info").html().trim();
assert.ok(regex.test(html)); const regex = /will automatically close in/g;
}); const html = find(".future-date-input .topic-status-info").html().trim();
assert.ok(regex.test(html));
skip("autoclose", async (assert) => { });
updateCurrentUser({ moderator: true });
const futureDateInputSelector = selectKit(".future-date-input-selector"); skip("autoclose", async (assert) => {
updateCurrentUser({ moderator: true });
await visit("/t/internationalization-localization"); const futureDateInputSelector = selectKit(".future-date-input-selector");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button"); await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await futureDateInputSelector.expand(); await click(".topic-admin-status-update button");
await futureDateInputSelector.selectRowByValue("next_week");
await futureDateInputSelector.expand();
assert.ok(futureDateInputSelector.header().label().includes("Next week")); await futureDateInputSelector.selectRowByValue("next_week");
assert.equal(futureDateInputSelector.header().value(), "next_week");
assert.ok(futureDateInputSelector.header().label().includes("Next week"));
const regex1 = /will automatically close in/g; assert.equal(futureDateInputSelector.header().value(), "next_week");
const html1 = find(".future-date-input .topic-status-info").html().trim();
assert.ok(regex1.test(html1)); const regex1 = /will automatically close in/g;
const html1 = find(".future-date-input .topic-status-info").html().trim();
await futureDateInputSelector.expand(); assert.ok(regex1.test(html1));
await futureDateInputSelector.selectRowByValue("pick_date_and_time");
await futureDateInputSelector.expand();
await fillIn(".future-date-input .date-picker", "2099-11-24"); await futureDateInputSelector.selectRowByValue("pick_date_and_time");
assert.ok( await fillIn(".future-date-input .date-picker", "2099-11-24");
futureDateInputSelector.header().label().includes("Pick date and time")
); assert.ok(
assert.equal(futureDateInputSelector.header().value(), "pick_date_and_time"); futureDateInputSelector.header().label().includes("Pick date and time")
);
const regex2 = /will automatically close in/g; assert.equal(
const html2 = find(".future-date-input .topic-status-info").html().trim(); futureDateInputSelector.header().value(),
assert.ok(regex2.test(html2)); "pick_date_and_time"
);
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("set_based_on_last_post"); const regex2 = /will automatically close in/g;
const html2 = find(".future-date-input .topic-status-info").html().trim();
await fillIn(".future-date-input input[type=number]", "2"); assert.ok(regex2.test(html2));
assert.ok( await futureDateInputSelector.expand();
futureDateInputSelector await futureDateInputSelector.selectRowByValue("set_based_on_last_post");
.header()
.label() await fillIn(".future-date-input input[type=number]", "2");
.includes("Close based on last post")
); assert.ok(
assert.equal( futureDateInputSelector
futureDateInputSelector.header().value(), .header()
"set_based_on_last_post" .label()
); .includes("Close based on last post")
);
const regex3 = /This topic will close.*after the last reply/g; assert.equal(
const html3 = find(".future-date-input .topic-status-info").html().trim(); futureDateInputSelector.header().value(),
assert.ok(regex3.test(html3)); "set_based_on_last_post"
}); );
test("close temporarily", async (assert) => { const regex3 = /This topic will close.*after the last reply/g;
updateCurrentUser({ moderator: true }); const html3 = find(".future-date-input .topic-status-info").html().trim();
const timerType = selectKit(".select-kit.timer-type"); assert.ok(regex3.test(html3));
const futureDateInputSelector = selectKit(".future-date-input-selector"); });
await visit("/t/internationalization-localization"); test("close temporarily", async (assert) => {
await click(".toggle-admin-menu"); updateCurrentUser({ moderator: true });
await click(".topic-admin-status-update button"); const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector");
await timerType.expand();
await timerType.selectRowByValue("open"); await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
assert.equal(futureDateInputSelector.header().label(), "Select a timeframe"); await click(".topic-admin-status-update button");
assert.equal(futureDateInputSelector.header().value(), null);
await timerType.expand();
await futureDateInputSelector.expand(); await timerType.selectRowByValue("open");
await futureDateInputSelector.selectRowByValue("next_week");
assert.equal(
assert.ok(futureDateInputSelector.header().label().includes("Next week")); futureDateInputSelector.header().label(),
assert.equal(futureDateInputSelector.header().value(), "next_week"); "Select a timeframe"
);
const regex1 = /will automatically open in/g; assert.equal(futureDateInputSelector.header().value(), null);
const html1 = find(".future-date-input .topic-status-info").html().trim();
assert.ok(regex1.test(html1)); await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("next_week");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("pick_date_and_time"); assert.ok(futureDateInputSelector.header().label().includes("Next week"));
assert.equal(futureDateInputSelector.header().value(), "next_week");
await fillIn(".future-date-input .date-picker", "2099-11-24");
const regex1 = /will automatically open in/g;
assert.equal(futureDateInputSelector.header().label(), "Pick date and time"); const html1 = find(".future-date-input .topic-status-info").html().trim();
assert.equal(futureDateInputSelector.header().value(), "pick_date_and_time"); assert.ok(regex1.test(html1));
const regex2 = /will automatically open in/g; await futureDateInputSelector.expand();
const html2 = find(".future-date-input .topic-status-info").html().trim(); await futureDateInputSelector.selectRowByValue("pick_date_and_time");
assert.ok(regex2.test(html2));
}); await fillIn(".future-date-input .date-picker", "2099-11-24");
test("schedule", async (assert) => { assert.equal(
updateCurrentUser({ moderator: true }); futureDateInputSelector.header().label(),
const timerType = selectKit(".select-kit.timer-type"); "Pick date and time"
const categoryChooser = selectKit(".modal-body .category-chooser"); );
const futureDateInputSelector = selectKit(".future-date-input-selector"); assert.equal(
futureDateInputSelector.header().value(),
await visit("/t/internationalization-localization"); "pick_date_and_time"
await click(".toggle-admin-menu"); );
await click(".topic-admin-status-update button");
const regex2 = /will automatically open in/g;
await timerType.expand(); const html2 = find(".future-date-input .topic-status-info").html().trim();
await timerType.selectRowByValue("publish_to_category"); assert.ok(regex2.test(html2));
});
assert.equal(categoryChooser.header().label(), "uncategorized");
assert.equal(categoryChooser.header().value(), null); test("schedule", async (assert) => {
updateCurrentUser({ moderator: true });
assert.equal(futureDateInputSelector.header().label(), "Select a timeframe"); const timerType = selectKit(".select-kit.timer-type");
assert.equal(futureDateInputSelector.header().value(), null); const categoryChooser = selectKit(".modal-body .category-chooser");
const futureDateInputSelector = selectKit(".future-date-input-selector");
await categoryChooser.expand();
await categoryChooser.selectRowByValue("7"); await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await futureDateInputSelector.expand(); await click(".topic-admin-status-update button");
await futureDateInputSelector.selectRowByValue("next_week");
await timerType.expand();
assert.ok(futureDateInputSelector.header().label().includes("Next week")); await timerType.selectRowByValue("publish_to_category");
assert.equal(futureDateInputSelector.header().value(), "next_week");
assert.equal(categoryChooser.header().label(), "uncategorized");
const regex = /will be published to #dev/g; assert.equal(categoryChooser.header().value(), null);
const text = find(".future-date-input .topic-status-info").text().trim();
assert.ok(regex.test(text)); assert.equal(
}); futureDateInputSelector.header().label(),
"Select a timeframe"
test("TL4 can't auto-delete", async (assert) => { );
updateCurrentUser({ moderator: false, admin: false, trust_level: 4 }); assert.equal(futureDateInputSelector.header().value(), null);
await visit("/t/internationalization-localization"); await categoryChooser.expand();
await click(".toggle-admin-menu"); await categoryChooser.selectRowByValue("7");
await click(".topic-admin-status-update button");
await futureDateInputSelector.expand();
const timerType = selectKit(".select-kit.timer-type"); await futureDateInputSelector.selectRowByValue("next_week");
await timerType.expand(); assert.ok(futureDateInputSelector.header().label().includes("Next week"));
assert.equal(futureDateInputSelector.header().value(), "next_week");
assert.ok(!timerType.rowByValue("delete").exists());
}); const regex = /will be published to #dev/g;
const text = find(".future-date-input .topic-status-info").text().trim();
test("auto delete", async (assert) => { assert.ok(regex.test(text));
updateCurrentUser({ moderator: true }); });
const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector"); test("TL4 can't auto-delete", async (assert) => {
updateCurrentUser({ moderator: false, admin: false, trust_level: 4 });
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu"); await visit("/t/internationalization-localization");
await click(".topic-admin-status-update button"); await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await timerType.expand();
await timerType.selectRowByValue("delete"); const timerType = selectKit(".select-kit.timer-type");
assert.equal(futureDateInputSelector.header().label(), "Select a timeframe"); await timerType.expand();
assert.equal(futureDateInputSelector.header().value(), null);
assert.ok(!timerType.rowByValue("delete").exists());
await futureDateInputSelector.expand(); });
await futureDateInputSelector.selectRowByValue("two_weeks");
test("auto delete", async (assert) => {
assert.ok(futureDateInputSelector.header().label().includes("Two Weeks")); updateCurrentUser({ moderator: true });
assert.equal(futureDateInputSelector.header().value(), "two_weeks"); const timerType = selectKit(".select-kit.timer-type");
const futureDateInputSelector = selectKit(".future-date-input-selector");
const regex = /will be automatically deleted/g;
const html = find(".future-date-input .topic-status-info").html().trim(); await visit("/t/internationalization-localization");
assert.ok(regex.test(html)); await click(".toggle-admin-menu");
}); await click(".topic-admin-status-update button");
test("Inline delete timer", async (assert) => { await timerType.expand();
updateCurrentUser({ moderator: true }); await timerType.selectRowByValue("delete");
const futureDateInputSelector = selectKit(".future-date-input-selector");
assert.equal(
await visit("/t/internationalization-localization"); futureDateInputSelector.header().label(),
await click(".toggle-admin-menu"); "Select a timeframe"
await click(".topic-admin-status-update button"); );
await futureDateInputSelector.expand(); assert.equal(futureDateInputSelector.header().value(), null);
await futureDateInputSelector.selectRowByValue("next_week");
await click(".modal-footer button.btn-primary"); await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("two_weeks");
const removeTimerButton = find(".topic-status-info .topic-timer-remove");
assert.equal(removeTimerButton.attr("title"), "remove timer"); assert.ok(futureDateInputSelector.header().label().includes("Two Weeks"));
assert.equal(futureDateInputSelector.header().value(), "two_weeks");
await click(".topic-status-info .topic-timer-remove");
const topicStatusInfo = find(".topic-status-info .topic-timer-remove"); const regex = /will be automatically deleted/g;
assert.equal(topicStatusInfo.length, 0); const html = find(".future-date-input .topic-status-info").html().trim();
assert.ok(regex.test(html));
});
test("Inline delete timer", async (assert) => {
updateCurrentUser({ moderator: true });
const futureDateInputSelector = selectKit(".future-date-input-selector");
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-status-update button");
await futureDateInputSelector.expand();
await futureDateInputSelector.selectRowByValue("next_week");
await click(".modal-footer button.btn-primary");
const removeTimerButton = find(".topic-status-info .topic-timer-remove");
assert.equal(removeTimerButton.attr("title"), "remove timer");
await click(".topic-status-info .topic-timer-remove");
const topicStatusInfo = find(".topic-status-info .topic-timer-remove");
assert.equal(topicStatusInfo.length, 0);
});
}); });

View File

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

View File

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

View File

@ -2,141 +2,144 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import I18n from "I18n"; import I18n from "I18n";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic move posts", { loggedIn: true });
test("default", async (assert) => { acceptance("Topic move posts", function (needs) {
await visit("/t/internationalization-localization"); needs.user();
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
await click("#post_11 .select-below");
assert.equal( test("default", async (assert) => {
find(".selected-posts .move-to-topic").text().trim(), await visit("/t/internationalization-localization");
I18n.t("topic.move_to.action"), await click(".toggle-admin-menu");
"it should show the move to button" await click(".topic-admin-multi-select .btn");
); await click("#post_11 .select-below");
await click(".selected-posts .move-to-topic"); assert.equal(
find(".selected-posts .move-to-topic").text().trim(),
I18n.t("topic.move_to.action"),
"it should show the move to button"
);
assert.ok( await click(".selected-posts .move-to-topic");
find(".choose-topic-modal .title")
.html()
.includes(I18n.t("topic.move_to.title")),
"it opens move to modal"
);
assert.ok( assert.ok(
find(".choose-topic-modal .radios") find(".choose-topic-modal .title")
.html() .html()
.includes(I18n.t("topic.split_topic.radio_label")), .includes(I18n.t("topic.move_to.title")),
"it shows an option to move to new topic" "it opens move to modal"
); );
assert.ok( assert.ok(
find(".choose-topic-modal .radios") find(".choose-topic-modal .radios")
.html() .html()
.includes(I18n.t("topic.merge_topic.radio_label")), .includes(I18n.t("topic.split_topic.radio_label")),
"it shows an option to move to existing topic" "it shows an option to move to new topic"
); );
assert.ok( assert.ok(
find(".choose-topic-modal .radios") find(".choose-topic-modal .radios")
.html() .html()
.includes(I18n.t("topic.move_to_new_message.radio_label")), .includes(I18n.t("topic.merge_topic.radio_label")),
"it shows an option to move to new message" "it shows an option to move to existing topic"
); );
});
assert.ok(
test("moving all posts", async (assert) => { find(".choose-topic-modal .radios")
await visit("/t/internationalization-localization"); .html()
await click(".toggle-admin-menu"); .includes(I18n.t("topic.move_to_new_message.radio_label")),
await click(".topic-admin-multi-select .btn"); "it shows an option to move to new message"
await click(".select-all"); );
await click(".selected-posts .move-to-topic"); });
assert.ok( test("moving all posts", async (assert) => {
find(".choose-topic-modal .title") await visit("/t/internationalization-localization");
.html() await click(".toggle-admin-menu");
.includes(I18n.t("topic.move_to.title")), await click(".topic-admin-multi-select .btn");
"it opens move to modal" await click(".select-all");
); await click(".selected-posts .move-to-topic");
assert.not( assert.ok(
find(".choose-topic-modal .radios") find(".choose-topic-modal .title")
.html() .html()
.includes(I18n.t("topic.split_topic.radio_label")), .includes(I18n.t("topic.move_to.title")),
"it does not show an option to move to new topic" "it opens move to modal"
); );
assert.ok( assert.not(
find(".choose-topic-modal .radios") find(".choose-topic-modal .radios")
.html() .html()
.includes(I18n.t("topic.merge_topic.radio_label")), .includes(I18n.t("topic.split_topic.radio_label")),
"it shows an option to move to existing topic" "it does not show an option to move to new topic"
); );
assert.not( assert.ok(
find(".choose-topic-modal .radios") find(".choose-topic-modal .radios")
.html() .html()
.includes(I18n.t("topic.move_to_new_message.radio_label")), .includes(I18n.t("topic.merge_topic.radio_label")),
"it does not show an option to move to new message" "it shows an option to move to existing topic"
); );
});
assert.not(
test("moving posts from personal message", async (assert) => { find(".choose-topic-modal .radios")
await visit("/t/pm-for-testing/12"); .html()
await click(".toggle-admin-menu"); .includes(I18n.t("topic.move_to_new_message.radio_label")),
await click(".topic-admin-multi-select .btn"); "it does not show an option to move to new message"
await click("#post_1 .select-post"); );
});
assert.equal(
find(".selected-posts .move-to-topic").text().trim(), test("moving posts from personal message", async (assert) => {
I18n.t("topic.move_to.action"), await visit("/t/pm-for-testing/12");
"it should show the move to button" await click(".toggle-admin-menu");
); await click(".topic-admin-multi-select .btn");
await click("#post_1 .select-post");
await click(".selected-posts .move-to-topic");
assert.equal(
assert.ok( find(".selected-posts .move-to-topic").text().trim(),
find(".choose-topic-modal .title") I18n.t("topic.move_to.action"),
.html() "it should show the move to button"
.includes(I18n.t("topic.move_to.title")), );
"it opens move to modal"
); await click(".selected-posts .move-to-topic");
assert.ok( assert.ok(
find(".choose-topic-modal .radios") find(".choose-topic-modal .title")
.html() .html()
.includes(I18n.t("topic.move_to_new_message.radio_label")), .includes(I18n.t("topic.move_to.title")),
"it shows an option to move to new message" "it opens move to modal"
); );
assert.ok( assert.ok(
find(".choose-topic-modal .radios") find(".choose-topic-modal .radios")
.html() .html()
.includes(I18n.t("topic.move_to_existing_message.radio_label")), .includes(I18n.t("topic.move_to_new_message.radio_label")),
"it shows an option to move to existing message" "it shows an option to move to new message"
); );
});
assert.ok(
test("group moderator moving posts", async (assert) => { find(".choose-topic-modal .radios")
await visit("/t/topic-for-group-moderators/2480"); .html()
await click(".toggle-admin-menu"); .includes(I18n.t("topic.move_to_existing_message.radio_label")),
await click(".topic-admin-multi-select .btn"); "it shows an option to move to existing message"
await click("#post_2 .select-below"); );
});
assert.equal(
find(".selected-posts .move-to-topic").text().trim(), test("group moderator moving posts", async (assert) => {
I18n.t("topic.move_to.action"), await visit("/t/topic-for-group-moderators/2480");
"it should show the move to button" await click(".toggle-admin-menu");
); await click(".topic-admin-multi-select .btn");
await click("#post_2 .select-below");
await click(".selected-posts .move-to-topic");
assert.equal(
assert.ok( find(".selected-posts .move-to-topic").text().trim(),
find(".choose-topic-modal .title") I18n.t("topic.move_to.action"),
.html() "it should show the move to button"
.includes(I18n.t("topic.move_to.title")), );
"it opens move to modal"
); await click(".selected-posts .move-to-topic");
assert.ok(
find(".choose-topic-modal .title")
.html()
.includes(I18n.t("topic.move_to.title")),
"it opens move to modal"
);
});
}); });

View File

@ -3,58 +3,59 @@ import { test } from "qunit";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic Notifications button", { acceptance("Topic Notifications button", function (needs) {
loggedIn: true, needs.user();
pretend(server, helper) {
needs.pretender((server, helper) => {
server.post("/t/280/notifications", () => { server.post("/t/280/notifications", () => {
return helper.response({}); return helper.response({});
}); });
}, });
});
test("Updating topic notification level", async (assert) => {
test("Updating topic notification level", async (assert) => { const notificationOptions = selectKit(
const notificationOptions = selectKit( "#topic-footer-buttons .topic-notifications-options"
"#topic-footer-buttons .topic-notifications-options" );
);
await visit("/t/internationalization-localization/280");
await visit("/t/internationalization-localization/280");
assert.ok(
assert.ok( notificationOptions.exists(),
notificationOptions.exists(), "it should display the notification options button in the topic's footer"
"it should display the notification options button in the topic's footer" );
);
await notificationOptions.expand();
await notificationOptions.expand(); await notificationOptions.selectRowByValue("3");
await notificationOptions.selectRowByValue("3");
assert.equal(
assert.equal( notificationOptions.header().label(),
notificationOptions.header().label(), "Watching",
"Watching", "it should display the right notification level"
"it should display the right notification level" );
);
const timelineNotificationOptions = selectKit(
const timelineNotificationOptions = selectKit( ".topic-timeline .widget-component-connector .topic-notifications-options"
".topic-timeline .widget-component-connector .topic-notifications-options" );
);
assert.equal(
assert.equal( timelineNotificationOptions.header().value(),
timelineNotificationOptions.header().value(), "3",
"3", "it should display the right notification level"
"it should display the right notification level" );
);
await timelineNotificationOptions.expand();
await timelineNotificationOptions.expand(); await timelineNotificationOptions.selectRowByValue("0");
await timelineNotificationOptions.selectRowByValue("0");
assert.equal(
assert.equal( timelineNotificationOptions.header().value(),
timelineNotificationOptions.header().value(), "0",
"0", "it should display the right notification level"
"it should display the right notification level" );
);
assert.equal(
assert.equal( notificationOptions.header().label(),
notificationOptions.header().label(), "Muted",
"Muted", "it should display the right notification level"
"it should display the right notification level" );
); });
}); });

View File

@ -13,103 +13,102 @@ function selectText(selector) {
selection.addRange(range); selection.addRange(range);
} }
acceptance("Topic - Quote button - logged in", { acceptance("Topic - Quote button - logged in", function (needs) {
loggedIn: true, needs.user();
settings: { needs.settings({
share_quote_visibility: "anonymous", share_quote_visibility: "anonymous",
share_quote_buttons: "twitter|email", share_quote_buttons: "twitter|email",
}, });
test("Does not show the quote share buttons by default", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
assert.ok(exists(".insert-quote"), "it shows the quote button");
assert.equal(
find(".quote-sharing").length,
0,
"it does not show quote sharing"
);
});
test("Shows quote share buttons with the right site settings", async function (assert) {
this.siteSettings.share_quote_visibility = "all";
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
assert.ok(exists(".quote-sharing"), "it shows the quote sharing options");
assert.ok(
exists(`.quote-sharing .btn[title='${I18n.t("share.twitter")}']`),
"it includes the twitter share button"
);
assert.ok(
exists(`.quote-sharing .btn[title='${I18n.t("share.email")}']`),
"it includes the email share button"
);
});
}); });
test("Does not show the quote share buttons by default", async (assert) => { acceptance("Topic - Quote button - anonymous", function (needs) {
await visit("/t/internationalization-localization/280"); needs.settings({
selectText("#post_5 blockquote");
assert.ok(exists(".insert-quote"), "it shows the quote button");
assert.equal(
find(".quote-sharing").length,
0,
"it does not show quote sharing"
);
});
test("Shows quote share buttons with the right site settings", async function (assert) {
this.siteSettings.share_quote_visibility = "all";
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
assert.ok(exists(".quote-sharing"), "it shows the quote sharing options");
assert.ok(
exists(`.quote-sharing .btn[title='${I18n.t("share.twitter")}']`),
"it includes the twitter share button"
);
assert.ok(
exists(`.quote-sharing .btn[title='${I18n.t("share.email")}']`),
"it includes the email share button"
);
});
acceptance("Topic - Quote button - anonymous", {
loggedIn: false,
settings: {
share_quote_visibility: "anonymous", share_quote_visibility: "anonymous",
share_quote_buttons: "twitter|email", share_quote_buttons: "twitter|email",
}, });
});
test("Shows quote share buttons with the right site settings", async function (assert) {
test("Shows quote share buttons with the right site settings", async function (assert) { await visit("/t/internationalization-localization/280");
await visit("/t/internationalization-localization/280"); selectText("#post_5 blockquote");
selectText("#post_5 blockquote");
assert.ok(find(".quote-sharing"), "it shows the quote sharing options");
assert.ok(find(".quote-sharing"), "it shows the quote sharing options"); assert.ok(
assert.ok( exists(`.quote-sharing .btn[title='${I18n.t("share.twitter")}']`),
exists(`.quote-sharing .btn[title='${I18n.t("share.twitter")}']`), "it includes the twitter share button"
"it includes the twitter share button" );
); assert.ok(
assert.ok( exists(`.quote-sharing .btn[title='${I18n.t("share.email")}']`),
exists(`.quote-sharing .btn[title='${I18n.t("share.email")}']`), "it includes the email share button"
"it includes the email share button" );
); assert.equal(
assert.equal( find(".insert-quote").length,
find(".insert-quote").length, 0,
0, "it does not show the quote button"
"it does not show the quote button" );
); });
});
test("Shows single share button when site setting only has one item", async function (assert) {
test("Shows single share button when site setting only has one item", async function (assert) { this.siteSettings.share_quote_buttons = "twitter";
this.siteSettings.share_quote_buttons = "twitter";
await visit("/t/internationalization-localization/280");
await visit("/t/internationalization-localization/280"); selectText("#post_5 blockquote");
selectText("#post_5 blockquote");
assert.ok(exists(".quote-sharing"), "it shows the quote sharing options");
assert.ok(exists(".quote-sharing"), "it shows the quote sharing options"); assert.ok(
assert.ok( exists(`.quote-sharing .btn[title='${I18n.t("share.twitter")}']`),
exists(`.quote-sharing .btn[title='${I18n.t("share.twitter")}']`), "it includes the twitter share button"
"it includes the twitter share button" );
); assert.equal(
assert.equal( find(".quote-share-label").length,
find(".quote-share-label").length, 0,
0, "it does not show the Share label"
"it does not show the Share label" );
); });
});
test("Shows nothing when visibility is disabled", async function (assert) {
test("Shows nothing when visibility is disabled", async function (assert) { this.siteSettings.share_quote_visibility = "none";
this.siteSettings.share_quote_visibility = "none";
await visit("/t/internationalization-localization/280");
await visit("/t/internationalization-localization/280"); selectText("#post_5 blockquote");
selectText("#post_5 blockquote");
assert.equal(
assert.equal( find(".quote-sharing").length,
find(".quote-sharing").length, 0,
0, "it does not show quote sharing"
"it does not show quote sharing" );
);
assert.equal(
assert.equal( find(".insert-quote").length,
find(".insert-quote").length, 0,
0, "it does not show the quote button"
"it does not show the quote button" );
); });
}); });

View File

@ -1,5 +1,4 @@
import { visit } from "@ember/test-helpers"; import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { test } from "qunit"; import { test } from "qunit";
import I18n from "I18n"; import I18n from "I18n";
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";
@ -7,314 +6,6 @@ import selectKit from "discourse/tests/helpers/select-kit-helper";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { IMAGE_VERSION as v } from "pretty-text/emoji/version"; import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
acceptance("Topic", {
loggedIn: true,
pretend(server, helper) {
server.put("/posts/398/wiki", () => {
return helper.response({});
});
},
});
test("Reply as new topic", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("button.share:eq(0)");
await click(".reply-as-new-topic a");
assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.equal(
find(".d-editor-input").val().trim(),
`Continuing the discussion from [Internationalization / localization](${window.location.origin}/t/internationalization-localization/280):`,
"it fills composer with the ring string"
);
assert.equal(
selectKit(".category-chooser").header().value(),
"2",
"it fills category selector with the right category"
);
});
test("Reply as new message", async (assert) => {
await visit("/t/pm-for-testing/12");
await click("button.share:eq(0)");
await click(".reply-as-new-topic a");
assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.equal(
find(".d-editor-input").val().trim(),
`Continuing the discussion from [PM for testing](${window.location.origin}/t/pm-for-testing/12):`,
"it fills composer with the ring string"
);
const targets = find(".item span", ".composer-fields");
assert.equal(
$(targets[0]).text(),
"someguy",
"it fills up the composer with the right user to start the PM to"
);
assert.equal(
$(targets[1]).text(),
"test",
"it fills up the composer with the right user to start the PM to"
);
assert.equal(
$(targets[2]).text(),
"Group",
"it fills up the composer with the right group to start the PM to"
);
});
test("Share Modal", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:first-child button.share");
assert.ok(exists("#share-link"), "it shows the share modal");
});
test("Showing and hiding the edit controls", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
assert.ok(exists("#edit-title"), "it shows the editing controls");
assert.ok(
!exists(".title-wrapper .remove-featured-link"),
"link to remove featured link is not shown"
);
await fillIn("#edit-title", "this is the new title");
await click("#topic-title .cancel-edit");
assert.ok(!exists("#edit-title"), "it hides the editing controls");
});
test("Updating the topic title and category", async (assert) => {
const categoryChooser = selectKit(".title-wrapper .category-chooser");
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
await fillIn("#edit-title", "this is the new title");
await categoryChooser.expand();
await categoryChooser.selectRowByValue(4);
await click("#topic-title .submit-edit");
assert.equal(
find("#topic-title .badge-category").text(),
"faq",
"it displays the new category"
);
assert.equal(
find(".fancy-title").text().trim(),
"this is the new title",
"it displays the new title"
);
});
test("Marking a topic as wiki", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(find("a.wiki").length === 0, "it does not show the wiki icon");
await click(".topic-post:eq(0) button.show-more-actions");
await click(".topic-post:eq(0) button.show-post-admin-menu");
await click(".btn.wiki");
assert.ok(find("a.wiki").length === 1, "it shows the wiki icon");
});
test("Visit topic routes", async (assert) => {
await visit("/t/12");
assert.equal(
find(".fancy-title").text().trim(),
"PM for testing",
"it routes to the right topic"
);
await visit("/t/280/20");
assert.equal(
find(".fancy-title").text().trim(),
"Internationalization / localization",
"it routes to the right topic"
);
});
test("Updating the topic title with emojis", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
await fillIn("#edit-title", "emojis title :bike: :blonde_woman:t6:");
await click("#topic-title .submit-edit");
assert.equal(
find(".fancy-title").html().trim(),
`emojis title <img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/bike.png?v=${v}" title="bike" alt="bike" class="emoji"> <img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/blonde_woman/6.png?v=${v}" title="blonde_woman:t6" alt="blonde_woman:t6" class="emoji">`,
"it displays the new title with emojis"
);
});
test("Updating the topic title with unicode emojis", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
await fillIn("#edit-title", "emojis title 👨‍🌾🙏");
await click("#topic-title .submit-edit");
assert.equal(
find(".fancy-title").html().trim(),
`emojis title <img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/man_farmer.png?v=${v}" title="man_farmer" alt="man_farmer" class="emoji"><img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/pray.png?v=${v}" title="pray" alt="pray" class="emoji">`,
"it displays the new title with escaped unicode emojis"
);
});
test("Updating the topic title with unicode emojis without whitespaces", async function (assert) {
this.siteSettings.enable_inline_emoji_translation = true;
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
await fillIn("#edit-title", "Test🙂Title");
await click("#topic-title .submit-edit");
assert.equal(
find(".fancy-title").html().trim(),
`Test<img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/slightly_smiling_face.png?v=${v}" title="slightly_smiling_face" alt="slightly_smiling_face" class="emoji">Title`,
"it displays the new title with escaped unicode emojis"
);
});
test("Suggested topics", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.equal(
find("#suggested-topics .suggested-topics-title").text().trim(),
I18n.t("suggested_topics.title")
);
});
skip("Deleting a topic", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:eq(0) button.show-more-actions");
await click(".widget-button.delete");
assert.ok(exists(".widget-button.recover"), "it shows the recover button");
});
test("Group category moderator posts", async (assert) => {
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) => {
await visit("/t/-/299/1");
assert.ok(
exists(".title-wrapper .topic-featured-link"),
"link is shown with topic title"
);
await click(".title-wrapper .edit-topic");
assert.ok(
exists(".title-wrapper .remove-featured-link"),
"link to remove featured link"
);
await click(".title-wrapper .remove-featured-link");
await click(".title-wrapper .submit-edit");
assert.ok(!exists(".title-wrapper .topic-featured-link"), "link is gone");
});
test("Converting to a public topic", async (assert) => {
await visit("/t/test-pm/34");
assert.ok(exists(".private_message"));
await click(".toggle-admin-menu");
await click(".topic-admin-convert button");
let categoryChooser = selectKit(".convert-to-public-topic .category-chooser");
await categoryChooser.expand();
await categoryChooser.selectRowByValue(21);
await click(".convert-to-public-topic .btn-primary");
assert.ok(!exists(".private_message"));
});
test("Unpinning unlisted topic", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
await click(".topic-admin-pin .btn");
await click(".btn-primary:last");
await click(".toggle-admin-menu");
await click(".topic-admin-visible .btn");
await click(".toggle-admin-menu");
assert.ok(exists(".topic-admin-pin"), "it should show the multi select menu");
});
test("selecting posts", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
assert.ok(
exists(".selected-posts:not(.hidden)"),
"it should show the multi select menu"
);
assert.ok(
exists(".select-all"),
"it should allow users to select all the posts"
);
});
test("select below", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
await click("#post_3 .select-below");
assert.ok(
find(".selected-posts")
.html()
.includes(I18n.t("topic.multi_select.description", { count: 18 })),
"it should select the right number of posts"
);
await click("#post_2 .select-below");
assert.ok(
find(".selected-posts")
.html()
.includes(I18n.t("topic.multi_select.description", { count: 19 })),
"it should select the right number of posts"
);
});
test("View Hidden Replies", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".gap");
assert.equal(find(".gap").length, 0, "it hides gap");
});
function selectText(selector) { function selectText(selector) {
const range = document.createRange(); const range = document.createRange();
const node = document.querySelector(selector); const node = document.querySelector(selector);
@ -325,92 +16,395 @@ function selectText(selector) {
selection.addRange(range); selection.addRange(range);
} }
test("Quoting a quote keeps the original poster name", async (assert) => { acceptance("Topic", function (needs) {
await visit("/t/internationalization-localization/280"); needs.user();
selectText("#post_5 blockquote"); needs.pretender((server, helper) => {
await click(".quote-button .insert-quote"); server.put("/posts/398/wiki", () => {
return helper.response({});
});
});
assert.ok( test("Reply as new topic", async (assert) => {
find(".d-editor-input") await visit("/t/internationalization-localization/280");
.val() await click("button.share:eq(0)");
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1 await click(".reply-as-new-topic a");
);
assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.equal(
find(".d-editor-input").val().trim(),
`Continuing the discussion from [Internationalization / localization](${window.location.origin}/t/internationalization-localization/280):`,
"it fills composer with the ring string"
);
assert.equal(
selectKit(".category-chooser").header().value(),
"2",
"it fills category selector with the right category"
);
});
test("Reply as new message", async (assert) => {
await visit("/t/pm-for-testing/12");
await click("button.share:eq(0)");
await click(".reply-as-new-topic a");
assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.equal(
find(".d-editor-input").val().trim(),
`Continuing the discussion from [PM for testing](${window.location.origin}/t/pm-for-testing/12):`,
"it fills composer with the ring string"
);
const targets = find(".item span", ".composer-fields");
assert.equal(
$(targets[0]).text(),
"someguy",
"it fills up the composer with the right user to start the PM to"
);
assert.equal(
$(targets[1]).text(),
"test",
"it fills up the composer with the right user to start the PM to"
);
assert.equal(
$(targets[2]).text(),
"Group",
"it fills up the composer with the right group to start the PM to"
);
});
test("Share Modal", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".topic-post:first-child button.share");
assert.ok(exists("#share-link"), "it shows the share modal");
});
test("Showing and hiding the edit controls", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
assert.ok(exists("#edit-title"), "it shows the editing controls");
assert.ok(
!exists(".title-wrapper .remove-featured-link"),
"link to remove featured link is not shown"
);
await fillIn("#edit-title", "this is the new title");
await click("#topic-title .cancel-edit");
assert.ok(!exists("#edit-title"), "it hides the editing controls");
});
test("Updating the topic title and category", async (assert) => {
const categoryChooser = selectKit(".title-wrapper .category-chooser");
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
await fillIn("#edit-title", "this is the new title");
await categoryChooser.expand();
await categoryChooser.selectRowByValue(4);
await click("#topic-title .submit-edit");
assert.equal(
find("#topic-title .badge-category").text(),
"faq",
"it displays the new category"
);
assert.equal(
find(".fancy-title").text().trim(),
"this is the new title",
"it displays the new title"
);
});
test("Marking a topic as wiki", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(find("a.wiki").length === 0, "it does not show the wiki icon");
await click(".topic-post:eq(0) button.show-more-actions");
await click(".topic-post:eq(0) button.show-post-admin-menu");
await click(".btn.wiki");
assert.ok(find("a.wiki").length === 1, "it shows the wiki icon");
});
test("Visit topic routes", async (assert) => {
await visit("/t/12");
assert.equal(
find(".fancy-title").text().trim(),
"PM for testing",
"it routes to the right topic"
);
await visit("/t/280/20");
assert.equal(
find(".fancy-title").text().trim(),
"Internationalization / localization",
"it routes to the right topic"
);
});
test("Updating the topic title with emojis", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
await fillIn("#edit-title", "emojis title :bike: :blonde_woman:t6:");
await click("#topic-title .submit-edit");
assert.equal(
find(".fancy-title").html().trim(),
`emojis title <img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/bike.png?v=${v}" title="bike" alt="bike" class="emoji"> <img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/blonde_woman/6.png?v=${v}" title="blonde_woman:t6" alt="blonde_woman:t6" class="emoji">`,
"it displays the new title with emojis"
);
});
test("Updating the topic title with unicode emojis", async (assert) => {
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
await fillIn("#edit-title", "emojis title 👨‍🌾🙏");
await click("#topic-title .submit-edit");
assert.equal(
find(".fancy-title").html().trim(),
`emojis title <img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/man_farmer.png?v=${v}" title="man_farmer" alt="man_farmer" class="emoji"><img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/pray.png?v=${v}" title="pray" alt="pray" class="emoji">`,
"it displays the new title with escaped unicode emojis"
);
});
test("Updating the topic title with unicode emojis without whitespaces", async function (assert) {
this.siteSettings.enable_inline_emoji_translation = true;
await visit("/t/internationalization-localization/280");
await click("#topic-title .d-icon-pencil-alt");
await fillIn("#edit-title", "Test🙂Title");
await click("#topic-title .submit-edit");
assert.equal(
find(".fancy-title").html().trim(),
`Test<img width=\"20\" height=\"20\" src="/images/emoji/emoji_one/slightly_smiling_face.png?v=${v}" title="slightly_smiling_face" alt="slightly_smiling_face" class="emoji">Title`,
"it displays the new title with escaped unicode emojis"
);
});
test("Suggested topics", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.equal(
find("#suggested-topics .suggested-topics-title").text().trim(),
I18n.t("suggested_topics.title")
);
});
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");
});
}); });
test("Quoting a quote of a different topic keeps the original topic title", async (assert) => { acceptance("Topic featured links", function (needs) {
await visit("/t/internationalization-localization/280"); needs.user();
selectText("#post_9 blockquote"); needs.settings({
await click(".quote-button .insert-quote"); 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"),
"link is shown with topic title"
);
assert.ok( await click(".title-wrapper .edit-topic");
find(".d-editor-input") assert.ok(
.val() exists(".title-wrapper .remove-featured-link"),
.indexOf( "link to remove featured link"
'quote="A new topic with a link to another topic, post:3, topic:62"' );
) !== -1
); await click(".title-wrapper .remove-featured-link");
await click(".title-wrapper .submit-edit");
assert.ok(!exists(".title-wrapper .topic-featured-link"), "link is gone");
});
test("Converting to a public topic", async (assert) => {
await visit("/t/test-pm/34");
assert.ok(exists(".private_message"));
await click(".toggle-admin-menu");
await click(".topic-admin-convert button");
let categoryChooser = selectKit(
".convert-to-public-topic .category-chooser"
);
await categoryChooser.expand();
await categoryChooser.selectRowByValue(21);
await click(".convert-to-public-topic .btn-primary");
assert.ok(!exists(".private_message"));
});
test("Unpinning unlisted topic", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
await click(".topic-admin-pin .btn");
await click(".btn-primary:last");
await click(".toggle-admin-menu");
await click(".topic-admin-visible .btn");
await click(".toggle-admin-menu");
assert.ok(
exists(".topic-admin-pin"),
"it should show the multi select menu"
);
});
test("selecting posts", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
assert.ok(
exists(".selected-posts:not(.hidden)"),
"it should show the multi select menu"
);
assert.ok(
exists(".select-all"),
"it should allow users to select all the posts"
);
});
test("select below", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".toggle-admin-menu");
await click(".topic-admin-multi-select .btn");
await click("#post_3 .select-below");
assert.ok(
find(".selected-posts")
.html()
.includes(I18n.t("topic.multi_select.description", { count: 18 })),
"it should select the right number of posts"
);
await click("#post_2 .select-below");
assert.ok(
find(".selected-posts")
.html()
.includes(I18n.t("topic.multi_select.description", { count: 19 })),
"it should select the right number of posts"
);
});
test("View Hidden Replies", async (assert) => {
await visit("/t/internationalization-localization/280");
await click(".gap");
assert.equal(find(".gap").length, 0, "it hides gap");
});
test("Quoting a quote keeps the original poster name", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
await click(".quote-button .insert-quote");
assert.ok(
find(".d-editor-input")
.val()
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
);
});
test("Quoting a quote of a different topic keeps the original topic title", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_9 blockquote");
await click(".quote-button .insert-quote");
assert.ok(
find(".d-editor-input")
.val()
.indexOf(
'quote="A new topic with a link to another topic, post:3, topic:62"'
) !== -1
);
});
test("Quoting a quote with the Reply button keeps the original poster name", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
await click(".reply");
assert.ok(
find(".d-editor-input")
.val()
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
);
});
test("Quoting a quote with replyAsNewTopic keeps the original poster name", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
await keyEvent(document, "keypress", "j".charCodeAt(0));
await keyEvent(document, "keypress", "t".charCodeAt(0));
assert.ok(
find(".d-editor-input")
.val()
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
);
});
test("Quoting by selecting text can mark the quote as full", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 .cooked");
await click(".quote-button .insert-quote");
assert.ok(
find(".d-editor-input")
.val()
.indexOf('quote="pekka, post:5, topic:280, full:true"') !== -1
);
});
}); });
test("Quoting a quote with the Reply button keeps the original poster name", async (assert) => { acceptance("Topic with title decorated", function (needs) {
await visit("/t/internationalization-localization/280"); needs.user();
selectText("#post_5 blockquote"); needs.hooks.beforeEach(() => {
await click(".reply");
assert.ok(
find(".d-editor-input")
.val()
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
);
});
test("Quoting a quote with replyAsNewTopic keeps the original poster name", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 blockquote");
await keyEvent(document, "keypress", "j".charCodeAt(0));
await keyEvent(document, "keypress", "t".charCodeAt(0));
assert.ok(
find(".d-editor-input")
.val()
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
);
});
test("Quoting by selecting text can mark the quote as full", async (assert) => {
await visit("/t/internationalization-localization/280");
selectText("#post_5 .cooked");
await click(".quote-button .insert-quote");
assert.ok(
find(".d-editor-input")
.val()
.indexOf('quote="pekka, post:5, topic:280, full:true"') !== -1
);
});
acceptance("Topic with title decorated", {
loggedIn: true,
beforeEach() {
withPluginApi("0.8.40", (api) => { withPluginApi("0.8.40", (api) => {
api.decorateTopicTitle((topic, node, topicTitleType) => { api.decorateTopicTitle((topic, node, topicTitleType) => {
node.innerText = `${node.innerText}-${topic.id}-${topicTitleType}`; node.innerText = `${node.innerText}-${topic.id}-${topicTitleType}`;
}); });
}); });
}, });
}); test("Decorate topic title", async (assert) => {
await visit("/t/internationalization-localization/280");
test("Decorate topic title", async (assert) => {
await visit("/t/internationalization-localization/280"); assert.ok(
find(".fancy-title")[0].innerText.endsWith("-280-topic-title"),
assert.ok( "it decorates topic title"
find(".fancy-title")[0].innerText.endsWith("-280-topic-title"), );
"it decorates topic title"
); assert.ok(
find(".raw-topic-link:nth-child(1)")[0].innerText.endsWith(
assert.ok( "-27331-topic-list-item-title"
find(".raw-topic-link:nth-child(1)")[0].innerText.endsWith( ),
"-27331-topic-list-item-title" "it decorates topic list item title"
), );
"it decorates topic list item title" });
);
}); });

View File

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

View File

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

View File

@ -2,74 +2,67 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; 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 userFixtures from "discourse/tests/fixtures/user-fixtures";
import { deepMerge } from "discourse-common/lib/object";
acceptance("User's bookmarks", { acceptance("User's bookmarks", function (needs) {
loggedIn: true, needs.user();
beforeEach() { test("removing a bookmark with no reminder does not show a confirmation", async (assert) => {
pretender.delete("/bookmarks/576", () => [ await visit("/u/eviltrout/activity/bookmarks");
200, assert.ok(find(".bookmark-list-item").length > 0);
{ "Content-Type": "application/json" },
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");
});
});
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";
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");
await dropdown.expand();
await dropdown.selectRowByValue("remove");
assert.ok(exists(".bootbox.modal"), "it asks for delete confirmation");
await click(".bootbox.modal a.btn-primary");
assert.not(exists(".bootbox.modal"));
});
}); });
test("listing user bookmarks", async (assert) => { acceptance("User's bookmarks - no bookmarks", function (needs) {
await visit("/u/eviltrout/activity/bookmarks"); needs.user();
needs.pretender((server, helper) => {
server.get("/u/eviltrout/bookmarks.json", () =>
helper.response({
bookmarks: [],
no_results_help: "no bookmarks",
})
);
});
assert.ok(find(".bookmark-list-item").length); test("listing users bookmarks - no bookmarks", async (assert) => {
}); await visit("/u/eviltrout/activity/bookmarks");
assert.equal(find(".alert.alert-info").text(), "no bookmarks");
test("removing a bookmark with a reminder shows a confirmation", async (assert) => { });
let listResponse = Object.assign(
{},
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,
]);
await visit("/u/eviltrout/activity/bookmarks");
const dropdown = selectKit(".bookmark-actions-dropdown");
await dropdown.expand();
await dropdown.selectRowByValue("remove");
assert.ok(exists(".bootbox.modal"), "it asks for delete confirmation");
await click(".bootbox.modal a.btn-primary");
assert.not(exists(".bootbox.modal"));
listResponse.user_bookmark_list.bookmarks[0].reminder_at = null;
});
test("listing users bookmarks - no bookmarks", async (assert) => {
pretender.get("/u/eviltrout/bookmarks.json", () => [
200,
{
"Content-Type": "application/json",
},
{
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,137 +1,27 @@
import { visit } from "@ember/test-helpers"; import { visit } from "@ember/test-helpers";
import { skip } from "qunit";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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 userFixtures from "discourse/tests/fixtures/user-fixtures";
import User from "discourse/models/user"; import User from "discourse/models/user";
acceptance("User Card - Show Local Time", { acceptance("User Card - Show Local Time", function (needs) {
loggedIn: true, needs.user();
settings: { display_local_time_in_user_card: true }, needs.settings({ display_local_time_in_user_card: true });
}); needs.pretender((server, helper) => {
let cardResponse = Object.assign({}, userFixtures["/u/charlie/card.json"]);
skip("user card local time", async (assert) => { delete cardResponse.user.timezone;
User.current().changeTimezone("Australia/Brisbane"); server.get("/u/charlie/card.json", () => helper.response(cardResponse));
let cardResponse = Object.assign({}, userFixtures["/u/eviltrout/card.json"]); });
cardResponse.user.timezone = "Australia/Perth";
test("user card local time - does not update timezone for another user", async (assert) => {
pretender.get("/u/eviltrout/card.json", () => [ User.current().changeTimezone("Australia/Brisbane");
200,
{ "Content-Type": "application/json" }, await visit("/t/internationalization-localization/280");
cardResponse, await click("a[data-user-card=charlie]:first");
]);
assert.not(
await visit("/t/internationalization-localization/280"); exists(".user-card .local-time"),
assert.ok(invisible(".user-card"), "user card is invisible by default"); "it does not show the local time if the user card returns a null/undefined timezone for another user"
await click("a[data-user-card=eviltrout]:first"); );
});
let expectedTime = moment
.tz("Australia/Brisbane")
.add(-2, "hours")
.format("h:mm a");
assert.ok(visible(".user-card"), "card should appear");
assert.equal(
find(".user-card .local-time").text().trim(),
expectedTime,
"user card contains the user's local time"
);
cardResponse = Object.assign({}, userFixtures["/u/charlie/card.json"]);
cardResponse.user.timezone = "America/New_York";
pretender.get("/u/charlie/card.json", () => [
200,
{ "Content-Type": "application/json" },
cardResponse,
]);
await click("a[data-user-card=charlie]:first");
expectedTime = moment
.tz("Australia/Brisbane")
.add(-14, "hours")
.format("h:mm a");
assert.equal(
find(".user-card .local-time").text().trim(),
expectedTime,
"opening another user card updates the local time in the card (no caching)"
);
});
test("user card local time - does not update timezone for another user", async (assert) => {
User.current().changeTimezone("Australia/Brisbane");
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");
assert.not(
exists(".user-card .local-time"),
"it does not show the local time if the user card returns a null/undefined timezone for another user"
);
});
acceptance("User Card", { loggedIn: true });
skip("user card", async (assert) => {
await visit("/t/internationalization-localization/280");
assert.ok(invisible(".user-card"), "user card is invisible by default");
await click("a[data-user-card=eviltrout]:first");
assert.ok(visible(".user-card"), "card should appear");
assert.equal(
find(".user-card .username").text().trim(),
"eviltrout",
"user card contains the data"
);
sandbox.stub(DiscourseURL, "routeTo");
await click(".card-content a.user-profile-link");
assert.ok(
DiscourseURL.routeTo.calledWith("/u/eviltrout"),
"it should navigate to the user profile"
);
await click("a[data-user-card=charlie]:first");
assert.ok(visible(".user-card"), "card should appear");
assert.equal(
find(".user-card .username").text().trim(),
"charlie",
"user card contains the data"
);
assert.ok(
!visible(".user-card .local-time"),
"local time with zone does not show by default"
);
await click(".card-content .compose-pm button");
assert.ok(
invisible(".user-card"),
"user card dismissed after hitting Message button"
);
const mention = find("a.mention");
const icon = document.createElement("span");
icon.classList.add("icon");
mention.append(icon);
await click("a.mention .icon");
assert.ok(visible(".user-card"), "card should appear");
assert.equal(
find(".user-card .username").text().trim(),
"eviltrout",
"user card contains the data"
);
}); });

View File

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

View File

@ -6,194 +6,198 @@ import Site from "discourse/models/site";
import Session from "discourse/models/session"; import Session from "discourse/models/session";
import cookie, { removeCookie } from "discourse/lib/cookie"; import cookie, { removeCookie } from "discourse/lib/cookie";
acceptance("User Preferences - Interface", { acceptance("User Preferences - Interface", function (needs) {
loggedIn: true, needs.user();
});
test("font size change", async (assert) => { test("font size change", async (assert) => {
removeCookie("text_size"); removeCookie("text_size");
const savePreferences = async () => { const savePreferences = async () => {
assert.ok(!exists(".saved"), "it hasn't been saved yet"); assert.ok(!exists(".saved"), "it hasn't been saved yet");
await click(".save-changes"); await click(".save-changes");
assert.ok(exists(".saved"), "it displays the saved message"); assert.ok(exists(".saved"), "it displays the saved message");
find(".saved").remove(); find(".saved").remove();
}; };
await visit("/u/eviltrout/preferences/interface"); await visit("/u/eviltrout/preferences/interface");
// Live changes without reload // Live changes without reload
await selectKit(".text-size .combobox").expand(); await selectKit(".text-size .combobox").expand();
await selectKit(".text-size .combobox").selectRowByValue("larger"); await selectKit(".text-size .combobox").selectRowByValue("larger");
assert.ok(document.documentElement.classList.contains("text-size-larger")); assert.ok(document.documentElement.classList.contains("text-size-larger"));
await selectKit(".text-size .combobox").expand(); await selectKit(".text-size .combobox").expand();
await selectKit(".text-size .combobox").selectRowByValue("largest"); await selectKit(".text-size .combobox").selectRowByValue("largest");
assert.ok(document.documentElement.classList.contains("text-size-largest")); assert.ok(document.documentElement.classList.contains("text-size-largest"));
assert.equal(cookie("text_size"), null, "cookie is not set"); assert.equal(cookie("text_size"), null, "cookie is not set");
// Click save (by default this sets for all browsers, no cookie) // Click save (by default this sets for all browsers, no cookie)
await savePreferences(); await savePreferences();
assert.equal(cookie("text_size"), null, "cookie is not set"); assert.equal(cookie("text_size"), null, "cookie is not set");
await selectKit(".text-size .combobox").expand(); await selectKit(".text-size .combobox").expand();
await selectKit(".text-size .combobox").selectRowByValue("larger"); await selectKit(".text-size .combobox").selectRowByValue("larger");
await click(".text-size input[type=checkbox]"); await click(".text-size input[type=checkbox]");
await savePreferences(); await savePreferences();
assert.equal(cookie("text_size"), "larger|1", "cookie is set"); assert.equal(cookie("text_size"), "larger|1", "cookie is set");
await click(".text-size input[type=checkbox]"); await click(".text-size input[type=checkbox]");
await selectKit(".text-size .combobox").expand(); await selectKit(".text-size .combobox").expand();
await selectKit(".text-size .combobox").selectRowByValue("largest"); await selectKit(".text-size .combobox").selectRowByValue("largest");
await savePreferences(); await savePreferences();
assert.equal(cookie("text_size"), null, "cookie is removed"); assert.equal(cookie("text_size"), null, "cookie is removed");
removeCookie("text_size"); removeCookie("text_size");
});
test("does not show option to disable dark mode by default", async (assert) => {
await visit("/u/eviltrout/preferences/interface");
assert.equal($(".control-group.dark-mode").length, 0);
});
test("shows light/dark color scheme pickers", async (assert) => {
let site = Site.current();
site.set("user_color_schemes", [
{ id: 2, name: "Cool Breeze" },
{ id: 3, name: "Dark Night", is_dark: true },
]);
await visit("/u/eviltrout/preferences/interface");
assert.ok($(".light-color-scheme").length, "has regular dropdown");
assert.ok($(".dark-color-scheme").length, "has dark color scheme dropdown");
});
function interfacePretender(server, helper) {
server.get("/color-scheme-stylesheet/2.json", () => {
return helper.response({
success: "OK",
});
}); });
}
acceptance("User Preferences Color Schemes (with default dark scheme)", { test("does not show option to disable dark mode by default", async (assert) => {
loggedIn: true, await visit("/u/eviltrout/preferences/interface");
settings: { default_dark_mode_color_scheme_id: 1 }, assert.equal($(".control-group.dark-mode").length, 0);
pretend: interfacePretender, });
test("shows light/dark color scheme pickers", async (assert) => {
let site = Site.current();
site.set("user_color_schemes", [
{ id: 2, name: "Cool Breeze" },
{ id: 3, name: "Dark Night", is_dark: true },
]);
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");
});
}); });
test("show option to disable dark mode", async (assert) => { acceptance(
await visit("/u/eviltrout/preferences/interface"); "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",
});
});
});
assert.ok( test("show option to disable dark mode", async (assert) => {
$(".control-group.dark-mode").length, await visit("/u/eviltrout/preferences/interface");
"it has the option to disable dark mode"
);
});
test("no color scheme picker by default", async (assert) => { assert.ok(
let site = Site.current(); $(".control-group.dark-mode").length,
site.set("user_color_schemes", []); "it has the option to disable dark mode"
);
});
await visit("/u/eviltrout/preferences/interface"); test("no color scheme picker by default", async (assert) => {
assert.equal($(".control-group.color-scheme").length, 0); let site = Site.current();
}); site.set("user_color_schemes", []);
test("light color scheme picker", async (assert) => { await visit("/u/eviltrout/preferences/interface");
let site = Site.current(); assert.equal($(".control-group.color-scheme").length, 0);
site.set("user_color_schemes", [{ id: 2, name: "Cool Breeze" }]); });
await visit("/u/eviltrout/preferences/interface"); test("light color scheme picker", async (assert) => {
assert.ok($(".light-color-scheme").length, "has regular picker dropdown"); let site = Site.current();
assert.equal( site.set("user_color_schemes", [{ id: 2, name: "Cool Breeze" }]);
$(".dark-color-scheme").length,
0,
"does not have a dark color scheme picker"
);
});
test("light and dark color scheme pickers", async (assert) => { await visit("/u/eviltrout/preferences/interface");
let site = Site.current(); assert.ok($(".light-color-scheme").length, "has regular picker dropdown");
let session = Session.current(); assert.equal(
session.userDarkSchemeId = 1; // same as default set in site settings $(".dark-color-scheme").length,
0,
"does not have a dark color scheme picker"
);
});
site.set("default_dark_color_scheme", { id: 1, name: "Dark" }); test("light and dark color scheme pickers", async (assert) => {
site.set("user_color_schemes", [ let site = Site.current();
{ id: 2, name: "Cool Breeze" }, let session = Session.current();
{ id: 3, name: "Dark Night", is_dark: true }, session.userDarkSchemeId = 1; // same as default set in site settings
]);
const savePreferences = async () => { site.set("default_dark_color_scheme", { id: 1, name: "Dark" });
assert.ok(!exists(".saved"), "it hasn't been saved yet"); site.set("user_color_schemes", [
await click(".save-changes"); { id: 2, name: "Cool Breeze" },
assert.ok(exists(".saved"), "it displays the saved message"); { id: 3, name: "Dark Night", is_dark: true },
find(".saved").remove(); ]);
};
await visit("/u/eviltrout/preferences/interface"); const savePreferences = async () => {
assert.ok($(".light-color-scheme").length, "has regular dropdown"); assert.ok(!exists(".saved"), "it hasn't been saved yet");
assert.ok($(".dark-color-scheme").length, "has dark color scheme dropdown"); await click(".save-changes");
assert.equal( assert.ok(exists(".saved"), "it displays the saved message");
$(".dark-color-scheme .selected-name").data("value"), find(".saved").remove();
session.userDarkSchemeId, };
"sets site default as selected dark scheme"
);
assert.equal(
$(".control-group.dark-mode").length,
0,
"it does not show disable dark mode checkbox"
);
removeCookie("color_scheme_id"); await visit("/u/eviltrout/preferences/interface");
removeCookie("dark_scheme_id"); assert.ok($(".light-color-scheme").length, "has regular dropdown");
assert.ok(
$(".dark-color-scheme").length,
"has dark color scheme dropdown"
);
assert.equal(
$(".dark-color-scheme .selected-name").data("value"),
session.userDarkSchemeId,
"sets site default as selected dark scheme"
);
assert.equal(
$(".control-group.dark-mode").length,
0,
"it does not show disable dark mode checkbox"
);
await selectKit(".light-color-scheme .combobox").expand(); removeCookie("color_scheme_id");
await selectKit(".light-color-scheme .combobox").selectRowByValue(2); removeCookie("dark_scheme_id");
assert.equal(cookie("color_scheme_id"), null, "cookie is not set");
assert.ok(
exists(".color-scheme-checkbox input:checked"),
"defaults to storing values in user options"
);
await savePreferences(); await selectKit(".light-color-scheme .combobox").expand();
assert.equal(cookie("color_scheme_id"), null, "cookie is unchanged"); await selectKit(".light-color-scheme .combobox").selectRowByValue(2);
assert.equal(cookie("color_scheme_id"), null, "cookie is not set");
assert.ok(
exists(".color-scheme-checkbox input:checked"),
"defaults to storing values in user options"
);
// Switch to saving changes in cookies await savePreferences();
await click(".color-scheme-checkbox input[type=checkbox]"); assert.equal(cookie("color_scheme_id"), null, "cookie is unchanged");
await savePreferences();
assert.equal(cookie("color_scheme_id"), 2, "cookie is set");
// dark scheme // Switch to saving changes in cookies
await selectKit(".dark-color-scheme .combobox").expand(); await click(".color-scheme-checkbox input[type=checkbox]");
assert.ok( await savePreferences();
selectKit(".dark-color-scheme .combobox").rowByValue(1).exists(), assert.equal(cookie("color_scheme_id"), 2, "cookie is set");
"default dark scheme is included"
);
await selectKit(".dark-color-scheme .combobox").selectRowByValue(-1); // dark scheme
assert.equal( await selectKit(".dark-color-scheme .combobox").expand();
cookie("dark_scheme_id"), assert.ok(
null, selectKit(".dark-color-scheme .combobox").rowByValue(1).exists(),
"cookie is not set before saving" "default dark scheme is included"
); );
await savePreferences(); await selectKit(".dark-color-scheme .combobox").selectRowByValue(-1);
assert.equal(cookie("dark_scheme_id"), -1, "cookie is set"); assert.equal(
cookie("dark_scheme_id"),
null,
"cookie is not set before saving"
);
await click("button.undo-preview"); await savePreferences();
assert.equal( assert.equal(cookie("dark_scheme_id"), -1, "cookie is set");
selectKit(".light-color-scheme .combobox").header().value(),
null,
"resets light scheme dropdown"
);
assert.equal( await click("button.undo-preview");
selectKit(".dark-color-scheme .combobox").header().value(), assert.equal(
session.userDarkSchemeId, selectKit(".light-color-scheme .combobox").header().value(),
"resets dark scheme dropdown" null,
); "resets light scheme dropdown"
}); );
assert.equal(
selectKit(".dark-color-scheme .combobox").header().value(),
session.userDarkSchemeId,
"resets dark scheme dropdown"
);
});
}
);

View File

@ -2,93 +2,88 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import pretender from "discourse/tests/helpers/create-pretender"; import pretender from "discourse/tests/helpers/create-pretender";
import Draft from "discourse/models/draft";
import { Promise } from "rsvp";
acceptance("User", { loggedIn: true }); acceptance("User Routes", function (needs) {
needs.user();
test("Invalid usernames", async (assert) => { test("Invalid usernames", async (assert) => {
pretender.get("/u/eviltrout%2F..%2F..%2F.json", () => { pretender.get("/u/eviltrout%2F..%2F..%2F.json", () => {
return [400, { "Content-Type": "application/json" }, {}]; return [400, { "Content-Type": "application/json" }, {}];
});
await visit("/u/eviltrout%2F..%2F..%2F/summary");
assert.equal(currentPath(), "exception-unknown");
}); });
await visit("/u/eviltrout%2F..%2F..%2F/summary"); test("Unicode usernames", async (assert) => {
await visit("/u/%E3%83%A9%E3%82%A4%E3%82%AA%E3%83%B3/summary");
assert.equal(currentPath(), "exception-unknown"); assert.equal(currentPath(), "user.summary");
}); });
test("Unicode usernames", async (assert) => { test("Invites", async (assert) => {
await visit("/u/%E3%83%A9%E3%82%A4%E3%82%AA%E3%83%B3/summary"); await visit("/u/eviltrout/invited/pending");
assert.ok($("body.user-invites-page").length, "has the body class");
assert.equal(currentPath(), "user.summary"); });
});
test("Messages", async (assert) => {
test("Invites", async (assert) => { await visit("/u/eviltrout/messages");
await visit("/u/eviltrout/invited/pending"); assert.ok($("body.user-messages-page").length, "has the body class");
assert.ok($("body.user-invites-page").length, "has the body class"); });
});
test("Notifications", async (assert) => {
test("Messages", async (assert) => { await visit("/u/eviltrout/notifications");
await visit("/u/eviltrout/messages"); assert.ok($("body.user-notifications-page").length, "has the body class");
assert.ok($("body.user-messages-page").length, "has the body class");
}); const $links = find(".item.notification a");
test("Notifications", async (assert) => { assert.ok(
await visit("/u/eviltrout/notifications"); $links[1].href.includes(
assert.ok($("body.user-notifications-page").length, "has the body class"); "/u/eviltrout/notifications/likes-received?acting_username=aquaman"
)
const $links = find(".item.notification a"); );
});
assert.ok(
$links[1].href.includes( test("Root URL - Viewing Self", async (assert) => {
"/u/eviltrout/notifications/likes-received?acting_username=aquaman" await visit("/u/eviltrout");
) assert.ok($("body.user-activity-page").length, "has the body class");
); assert.equal(
}); currentPath(),
"user.userActivity.index",
test("Root URL - Viewing Self", async (assert) => { "it defaults to activity"
await visit("/u/eviltrout"); );
assert.ok($("body.user-activity-page").length, "has the body class"); assert.ok(exists(".container.viewing-self"), "has the viewing-self class");
assert.equal( });
currentPath(),
"user.userActivity.index", test("Viewing Summary", async (assert) => {
"it defaults to activity" await visit("/u/eviltrout/summary");
);
assert.ok(exists(".container.viewing-self"), "has the viewing-self class"); assert.ok(exists(".replies-section li a"), "replies");
}); assert.ok(exists(".topics-section li a"), "topics");
assert.ok(exists(".links-section li a"), "links");
test("Viewing Summary", async (assert) => { assert.ok(exists(".replied-section .user-info"), "liked by");
await visit("/u/eviltrout/summary"); assert.ok(exists(".liked-by-section .user-info"), "liked by");
assert.ok(exists(".liked-section .user-info"), "liked");
assert.ok(exists(".replies-section li a"), "replies"); assert.ok(exists(".badges-section .badge-card"), "badges");
assert.ok(exists(".topics-section li a"), "topics"); assert.ok(
assert.ok(exists(".links-section li a"), "links"); exists(".top-categories-section .category-link"),
assert.ok(exists(".replied-section .user-info"), "liked by"); "top categories"
assert.ok(exists(".liked-by-section .user-info"), "liked by"); );
assert.ok(exists(".liked-section .user-info"), "liked"); });
assert.ok(exists(".badges-section .badge-card"), "badges");
assert.ok(exists(".top-categories-section .category-link"), "top categories"); test("Viewing Drafts", async (assert) => {
}); await visit("/u/eviltrout/activity/drafts");
assert.ok(exists(".user-stream"), "has drafts stream");
test("Viewing Drafts", async (assert) => { assert.ok(
sandbox.stub(Draft, "get").returns( exists(".user-stream .user-stream-item-draft-actions"),
Promise.resolve({ "has draft action buttons"
draft: null, );
draft_sequence: 0,
}) await click(".user-stream button.resume-draft:eq(0)");
); assert.ok(
exists(".d-editor-input"),
await visit("/u/eviltrout/activity/drafts"); "composer is visible after resuming a draft"
assert.ok(exists(".user-stream"), "has drafts stream"); );
assert.ok( });
exists(".user-stream .user-stream-item-draft-actions"),
"has draft action buttons"
);
await click(".user-stream button.resume-draft:eq(0)");
assert.ok(
exists(".d-editor-input"),
"composer is visible after resuming a draft"
);
sandbox.restore();
}); });

View File

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

View File

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

View File

@ -146,6 +146,11 @@ export function discourseModule(name, hooks) {
export function addPretenderCallback(name, fn) { export function addPretenderCallback(name, fn) {
if (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; _pretenderCallbacks[name] = fn;
} }
} }
@ -159,7 +164,7 @@ export function acceptance(name, optionsOrCallback) {
callback = optionsOrCallback; callback = optionsOrCallback;
} else if (typeof optionsOrCallback === "object") { } else if (typeof optionsOrCallback === "object") {
deprecated( 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" } { since: "2.6.0" }
); );
options = optionsOrCallback; options = optionsOrCallback;
@ -168,6 +173,7 @@ export function acceptance(name, optionsOrCallback) {
addPretenderCallback(name, options.pretend); addPretenderCallback(name, options.pretend);
let loggedIn = false; let loggedIn = false;
let mobileView = false;
let siteChanges; let siteChanges;
let settingChanges; let settingChanges;
let userChanges; let userChanges;
@ -180,7 +186,7 @@ export function acceptance(name, optionsOrCallback) {
HeaderComponent.reopen({ examineDockHeader: function () {} }); HeaderComponent.reopen({ examineDockHeader: function () {} });
resetExtraClasses(); resetExtraClasses();
if (options.mobileView) { if (mobileView) {
forceMobile(); forceMobile();
} }
@ -266,6 +272,9 @@ export function acceptance(name, optionsOrCallback) {
settings(changes) { settings(changes) {
settingChanges = changes; settingChanges = changes;
}, },
mobileView() {
mobileView = true;
},
}; };
if (options.loggedIn) { if (options.loggedIn) {
@ -277,6 +286,9 @@ export function acceptance(name, optionsOrCallback) {
if (options.settings) { if (options.settings) {
needs.settings(options.settings); needs.settings(options.settings);
} }
if (options.mobileView) {
needs.mobileView();
}
if (callback) { if (callback) {
// New, preferred way // New, preferred way

View File

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

View File

@ -3,133 +3,131 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer"; import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("Details Button", { acceptance("Details Button", function (needs) {
loggedIn: true, needs.user();
beforeEach: function () { needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
clearPopupMenuOptionsCallback();
}, test("details button", async (assert) => {
}); const popupMenu = selectKit(".toolbar-popup-menu-options");
test("details button", async (assert) => { await visit("/");
const popupMenu = selectKit(".toolbar-popup-menu-options"); await click("#create-topic");
await visit("/"); await popupMenu.expand();
await click("#create-topic"); await popupMenu.selectRowByValue("insertDetails");
await popupMenu.expand(); assert.equal(
await popupMenu.selectRowByValue("insertDetails"); find(".d-editor-input").val(),
`\n[details="${I18n.t("composer.details_title")}"]\n${I18n.t(
assert.equal( "composer.details_text"
find(".d-editor-input").val(), )}\n[/details]\n`,
`\n[details="${I18n.t("composer.details_title")}"]\n${I18n.t( "it should contain the right output"
"composer.details_text" );
)}\n[/details]\n`,
"it should contain the right output" await fillIn(".d-editor-input", "This is my title");
);
const textarea = find(".d-editor-input")[0];
await fillIn(".d-editor-input", "This is my title"); textarea.selectionStart = 0;
textarea.selectionEnd = textarea.value.length;
const textarea = find(".d-editor-input")[0];
textarea.selectionStart = 0; await popupMenu.expand();
textarea.selectionEnd = textarea.value.length; await popupMenu.selectRowByValue("insertDetails");
await popupMenu.expand(); assert.equal(
await popupMenu.selectRowByValue("insertDetails"); find(".d-editor-input").val(),
`\n[details="${I18n.t(
assert.equal( "composer.details_title"
find(".d-editor-input").val(), )}"]\nThis is my title\n[/details]\n`,
`\n[details="${I18n.t( "it should contain the right selected output"
"composer.details_title" );
)}"]\nThis is my title\n[/details]\n`,
"it should contain the right selected output" assert.equal(
); textarea.selectionStart,
21,
assert.equal( "it should start highlighting at the right position"
textarea.selectionStart, );
21, assert.equal(
"it should start highlighting at the right position" textarea.selectionEnd,
); 37,
assert.equal( "it should end highlighting at the right position"
textarea.selectionEnd, );
37,
"it should end highlighting at the right position" await fillIn(".d-editor-input", "Before some text in between After");
);
textarea.selectionStart = 7;
await fillIn(".d-editor-input", "Before some text in between After"); textarea.selectionEnd = 28;
textarea.selectionStart = 7; await popupMenu.expand();
textarea.selectionEnd = 28; await popupMenu.selectRowByValue("insertDetails");
await popupMenu.expand(); assert.equal(
await popupMenu.selectRowByValue("insertDetails"); find(".d-editor-input").val(),
`Before \n[details="${I18n.t(
assert.equal( "composer.details_title"
find(".d-editor-input").val(), )}"]\nsome text in between\n[/details]\n After`,
`Before \n[details="${I18n.t( "it should contain the right output"
"composer.details_title" );
)}"]\nsome text in between\n[/details]\n After`,
"it should contain the right output" assert.equal(
); textarea.selectionStart,
28,
assert.equal( "it should start highlighting at the right position"
textarea.selectionStart, );
28, assert.equal(
"it should start highlighting at the right position" textarea.selectionEnd,
); 48,
assert.equal( "it should end highlighting at the right position"
textarea.selectionEnd, );
48,
"it should end highlighting at the right position" await fillIn(".d-editor-input", "Before \nsome text in between\n After");
);
textarea.selectionStart = 8;
await fillIn(".d-editor-input", "Before \nsome text in between\n After"); textarea.selectionEnd = 29;
textarea.selectionStart = 8; await popupMenu.expand();
textarea.selectionEnd = 29; await popupMenu.selectRowByValue("insertDetails");
await popupMenu.expand(); assert.equal(
await popupMenu.selectRowByValue("insertDetails"); find(".d-editor-input").val(),
`Before \n\n[details="${I18n.t(
assert.equal( "composer.details_title"
find(".d-editor-input").val(), )}"]\nsome text in between\n[/details]\n\n After`,
`Before \n\n[details="${I18n.t( "it should contain the right output"
"composer.details_title" );
)}"]\nsome text in between\n[/details]\n\n After`,
"it should contain the right output" assert.equal(
); textarea.selectionStart,
29,
assert.equal( "it should start highlighting at the right position"
textarea.selectionStart, );
29, assert.equal(
"it should start highlighting at the right position" textarea.selectionEnd,
); 49,
assert.equal( "it should end highlighting at the right position"
textarea.selectionEnd, );
49, });
"it should end highlighting at the right position"
); test("details button surrounds all selected text in a single details block", async (assert) => {
}); const multilineInput = "first line\n\nsecond line\n\nthird line";
const popupMenu = selectKit(".toolbar-popup-menu-options");
test("details button surrounds all selected text in a single details block", async (assert) => {
const multilineInput = "first line\n\nsecond line\n\nthird line"; await visit("/");
const popupMenu = selectKit(".toolbar-popup-menu-options"); await click("#create-topic");
await fillIn(".d-editor-input", multilineInput);
await visit("/");
await click("#create-topic"); const textarea = find(".d-editor-input")[0];
await fillIn(".d-editor-input", multilineInput); textarea.selectionStart = 0;
textarea.selectionEnd = textarea.value.length;
const textarea = find(".d-editor-input")[0];
textarea.selectionStart = 0; await popupMenu.expand();
textarea.selectionEnd = textarea.value.length; await popupMenu.selectRowByValue("insertDetails");
await popupMenu.expand(); assert.equal(
await popupMenu.selectRowByValue("insertDetails"); find(".d-editor-input").val(),
`\n[details="${I18n.t(
assert.equal( "composer.details_title"
find(".d-editor-input").val(), )}"]\n${multilineInput}\n[/details]\n`,
`\n[details="${I18n.t( "it should contain the right output"
"composer.details_title" );
)}"]\n${multilineInput}\n[/details]\n`, });
"it should contain the right output"
);
}); });

View File

@ -1,50 +1,54 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Local Dates - composer", { acceptance("Local Dates - composer", function (needs) {
loggedIn: true, needs.user();
settings: { discourse_local_dates_enabled: true }, needs.settings({ discourse_local_dates_enabled: true });
});
test("composer bbcode", async (assert) => { test("composer bbcode", async (assert) => {
const getAttr = (attr) => { const getAttr = (attr) => {
return find(".d-editor-preview .discourse-local-date.cooked-date").attr( return find(".d-editor-preview .discourse-local-date.cooked-date").attr(
`data-${attr}` `data-${attr}`
);
};
await visit("/");
await click("#create-topic");
await fillIn(
".d-editor-input",
'[date=2017-10-23 time=01:30:00 displayedTimezone="America/Chicago" format="LLLL" calendar="off" recurring="1.weeks" timezone="Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]'
); );
};
await visit("/"); assert.equal(getAttr("date"), "2017-10-23", "it has the correct date");
await click("#create-topic"); assert.equal(getAttr("time"), "01:30:00", "it has the correct time");
assert.equal(
getAttr("displayed-timezone"),
"America/Chicago",
"it has the correct displayed timezone"
);
assert.equal(getAttr("format"), "LLLL", "it has the correct format");
assert.equal(
getAttr("timezones"),
"Europe/Paris|America/Los_Angeles",
"it has the correct timezones"
);
assert.equal(
getAttr("recurring"),
"1.weeks",
"it has the correct recurring"
);
assert.equal(
getAttr("timezone"),
"Asia/Calcutta",
"it has the correct timezone"
);
await fillIn( await fillIn(
".d-editor-input", ".d-editor-input",
'[date=2017-10-23 time=01:30:00 displayedTimezone="America/Chicago" format="LLLL" calendar="off" recurring="1.weeks" timezone="Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]' '[date=2017-10-24 format="LL" timezone="Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]'
); );
assert.equal(getAttr("date"), "2017-10-23", "it has the correct date"); assert.equal(getAttr("date"), "2017-10-24", "it has the correct date");
assert.equal(getAttr("time"), "01:30:00", "it has the correct time"); assert.notOk(getAttr("time"), "it doesnt have time");
assert.equal( });
getAttr("displayed-timezone"),
"America/Chicago",
"it has the correct displayed timezone"
);
assert.equal(getAttr("format"), "LLLL", "it has the correct format");
assert.equal(
getAttr("timezones"),
"Europe/Paris|America/Los_Angeles",
"it has the correct timezones"
);
assert.equal(getAttr("recurring"), "1.weeks", "it has the correct recurring");
assert.equal(
getAttr("timezone"),
"Asia/Calcutta",
"it has the correct timezone"
);
await fillIn(
".d-editor-input",
'[date=2017-10-24 format="LL" timezone="Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]'
);
assert.equal(getAttr("date"), "2017-10-24", "it has the correct date");
assert.notOk(getAttr("time"), "it doesnt have time");
}); });

View File

@ -1,119 +1,115 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer"; import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import { Promise } from "rsvp";
acceptance("Poll breakdown", { acceptance("Poll breakdown", function (needs) {
loggedIn: true, needs.user();
settings: { poll_enabled: true, poll_groupable_user_fields: "something" }, needs.settings({
beforeEach() { poll_enabled: true,
clearPopupMenuOptionsCallback(); poll_groupable_user_fields: "something",
}, });
pretend(server, helper) { needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
server.get("/polls/grouped_poll_results.json", () => { needs.pretender((server, helper) => {
return new Promise((resolve) => { server.get("/polls/grouped_poll_results.json", () =>
resolve( helper.response({
helper.response({ grouped_results: [
grouped_results: [ {
group: "Engineering",
options: [
{ {
group: "Engineering", digest: "687a1ccf3c6a260f9aeeb7f68a1d463c",
options: [ html: "This Is",
{ votes: 1,
digest: "687a1ccf3c6a260f9aeeb7f68a1d463c",
html: "This Is",
votes: 1,
},
{
digest: "9377906763a1221d31d656ea0c4a4495",
html: "A test for sure",
votes: 1,
},
{
digest: "ecf47c65a85a0bb20029072b1b721977",
html: "Why not give it some more",
votes: 1,
},
],
}, },
{ {
group: "Marketing", digest: "9377906763a1221d31d656ea0c4a4495",
options: [ html: "A test for sure",
{ votes: 1,
digest: "687a1ccf3c6a260f9aeeb7f68a1d463c", },
html: "This Is", {
votes: 1, digest: "ecf47c65a85a0bb20029072b1b721977",
}, html: "Why not give it some more",
{ votes: 1,
digest: "9377906763a1221d31d656ea0c4a4495",
html: "A test for sure",
votes: 1,
},
{
digest: "ecf47c65a85a0bb20029072b1b721977",
html: "Why not give it some more",
votes: 1,
},
],
}, },
], ],
}) },
); {
}); group: "Marketing",
}); options: [
}, {
}); digest: "687a1ccf3c6a260f9aeeb7f68a1d463c",
html: "This Is",
test("Displaying the poll breakdown modal", async (assert) => { votes: 1,
await visit("/t/-/topic_with_pie_chart_poll"); },
{
assert.equal( digest: "9377906763a1221d31d656ea0c4a4495",
find(".poll-show-breakdown").text(), html: "A test for sure",
"Show breakdown", votes: 1,
"shows the breakdown button when poll_groupable_user_fields is non-empty" },
); {
digest: "ecf47c65a85a0bb20029072b1b721977",
await click(".poll-show-breakdown:first"); html: "Why not give it some more",
votes: 1,
assert.equal( },
find(".poll-breakdown-total-votes")[0].textContent.trim(), ],
"2 votes", },
"display the correct total vote count" ],
); })
);
assert.equal( });
find(".poll-breakdown-chart-container").length,
2, test("Displaying the poll breakdown modal", async (assert) => {
"renders a chart for each of the groups in group_results response" await visit("/t/-/topic_with_pie_chart_poll");
);
assert.equal(
assert.ok( find(".poll-show-breakdown").text(),
find(".poll-breakdown-chart-container > canvas")[0].$chartjs, "Show breakdown",
"$chartjs is defined on the pie charts" "shows the breakdown button when poll_groupable_user_fields is non-empty"
); );
});
await click(".poll-show-breakdown:first");
test("Changing the display mode from percentage to count", async (assert) => {
await visit("/t/-/topic_with_pie_chart_poll"); assert.equal(
await click(".poll-show-breakdown:first"); find(".poll-breakdown-total-votes")[0].textContent.trim(),
"2 votes",
assert.equal( "display the correct total vote count"
find(".poll-breakdown-option-count:first")[0].textContent.trim(), );
"40.0%",
"displays the correct vote percentage" assert.equal(
); find(".poll-breakdown-chart-container").length,
2,
await click(".modal-tabs .count"); "renders a chart for each of the groups in group_results response"
);
assert.equal(
find(".poll-breakdown-option-count:first")[0].textContent.trim(), assert.ok(
"2", find(".poll-breakdown-chart-container > canvas")[0].$chartjs,
"displays the correct vote count" "$chartjs is defined on the pie charts"
); );
});
await click(".modal-tabs .percentage");
test("Changing the display mode from percentage to count", async (assert) => {
assert.equal( await visit("/t/-/topic_with_pie_chart_poll");
find(".poll-breakdown-option-count:last")[0].textContent.trim(), await click(".poll-show-breakdown:first");
"20.0%",
"displays the percentage again" assert.equal(
); find(".poll-breakdown-option-count:first")[0].textContent.trim(),
"40.0%",
"displays the correct vote percentage"
);
await click(".modal-tabs .count");
assert.equal(
find(".poll-breakdown-option-count:first")[0].textContent.trim(),
"2",
"displays the correct vote count"
);
await click(".modal-tabs .percentage");
assert.equal(
find(".poll-breakdown-option-count:last")[0].textContent.trim(),
"20.0%",
"displays the percentage again"
);
});
}); });

View File

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

View File

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

View File

@ -1,36 +1,39 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Rendering polls with pie charts", { acceptance("Rendering polls with pie charts", function (needs) {
loggedIn: true, needs.user();
settings: { poll_enabled: true, poll_groupable_user_fields: "something" }, needs.settings({
}); poll_enabled: true,
poll_groupable_user_fields: "something",
test("Displays the pie chart", async (assert) => { });
await visit("/t/-/topic_with_pie_chart_poll");
test("Displays the pie chart", async (assert) => {
const poll = find(".poll")[0]; await visit("/t/-/topic_with_pie_chart_poll");
assert.equal( const poll = find(".poll")[0];
find(".info-number", poll)[0].innerHTML,
"2", assert.equal(
"it should display the right number of voters" find(".info-number", poll)[0].innerHTML,
); "2",
"it should display the right number of voters"
assert.equal( );
find(".info-number", poll)[1].innerHTML,
"5", assert.equal(
"it should display the right number of votes" find(".info-number", poll)[1].innerHTML,
); "5",
"it should display the right number of votes"
assert.equal( );
poll.classList.contains("pie"),
true, assert.equal(
"pie class is present on poll div" poll.classList.contains("pie"),
); true,
"pie class is present on poll div"
assert.equal( );
find(".poll-results-chart", poll).length,
1, assert.equal(
"Renders the chart div instead of bar container" find(".poll-results-chart", poll).length,
); 1,
"Renders the chart div instead of bar container"
);
});
}); });

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer"; import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Rendering polls with bar charts - desktop", { acceptance("Rendering polls with bar charts - desktop", function (needs) {
loggedIn: true, needs.user();
settings: { poll_enabled: true }, needs.settings({ poll_enabled: true });
beforeEach() { needs.hooks.beforeEach(() => {
clearPopupMenuOptionsCallback(); clearPopupMenuOptionsCallback();
}, });
pretend(server) { needs.pretender((server, helper) => {
server.get("/polls/voters.json", (request) => { server.get("/polls/voters.json", (request) => {
let body = {}; let body = {};
if ( if (
@ -35,78 +35,78 @@ acceptance("Rendering polls with bar charts - desktop", {
})), })),
}; };
} }
return [200, { "Content-Type": "application/json" }, body]; return helper.response(body);
}); });
}, });
});
test("Polls", async (assert) => {
test("Polls", async (assert) => { await visit("/t/-/15");
await visit("/t/-/15");
const polls = find(".poll");
const polls = find(".poll");
assert.equal(polls.length, 2, "it should render the polls correctly");
assert.equal(polls.length, 2, "it should render the polls correctly");
assert.equal(
assert.equal( find(".info-number", polls[0]).text(),
find(".info-number", polls[0]).text(), "2",
"2", "it should display the right number of votes"
"it should display the right number of votes" );
);
assert.equal(
assert.equal( find(".info-number", polls[1]).text(),
find(".info-number", polls[1]).text(), "3",
"3", "it should display the right number of votes"
"it should display the right number of votes" );
); });
});
test("Public poll", async (assert) => {
test("Public poll", async (assert) => { await visit("/t/-/14");
await visit("/t/-/14");
const polls = find(".poll");
const polls = find(".poll"); assert.equal(polls.length, 1, "it should render the poll correctly");
assert.equal(polls.length, 1, "it should render the poll correctly");
await click("button.toggle-results");
await click("button.toggle-results");
assert.equal(
assert.equal( find(".poll-voters:first li").length,
find(".poll-voters:first li").length, 25,
25, "it should display the right number of voters"
"it should display the right number of voters" );
);
await click(".poll-voters-toggle-expand:first a");
await click(".poll-voters-toggle-expand:first a");
assert.equal(
assert.equal( find(".poll-voters:first li").length,
find(".poll-voters:first li").length, 26,
26, "it should display the right number of voters"
"it should display the right number of voters" );
); });
});
test("Public number poll", async (assert) => {
test("Public number poll", async (assert) => { await visit("/t/-/13");
await visit("/t/-/13");
const polls = find(".poll");
const polls = find(".poll"); assert.equal(polls.length, 1, "it should render the poll correctly");
assert.equal(polls.length, 1, "it should render the poll correctly");
await click("button.toggle-results");
await click("button.toggle-results");
assert.equal(
assert.equal( find(".poll-voters:first li").length,
find(".poll-voters:first li").length, 25,
25, "it should display the right number of voters"
"it should display the right number of voters" );
);
assert.notOk(
assert.notOk( find(".poll-voters:first li:first a").attr("href"),
find(".poll-voters:first li:first a").attr("href"), "user URL does not exist"
"user URL does not exist" );
);
await click(".poll-voters-toggle-expand:first a");
await click(".poll-voters-toggle-expand:first a");
assert.equal(
assert.equal( find(".poll-voters:first li").length,
find(".poll-voters:first li").length, 30,
30, "it should display the right number of voters"
"it should display the right number of voters" );
); });
}); });

View File

@ -1,54 +1,51 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer"; import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
acceptance("Rendering polls with bar charts - mobile", { acceptance("Rendering polls with bar charts - mobile", function (needs) {
loggedIn: true, needs.user();
mobileView: true, needs.mobileView();
settings: { poll_enabled: true }, needs.settings({ poll_enabled: true });
beforeEach() { needs.pretender((server, helper) => {
clearPopupMenuOptionsCallback();
},
pretend(server) {
// eslint-disable-next-line
server.get("/polls/voters.json", () => { server.get("/polls/voters.json", () => {
const body = { return helper.response({
voters: Array.from(new Array(10), (_, i) => ({ voters: Array.from(new Array(10), (_, i) => ({
id: 500 + i, id: 500 + i,
username: `bruce${500 + i}`, username: `bruce${500 + i}`,
avatar_template: "/images/avatar.png", avatar_template: "/images/avatar.png",
name: "Bruce Wayne", name: "Bruce Wayne",
})), })),
}; });
return [200, { "Content-Type": "application/json" }, body];
}); });
}, });
}); needs.hooks.beforeEach(() => {
clearPopupMenuOptionsCallback();
test("Public number poll", async (assert) => { });
await visit("/t/-/13");
test("Public number poll", async (assert) => {
const polls = find(".poll"); await visit("/t/-/13");
assert.equal(polls.length, 1, "it should render the poll correctly");
const polls = find(".poll");
await click("button.toggle-results"); assert.equal(polls.length, 1, "it should render the poll correctly");
assert.equal( await click("button.toggle-results");
find(".poll-voters:first li").length,
25, assert.equal(
"it should display the right number of voters" find(".poll-voters:first li").length,
); 25,
"it should display the right number of voters"
assert.notOk( );
find(".poll-voters:first li:first a").attr("href"),
"user URL does not exist" assert.notOk(
); find(".poll-voters:first li:first a").attr("href"),
"user URL does not exist"
await click(".poll-voters-toggle-expand:first a"); );
assert.equal( await click(".poll-voters-toggle-expand:first a");
find(".poll-voters:first li").length,
35, assert.equal(
"it should display the right number of voters" find(".poll-voters:first li").length,
); 35,
"it should display the right number of voters"
);
});
}); });