mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 09:10:25 +08:00
DEV: De-arrowify tests (#11068)
Using arrow functions changes `this` context, which is undesired in tests, e.g. it makes it impossible to setup things like pretender (`this.server`) in `beforeEach` hooks. Ember guides always use classic functions in examples (e.g. https://guides.emberjs.com/release/testing/test-types/), and that's what it uses in its own test suite, as do various addons and ember apps. It was also already used in Discourse where `this` was required. Moving forward, it will be needed in more places as we migrate toward ember-cli. (I might later add a custom rule to eslint-discourse-ember to enforce this)
This commit is contained in:
parent
d5fb0b9435
commit
a17d54d0bf
185 changed files with 762 additions and 762 deletions
|
@ -7,7 +7,7 @@ acceptance("Details Button", function (needs) {
|
|||
needs.user();
|
||||
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
|
||||
|
||||
test("details button", async (assert) => {
|
||||
test("details button", async function (assert) {
|
||||
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
||||
|
||||
await visit("/");
|
||||
|
@ -107,7 +107,7 @@ acceptance("Details Button", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("details button surrounds all selected text in a single details block", async (assert) => {
|
||||
test("details button surrounds all selected text in a single details block", async function (assert) {
|
||||
const multilineInput = "first line\n\nsecond line\n\nthird line";
|
||||
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ const defaultOpts = buildOptions({
|
|||
getURL: (url) => url,
|
||||
});
|
||||
|
||||
test("details", (assert) => {
|
||||
test("details", function (assert) {
|
||||
const cooked = (input, expected, text) => {
|
||||
assert.equal(
|
||||
new PrettyText(defaultOpts).cook(input),
|
||||
|
|
|
@ -4,7 +4,7 @@ acceptance("Local Dates - composer", function (needs) {
|
|||
needs.user();
|
||||
needs.settings({ discourse_local_dates_enabled: true });
|
||||
|
||||
test("composer bbcode", async (assert) => {
|
||||
test("composer bbcode", async function (assert) {
|
||||
const getAttr = (attr) => {
|
||||
return queryAll(
|
||||
".d-editor-preview .discourse-local-date.cooked-date"
|
||||
|
|
|
@ -17,7 +17,7 @@ function buildDateHelper(params = {}) {
|
|||
});
|
||||
}
|
||||
|
||||
test("#format", (assert) => {
|
||||
test("#format", function (assert) {
|
||||
let date = buildDateHelper({
|
||||
day: 15,
|
||||
month: 2,
|
||||
|
@ -28,7 +28,7 @@ test("#format", (assert) => {
|
|||
assert.equal(date.format(), "2020-03-15T15:36:00.000+01:00");
|
||||
});
|
||||
|
||||
test("#repetitionsBetweenDates", (assert) => {
|
||||
test("#repetitionsBetweenDates", function (assert) {
|
||||
let date;
|
||||
|
||||
date = buildDateHelper({
|
||||
|
@ -96,7 +96,7 @@ test("#repetitionsBetweenDates", (assert) => {
|
|||
);
|
||||
});
|
||||
|
||||
test("#add", (assert) => {
|
||||
test("#add", function (assert) {
|
||||
let date;
|
||||
let futureLocalDate;
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ QUnit.assert.buildsCorrectDate = function (options, expected, message) {
|
|||
}
|
||||
};
|
||||
|
||||
test("date", (assert) => {
|
||||
test("date", function (assert) {
|
||||
freezeTime({ date: "2020-03-11" }, () => {
|
||||
assert.buildsCorrectDate(
|
||||
{ date: "2020-03-22", timezone: PARIS },
|
||||
|
@ -71,7 +71,7 @@ test("date", (assert) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("date and time", (assert) => {
|
||||
test("date and time", function (assert) {
|
||||
assert.buildsCorrectDate(
|
||||
{ date: "2020-04-11", time: "11:00" },
|
||||
{ formated: "April 11, 2020 1:00 PM" },
|
||||
|
@ -85,7 +85,7 @@ test("date and time", (assert) => {
|
|||
);
|
||||
});
|
||||
|
||||
test("option[format]", (assert) => {
|
||||
test("option[format]", function (assert) {
|
||||
freezeTime({ date: "2020-03-11" }, () => {
|
||||
assert.buildsCorrectDate(
|
||||
{ format: "YYYY" },
|
||||
|
@ -95,7 +95,7 @@ test("option[format]", (assert) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("option[displayedTimezone]", (assert) => {
|
||||
test("option[displayedTimezone]", function (assert) {
|
||||
freezeTime({}, () => {
|
||||
assert.buildsCorrectDate(
|
||||
{ displayedTimezone: SYDNEY },
|
||||
|
@ -129,7 +129,7 @@ test("option[displayedTimezone]", (assert) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("option[timezone]", (assert) => {
|
||||
test("option[timezone]", function (assert) {
|
||||
freezeTime({}, () => {
|
||||
assert.buildsCorrectDate(
|
||||
{ timezone: SYDNEY, displayedTimezone: PARIS },
|
||||
|
@ -139,7 +139,7 @@ test("option[timezone]", (assert) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("option[recurring]", (assert) => {
|
||||
test("option[recurring]", function (assert) {
|
||||
freezeTime({ date: "2020-04-06 06:00", timezone: LAGOS }, () => {
|
||||
assert.buildsCorrectDate(
|
||||
{
|
||||
|
@ -219,7 +219,7 @@ test("option[recurring]", (assert) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("option[countown]", (assert) => {
|
||||
test("option[countown]", function (assert) {
|
||||
freezeTime({ date: "2020-03-21 23:59" }, () => {
|
||||
assert.buildsCorrectDate(
|
||||
{
|
||||
|
@ -247,7 +247,7 @@ test("option[countown]", (assert) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("option[calendar]", (assert) => {
|
||||
test("option[calendar]", function (assert) {
|
||||
freezeTime({ date: "2020-03-23 23:00" }, () => {
|
||||
assert.buildsCorrectDate(
|
||||
{ date: "2020-03-22", time: "23:59", timezone: PARIS },
|
||||
|
@ -328,7 +328,7 @@ test("option[calendar]", (assert) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("previews", (assert) => {
|
||||
test("previews", function (assert) {
|
||||
freezeTime({ date: "2020-03-22" }, () => {
|
||||
assert.buildsCorrectDate(
|
||||
{ timezone: PARIS },
|
||||
|
|
|
@ -58,7 +58,7 @@ acceptance("Poll breakdown", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("Displaying the poll breakdown modal", async (assert) => {
|
||||
test("Displaying the poll breakdown modal", async function (assert) {
|
||||
await visit("/t/-/topic_with_pie_chart_poll");
|
||||
|
||||
assert.equal(
|
||||
|
@ -87,7 +87,7 @@ acceptance("Poll breakdown", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("Changing the display mode from percentage to count", async (assert) => {
|
||||
test("Changing the display mode from percentage to count", async function (assert) {
|
||||
await visit("/t/-/topic_with_pie_chart_poll");
|
||||
await click(".poll-show-breakdown:first");
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ acceptance("Poll Builder - polls are disabled", function (needs) {
|
|||
});
|
||||
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
|
||||
|
||||
test("regular user - sufficient trust level", async (assert) => {
|
||||
test("regular user - sufficient trust level", async function (assert) {
|
||||
updateCurrentUser({ moderator: false, admin: false, trust_level: 3 });
|
||||
|
||||
await displayPollBuilderButton();
|
||||
|
@ -25,7 +25,7 @@ acceptance("Poll Builder - polls are disabled", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("regular user - insufficient trust level", async (assert) => {
|
||||
test("regular user - insufficient trust level", async function (assert) {
|
||||
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
|
||||
|
||||
await displayPollBuilderButton();
|
||||
|
@ -36,7 +36,7 @@ acceptance("Poll Builder - polls are disabled", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("staff", async (assert) => {
|
||||
test("staff", async function (assert) {
|
||||
updateCurrentUser({ moderator: true });
|
||||
|
||||
await displayPollBuilderButton();
|
||||
|
|
|
@ -16,7 +16,7 @@ acceptance("Poll Builder - polls are enabled", function (needs) {
|
|||
});
|
||||
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
|
||||
|
||||
test("regular user - sufficient trust level", async (assert) => {
|
||||
test("regular user - sufficient trust level", async function (assert) {
|
||||
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
|
||||
|
||||
await displayPollBuilderButton();
|
||||
|
@ -27,7 +27,7 @@ acceptance("Poll Builder - polls are enabled", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("regular user - insufficient trust level", async (assert) => {
|
||||
test("regular user - insufficient trust level", async function (assert) {
|
||||
updateCurrentUser({ moderator: false, admin: false, trust_level: 0 });
|
||||
|
||||
await displayPollBuilderButton();
|
||||
|
@ -38,7 +38,7 @@ acceptance("Poll Builder - polls are enabled", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("staff - with insufficient trust level", async (assert) => {
|
||||
test("staff - with insufficient trust level", async function (assert) {
|
||||
updateCurrentUser({ moderator: true, trust_level: 0 });
|
||||
|
||||
await displayPollBuilderButton();
|
||||
|
@ -49,7 +49,7 @@ acceptance("Poll Builder - polls are enabled", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("poll preview", async (assert) => {
|
||||
test("poll preview", async function (assert) {
|
||||
await displayPollBuilderButton();
|
||||
|
||||
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
||||
|
|
|
@ -8,7 +8,7 @@ acceptance("Rendering polls with pie charts", function (needs) {
|
|||
poll_groupable_user_fields: "something",
|
||||
});
|
||||
|
||||
test("Displays the pie chart", async (assert) => {
|
||||
test("Displays the pie chart", async function (assert) {
|
||||
await visit("/t/-/topic_with_pie_chart_poll");
|
||||
|
||||
const poll = queryAll(".poll")[0];
|
||||
|
|
|
@ -676,7 +676,7 @@ acceptance("Poll quote", function (needs) {
|
|||
});
|
||||
});
|
||||
|
||||
test("Quoted polls", async (assert) => {
|
||||
test("Quoted polls", async function (assert) {
|
||||
await visit("/t/-/topic_with_two_quoted_polls");
|
||||
await click(".quote-controls");
|
||||
assert.equal(queryAll(".poll").length, 2);
|
||||
|
|
|
@ -40,7 +40,7 @@ acceptance("Rendering polls with bar charts - desktop", function (needs) {
|
|||
});
|
||||
});
|
||||
|
||||
test("Polls", async (assert) => {
|
||||
test("Polls", async function (assert) {
|
||||
await visit("/t/-/15");
|
||||
|
||||
const polls = queryAll(".poll");
|
||||
|
@ -60,7 +60,7 @@ acceptance("Rendering polls with bar charts - desktop", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("Public poll", async (assert) => {
|
||||
test("Public poll", async function (assert) {
|
||||
await visit("/t/-/14");
|
||||
|
||||
const polls = queryAll(".poll");
|
||||
|
@ -83,7 +83,7 @@ acceptance("Rendering polls with bar charts - desktop", function (needs) {
|
|||
);
|
||||
});
|
||||
|
||||
test("Public number poll", async (assert) => {
|
||||
test("Public number poll", async function (assert) {
|
||||
await visit("/t/-/13");
|
||||
|
||||
const polls = queryAll(".poll");
|
||||
|
|
|
@ -22,7 +22,7 @@ acceptance("Rendering polls with bar charts - mobile", function (needs) {
|
|||
clearPopupMenuOptionsCallback();
|
||||
});
|
||||
|
||||
test("Public number poll", async (assert) => {
|
||||
test("Public number poll", async function (assert) {
|
||||
await visit("/t/-/13");
|
||||
|
||||
const polls = queryAll(".poll");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue