REFACTOR: Import QUnit and related helpers rather than globals
We used many global functions to handle tests when they should be imported like other libraries in our application. This also gets us closer to the way Ember CLI prefers our tests to be laid out.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { moduleFor } from "ember-qunit";
|
||||
import { test } from "qunit";
|
||||
import { mapRoutes } from "discourse/mapping-router";
|
||||
|
||||
moduleFor("controller:avatar-selector", "controller:avatar-selector", {
|
||||
@@ -7,7 +9,7 @@ moduleFor("controller:avatar-selector", "controller:avatar-selector", {
|
||||
needs: ["controller:modal"],
|
||||
});
|
||||
|
||||
QUnit.test("avatarTemplate", function (assert) {
|
||||
test("avatarTemplate", function (assert) {
|
||||
const avatarSelectorController = this.subject();
|
||||
|
||||
avatarSelectorController.setProperties({
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { moduleFor } from "ember-qunit";
|
||||
import { test } from "qunit";
|
||||
import { logIn } from "discourse/tests/helpers/qunit-helpers";
|
||||
import User from "discourse/models/user";
|
||||
import KeyboardShortcutInitializer from "discourse/initializers/keyboard-shortcuts";
|
||||
@@ -26,39 +28,29 @@ function mockMomentTz(dateString) {
|
||||
fakeTime(dateString, BookmarkController.userTimezone);
|
||||
}
|
||||
|
||||
QUnit.test("showLaterToday when later today is tomorrow do not show", function (
|
||||
assert
|
||||
) {
|
||||
test("showLaterToday when later today is tomorrow do not show", function (assert) {
|
||||
mockMomentTz("2019-12-11T22:00:00");
|
||||
|
||||
assert.equal(BookmarkController.get("showLaterToday"), false);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"showLaterToday when later today is after 5pm but before 6pm",
|
||||
function (assert) {
|
||||
mockMomentTz("2019-12-11T15:00:00");
|
||||
assert.equal(BookmarkController.get("showLaterToday"), true);
|
||||
}
|
||||
);
|
||||
test("showLaterToday when later today is after 5pm but before 6pm", function (assert) {
|
||||
mockMomentTz("2019-12-11T15:00:00");
|
||||
assert.equal(BookmarkController.get("showLaterToday"), true);
|
||||
});
|
||||
|
||||
QUnit.test("showLaterToday when now is after the cutoff time (5pm)", function (
|
||||
assert
|
||||
) {
|
||||
test("showLaterToday when now is after the cutoff time (5pm)", function (assert) {
|
||||
mockMomentTz("2019-12-11T17:00:00");
|
||||
assert.equal(BookmarkController.get("showLaterToday"), false);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"showLaterToday when later today is before the end of the day, show",
|
||||
function (assert) {
|
||||
mockMomentTz("2019-12-11T10:00:00");
|
||||
test("showLaterToday when later today is before the end of the day, show", function (assert) {
|
||||
mockMomentTz("2019-12-11T10:00:00");
|
||||
|
||||
assert.equal(BookmarkController.get("showLaterToday"), true);
|
||||
}
|
||||
);
|
||||
assert.equal(BookmarkController.get("showLaterToday"), true);
|
||||
});
|
||||
|
||||
QUnit.test("nextWeek gets next week correctly", function (assert) {
|
||||
test("nextWeek gets next week correctly", function (assert) {
|
||||
mockMomentTz("2019-12-11T08:00:00");
|
||||
|
||||
assert.equal(
|
||||
@@ -67,7 +59,7 @@ QUnit.test("nextWeek gets next week correctly", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("nextMonth gets next month correctly", function (assert) {
|
||||
test("nextMonth gets next month correctly", function (assert) {
|
||||
mockMomentTz("2019-12-11T08:00:00");
|
||||
|
||||
assert.equal(
|
||||
@@ -76,7 +68,7 @@ QUnit.test("nextMonth gets next month correctly", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("laterThisWeek gets 2 days from now", function (assert) {
|
||||
test("laterThisWeek gets 2 days from now", function (assert) {
|
||||
mockMomentTz("2019-12-10T08:00:00");
|
||||
|
||||
assert.equal(
|
||||
@@ -85,27 +77,24 @@ QUnit.test("laterThisWeek gets 2 days from now", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"laterThisWeek returns null if we are at Thursday already",
|
||||
function (assert) {
|
||||
mockMomentTz("2019-12-12T08:00:00");
|
||||
test("laterThisWeek returns null if we are at Thursday already", function (assert) {
|
||||
mockMomentTz("2019-12-12T08:00:00");
|
||||
|
||||
assert.equal(BookmarkController.laterThisWeek(), null);
|
||||
}
|
||||
);
|
||||
assert.equal(BookmarkController.laterThisWeek(), null);
|
||||
});
|
||||
|
||||
QUnit.test("showLaterThisWeek returns true if < Thursday", function (assert) {
|
||||
test("showLaterThisWeek returns true if < Thursday", function (assert) {
|
||||
mockMomentTz("2019-12-10T08:00:00");
|
||||
|
||||
assert.equal(BookmarkController.showLaterThisWeek, true);
|
||||
});
|
||||
|
||||
QUnit.test("showLaterThisWeek returns false if > Thursday", function (assert) {
|
||||
test("showLaterThisWeek returns false if > Thursday", function (assert) {
|
||||
mockMomentTz("2019-12-12T08:00:00");
|
||||
|
||||
assert.equal(BookmarkController.showLaterThisWeek, false);
|
||||
});
|
||||
QUnit.test("tomorrow gets tomorrow correctly", function (assert) {
|
||||
test("tomorrow gets tomorrow correctly", function (assert) {
|
||||
mockMomentTz("2019-12-11T08:00:00");
|
||||
|
||||
assert.equal(
|
||||
@@ -114,146 +103,125 @@ QUnit.test("tomorrow gets tomorrow correctly", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"startOfDay changes the time of the provided date to 8:00am correctly",
|
||||
function (assert) {
|
||||
let dt = moment.tz(
|
||||
"2019-12-11T11:37:16",
|
||||
BookmarkController.currentUser.resolvedTimezone(
|
||||
BookmarkController.currentUser
|
||||
)
|
||||
);
|
||||
test("startOfDay changes the time of the provided date to 8:00am correctly", function (assert) {
|
||||
let dt = moment.tz(
|
||||
"2019-12-11T11:37:16",
|
||||
BookmarkController.currentUser.resolvedTimezone(
|
||||
BookmarkController.currentUser
|
||||
)
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
BookmarkController.startOfDay(dt).format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 08:00:00"
|
||||
);
|
||||
}
|
||||
);
|
||||
assert.equal(
|
||||
BookmarkController.startOfDay(dt).format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 08:00:00"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"laterToday gets 3 hours from now and if before half-past, it rounds down",
|
||||
function (assert) {
|
||||
mockMomentTz("2019-12-11T08:13:00");
|
||||
test("laterToday gets 3 hours from now and if before half-past, it rounds down", function (assert) {
|
||||
mockMomentTz("2019-12-11T08:13:00");
|
||||
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 11:00:00"
|
||||
);
|
||||
}
|
||||
);
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 11:00:00"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"laterToday gets 3 hours from now and if after half-past, it rounds up to the next hour",
|
||||
function (assert) {
|
||||
mockMomentTz("2019-12-11T08:43:00");
|
||||
test("laterToday gets 3 hours from now and if after half-past, it rounds up to the next hour", function (assert) {
|
||||
mockMomentTz("2019-12-11T08:43:00");
|
||||
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 12:00:00"
|
||||
);
|
||||
}
|
||||
);
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 12:00:00"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"laterToday is capped to 6pm. later today at 3pm = 6pm, 3:30pm = 6pm, 4pm = 6pm, 4:59pm = 6pm",
|
||||
function (assert) {
|
||||
mockMomentTz("2019-12-11T15:00:00");
|
||||
test("laterToday is capped to 6pm. later today at 3pm = 6pm, 3:30pm = 6pm, 4pm = 6pm, 4:59pm = 6pm", function (assert) {
|
||||
mockMomentTz("2019-12-11T15:00:00");
|
||||
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 18:00:00",
|
||||
"3pm should max to 6pm"
|
||||
);
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 18:00:00",
|
||||
"3pm should max to 6pm"
|
||||
);
|
||||
|
||||
mockMomentTz("2019-12-11T15:31:00");
|
||||
mockMomentTz("2019-12-11T15:31:00");
|
||||
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 18:00:00",
|
||||
"3:30pm should max to 6pm"
|
||||
);
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 18:00:00",
|
||||
"3:30pm should max to 6pm"
|
||||
);
|
||||
|
||||
mockMomentTz("2019-12-11T16:00:00");
|
||||
mockMomentTz("2019-12-11T16:00:00");
|
||||
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 18:00:00",
|
||||
"4pm should max to 6pm"
|
||||
);
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 18:00:00",
|
||||
"4pm should max to 6pm"
|
||||
);
|
||||
|
||||
mockMomentTz("2019-12-11T16:59:00");
|
||||
mockMomentTz("2019-12-11T16:59:00");
|
||||
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 18:00:00",
|
||||
"4:59pm should max to 6pm"
|
||||
);
|
||||
}
|
||||
);
|
||||
assert.equal(
|
||||
BookmarkController.laterToday().format("YYYY-MM-DD HH:mm:ss"),
|
||||
"2019-12-11 18:00:00",
|
||||
"4:59pm should max to 6pm"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("showLaterToday returns false if >= 5PM", function (assert) {
|
||||
test("showLaterToday returns false if >= 5PM", function (assert) {
|
||||
mockMomentTz("2019-12-11T17:00:01");
|
||||
assert.equal(BookmarkController.showLaterToday, false);
|
||||
});
|
||||
|
||||
QUnit.test("showLaterToday returns false if >= 5PM", function (assert) {
|
||||
test("showLaterToday returns false if >= 5PM", function (assert) {
|
||||
mockMomentTz("2019-12-11T17:00:01");
|
||||
assert.equal(BookmarkController.showLaterToday, false);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"reminderAt - custom - defaults to 8:00am if the time is not selected",
|
||||
function (assert) {
|
||||
BookmarkController.customReminderDate = "2028-12-12";
|
||||
BookmarkController.selectedReminderType =
|
||||
BookmarkController.reminderTypes.CUSTOM;
|
||||
const reminderAt = BookmarkController._reminderAt();
|
||||
assert.equal(BookmarkController.customReminderTime, "08:00");
|
||||
assert.equal(
|
||||
reminderAt.toString(),
|
||||
moment
|
||||
.tz(
|
||||
"2028-12-12 08:00",
|
||||
BookmarkController.currentUser.resolvedTimezone(
|
||||
BookmarkController.currentUser
|
||||
)
|
||||
test("reminderAt - custom - defaults to 8:00am if the time is not selected", function (assert) {
|
||||
BookmarkController.customReminderDate = "2028-12-12";
|
||||
BookmarkController.selectedReminderType =
|
||||
BookmarkController.reminderTypes.CUSTOM;
|
||||
const reminderAt = BookmarkController._reminderAt();
|
||||
assert.equal(BookmarkController.customReminderTime, "08:00");
|
||||
assert.equal(
|
||||
reminderAt.toString(),
|
||||
moment
|
||||
.tz(
|
||||
"2028-12-12 08:00",
|
||||
BookmarkController.currentUser.resolvedTimezone(
|
||||
BookmarkController.currentUser
|
||||
)
|
||||
.toString(),
|
||||
"the custom date and time are parsed correctly with default time"
|
||||
);
|
||||
}
|
||||
);
|
||||
)
|
||||
.toString(),
|
||||
"the custom date and time are parsed correctly with default time"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"loadLastUsedCustomReminderDatetime fills the custom reminder date + time if present in localStorage",
|
||||
function (assert) {
|
||||
mockMomentTz("2019-12-11T08:00:00");
|
||||
localStorage.lastCustomBookmarkReminderDate = "2019-12-12";
|
||||
localStorage.lastCustomBookmarkReminderTime = "08:00";
|
||||
test("loadLastUsedCustomReminderDatetime fills the custom reminder date + time if present in localStorage", function (assert) {
|
||||
mockMomentTz("2019-12-11T08:00:00");
|
||||
localStorage.lastCustomBookmarkReminderDate = "2019-12-12";
|
||||
localStorage.lastCustomBookmarkReminderTime = "08:00";
|
||||
|
||||
BookmarkController._loadLastUsedCustomReminderDatetime();
|
||||
BookmarkController._loadLastUsedCustomReminderDatetime();
|
||||
|
||||
assert.equal(BookmarkController.lastCustomReminderDate, "2019-12-12");
|
||||
assert.equal(BookmarkController.lastCustomReminderTime, "08:00");
|
||||
}
|
||||
);
|
||||
assert.equal(BookmarkController.lastCustomReminderDate, "2019-12-12");
|
||||
assert.equal(BookmarkController.lastCustomReminderTime, "08:00");
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"loadLastUsedCustomReminderDatetime does not fills the custom reminder date + time if the datetime in localStorage is < now",
|
||||
function (assert) {
|
||||
mockMomentTz("2019-12-11T08:00:00");
|
||||
localStorage.lastCustomBookmarkReminderDate = "2019-12-11";
|
||||
localStorage.lastCustomBookmarkReminderTime = "07:00";
|
||||
test("loadLastUsedCustomReminderDatetime does not fills the custom reminder date + time if the datetime in localStorage is < now", function (assert) {
|
||||
mockMomentTz("2019-12-11T08:00:00");
|
||||
localStorage.lastCustomBookmarkReminderDate = "2019-12-11";
|
||||
localStorage.lastCustomBookmarkReminderTime = "07:00";
|
||||
|
||||
BookmarkController._loadLastUsedCustomReminderDatetime();
|
||||
BookmarkController._loadLastUsedCustomReminderDatetime();
|
||||
|
||||
assert.equal(BookmarkController.lastCustomReminderDate, null);
|
||||
assert.equal(BookmarkController.lastCustomReminderTime, null);
|
||||
}
|
||||
);
|
||||
assert.equal(BookmarkController.lastCustomReminderDate, null);
|
||||
assert.equal(BookmarkController.lastCustomReminderTime, null);
|
||||
});
|
||||
|
||||
QUnit.test("user timezone updates when the modal is shown", function (assert) {
|
||||
test("user timezone updates when the modal is shown", function (assert) {
|
||||
User.current().changeTimezone(null);
|
||||
let stub = sandbox.stub(moment.tz, "guess").returns("Europe/Moscow");
|
||||
BookmarkController.onShow();
|
||||
@@ -274,19 +242,13 @@ QUnit.test("user timezone updates when the modal is shown", function (assert) {
|
||||
stub.restore();
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"opening the modal with an existing bookmark with reminder at prefills the custom reminder type",
|
||||
function (assert) {
|
||||
let name = "test";
|
||||
let reminderAt = "2020-05-15T09:45:00";
|
||||
BookmarkController.model = { id: 1, name: name, reminderAt: reminderAt };
|
||||
BookmarkController.onShow();
|
||||
assert.equal(
|
||||
BookmarkController.selectedReminderType,
|
||||
REMINDER_TYPES.CUSTOM
|
||||
);
|
||||
assert.equal(BookmarkController.customReminderDate, "2020-05-15");
|
||||
assert.equal(BookmarkController.customReminderTime, "09:45");
|
||||
assert.equal(BookmarkController.model.name, name);
|
||||
}
|
||||
);
|
||||
test("opening the modal with an existing bookmark with reminder at prefills the custom reminder type", function (assert) {
|
||||
let name = "test";
|
||||
let reminderAt = "2020-05-15T09:45:00";
|
||||
BookmarkController.model = { id: 1, name: name, reminderAt: reminderAt };
|
||||
BookmarkController.onShow();
|
||||
assert.equal(BookmarkController.selectedReminderType, REMINDER_TYPES.CUSTOM);
|
||||
assert.equal(BookmarkController.customReminderDate, "2020-05-15");
|
||||
assert.equal(BookmarkController.customReminderTime, "09:45");
|
||||
assert.equal(BookmarkController.model.name, name);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { test } from "qunit";
|
||||
import I18n from "I18n";
|
||||
import { controllerModule } from "discourse/tests/helpers/qunit-helpers";
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { moduleFor } from "ember-qunit";
|
||||
import { test } from "qunit";
|
||||
moduleFor("controller:history");
|
||||
|
||||
QUnit.test("displayEdit", async function (assert) {
|
||||
test("displayEdit", async function (assert) {
|
||||
const HistoryController = this.subject();
|
||||
|
||||
HistoryController.setProperties({
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { moduleFor } from "ember-qunit";
|
||||
import { test } from "qunit";
|
||||
import EmberObject from "@ember/object";
|
||||
moduleFor("controller:preferences/account");
|
||||
|
||||
QUnit.test("updating of associated accounts", function (assert) {
|
||||
test("updating of associated accounts", function (assert) {
|
||||
const controller = this.subject({
|
||||
siteSettings: {
|
||||
enable_google_oauth2_logins: true,
|
||||
|
||||
+10
-11
@@ -1,14 +1,13 @@
|
||||
import { moduleFor } from "ember-qunit";
|
||||
import { test } from "qunit";
|
||||
moduleFor("controller:preferences/second-factor");
|
||||
|
||||
QUnit.test(
|
||||
"displayOAuthWarning when OAuth login methods are enabled",
|
||||
function (assert) {
|
||||
const controller = this.subject({
|
||||
siteSettings: {
|
||||
enable_google_oauth2_logins: true,
|
||||
},
|
||||
});
|
||||
test("displayOAuthWarning when OAuth login methods are enabled", function (assert) {
|
||||
const controller = this.subject({
|
||||
siteSettings: {
|
||||
enable_google_oauth2_logins: true,
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(controller.get("displayOAuthWarning"), true);
|
||||
}
|
||||
);
|
||||
assert.equal(controller.get("displayOAuthWarning"), true);
|
||||
});
|
||||
|
||||
+145
-155
@@ -1,3 +1,5 @@
|
||||
import { moduleFor } from "ember-qunit";
|
||||
import { test } from "qunit";
|
||||
import EmberObject from "@ember/object";
|
||||
import { mapRoutes } from "discourse/mapping-router";
|
||||
import createStore from "discourse/tests/helpers/create-store";
|
||||
@@ -9,7 +11,7 @@ moduleFor("controller:reorder-categories", "controller:reorder-categories", {
|
||||
needs: ["controller:modal"],
|
||||
});
|
||||
|
||||
QUnit.test("reorder set unique position number", function (assert) {
|
||||
test("reorder set unique position number", function (assert) {
|
||||
const store = createStore();
|
||||
|
||||
const categories = [];
|
||||
@@ -29,187 +31,175 @@ QUnit.test("reorder set unique position number", function (assert) {
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"reorder places subcategories after their parent categories, while maintaining the relative order",
|
||||
function (assert) {
|
||||
const store = createStore();
|
||||
test("reorder places subcategories after their parent categories, while maintaining the relative order", function (assert) {
|
||||
const store = createStore();
|
||||
|
||||
const parent = store.createRecord("category", {
|
||||
id: 1,
|
||||
position: 1,
|
||||
slug: "parent",
|
||||
});
|
||||
const child1 = store.createRecord("category", {
|
||||
id: 2,
|
||||
position: 3,
|
||||
slug: "child1",
|
||||
parent_category_id: 1,
|
||||
});
|
||||
const child2 = store.createRecord("category", {
|
||||
id: 3,
|
||||
position: 0,
|
||||
slug: "child2",
|
||||
parent_category_id: 1,
|
||||
});
|
||||
const other = store.createRecord("category", {
|
||||
id: 4,
|
||||
position: 2,
|
||||
slug: "other",
|
||||
});
|
||||
const parent = store.createRecord("category", {
|
||||
id: 1,
|
||||
position: 1,
|
||||
slug: "parent",
|
||||
});
|
||||
const child1 = store.createRecord("category", {
|
||||
id: 2,
|
||||
position: 3,
|
||||
slug: "child1",
|
||||
parent_category_id: 1,
|
||||
});
|
||||
const child2 = store.createRecord("category", {
|
||||
id: 3,
|
||||
position: 0,
|
||||
slug: "child2",
|
||||
parent_category_id: 1,
|
||||
});
|
||||
const other = store.createRecord("category", {
|
||||
id: 4,
|
||||
position: 2,
|
||||
slug: "other",
|
||||
});
|
||||
|
||||
const categories = [child2, parent, other, child1];
|
||||
const expectedOrderSlugs = ["parent", "child2", "child1", "other"];
|
||||
const categories = [child2, parent, other, child1];
|
||||
const expectedOrderSlugs = ["parent", "child2", "child1", "other"];
|
||||
|
||||
const site = EmberObject.create({ categories: categories });
|
||||
const reorderCategoriesController = this.subject({ site });
|
||||
const site = EmberObject.create({ categories: categories });
|
||||
const reorderCategoriesController = this.subject({ site });
|
||||
|
||||
reorderCategoriesController.reorder();
|
||||
reorderCategoriesController.reorder();
|
||||
|
||||
assert.deepEqual(
|
||||
reorderCategoriesController.get("categoriesOrdered").mapBy("slug"),
|
||||
expectedOrderSlugs
|
||||
);
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
reorderCategoriesController.get("categoriesOrdered").mapBy("slug"),
|
||||
expectedOrderSlugs
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"changing the position number of a category should place it at given position",
|
||||
function (assert) {
|
||||
const store = createStore();
|
||||
test("changing the position number of a category should place it at given position", function (assert) {
|
||||
const store = createStore();
|
||||
|
||||
const elem1 = store.createRecord("category", {
|
||||
id: 1,
|
||||
position: 0,
|
||||
slug: "foo",
|
||||
});
|
||||
const elem1 = store.createRecord("category", {
|
||||
id: 1,
|
||||
position: 0,
|
||||
slug: "foo",
|
||||
});
|
||||
|
||||
const elem2 = store.createRecord("category", {
|
||||
id: 2,
|
||||
position: 1,
|
||||
slug: "bar",
|
||||
});
|
||||
const elem2 = store.createRecord("category", {
|
||||
id: 2,
|
||||
position: 1,
|
||||
slug: "bar",
|
||||
});
|
||||
|
||||
const elem3 = store.createRecord("category", {
|
||||
id: 3,
|
||||
position: 2,
|
||||
slug: "test",
|
||||
});
|
||||
const elem3 = store.createRecord("category", {
|
||||
id: 3,
|
||||
position: 2,
|
||||
slug: "test",
|
||||
});
|
||||
|
||||
const categories = [elem1, elem2, elem3];
|
||||
const site = EmberObject.create({ categories: categories });
|
||||
const reorderCategoriesController = this.subject({ site });
|
||||
const categories = [elem1, elem2, elem3];
|
||||
const site = EmberObject.create({ categories: categories });
|
||||
const reorderCategoriesController = this.subject({ site });
|
||||
|
||||
reorderCategoriesController.actions.change.call(
|
||||
reorderCategoriesController,
|
||||
elem1,
|
||||
{ target: { value: "2" } }
|
||||
);
|
||||
reorderCategoriesController.actions.change.call(
|
||||
reorderCategoriesController,
|
||||
elem1,
|
||||
{ target: { value: "2" } }
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
reorderCategoriesController.get("categoriesOrdered").mapBy("slug"),
|
||||
["test", "bar", "foo"]
|
||||
);
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
reorderCategoriesController.get("categoriesOrdered").mapBy("slug"),
|
||||
["test", "bar", "foo"]
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"changing the position number of a category should place it at given position and respect children",
|
||||
function (assert) {
|
||||
const store = createStore();
|
||||
test("changing the position number of a category should place it at given position and respect children", function (assert) {
|
||||
const store = createStore();
|
||||
|
||||
const elem1 = store.createRecord("category", {
|
||||
id: 1,
|
||||
position: 0,
|
||||
slug: "foo",
|
||||
});
|
||||
const elem1 = store.createRecord("category", {
|
||||
id: 1,
|
||||
position: 0,
|
||||
slug: "foo",
|
||||
});
|
||||
|
||||
const child1 = store.createRecord("category", {
|
||||
id: 4,
|
||||
position: 1,
|
||||
slug: "foochild",
|
||||
parent_category_id: 1,
|
||||
});
|
||||
const child1 = store.createRecord("category", {
|
||||
id: 4,
|
||||
position: 1,
|
||||
slug: "foochild",
|
||||
parent_category_id: 1,
|
||||
});
|
||||
|
||||
const elem2 = store.createRecord("category", {
|
||||
id: 2,
|
||||
position: 2,
|
||||
slug: "bar",
|
||||
});
|
||||
const elem2 = store.createRecord("category", {
|
||||
id: 2,
|
||||
position: 2,
|
||||
slug: "bar",
|
||||
});
|
||||
|
||||
const elem3 = store.createRecord("category", {
|
||||
id: 3,
|
||||
position: 3,
|
||||
slug: "test",
|
||||
});
|
||||
const elem3 = store.createRecord("category", {
|
||||
id: 3,
|
||||
position: 3,
|
||||
slug: "test",
|
||||
});
|
||||
|
||||
const categories = [elem1, child1, elem2, elem3];
|
||||
const site = EmberObject.create({ categories: categories });
|
||||
const reorderCategoriesController = this.subject({ site });
|
||||
const categories = [elem1, child1, elem2, elem3];
|
||||
const site = EmberObject.create({ categories: categories });
|
||||
const reorderCategoriesController = this.subject({ site });
|
||||
|
||||
reorderCategoriesController.actions.change.call(
|
||||
reorderCategoriesController,
|
||||
elem1,
|
||||
{ target: { value: 3 } }
|
||||
);
|
||||
reorderCategoriesController.actions.change.call(
|
||||
reorderCategoriesController,
|
||||
elem1,
|
||||
{ target: { value: 3 } }
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
reorderCategoriesController.get("categoriesOrdered").mapBy("slug"),
|
||||
["test", "bar", "foo", "foochild"]
|
||||
);
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
reorderCategoriesController.get("categoriesOrdered").mapBy("slug"),
|
||||
["test", "bar", "foo", "foochild"]
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"changing the position through click on arrow of a category should place it at given position and respect children",
|
||||
function (assert) {
|
||||
const store = createStore();
|
||||
test("changing the position through click on arrow of a category should place it at given position and respect children", function (assert) {
|
||||
const store = createStore();
|
||||
|
||||
const elem1 = store.createRecord("category", {
|
||||
id: 1,
|
||||
position: 0,
|
||||
slug: "foo",
|
||||
});
|
||||
const elem1 = store.createRecord("category", {
|
||||
id: 1,
|
||||
position: 0,
|
||||
slug: "foo",
|
||||
});
|
||||
|
||||
const child1 = store.createRecord("category", {
|
||||
id: 4,
|
||||
position: 1,
|
||||
slug: "foochild",
|
||||
parent_category_id: 1,
|
||||
});
|
||||
const child1 = store.createRecord("category", {
|
||||
id: 4,
|
||||
position: 1,
|
||||
slug: "foochild",
|
||||
parent_category_id: 1,
|
||||
});
|
||||
|
||||
const child2 = store.createRecord("category", {
|
||||
id: 5,
|
||||
position: 2,
|
||||
slug: "foochildchild",
|
||||
parent_category_id: 4,
|
||||
});
|
||||
const child2 = store.createRecord("category", {
|
||||
id: 5,
|
||||
position: 2,
|
||||
slug: "foochildchild",
|
||||
parent_category_id: 4,
|
||||
});
|
||||
|
||||
const elem2 = store.createRecord("category", {
|
||||
id: 2,
|
||||
position: 3,
|
||||
slug: "bar",
|
||||
});
|
||||
const elem2 = store.createRecord("category", {
|
||||
id: 2,
|
||||
position: 3,
|
||||
slug: "bar",
|
||||
});
|
||||
|
||||
const elem3 = store.createRecord("category", {
|
||||
id: 3,
|
||||
position: 4,
|
||||
slug: "test",
|
||||
});
|
||||
const elem3 = store.createRecord("category", {
|
||||
id: 3,
|
||||
position: 4,
|
||||
slug: "test",
|
||||
});
|
||||
|
||||
const categories = [elem1, child1, child2, elem2, elem3];
|
||||
const site = EmberObject.create({ categories: categories });
|
||||
const reorderCategoriesController = this.subject({ site });
|
||||
const categories = [elem1, child1, child2, elem2, elem3];
|
||||
const site = EmberObject.create({ categories: categories });
|
||||
const reorderCategoriesController = this.subject({ site });
|
||||
|
||||
reorderCategoriesController.reorder();
|
||||
reorderCategoriesController.reorder();
|
||||
|
||||
reorderCategoriesController.actions.moveDown.call(
|
||||
reorderCategoriesController,
|
||||
elem1
|
||||
);
|
||||
reorderCategoriesController.actions.moveDown.call(
|
||||
reorderCategoriesController,
|
||||
elem1
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
reorderCategoriesController.get("categoriesOrdered").mapBy("slug"),
|
||||
["bar", "foo", "foochild", "foochildchild", "test"]
|
||||
);
|
||||
}
|
||||
);
|
||||
assert.deepEqual(
|
||||
reorderCategoriesController.get("categoriesOrdered").mapBy("slug"),
|
||||
["bar", "foo", "foochild", "foochildchild", "test"]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { moduleFor } from "ember-qunit";
|
||||
import { test } from "qunit";
|
||||
import EmberObject from "@ember/object";
|
||||
import { next } from "@ember/runloop";
|
||||
import Topic from "discourse/models/topic";
|
||||
@@ -25,7 +27,7 @@ function topicWithStream(streamDetails) {
|
||||
return topic;
|
||||
}
|
||||
|
||||
QUnit.test("editTopic", function (assert) {
|
||||
test("editTopic", function (assert) {
|
||||
const model = Topic.create();
|
||||
const controller = this.subject({ model });
|
||||
|
||||
@@ -60,7 +62,7 @@ QUnit.test("editTopic", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("toggleMultiSelect", function (assert) {
|
||||
test("toggleMultiSelect", function (assert) {
|
||||
const model = Topic.create();
|
||||
const controller = this.subject({ model });
|
||||
|
||||
@@ -100,7 +102,7 @@ QUnit.test("toggleMultiSelect", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("selectedPosts", function (assert) {
|
||||
test("selectedPosts", function (assert) {
|
||||
let model = topicWithStream({ posts: [{ id: 1 }, { id: 2 }, { id: 3 }] });
|
||||
const controller = this.subject({ model });
|
||||
|
||||
@@ -117,7 +119,7 @@ QUnit.test("selectedPosts", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("selectedAllPosts", function (assert) {
|
||||
test("selectedAllPosts", function (assert) {
|
||||
let model = topicWithStream({ stream: [1, 2, 3] });
|
||||
const controller = this.subject({ model });
|
||||
|
||||
@@ -147,7 +149,7 @@ QUnit.test("selectedAllPosts", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("selectedPostsUsername", function (assert) {
|
||||
test("selectedPostsUsername", function (assert) {
|
||||
let model = topicWithStream({
|
||||
posts: [
|
||||
{ id: 1, username: "gary" },
|
||||
@@ -198,7 +200,7 @@ QUnit.test("selectedPostsUsername", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("showSelectedPostsAtBottom", function (assert) {
|
||||
test("showSelectedPostsAtBottom", function (assert) {
|
||||
const site = EmberObject.create({ mobileView: false });
|
||||
const model = Topic.create({ posts_count: 3 });
|
||||
const controller = this.subject({ model, site });
|
||||
@@ -220,7 +222,7 @@ QUnit.test("showSelectedPostsAtBottom", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("canDeleteSelected", function (assert) {
|
||||
test("canDeleteSelected", function (assert) {
|
||||
const currentUser = User.create({ admin: false });
|
||||
this.registry.register("current-user:main", currentUser, {
|
||||
instantiate: false,
|
||||
@@ -271,7 +273,7 @@ QUnit.test("canDeleteSelected", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("Can split/merge topic", function (assert) {
|
||||
test("Can split/merge topic", function (assert) {
|
||||
let model = topicWithStream({
|
||||
posts: [
|
||||
{ id: 1, post_number: 1, post_type: 1 },
|
||||
@@ -316,7 +318,7 @@ QUnit.test("Can split/merge topic", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("canChangeOwner", function (assert) {
|
||||
test("canChangeOwner", function (assert) {
|
||||
const currentUser = User.create({ admin: false });
|
||||
this.registry.register("current-user:main", currentUser, {
|
||||
instantiate: false,
|
||||
@@ -358,7 +360,7 @@ QUnit.test("canChangeOwner", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("canMergePosts", function (assert) {
|
||||
test("canMergePosts", function (assert) {
|
||||
let model = topicWithStream({
|
||||
posts: [
|
||||
{ id: 1, username: "gary", can_delete: true },
|
||||
@@ -405,7 +407,7 @@ QUnit.test("canMergePosts", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("Select/deselect all", function (assert) {
|
||||
test("Select/deselect all", function (assert) {
|
||||
let model = topicWithStream({ stream: [1, 2, 3] });
|
||||
const controller = this.subject({ model });
|
||||
|
||||
@@ -432,7 +434,7 @@ QUnit.test("Select/deselect all", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("togglePostSelection", function (assert) {
|
||||
test("togglePostSelection", function (assert) {
|
||||
const controller = this.subject();
|
||||
const selectedPostIds = controller.get("selectedPostIds");
|
||||
|
||||
@@ -455,7 +457,7 @@ QUnit.test("togglePostSelection", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
// QUnit.test("selectReplies", function(assert) {
|
||||
// test("selectReplies", function(assert) {
|
||||
// const controller = this.subject();
|
||||
// const selectedPostIds = controller.get("selectedPostIds");
|
||||
//
|
||||
@@ -468,7 +470,7 @@ QUnit.test("togglePostSelection", function (assert) {
|
||||
// assert.equal(selectedPostIds[2], 100, "selected post #100");
|
||||
// });
|
||||
|
||||
QUnit.test("selectBelow", function (assert) {
|
||||
test("selectBelow", function (assert) {
|
||||
const site = EmberObject.create({
|
||||
post_types: { small_action: 3, whisper: 4 },
|
||||
});
|
||||
@@ -493,7 +495,7 @@ QUnit.test("selectBelow", function (assert) {
|
||||
assert.equal(selectedPostIds[3], 8, "also selected 3rd post below post #3");
|
||||
});
|
||||
|
||||
QUnit.test("topVisibleChanged", function (assert) {
|
||||
test("topVisibleChanged", function (assert) {
|
||||
let model = topicWithStream({
|
||||
posts: [{ id: 1 }],
|
||||
});
|
||||
@@ -509,38 +511,35 @@ QUnit.test("topVisibleChanged", function (assert) {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"deletePost - no modal is shown if post does not have replies",
|
||||
function (assert) {
|
||||
pretender.get("/posts/2/reply-ids.json", () => {
|
||||
return [200, { "Content-Type": "application/json" }, []];
|
||||
});
|
||||
test("deletePost - no modal is shown if post does not have replies", function (assert) {
|
||||
pretender.get("/posts/2/reply-ids.json", () => {
|
||||
return [200, { "Content-Type": "application/json" }, []];
|
||||
});
|
||||
|
||||
let destroyed;
|
||||
const post = EmberObject.create({
|
||||
id: 2,
|
||||
post_number: 2,
|
||||
can_delete: true,
|
||||
reply_count: 3,
|
||||
destroy: () => {
|
||||
destroyed = true;
|
||||
return Promise.resolve();
|
||||
},
|
||||
});
|
||||
let destroyed;
|
||||
const post = EmberObject.create({
|
||||
id: 2,
|
||||
post_number: 2,
|
||||
can_delete: true,
|
||||
reply_count: 3,
|
||||
destroy: () => {
|
||||
destroyed = true;
|
||||
return Promise.resolve();
|
||||
},
|
||||
});
|
||||
|
||||
const currentUser = EmberObject.create({ moderator: true });
|
||||
let model = topicWithStream({
|
||||
stream: [2, 3, 4],
|
||||
posts: [post, { id: 3 }, { id: 4 }],
|
||||
});
|
||||
const controller = this.subject({ model, currentUser });
|
||||
const currentUser = EmberObject.create({ moderator: true });
|
||||
let model = topicWithStream({
|
||||
stream: [2, 3, 4],
|
||||
posts: [post, { id: 3 }, { id: 4 }],
|
||||
});
|
||||
const controller = this.subject({ model, currentUser });
|
||||
|
||||
const done = assert.async();
|
||||
controller.send("deletePost", post);
|
||||
const done = assert.async();
|
||||
controller.send("deletePost", post);
|
||||
|
||||
next(() => {
|
||||
assert.ok(destroyed, "post was destroyed");
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
next(() => {
|
||||
assert.ok(destroyed, "post was destroyed");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user