mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: allows fabricators to use faker (#26555)
The complexity of the situation is that we don't want to load faker into production by default but fabricators and styleguide are available on production. This is made possible through app/assets/javascripts/discourse/app/lib/load-faker.js which contains a function to ensure faker is loaded asynchronously (loadFaker) and another function to access the loaded faker (getLoadedFaker). Note 1: this commit also refactors fabricators to have access to context and use faker where possible Note 2: this commit moves automation to admin bundle --------- Co-authored-by: David Taylor <david@taylorhq.com>
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
module("Discourse Chat | Unit | Helpers | format-chat-date", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("link to chat message", async function (assert) {
|
||||
const channel = fabricators.channel();
|
||||
this.message = fabricators.message({ channel });
|
||||
const channel = new ChatFabricators(getOwner(this)).channel();
|
||||
this.message = new ChatFabricators(getOwner(this)).message({ channel });
|
||||
|
||||
await render(hbs`{{format-chat-date this.message}}`);
|
||||
|
||||
@@ -21,9 +22,12 @@ module("Discourse Chat | Unit | Helpers | format-chat-date", function (hooks) {
|
||||
});
|
||||
|
||||
test("link to chat message thread", async function (assert) {
|
||||
const channel = fabricators.channel();
|
||||
const thread = fabricators.thread();
|
||||
this.message = fabricators.message({ channel, thread });
|
||||
const channel = new ChatFabricators(getOwner(this)).channel();
|
||||
const thread = new ChatFabricators(getOwner(this)).thread();
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
channel,
|
||||
thread,
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`{{format-chat-date this.message (hash threadContext=true)}}`
|
||||
|
||||
@@ -1,21 +1,30 @@
|
||||
import { getOwner } from "@ember/application";
|
||||
import { setupTest } from "ember-qunit";
|
||||
import { module, test } from "qunit";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import CoreFabricators from "discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import {
|
||||
getReactionText,
|
||||
MAX_DISPLAYED_USERNAMES,
|
||||
} from "discourse/plugins/chat/discourse/lib/get-reaction-text";
|
||||
|
||||
module("Discourse Chat | Unit | get-reaction-text", function () {
|
||||
module("Discourse Chat | Unit | get-reaction-text", function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test("no reaction ", function (assert) {
|
||||
const reaction = fabricators.reaction({ count: 0, users: [] });
|
||||
const currentUser = fabricators.user();
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: 0,
|
||||
users: [],
|
||||
});
|
||||
const currentUser = new CoreFabricators(getOwner(this)).user();
|
||||
|
||||
assert.strictEqual(getReactionText(reaction, currentUser), undefined);
|
||||
});
|
||||
|
||||
test("current user reacted - one reaction", function (assert) {
|
||||
const currentUser = fabricators.user();
|
||||
const reaction = fabricators.reaction({
|
||||
const currentUser = new CoreFabricators(getOwner(this)).user();
|
||||
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: 1,
|
||||
users: [currentUser],
|
||||
reacted: true,
|
||||
@@ -28,9 +37,11 @@ module("Discourse Chat | Unit | get-reaction-text", function () {
|
||||
});
|
||||
|
||||
test("current user reacted - two reactions", function (assert) {
|
||||
const currentUser = fabricators.user();
|
||||
const secondUser = fabricators.user({ username: "martin" });
|
||||
const reaction = fabricators.reaction({
|
||||
const currentUser = new CoreFabricators(getOwner(this)).user();
|
||||
const secondUser = new CoreFabricators(getOwner(this)).user({
|
||||
username: "martin",
|
||||
});
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: 2,
|
||||
users: [currentUser, secondUser],
|
||||
reacted: true,
|
||||
@@ -43,11 +54,12 @@ module("Discourse Chat | Unit | get-reaction-text", function () {
|
||||
});
|
||||
|
||||
test("current user reacted - more than display limit reactions", function (assert) {
|
||||
const currentUser = fabricators.user();
|
||||
const currentUser = new CoreFabricators(getOwner(this)).user();
|
||||
const otherUsers = Array.from(Array(MAX_DISPLAYED_USERNAMES + 1)).map(
|
||||
(_, i) => fabricators.user({ username: "user" + i })
|
||||
(_, i) =>
|
||||
new CoreFabricators(getOwner(this)).user({ username: "user" + i })
|
||||
);
|
||||
const reaction = fabricators.reaction({
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: [currentUser].concat(otherUsers).length,
|
||||
users: [currentUser].concat(otherUsers),
|
||||
reacted: true,
|
||||
@@ -60,11 +72,12 @@ module("Discourse Chat | Unit | get-reaction-text", function () {
|
||||
});
|
||||
|
||||
test("current user reacted - less or equal than display limit reactions", function (assert) {
|
||||
const currentUser = fabricators.user();
|
||||
const currentUser = new CoreFabricators(getOwner(this)).user();
|
||||
const otherUsers = Array.from(Array(MAX_DISPLAYED_USERNAMES - 2)).map(
|
||||
(_, i) => fabricators.user({ username: "user" + i })
|
||||
(_, i) =>
|
||||
new CoreFabricators(getOwner(this)).user({ username: "user" + i })
|
||||
);
|
||||
const reaction = fabricators.reaction({
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: [currentUser].concat(otherUsers).length,
|
||||
users: [currentUser].concat(otherUsers),
|
||||
reacted: true,
|
||||
@@ -77,8 +90,8 @@ module("Discourse Chat | Unit | get-reaction-text", function () {
|
||||
});
|
||||
|
||||
test("current user reacted - one reaction", function (assert) {
|
||||
const currentUser = fabricators.user();
|
||||
const reaction = fabricators.reaction({
|
||||
const currentUser = new CoreFabricators(getOwner(this)).user();
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: 1,
|
||||
users: [currentUser],
|
||||
reacted: true,
|
||||
@@ -91,9 +104,11 @@ module("Discourse Chat | Unit | get-reaction-text", function () {
|
||||
});
|
||||
|
||||
test("current user reacted - two reactions", function (assert) {
|
||||
const currentUser = fabricators.user();
|
||||
const secondUser = fabricators.user({ username: "martin" });
|
||||
const reaction = fabricators.reaction({
|
||||
const currentUser = new CoreFabricators(getOwner(this)).user();
|
||||
const secondUser = new CoreFabricators(getOwner(this)).user({
|
||||
username: "martin",
|
||||
});
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: 2,
|
||||
users: [currentUser, secondUser],
|
||||
reacted: true,
|
||||
@@ -106,11 +121,12 @@ module("Discourse Chat | Unit | get-reaction-text", function () {
|
||||
});
|
||||
|
||||
test("current user reacted - more than display limit reactions", function (assert) {
|
||||
const currentUser = fabricators.user();
|
||||
const currentUser = new CoreFabricators(getOwner(this)).user();
|
||||
const otherUsers = Array.from(Array(MAX_DISPLAYED_USERNAMES + 1)).map(
|
||||
(_, i) => fabricators.user({ username: "user" + i })
|
||||
(_, i) =>
|
||||
new CoreFabricators(getOwner(this)).user({ username: "user" + i })
|
||||
);
|
||||
const reaction = fabricators.reaction({
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: [currentUser].concat(otherUsers).length,
|
||||
users: [currentUser].concat(otherUsers),
|
||||
reacted: true,
|
||||
@@ -123,11 +139,12 @@ module("Discourse Chat | Unit | get-reaction-text", function () {
|
||||
});
|
||||
|
||||
test("current user reacted - less or equal than display limit reactions", function (assert) {
|
||||
const currentUser = fabricators.user();
|
||||
const currentUser = new CoreFabricators(getOwner(this)).user();
|
||||
const otherUsers = Array.from(Array(MAX_DISPLAYED_USERNAMES - 2)).map(
|
||||
(_, i) => fabricators.user({ username: "user" + i })
|
||||
(_, i) =>
|
||||
new CoreFabricators(getOwner(this)).user({ username: "user" + i })
|
||||
);
|
||||
const reaction = fabricators.reaction({
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: [currentUser].concat(otherUsers).length,
|
||||
users: [currentUser].concat(otherUsers),
|
||||
reacted: true,
|
||||
@@ -140,58 +157,64 @@ module("Discourse Chat | Unit | get-reaction-text", function () {
|
||||
});
|
||||
|
||||
test("current user didn't react - one reaction", function (assert) {
|
||||
const user = fabricators.user({ username: "martin" });
|
||||
const reaction = fabricators.reaction({
|
||||
const user = new CoreFabricators(getOwner(this)).user({
|
||||
username: "martin",
|
||||
});
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: 1,
|
||||
users: [user],
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
getReactionText(reaction, fabricators.user()),
|
||||
getReactionText(reaction, new CoreFabricators(getOwner(this)).user()),
|
||||
"<span>martin reacted with </span>:heart:"
|
||||
);
|
||||
});
|
||||
|
||||
test("current user didn't react - two reactions", function (assert) {
|
||||
const firstUser = fabricators.user({ username: "claude" });
|
||||
const secondUser = fabricators.user({ username: "martin" });
|
||||
const reaction = fabricators.reaction({
|
||||
const firstUser = new CoreFabricators(getOwner(this)).user({
|
||||
username: "claude",
|
||||
});
|
||||
const secondUser = new CoreFabricators(getOwner(this)).user({
|
||||
username: "martin",
|
||||
});
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: 2,
|
||||
users: [firstUser, secondUser],
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
getReactionText(reaction, fabricators.user()),
|
||||
getReactionText(reaction, new CoreFabricators(getOwner(this)).user()),
|
||||
"<span>claude and martin reacted with </span>:heart:"
|
||||
);
|
||||
});
|
||||
|
||||
test("current user didn't react - more than display limit reactions", function (assert) {
|
||||
const users = Array.from(Array(MAX_DISPLAYED_USERNAMES + 1)).map((_, i) =>
|
||||
fabricators.user({ username: "user" + i })
|
||||
new CoreFabricators(getOwner(this)).user({ username: "user" + i })
|
||||
);
|
||||
const reaction = fabricators.reaction({
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: users.length,
|
||||
users,
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
getReactionText(reaction, fabricators.user()),
|
||||
getReactionText(reaction, new CoreFabricators(getOwner(this)).user()),
|
||||
"<span>user0, user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, user11, user12, user13, user14 and 1 other reacted with </span>:heart:"
|
||||
);
|
||||
});
|
||||
|
||||
test("current user didn't react - less or equal than display limit reactions", function (assert) {
|
||||
const users = Array.from(Array(MAX_DISPLAYED_USERNAMES - 1)).map((_, i) =>
|
||||
fabricators.user({ username: "user" + i })
|
||||
new CoreFabricators(getOwner(this)).user({ username: "user" + i })
|
||||
);
|
||||
const reaction = fabricators.reaction({
|
||||
const reaction = new ChatFabricators(getOwner(this)).reaction({
|
||||
count: users.length,
|
||||
users,
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
getReactionText(reaction, fabricators.user()),
|
||||
getReactionText(reaction, new CoreFabricators(getOwner(this)).user()),
|
||||
"<span>user0, user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, user11, user12 and user13 reacted with </span>:heart:"
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { getOwner } from "@ember/application";
|
||||
import { setupTest } from "ember-qunit";
|
||||
import { module, test } from "qunit";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatMessage from "discourse/plugins/chat/discourse/models/chat-message";
|
||||
|
||||
module("Discourse Chat | Unit | Models | chat-message", function () {
|
||||
module("Discourse Chat | Unit | Models | chat-message", function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test(".persisted", function (assert) {
|
||||
const channel = fabricators.channel();
|
||||
const channel = new ChatFabricators(getOwner(this)).channel();
|
||||
let message = ChatMessage.create(channel, { id: null });
|
||||
assert.strictEqual(message.persisted, false);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getOwner } from "@ember/application";
|
||||
import { setupTest } from "ember-qunit";
|
||||
import { module, test } from "qunit";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
module(
|
||||
"Discourse Chat | Unit | Service | chat-drafts-manager",
|
||||
@@ -13,13 +13,13 @@ module(
|
||||
});
|
||||
|
||||
test("storing and retrieving message", async function (assert) {
|
||||
const message1 = fabricators.message();
|
||||
const message1 = new ChatFabricators(getOwner(this)).message();
|
||||
|
||||
await this.subject.add(message1, message1.channel.id);
|
||||
|
||||
assert.strictEqual(this.subject.get(message1.channel.id), message1);
|
||||
|
||||
const message2 = fabricators.message();
|
||||
const message2 = new ChatFabricators(getOwner(this)).message();
|
||||
|
||||
await this.subject.add(message2, message2.channel.id);
|
||||
|
||||
@@ -27,7 +27,7 @@ module(
|
||||
});
|
||||
|
||||
test("#reset", async function (assert) {
|
||||
const message = fabricators.message();
|
||||
const message = new ChatFabricators(getOwner(this)).message();
|
||||
|
||||
await this.subject.add(message, message.channel.id);
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { getOwner } from "@ember/application";
|
||||
import { set } from "@ember/object";
|
||||
import { test } from "qunit";
|
||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
acceptance("Discourse Chat | Unit | Service | chat-guardian", function (needs) {
|
||||
needs.hooks.beforeEach(function () {
|
||||
@@ -69,7 +70,7 @@ acceptance("Discourse Chat | Unit | Service | chat-guardian", function (needs) {
|
||||
});
|
||||
|
||||
test("#canArchiveChannel", async function (assert) {
|
||||
const channel = fabricators.channel();
|
||||
const channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
set(this.currentUser, "has_chat_enabled", true);
|
||||
set(this.currentUser, "admin", true);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { logIn } from "discourse/tests/helpers/qunit-helpers";
|
||||
import ChatMessageInteractor, {
|
||||
resetRemovedChatComposerSecondaryActions,
|
||||
} from "discourse/plugins/chat/discourse/lib/chat-message-interactor";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
module("Chat | Unit | Utility | plugin-api", function (hooks) {
|
||||
setupTest(hooks);
|
||||
@@ -40,7 +40,7 @@ module("Chat | Unit | Utility | plugin-api", function (hooks) {
|
||||
instantiate: false,
|
||||
});
|
||||
|
||||
const message = fabricators.message({
|
||||
const message = new ChatFabricators(getOwner(this)).message({
|
||||
user: currentUser,
|
||||
});
|
||||
const context = "channel";
|
||||
|
||||
Reference in New Issue
Block a user