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:
parent
1801e3d64c
commit
1060e4573a
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Fabricators are used to create fake data for testing purposes.
|
||||
The following fabricators are available in lib folder to allow
|
||||
styleguide to use them, and eventually to generate dummy data
|
||||
in a placeholder component. It should not be used for any other case.
|
||||
*/
|
||||
|
||||
import { setOwner } from "@ember/application";
|
||||
import ApplicationInstance from "@ember/application/instance";
|
||||
import { service } from "@ember/service";
|
||||
import { getLoadedFaker } from "discourse/lib/load-faker";
|
||||
|
||||
let sequence = 1;
|
||||
|
||||
export function incrementSequence() {
|
||||
return sequence++;
|
||||
}
|
||||
|
||||
export default class CoreFabricators {
|
||||
@service store;
|
||||
|
||||
constructor(owner) {
|
||||
if (owner && !(owner instanceof ApplicationInstance)) {
|
||||
throw new Error(
|
||||
"First argument of CoreFabricators constructor must be the owning ApplicationInstance"
|
||||
);
|
||||
}
|
||||
|
||||
setOwner(this, owner);
|
||||
}
|
||||
|
||||
category(args = {}) {
|
||||
const name = args.name || getLoadedFaker().faker.commerce.product();
|
||||
|
||||
return this.store.createRecord("category", {
|
||||
id: args.id || incrementSequence(),
|
||||
color: args.color || getLoadedFaker().faker.color.rgb({ prefix: "" }),
|
||||
read_restricted: args.read_restricted ?? false,
|
||||
name,
|
||||
slug: args.slug || name.toLowerCase(),
|
||||
});
|
||||
}
|
||||
|
||||
user(args = {}) {
|
||||
return this.store.createRecord("user", {
|
||||
id: args.id || incrementSequence(),
|
||||
username: args.username || getLoadedFaker().faker.person.firstName(),
|
||||
name: args.name,
|
||||
avatar_template: "/letter_avatar_proxy/v3/letter/t/41988e/{size}.png",
|
||||
suspended_till: args.suspended_till,
|
||||
});
|
||||
}
|
||||
|
||||
bookmark(args = {}) {
|
||||
return this.store.createRecord("bookmark", {
|
||||
id: args.id || incrementSequence(),
|
||||
});
|
||||
}
|
||||
|
||||
group(args = {}) {
|
||||
return this.store.createRecord("group", {
|
||||
name: args.name || getLoadedFaker().faker.word.noun(),
|
||||
});
|
||||
}
|
||||
|
||||
upload() {
|
||||
return {
|
||||
extension: "jpeg",
|
||||
filesize: 126177,
|
||||
height: 800,
|
||||
human_filesize: "123 KB",
|
||||
id: incrementSequence(),
|
||||
original_filename: "avatar.PNG.jpg",
|
||||
retain_hours: null,
|
||||
short_path: "/images/avatar.png",
|
||||
short_url: "upload://yoj8pf9DdIeHRRULyw7i57GAYdz.jpeg",
|
||||
thumbnail_height: 320,
|
||||
thumbnail_width: 690,
|
||||
url: "/images/avatar.png",
|
||||
width: 1920,
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,7 +1,21 @@
|
|||
let faker;
|
||||
|
||||
/*
|
||||
Plugins & themes are unable to async-import npm modules directly.
|
||||
This wrapper provides them with a way to use fakerjs, while keeping the `import()` in core's codebase.
|
||||
*/
|
||||
export default async function loadFaker() {
|
||||
return await import("@faker-js/faker");
|
||||
faker ??= await import("@faker-js/faker");
|
||||
return faker;
|
||||
}
|
||||
|
||||
export function setLoadedFaker(module) {
|
||||
faker = module;
|
||||
}
|
||||
|
||||
export function getLoadedFaker() {
|
||||
if (!faker) {
|
||||
throw "Faker has not been loaded yet. Ensure `setLoadedFaker()` or `loadFaker()` have been called first";
|
||||
}
|
||||
return faker;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ import { setupS3CDN, setupURL } from "discourse-common/lib/get-url";
|
|||
import { buildResolver } from "discourse-common/resolver";
|
||||
import Application from "../app";
|
||||
import { loadSprites } from "../lib/svg-sprite-loader";
|
||||
import * as FakerModule from "@faker-js/faker";
|
||||
import { setLoadedFaker } from "discourse/lib/load-faker";
|
||||
|
||||
const Plugin = $.fn.modal;
|
||||
const Modal = Plugin.Constructor;
|
||||
|
@ -433,6 +435,8 @@ export default function setupTests(config) {
|
|||
);
|
||||
}
|
||||
|
||||
setLoadedFaker(FakerModule);
|
||||
|
||||
if (!hasPluginJs && !hasThemeJs) {
|
||||
configureRaiseOnDeprecation();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Fabricators are used to create fake data for testing purposes.
|
||||
The following fabricators are available in lib folder to allow
|
||||
styleguide to use them, and eventually to generate dummy data
|
||||
in a placeholder component. It should not be used for any other case.
|
||||
*/
|
||||
|
||||
import { setOwner } from "@ember/application";
|
||||
import ApplicationInstance from "@ember/application/instance";
|
||||
import { incrementSequence } from "discourse/lib/fabricators";
|
||||
import Automation from "../models/discourse-automation-automation";
|
||||
import Field from "../models/discourse-automation-field";
|
||||
|
||||
export default class AutomationFabricators {
|
||||
constructor(owner) {
|
||||
if (owner && !(owner instanceof ApplicationInstance)) {
|
||||
throw new Error(
|
||||
"First argument of AutomationFabricators constructor must be the owning ApplicationInstance"
|
||||
);
|
||||
}
|
||||
setOwner(this, owner);
|
||||
}
|
||||
|
||||
field(args = {}) {
|
||||
const template = args.template || {};
|
||||
template.accepts_placeholders = args.accepts_placeholders ?? true;
|
||||
template.accepted_contexts = args.accepted_contexts ?? [];
|
||||
template.name = args.name ?? "name";
|
||||
template.component = args.component ?? "boolean";
|
||||
template.value = args.value ?? false;
|
||||
template.is_required = args.is_required ?? false;
|
||||
template.extra = args.extra ?? {};
|
||||
return Field.create(template, {
|
||||
type: args.target ?? "script",
|
||||
name: "script_name",
|
||||
});
|
||||
}
|
||||
|
||||
automation(args = {}) {
|
||||
const automation = new Automation();
|
||||
automation.id = args.id || incrementSequence();
|
||||
automation.trigger = {
|
||||
id: incrementSequence().toString(),
|
||||
};
|
||||
automation.script = {
|
||||
id: incrementSequence().toString(),
|
||||
};
|
||||
|
||||
return automation;
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ import { action } from "@ember/object";
|
|||
import { hash } from "rsvp";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import Field from "../admin/models/discourse-automation-field";
|
||||
import Field from "../models/discourse-automation-field";
|
||||
|
||||
export default class AutomationEdit extends DiscourseRoute {
|
||||
controllerName = "admin-plugins-discourse-automation-edit";
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
Fabricators are used to create fake data for testing purposes.
|
||||
The following fabricators are available in lib folder to allow
|
||||
styleguide to use them, and eventually to generate dummy data
|
||||
in a placeholder component. It should not be used for any other case.
|
||||
*/
|
||||
|
||||
import Automation from "../admin/models/discourse-automation-automation";
|
||||
import Field from "../admin/models/discourse-automation-field";
|
||||
|
||||
let sequence = 0;
|
||||
|
||||
function fieldFabricator(args = {}) {
|
||||
const template = args.template || {};
|
||||
template.accepts_placeholders = args.accepts_placeholders ?? true;
|
||||
template.accepted_contexts = args.accepted_contexts ?? [];
|
||||
template.name = args.name ?? "name";
|
||||
template.component = args.component ?? "boolean";
|
||||
template.value = args.value ?? false;
|
||||
template.is_required = args.is_required ?? false;
|
||||
template.extra = args.extra ?? {};
|
||||
return Field.create(template, {
|
||||
type: args.target ?? "script",
|
||||
name: "script_name",
|
||||
});
|
||||
}
|
||||
|
||||
function automationFabricator(args = {}) {
|
||||
const automation = new Automation();
|
||||
automation.id = args.id || sequence++;
|
||||
automation.trigger = {
|
||||
id: (sequence++).toString(),
|
||||
};
|
||||
automation.script = {
|
||||
id: (sequence++).toString(),
|
||||
};
|
||||
|
||||
return automation;
|
||||
}
|
||||
|
||||
export default {
|
||||
field: fieldFabricator,
|
||||
automation: automationFabricator,
|
||||
};
|
|
@ -1,18 +1,19 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { click, render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-boolean-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field();
|
||||
this.field = new AutomationFabricators(getOwner(this)).field();
|
||||
|
||||
await render(
|
||||
hbs`<AutomationField @automation={{this.automation}} @field={{this.field}} />`
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-categories-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("sets values", async function (assert) {
|
||||
this.field = fabricators.field({ component: "categories" });
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "categories",
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<AutomationField @automation={{this.automation}} @field={{this.field}} />`
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-category-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({ component: "category" });
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "category",
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<AutomationField @automation={{this.automation}} @field={{this.field}} />`
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module(
|
||||
"Integration | Component | da-category-notification-level-field",
|
||||
|
@ -11,11 +12,11 @@ module(
|
|||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "category_notification_level",
|
||||
});
|
||||
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-choices-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "choices",
|
||||
extra: { content: [{ name: "One", id: 1 }] },
|
||||
});
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-custom-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
|
||||
pretender.get("/admin/customize/user_fields", () => {
|
||||
return response({
|
||||
|
@ -33,7 +34,9 @@ module("Integration | Component | da-custom-field", function (hooks) {
|
|||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({ component: "custom_field" });
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "custom_field",
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<AutomationField @automation={{this.automation}} @field={{this.field}} />`
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { fillIn, render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-date-time-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({ component: "date_time" });
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "date_time",
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<AutomationField @automation={{this.automation}} @field={{this.field}} />`
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-group-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
|
||||
pretender.get("/groups/search.json", () => {
|
||||
return response([
|
||||
|
@ -26,7 +27,9 @@ module("Integration | Component | da-group-field", function (hooks) {
|
|||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({ component: "group" });
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "group",
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<AutomationField @automation={{this.automation}} @field={{this.field}} />`
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { fillIn, render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-message-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({ component: "message" });
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "message",
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<AutomationField @automation={{this.automation}} @field={{this.field}} />`
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { click, fillIn, render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-pms-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "pms",
|
||||
});
|
||||
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { fillIn, render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-post-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({ component: "post" });
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "post",
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<AutomationField @automation={{this.automation}} @field={{this.field}} />`
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-tags-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "tags",
|
||||
});
|
||||
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { fillIn, render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-text-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({ component: "text" });
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "text",
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<AutomationField @automation={{this.automation}} @field={{this.field}} />`
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-text-list-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "text_list",
|
||||
});
|
||||
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-trust-levels-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "trust-levels",
|
||||
});
|
||||
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-user-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
|
||||
pretender.get("/u/search/users", () =>
|
||||
response({
|
||||
|
@ -26,7 +27,7 @@ module("Integration | Component | da-user-field", function (hooks) {
|
|||
});
|
||||
|
||||
test("set value", async function (assert) {
|
||||
this.field = fabricators.field({
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "user",
|
||||
});
|
||||
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import fabricators from "discourse/plugins/automation/discourse/lib/fabricators";
|
||||
import AutomationFabricators from "discourse/plugins/automation/admin/lib/fabricators";
|
||||
|
||||
module("Integration | Component | da-users-field", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.automation = fabricators.automation();
|
||||
this.automation = new AutomationFabricators(getOwner(this)).automation();
|
||||
|
||||
pretender.get("/u/search/users", () =>
|
||||
response({
|
||||
|
@ -31,7 +32,7 @@ module("Integration | Component | da-users-field", function (hooks) {
|
|||
});
|
||||
|
||||
test("sets values", async function (assert) {
|
||||
this.field = fabricators.field({
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "users",
|
||||
});
|
||||
|
||||
|
@ -49,7 +50,7 @@ module("Integration | Component | da-users-field", function (hooks) {
|
|||
});
|
||||
|
||||
test("allows emails", async function (assert) {
|
||||
this.field = fabricators.field({
|
||||
this.field = new AutomationFabricators(getOwner(this)).field({
|
||||
component: "users",
|
||||
});
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { cached } from "@glimmer/tracking";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatComposerMessageDetails extends Component {
|
||||
@service site;
|
||||
|
@ -12,14 +13,16 @@ export default class ChatStyleguideChatComposerMessageDetails extends Component
|
|||
|
||||
@cached
|
||||
get message() {
|
||||
return fabricators.message({ user: this.currentUser });
|
||||
return new ChatFabricators(getOwner(this)).message({
|
||||
user: this.currentUser,
|
||||
});
|
||||
}
|
||||
|
||||
@action
|
||||
toggleMode() {
|
||||
if (this.message.editing) {
|
||||
this.message.editing = false;
|
||||
this.message.inReplyTo = fabricators.message();
|
||||
this.message.inReplyTo = new ChatFabricators(getOwner(this)).message();
|
||||
} else {
|
||||
this.message.editing = true;
|
||||
this.message.inReplyTo = null;
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import { CHANNEL_STATUSES } from "discourse/plugins/chat/discourse/models/chat-channel";
|
||||
|
||||
export default class ChatStyleguideChatComposer extends Component {
|
||||
@service chatChannelComposer;
|
||||
@service chatChannelPane;
|
||||
|
||||
channel = fabricators.channel({ id: -999 });
|
||||
channel = new ChatFabricators(getOwner(this)).channel({ id: -999 });
|
||||
|
||||
@action
|
||||
toggleDisabled() {
|
||||
|
|
|
@ -3,7 +3,7 @@ import { getOwner } from "@ember/application";
|
|||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import ChatMessagesManager from "discourse/plugins/chat/discourse/lib/chat-messages-manager";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatMessage extends Component {
|
||||
@service currentUser;
|
||||
|
@ -12,7 +12,9 @@ export default class ChatStyleguideChatMessage extends Component {
|
|||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.message = fabricators.message({ user: this.currentUser });
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
user: this.currentUser,
|
||||
});
|
||||
this.message.cook();
|
||||
}
|
||||
|
||||
|
@ -30,7 +32,7 @@ export default class ChatStyleguideChatMessage extends Component {
|
|||
if (this.message.bookmark) {
|
||||
this.message.bookmark = null;
|
||||
} else {
|
||||
this.message.bookmark = fabricators.bookmark();
|
||||
this.message.bookmark = new ChatFabricators(getOwner(this)).bookmark();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +57,7 @@ export default class ChatStyleguideChatMessage extends Component {
|
|||
this.message.channel.threadingEnabled = false;
|
||||
this.message.thread = null;
|
||||
} else {
|
||||
this.message.thread = fabricators.thread({
|
||||
this.message.thread = new ChatFabricators(getOwner(this)).thread({
|
||||
channel: this.message.channel,
|
||||
});
|
||||
this.message.thread.preview.replyCount = 1;
|
||||
|
@ -75,8 +77,11 @@ export default class ChatStyleguideChatMessage extends Component {
|
|||
this.message.reactions = [];
|
||||
} else {
|
||||
this.message.reactions = [
|
||||
fabricators.reaction({ emoji: "heart" }),
|
||||
fabricators.reaction({ emoji: "rocket", reacted: true }),
|
||||
new ChatFabricators(getOwner(this)).reaction({ emoji: "heart" }),
|
||||
new ChatFabricators(getOwner(this)).reaction({
|
||||
emoji: "rocket",
|
||||
reacted: true,
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +91,10 @@ export default class ChatStyleguideChatMessage extends Component {
|
|||
if (this.message.uploads?.length) {
|
||||
this.message.uploads = [];
|
||||
} else {
|
||||
this.message.uploads = [fabricators.upload(), fabricators.upload()];
|
||||
this.message.uploads = [
|
||||
new ChatFabricators(getOwner(this)).upload(),
|
||||
new ChatFabricators(getOwner(this)).upload(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import ChatModalArchiveChannel from "discourse/plugins/chat/discourse/components/chat/modal/archive-channel";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatModalArchiveChannel extends Component {
|
||||
@service modal;
|
||||
|
||||
channel = fabricators.channel();
|
||||
channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
@action
|
||||
openModal() {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import ChatModalChannelSummary from "discourse/plugins/chat/discourse/components/chat/modal/channel-summary";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatModalChannelSummary extends Component {
|
||||
@service modal;
|
||||
|
@ -10,7 +11,7 @@ export default class ChatStyleguideChatModalChannelSummary extends Component {
|
|||
@action
|
||||
openModal() {
|
||||
return this.modal.show(ChatModalChannelSummary, {
|
||||
model: { channelId: fabricators.channel().id },
|
||||
model: { channelId: new ChatFabricators(getOwner(this)).channel().id },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import ChatModalDeleteChannel from "discourse/plugins/chat/discourse/components/chat/modal/delete-channel";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatModalDeleteChannel extends Component {
|
||||
@service modal;
|
||||
|
||||
channel = fabricators.channel();
|
||||
channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
@action
|
||||
openModal() {
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import ChatModalEditChannelDescription from "discourse/plugins/chat/discourse/components/chat/modal/edit-channel-description";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatModalEditChannelDescription extends Component {
|
||||
@service modal;
|
||||
|
||||
channel = fabricators.channel();
|
||||
channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
@action
|
||||
openModal() {
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import ChatModalEditChannelName from "discourse/plugins/chat/discourse/components/chat/modal/edit-channel-name";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatModalEditChannelName extends Component {
|
||||
@service modal;
|
||||
|
||||
channel = fabricators.channel();
|
||||
channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
@action
|
||||
openModal() {
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import ChatModalMoveMessageToChannel from "discourse/plugins/chat/discourse/components/chat/modal/move-message-to-channel";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatModalMoveMessageToChannel extends Component {
|
||||
@service modal;
|
||||
|
||||
channel = fabricators.channel();
|
||||
selectedMessageIds = [fabricators.message({ channel: this.channel })].mapBy(
|
||||
"id"
|
||||
);
|
||||
channel = new ChatFabricators(getOwner(this)).channel();
|
||||
selectedMessageIds = [
|
||||
new ChatFabricators(getOwner(this)).message({ channel: this.channel }),
|
||||
].mapBy("id");
|
||||
|
||||
@action
|
||||
openModal() {
|
||||
|
@ -18,7 +19,9 @@ export default class ChatStyleguideChatModalMoveMessageToChannel extends Compone
|
|||
model: {
|
||||
sourceChannel: this.channel,
|
||||
selectedMessageIds: [
|
||||
fabricators.message({ channel: this.channel }),
|
||||
new ChatFabricators(getOwner(this)).message({
|
||||
channel: this.channel,
|
||||
}),
|
||||
].mapBy("id"),
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import ChatModalThreadSettings from "discourse/plugins/chat/discourse/components/chat/modal/thread-settings";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatModalThreadSettings extends Component {
|
||||
@service modal;
|
||||
|
@ -10,7 +11,7 @@ export default class ChatStyleguideChatModalThreadSettings extends Component {
|
|||
@action
|
||||
openModal() {
|
||||
return this.modal.show(ChatModalThreadSettings, {
|
||||
model: fabricators.thread(),
|
||||
model: new ChatFabricators(getOwner(this)).thread(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import ChatModalToggleChannelStatus from "discourse/plugins/chat/discourse/components/chat/modal/toggle-channel-status";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatModalToggleChannelStatus extends Component {
|
||||
@service modal;
|
||||
|
@ -10,7 +11,7 @@ export default class ChatStyleguideChatModalToggleChannelStatus extends Componen
|
|||
@action
|
||||
openModal() {
|
||||
return this.modal.show(ChatModalToggleChannelStatus, {
|
||||
model: fabricators.channel(),
|
||||
model: new ChatFabricators(getOwner(this)).channel(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { service } from "@ember/service";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
export default class ChatStyleguideChatThreadListItem extends Component {
|
||||
@service currentUser;
|
||||
|
||||
thread = fabricators.thread();
|
||||
thread = new ChatFabricators(getOwner(this)).thread();
|
||||
}
|
||||
|
|
|
@ -4,11 +4,10 @@ The following fabricators are available in lib folder to allow
|
|||
styleguide to use them, and eventually to generate dummy data
|
||||
in a placeholder component. It should not be used for any other case.
|
||||
*/
|
||||
|
||||
import Bookmark from "discourse/models/bookmark";
|
||||
import { setOwner } from "@ember/application";
|
||||
import ApplicationInstance from "@ember/application/instance";
|
||||
import CoreFabricators, { incrementSequence } from "discourse/lib/fabricators";
|
||||
import Category from "discourse/models/category";
|
||||
import Group from "discourse/models/group";
|
||||
import User from "discourse/models/user";
|
||||
import ChatChannel, {
|
||||
CHANNEL_STATUSES,
|
||||
CHATABLE_TYPES,
|
||||
|
@ -19,184 +18,134 @@ import ChatMessageReaction from "discourse/plugins/chat/discourse/models/chat-me
|
|||
import ChatThread from "discourse/plugins/chat/discourse/models/chat-thread";
|
||||
import ChatThreadPreview from "discourse/plugins/chat/discourse/models/chat-thread-preview";
|
||||
|
||||
let sequence = 0;
|
||||
|
||||
function messageFabricator(args = {}) {
|
||||
const channel = args.channel || channelFabricator();
|
||||
|
||||
const message = ChatMessage.create(
|
||||
channel,
|
||||
Object.assign(
|
||||
{
|
||||
id: args.id || sequence++,
|
||||
user: args.user || userFabricator(),
|
||||
message:
|
||||
args.message ||
|
||||
"@discobot **abc**defghijklmnopqrstuvwxyz [discourse](discourse.org) :rocket: ",
|
||||
created_at: args.created_at || moment(),
|
||||
},
|
||||
args
|
||||
)
|
||||
);
|
||||
|
||||
const excerptLength = 50;
|
||||
const text = message.message.toString();
|
||||
if (text.length <= excerptLength) {
|
||||
message.excerpt = text;
|
||||
} else {
|
||||
message.excerpt = text.slice(0, excerptLength) + "...";
|
||||
export default class ChatFabricators {
|
||||
constructor(owner) {
|
||||
if (owner && !(owner instanceof ApplicationInstance)) {
|
||||
throw new Error(
|
||||
"First argument of ChatFabricators constructor must be the owning ApplicationInstance"
|
||||
);
|
||||
}
|
||||
setOwner(this, owner);
|
||||
this.coreFabricators = new CoreFabricators(owner);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
message(args = {}) {
|
||||
const channel = args.channel || this.channel();
|
||||
|
||||
function channelFabricator(args = {}) {
|
||||
const id = args.id || sequence++;
|
||||
const chatable = args.chatable || categoryFabricator();
|
||||
const message = ChatMessage.create(
|
||||
channel,
|
||||
Object.assign(
|
||||
{
|
||||
id: args.id || incrementSequence(),
|
||||
user: args.user || this.coreFabricators.user(),
|
||||
message:
|
||||
args.message ||
|
||||
"@discobot **abc**defghijklmnopqrstuvwxyz [discourse](discourse.org) :rocket: ",
|
||||
created_at: args.created_at || moment(),
|
||||
},
|
||||
args
|
||||
)
|
||||
);
|
||||
|
||||
const channel = ChatChannel.create({
|
||||
id,
|
||||
chatable_type:
|
||||
(chatable instanceof Category
|
||||
? CHATABLE_TYPES.categoryChannel
|
||||
: CHATABLE_TYPES.directMessageChannel) ||
|
||||
chatable?.type ||
|
||||
args.chatable_type,
|
||||
chatable_id: chatable?.id || args.chatable_id,
|
||||
title: args.title
|
||||
? args.title
|
||||
: chatable instanceof Category
|
||||
? "General"
|
||||
: null,
|
||||
description: args.description,
|
||||
chatable,
|
||||
status: args.status || CHANNEL_STATUSES.open,
|
||||
slug: chatable?.slug || chatable instanceof Category ? "general" : null,
|
||||
meta: Object.assign({ can_delete_self: true }, args.meta || {}),
|
||||
archive_failed: args.archive_failed ?? false,
|
||||
memberships_count: args.memberships_count ?? 0,
|
||||
});
|
||||
const excerptLength = 50;
|
||||
const text = message.message.toString();
|
||||
if (text.length <= excerptLength) {
|
||||
message.excerpt = text;
|
||||
} else {
|
||||
message.excerpt = text.slice(0, excerptLength) + "...";
|
||||
}
|
||||
|
||||
channel.lastMessage = messageFabricator({ channel });
|
||||
return message;
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
channel(args = {}) {
|
||||
const id = args.id || incrementSequence();
|
||||
const chatable = args.chatable || this.coreFabricators.category();
|
||||
|
||||
function categoryFabricator(args = {}) {
|
||||
return Category.create({
|
||||
id: args.id || sequence++,
|
||||
color: args.color || "D56353",
|
||||
read_restricted: args.read_restricted ?? false,
|
||||
name: args.name || "General",
|
||||
slug: args.slug || "general",
|
||||
});
|
||||
}
|
||||
|
||||
function directMessageFabricator(args = {}) {
|
||||
return ChatDirectMessage.create({
|
||||
group: args.group ?? false,
|
||||
users: args.users ?? [userFabricator(), userFabricator()],
|
||||
});
|
||||
}
|
||||
|
||||
function directMessageChannelFabricator(args = {}) {
|
||||
const directMessage =
|
||||
args.chatable ||
|
||||
directMessageFabricator({
|
||||
id: args.chatable_id || sequence++,
|
||||
group: args.group ?? false,
|
||||
users: args.users,
|
||||
const channel = ChatChannel.create({
|
||||
id,
|
||||
chatable_type:
|
||||
(chatable instanceof Category
|
||||
? CHATABLE_TYPES.categoryChannel
|
||||
: CHATABLE_TYPES.directMessageChannel) ||
|
||||
chatable?.type ||
|
||||
args.chatable_type,
|
||||
chatable_id: chatable?.id || args.chatable_id,
|
||||
title: args.title
|
||||
? args.title
|
||||
: chatable instanceof Category
|
||||
? chatable.name
|
||||
: null,
|
||||
description: args.description,
|
||||
chatable,
|
||||
status: args.status || CHANNEL_STATUSES.open,
|
||||
slug:
|
||||
chatable?.slug || chatable instanceof Category ? chatable.slugt : null,
|
||||
meta: Object.assign({ can_delete_self: true }, args.meta || {}),
|
||||
archive_failed: args.archive_failed ?? false,
|
||||
memberships_count: args.memberships_count ?? 0,
|
||||
});
|
||||
|
||||
return channelFabricator(
|
||||
Object.assign(args, {
|
||||
chatable_type: CHATABLE_TYPES.directMessageChannel,
|
||||
chatable_id: directMessage.id,
|
||||
chatable: directMessage,
|
||||
memberships_count: directMessage.users.length,
|
||||
})
|
||||
);
|
||||
}
|
||||
channel.lastMessage = this.message({ channel });
|
||||
|
||||
function userFabricator(args = {}) {
|
||||
return User.create({
|
||||
id: args.id || sequence++,
|
||||
username: args.username || "hawk",
|
||||
name: args.name,
|
||||
avatar_template: "/letter_avatar_proxy/v3/letter/t/41988e/{size}.png",
|
||||
suspended_till: args.suspended_till,
|
||||
});
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
function bookmarkFabricator(args = {}) {
|
||||
return Bookmark.create({
|
||||
id: args.id || sequence++,
|
||||
});
|
||||
}
|
||||
directMessage(args = {}) {
|
||||
return ChatDirectMessage.create({
|
||||
group: args.group ?? false,
|
||||
users: args.users ?? [
|
||||
this.coreFabricators.user(),
|
||||
this.coreFabricators.user(),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
function threadFabricator(args = {}) {
|
||||
const channel = args.channel || channelFabricator();
|
||||
return ChatThread.create(channel, {
|
||||
id: args.id || sequence++,
|
||||
title: args.title,
|
||||
original_message: args.original_message || messageFabricator({ channel }),
|
||||
preview: args.preview || threadPreviewFabricator({ channel }),
|
||||
});
|
||||
}
|
||||
function threadPreviewFabricator(args = {}) {
|
||||
return ChatThreadPreview.create({
|
||||
last_reply_id: args.last_reply_id || sequence++,
|
||||
last_reply_created_at: args.last_reply_created_at || Date.now(),
|
||||
last_reply_excerpt: args.last_reply_excerpt || "This is a reply",
|
||||
participant_count: args.participant_count ?? 0,
|
||||
participant_users: args.participant_users ?? [],
|
||||
});
|
||||
}
|
||||
directMessageChannel(args = {}) {
|
||||
const directMessage =
|
||||
args.chatable ||
|
||||
this.directMessage({
|
||||
id: args.chatable_id || incrementSequence(),
|
||||
group: args.group ?? false,
|
||||
users: args.users,
|
||||
});
|
||||
|
||||
function reactionFabricator(args = {}) {
|
||||
return ChatMessageReaction.create({
|
||||
count: args.count ?? 1,
|
||||
users: args.users || [userFabricator()],
|
||||
emoji: args.emoji || "heart",
|
||||
reacted: args.reacted ?? false,
|
||||
});
|
||||
}
|
||||
return this.channel(
|
||||
Object.assign(args, {
|
||||
chatable_type: CHATABLE_TYPES.directMessageChannel,
|
||||
chatable_id: directMessage.id,
|
||||
chatable: directMessage,
|
||||
memberships_count: directMessage.users.length,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function groupFabricator(args = {}) {
|
||||
return Group.create({
|
||||
name: args.name || "Engineers",
|
||||
});
|
||||
}
|
||||
thread(args = {}) {
|
||||
const channel = args.channel || this.channel();
|
||||
return ChatThread.create(channel, {
|
||||
id: args.id || incrementSequence(),
|
||||
title: args.title,
|
||||
original_message: args.original_message || this.message({ channel }),
|
||||
preview: args.preview || this.threadPreview({ channel }),
|
||||
});
|
||||
}
|
||||
|
||||
function uploadFabricator() {
|
||||
return {
|
||||
extension: "jpeg",
|
||||
filesize: 126177,
|
||||
height: 800,
|
||||
human_filesize: "123 KB",
|
||||
id: 202,
|
||||
original_filename: "avatar.PNG.jpg",
|
||||
retain_hours: null,
|
||||
short_path: "/images/avatar.png",
|
||||
short_url: "upload://yoj8pf9DdIeHRRULyw7i57GAYdz.jpeg",
|
||||
thumbnail_height: 320,
|
||||
thumbnail_width: 690,
|
||||
url: "/images/avatar.png",
|
||||
width: 1920,
|
||||
};
|
||||
}
|
||||
threadPreview(args = {}) {
|
||||
return ChatThreadPreview.create({
|
||||
last_reply_id: args.last_reply_id || incrementSequence(),
|
||||
last_reply_created_at: args.last_reply_created_at || Date.now(),
|
||||
last_reply_excerpt: args.last_reply_excerpt || "This is a reply",
|
||||
participant_count: args.participant_count ?? 0,
|
||||
participant_users: args.participant_users ?? [],
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
bookmark: bookmarkFabricator,
|
||||
user: userFabricator,
|
||||
channel: channelFabricator,
|
||||
directMessageChannel: directMessageChannelFabricator,
|
||||
message: messageFabricator,
|
||||
thread: threadFabricator,
|
||||
threadPreview: threadPreviewFabricator,
|
||||
reaction: reactionFabricator,
|
||||
upload: uploadFabricator,
|
||||
category: categoryFabricator,
|
||||
directMessage: directMessageFabricator,
|
||||
group: groupFabricator,
|
||||
};
|
||||
reaction(args = {}) {
|
||||
return ChatMessageReaction.create({
|
||||
count: args.count ?? 1,
|
||||
users: args.users || [this.coreFabricators.user()],
|
||||
emoji: args.emoji || "heart",
|
||||
reacted: args.reacted ?? false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { module, test } from "qunit";
|
||||
import CoreFabricators from "discourse/lib/fabricators";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import ChannelIcon from "discourse/plugins/chat/discourse/components/channel-icon";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
|
||||
|
||||
module("Discourse Chat | Component | <ChannelIcon />", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("category channel - badge", async function (assert) {
|
||||
const channel = fabricators.channel();
|
||||
const channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
await render(<template><ChannelIcon @channel={{channel}} /></template>);
|
||||
|
||||
|
@ -21,7 +23,7 @@ module("Discourse Chat | Component | <ChannelIcon />", function (hooks) {
|
|||
});
|
||||
|
||||
test("category channel - escapes label", async function (assert) {
|
||||
const channel = fabricators.channel({
|
||||
const channel = new ChatFabricators(getOwner(this)).channel({
|
||||
chatable_type: CHATABLE_TYPES.categoryChannel,
|
||||
title: "<div class='xss'>evil</div>",
|
||||
});
|
||||
|
@ -32,8 +34,10 @@ module("Discourse Chat | Component | <ChannelIcon />", function (hooks) {
|
|||
});
|
||||
|
||||
test("category channel - read restricted", async function (assert) {
|
||||
const channel = fabricators.channel({
|
||||
chatable: fabricators.category({ read_restricted: true }),
|
||||
const channel = new ChatFabricators(getOwner(this)).channel({
|
||||
chatable: new CoreFabricators(getOwner(this)).category({
|
||||
read_restricted: true,
|
||||
}),
|
||||
});
|
||||
|
||||
await render(<template><ChannelIcon @channel={{channel}} /></template>);
|
||||
|
@ -42,8 +46,10 @@ module("Discourse Chat | Component | <ChannelIcon />", function (hooks) {
|
|||
});
|
||||
|
||||
test("category channel - not read restricted", async function (assert) {
|
||||
const channel = fabricators.channel({
|
||||
chatable: fabricators.category({ read_restricted: false }),
|
||||
const channel = new ChatFabricators(getOwner(this)).channel({
|
||||
chatable: new CoreFabricators(getOwner(this)).category({
|
||||
read_restricted: false,
|
||||
}),
|
||||
});
|
||||
|
||||
await render(<template><ChannelIcon @channel={{channel}} /></template>);
|
||||
|
@ -52,9 +58,9 @@ module("Discourse Chat | Component | <ChannelIcon />", function (hooks) {
|
|||
});
|
||||
|
||||
test("dm channel - one user", async function (assert) {
|
||||
const channel = fabricators.directMessageChannel({
|
||||
chatable: fabricators.directMessage({
|
||||
users: [fabricators.user()],
|
||||
const channel = new ChatFabricators(getOwner(this)).directMessageChannel({
|
||||
chatable: new ChatFabricators(getOwner(this)).directMessage({
|
||||
users: [new CoreFabricators(getOwner(this)).user()],
|
||||
}),
|
||||
});
|
||||
const user = channel.chatable.users[0];
|
||||
|
@ -65,8 +71,12 @@ module("Discourse Chat | Component | <ChannelIcon />", function (hooks) {
|
|||
});
|
||||
|
||||
test("dm channel - multiple users", async function (assert) {
|
||||
const channel = fabricators.directMessageChannel({
|
||||
users: [fabricators.user(), fabricators.user(), fabricators.user()],
|
||||
const channel = new ChatFabricators(getOwner(this)).directMessageChannel({
|
||||
users: [
|
||||
new CoreFabricators(getOwner(this)).user(),
|
||||
new CoreFabricators(getOwner(this)).user(),
|
||||
new CoreFabricators(getOwner(this)).user(),
|
||||
],
|
||||
});
|
||||
channel.chatable.group = true;
|
||||
const users = channel.chatable.users;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { module, test } from "qunit";
|
||||
import CoreFabricators from "discourse/lib/fabricators";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import ChannelName from "discourse/plugins/chat/discourse/components/channel-name";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
|
||||
|
||||
const CHANNEL_NAME_LABEL = ".chat-channel-name__label";
|
||||
|
@ -12,7 +14,7 @@ module("Discourse Chat | Component | <ChannelName />", function (hooks) {
|
|||
setupRenderingTest(hooks);
|
||||
|
||||
test("category channel - label", async function (assert) {
|
||||
const channel = fabricators.channel();
|
||||
const channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
await render(<template><ChannelName @channel={{channel}} /></template>);
|
||||
|
||||
|
@ -20,7 +22,7 @@ module("Discourse Chat | Component | <ChannelName />", function (hooks) {
|
|||
});
|
||||
|
||||
test("category channel - escapes label", async function (assert) {
|
||||
const channel = fabricators.channel({
|
||||
const channel = new ChatFabricators(getOwner(this)).channel({
|
||||
chatable_type: CHATABLE_TYPES.categoryChannel,
|
||||
title: "<div class='xss'>evil</div>",
|
||||
});
|
||||
|
@ -31,9 +33,9 @@ module("Discourse Chat | Component | <ChannelName />", function (hooks) {
|
|||
});
|
||||
|
||||
test("dm channel - one user", async function (assert) {
|
||||
const channel = fabricators.directMessageChannel({
|
||||
chatable: fabricators.directMessage({
|
||||
users: [fabricators.user()],
|
||||
const channel = new ChatFabricators(getOwner(this)).directMessageChannel({
|
||||
chatable: new ChatFabricators(getOwner(this)).directMessage({
|
||||
users: [new CoreFabricators(getOwner(this)).user()],
|
||||
}),
|
||||
});
|
||||
const user = channel.chatable.users[0];
|
||||
|
@ -47,8 +49,12 @@ module("Discourse Chat | Component | <ChannelName />", function (hooks) {
|
|||
});
|
||||
|
||||
test("dm channel - multiple users", async function (assert) {
|
||||
const channel = fabricators.directMessageChannel({
|
||||
users: [fabricators.user(), fabricators.user(), fabricators.user()],
|
||||
const channel = new ChatFabricators(getOwner(this)).directMessageChannel({
|
||||
users: [
|
||||
new CoreFabricators(getOwner(this)).user(),
|
||||
new CoreFabricators(getOwner(this)).user(),
|
||||
new CoreFabricators(getOwner(this)).user(),
|
||||
],
|
||||
});
|
||||
channel.chatable.group = true;
|
||||
const users = channel.chatable.users;
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import ChannelTitle from "discourse/plugins/chat/discourse/components/channel-title";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
module("Discourse Chat | Component | <ChannelTitle />", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("icon", async function (assert) {
|
||||
const channel = fabricators.channel();
|
||||
const channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
await render(<template><ChannelTitle @channel={{channel}} /></template>);
|
||||
|
||||
|
@ -16,7 +17,7 @@ module("Discourse Chat | Component | <ChannelTitle />", function (hooks) {
|
|||
});
|
||||
|
||||
test("label", async function (assert) {
|
||||
const channel = fabricators.channel();
|
||||
const channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
await render(<template><ChannelTitle @channel={{channel}} /></template>);
|
||||
|
||||
|
|
|
@ -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 { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import I18n from "discourse-i18n";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
module("Discourse Chat | Component | chat-channel-card", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.channel = fabricators.channel();
|
||||
this.channel = new ChatFabricators(getOwner(this)).channel();
|
||||
this.channel.description =
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
|
||||
});
|
||||
|
@ -103,11 +104,6 @@ module("Discourse Chat | Component | chat-channel-card", function (hooks) {
|
|||
test("Read restricted chatable", async function (assert) {
|
||||
this.channel.chatable.read_restricted = true;
|
||||
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
|
||||
|
||||
assert.true(exists(".d-icon-lock"));
|
||||
assert.strictEqual(
|
||||
query(".chat-channel-card").style.borderLeftColor,
|
||||
"rgb(213, 99, 83)"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { click, render } from "@ember/test-helpers";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import { module, test } from "qunit";
|
||||
|
@ -5,7 +6,7 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import { query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import I18n from "discourse-i18n";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
module("Discourse Chat | Component | chat-channel-leave-btn", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
@ -13,7 +14,7 @@ module("Discourse Chat | Component | chat-channel-leave-btn", function (hooks) {
|
|||
test("accepts an optional onLeaveChannel callback", async function (assert) {
|
||||
this.foo = 1;
|
||||
this.onLeaveChannel = () => (this.foo = 2);
|
||||
this.channel = fabricators.directMessageChannel();
|
||||
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
||||
|
||||
await render(
|
||||
hbs`<ChatChannelLeaveBtn @channel={{this.channel}} @onLeaveChannel={{this.onLeaveChannel}} />`
|
||||
|
@ -29,7 +30,7 @@ module("Discourse Chat | Component | chat-channel-leave-btn", function (hooks) {
|
|||
});
|
||||
|
||||
test("has a specific title for direct message channel", async function (assert) {
|
||||
this.channel = fabricators.directMessageChannel();
|
||||
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
||||
|
||||
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
|
||||
|
||||
|
@ -38,7 +39,7 @@ module("Discourse Chat | Component | chat-channel-leave-btn", function (hooks) {
|
|||
});
|
||||
|
||||
test("has a specific title for message channel", async function (assert) {
|
||||
this.channel = fabricators.channel();
|
||||
this.channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
|
||||
|
||||
|
@ -48,7 +49,7 @@ module("Discourse Chat | Component | chat-channel-leave-btn", function (hooks) {
|
|||
|
||||
test("is not visible on mobile", async function (assert) {
|
||||
this.site.desktopView = false;
|
||||
this.channel = fabricators.channel();
|
||||
this.channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
await render(hbs`<ChatChannelLeaveBtn @channel={{this.channel}} />`);
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
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 { exists } 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 | Component | chat-channel-metadata", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("displays last message created at", async function (assert) {
|
||||
let lastMessageSentAt = moment().subtract(1, "day").format();
|
||||
this.channel = fabricators.directMessageChannel();
|
||||
this.channel.lastMessage = fabricators.message({
|
||||
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
||||
this.channel.lastMessage = new ChatFabricators(getOwner(this)).message({
|
||||
channel: this.channel,
|
||||
created_at: lastMessageSentAt,
|
||||
});
|
||||
|
@ -30,7 +31,7 @@ module("Discourse Chat | Component | chat-channel-metadata", function (hooks) {
|
|||
});
|
||||
|
||||
test("unreadIndicator", async function (assert) {
|
||||
this.channel = fabricators.directMessageChannel();
|
||||
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
||||
this.channel.tracking.unreadCount = 1;
|
||||
|
||||
this.unreadIndicator = true;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
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 { exists, 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 | Component | chat-channel-preview-card",
|
||||
|
@ -11,7 +12,12 @@ module(
|
|||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.set("channel", fabricators.channel({ chatable_type: "Category" }));
|
||||
this.set(
|
||||
"channel",
|
||||
new ChatFabricators(getOwner(this)).channel({
|
||||
chatable_type: "Category",
|
||||
})
|
||||
);
|
||||
|
||||
this.channel.description = "Important stuff is announced here.";
|
||||
this.channel.title = "announcements";
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import CoreFabricators from "discourse/lib/fabricators";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
module("Discourse Chat | Component | chat-channel-row", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
this.categoryChatChannel = fabricators.channel();
|
||||
this.directMessageChannel = fabricators.directMessageChannel();
|
||||
this.categoryChatChannel = new ChatFabricators(getOwner(this)).channel();
|
||||
this.directMessageChannel = new ChatFabricators(
|
||||
getOwner(this)
|
||||
).directMessageChannel();
|
||||
});
|
||||
|
||||
test("links to correct channel", async function (assert) {
|
||||
|
@ -49,7 +53,9 @@ module("Discourse Chat | Component | chat-channel-row", function (hooks) {
|
|||
});
|
||||
|
||||
test("renders correct channel metadata", async function (assert) {
|
||||
this.categoryChatChannel.lastMessage = fabricators.message({
|
||||
this.categoryChatChannel.lastMessage = new ChatFabricators(
|
||||
getOwner(this)
|
||||
).message({
|
||||
created_at: moment().toISOString(),
|
||||
});
|
||||
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||
|
@ -152,8 +158,10 @@ module("Discourse Chat | Component | chat-channel-row", function (hooks) {
|
|||
});
|
||||
|
||||
test("user status with direct message channel", async function (assert) {
|
||||
this.directMessageChannel.chatable = fabricators.directMessage({
|
||||
users: [fabricators.user()],
|
||||
this.directMessageChannel.chatable = new ChatFabricators(
|
||||
getOwner(this)
|
||||
).directMessage({
|
||||
users: [new CoreFabricators(getOwner(this)).user()],
|
||||
});
|
||||
const status = { description: "Off to dentist", emoji: "tooth" };
|
||||
this.directMessageChannel.chatable.users[0].status = status;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
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 I18n from "discourse-i18n";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import {
|
||||
CHANNEL_STATUSES,
|
||||
channelStatusIcon,
|
||||
|
@ -13,7 +14,7 @@ module("Discourse Chat | Component | chat-channel-status", function (hooks) {
|
|||
setupRenderingTest(hooks);
|
||||
|
||||
test("renders nothing when channel is opened", async function (assert) {
|
||||
this.channel = fabricators.channel();
|
||||
this.channel = new ChatFabricators(getOwner(this)).channel();
|
||||
|
||||
await render(hbs`<ChatChannelStatus @channel={{this.channel}} />`);
|
||||
|
||||
|
@ -21,7 +22,9 @@ module("Discourse Chat | Component | chat-channel-status", function (hooks) {
|
|||
});
|
||||
|
||||
test("defaults to long format", async function (assert) {
|
||||
this.channel = fabricators.channel({ status: CHANNEL_STATUSES.closed });
|
||||
this.channel = new ChatFabricators(getOwner(this)).channel({
|
||||
status: CHANNEL_STATUSES.closed,
|
||||
});
|
||||
|
||||
await render(hbs`<ChatChannelStatus @channel={{this.channel}} />`);
|
||||
|
||||
|
@ -31,7 +34,7 @@ module("Discourse Chat | Component | chat-channel-status", function (hooks) {
|
|||
});
|
||||
|
||||
test("accepts a format argument", async function (assert) {
|
||||
this.channel = fabricators.channel({
|
||||
this.channel = new ChatFabricators(getOwner(this)).channel({
|
||||
status: CHANNEL_STATUSES.archived,
|
||||
});
|
||||
|
||||
|
@ -45,7 +48,7 @@ module("Discourse Chat | Component | chat-channel-status", function (hooks) {
|
|||
});
|
||||
|
||||
test("renders the correct icon", async function (assert) {
|
||||
this.channel = fabricators.channel({
|
||||
this.channel = new ChatFabricators(getOwner(this)).channel({
|
||||
status: CHANNEL_STATUSES.archived,
|
||||
});
|
||||
|
||||
|
@ -56,7 +59,7 @@ module("Discourse Chat | Component | chat-channel-status", function (hooks) {
|
|||
|
||||
test("renders archive status", async function (assert) {
|
||||
this.currentUser.admin = true;
|
||||
this.channel = fabricators.channel({
|
||||
this.channel = new ChatFabricators(getOwner(this)).channel({
|
||||
status: CHANNEL_STATUSES.archived,
|
||||
archive_failed: true,
|
||||
});
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render, triggerEvent, waitFor } from "@ember/test-helpers";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import { module, test } from "qunit";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import { publishToMessageBus } 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 | Component | chat-channel | status on mentions",
|
||||
|
@ -58,7 +59,7 @@ module(
|
|||
})
|
||||
);
|
||||
|
||||
this.channel = fabricators.channel({
|
||||
this.channel = new ChatFabricators(getOwner(this)).channel({
|
||||
id: channelId,
|
||||
currentUserMembership: { following: true },
|
||||
meta: { can_join_chat_channel: false },
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
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 fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
module(
|
||||
"Discourse Chat | Component | chat-composer-message-details",
|
||||
|
@ -10,7 +11,7 @@ module(
|
|||
setupRenderingTest(hooks);
|
||||
|
||||
test("data-id attribute", async function (assert) {
|
||||
this.message = fabricators.message();
|
||||
this.message = new ChatFabricators(getOwner(this)).message();
|
||||
|
||||
await render(
|
||||
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
||||
|
@ -22,7 +23,9 @@ module(
|
|||
});
|
||||
|
||||
test("editing a message has the pencil icon", async function (assert) {
|
||||
this.message = fabricators.message({ editing: true });
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
editing: true,
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
||||
|
@ -32,8 +35,10 @@ module(
|
|||
});
|
||||
|
||||
test("replying to a message has the reply icon", async function (assert) {
|
||||
const firstMessage = fabricators.message();
|
||||
this.message = fabricators.message({ inReplyTo: firstMessage });
|
||||
const firstMessage = new ChatFabricators(getOwner(this)).message();
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
inReplyTo: firstMessage,
|
||||
});
|
||||
|
||||
await render(
|
||||
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
||||
|
@ -43,7 +48,7 @@ module(
|
|||
});
|
||||
|
||||
test("displays user avatar", async function (assert) {
|
||||
this.message = fabricators.message();
|
||||
this.message = new ChatFabricators(getOwner(this)).message();
|
||||
|
||||
await render(
|
||||
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
||||
|
@ -55,7 +60,7 @@ module(
|
|||
});
|
||||
|
||||
test("displays message excerpt", async function (assert) {
|
||||
this.message = fabricators.message();
|
||||
this.message = new ChatFabricators(getOwner(this)).message();
|
||||
|
||||
await render(
|
||||
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
||||
|
@ -65,7 +70,7 @@ module(
|
|||
});
|
||||
|
||||
test("displays user’s username", async function (assert) {
|
||||
this.message = fabricators.message();
|
||||
this.message = new ChatFabricators(getOwner(this)).message();
|
||||
|
||||
await render(
|
||||
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
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 { exists, 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";
|
||||
import ChatMessage from "discourse/plugins/chat/discourse/models/chat-message";
|
||||
|
||||
module("Discourse Chat | Component | chat-message-avatar", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("chat_webhook_event", async function (assert) {
|
||||
this.message = ChatMessage.create(fabricators.channel(), {
|
||||
chat_webhook_event: { emoji: ":heart:" },
|
||||
});
|
||||
this.message = ChatMessage.create(
|
||||
new ChatFabricators(getOwner(this)).channel(),
|
||||
{
|
||||
chat_webhook_event: { emoji: ":heart:" },
|
||||
}
|
||||
);
|
||||
|
||||
await render(hbs`<Chat::Message::Avatar @message={{this.message}} />`);
|
||||
|
||||
|
@ -20,9 +24,12 @@ module("Discourse Chat | Component | chat-message-avatar", function (hooks) {
|
|||
});
|
||||
|
||||
test("user", async function (assert) {
|
||||
this.message = ChatMessage.create(fabricators.channel(), {
|
||||
user: { username: "discobot" },
|
||||
});
|
||||
this.message = ChatMessage.create(
|
||||
new ChatFabricators(getOwner(this)).channel(),
|
||||
{
|
||||
user: { username: "discobot" },
|
||||
}
|
||||
);
|
||||
|
||||
await render(hbs`<Chat::Message::Avatar @message={{this.message}} />`);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import { module, test } from "qunit";
|
||||
|
@ -5,7 +6,7 @@ import Bookmark from "discourse/models/bookmark";
|
|||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import I18n from "discourse-i18n";
|
||||
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 | Component | chat-message-info", function (hooks) {
|
||||
|
@ -16,7 +17,7 @@ module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|||
`;
|
||||
|
||||
test("chat_webhook_event", async function (assert) {
|
||||
this.message = fabricators.message({
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
chat_webhook_event: { username: "discobot" },
|
||||
});
|
||||
|
||||
|
@ -33,7 +34,7 @@ module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|||
});
|
||||
|
||||
test("user", async function (assert) {
|
||||
this.message = fabricators.message({
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
user: { username: "discobot" },
|
||||
});
|
||||
|
||||
|
@ -46,7 +47,7 @@ module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|||
});
|
||||
|
||||
test("date", async function (assert) {
|
||||
this.message = fabricators.message({
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
user: { username: "discobot" },
|
||||
created_at: moment(),
|
||||
});
|
||||
|
@ -57,7 +58,7 @@ module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|||
});
|
||||
|
||||
test("bookmark (with reminder)", async function (assert) {
|
||||
this.message = fabricators.message({
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
user: { username: "discobot" },
|
||||
bookmark: Bookmark.create({
|
||||
reminder_at: moment(),
|
||||
|
@ -73,12 +74,15 @@ module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|||
});
|
||||
|
||||
test("bookmark (no reminder)", async function (assert) {
|
||||
this.message = ChatMessage.create(fabricators.channel(), {
|
||||
user: { username: "discobot" },
|
||||
bookmark: Bookmark.create({
|
||||
name: "some name",
|
||||
}),
|
||||
});
|
||||
this.message = ChatMessage.create(
|
||||
new ChatFabricators(getOwner(this)).channel(),
|
||||
{
|
||||
user: { username: "discobot" },
|
||||
bookmark: Bookmark.create({
|
||||
name: "some name",
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
await render(template);
|
||||
|
||||
|
@ -87,7 +91,9 @@ module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|||
|
||||
test("user status", async function (assert) {
|
||||
const status = { description: "off to dentist", emoji: "tooth" };
|
||||
this.message = fabricators.message({ user: { status } });
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
user: { status },
|
||||
});
|
||||
|
||||
await render(template);
|
||||
|
||||
|
@ -95,7 +101,7 @@ module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|||
});
|
||||
|
||||
test("flag status", async function (assert) {
|
||||
this.message = fabricators.message({
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
user: { username: "discobot" },
|
||||
user_flag_status: 0,
|
||||
});
|
||||
|
@ -108,7 +114,7 @@ module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|||
});
|
||||
|
||||
test("reviewable", async function (assert) {
|
||||
this.message = fabricators.message({
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
user: { username: "discobot" },
|
||||
user_flag_status: 0,
|
||||
});
|
||||
|
@ -121,7 +127,7 @@ module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|||
});
|
||||
|
||||
test("with username classes", async function (assert) {
|
||||
this.message = fabricators.message({
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
user: {
|
||||
username: "discobot",
|
||||
admin: true,
|
||||
|
@ -141,7 +147,7 @@ module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|||
});
|
||||
|
||||
test("without username classes", async function (assert) {
|
||||
this.message = fabricators.message({
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
user: { username: "discobot" },
|
||||
});
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { getOwner } from "@ember/application";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import { module, test } from "qunit";
|
||||
import CoreFabricators from "discourse/lib/fabricators";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import I18n from "discourse-i18n";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
module(
|
||||
"Discourse Chat | Component | Chat::Message::LeftGutter",
|
||||
|
@ -15,7 +17,7 @@ module(
|
|||
`;
|
||||
|
||||
test("default", async function (assert) {
|
||||
this.message = fabricators.message();
|
||||
this.message = new ChatFabricators(getOwner(this)).message();
|
||||
|
||||
await render(template);
|
||||
|
||||
|
@ -23,7 +25,9 @@ module(
|
|||
});
|
||||
|
||||
test("with reviewable", async function (assert) {
|
||||
this.message = fabricators.message({ reviewable_id: 1 });
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
reviewable_id: 1,
|
||||
});
|
||||
|
||||
await render(template);
|
||||
|
||||
|
@ -33,7 +37,9 @@ module(
|
|||
});
|
||||
|
||||
test("with flag status", async function (assert) {
|
||||
this.message = fabricators.message({ user_flag_status: 0 });
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
user_flag_status: 0,
|
||||
});
|
||||
|
||||
await render(template);
|
||||
|
||||
|
@ -43,7 +49,9 @@ module(
|
|||
});
|
||||
|
||||
test("bookmark", async function (assert) {
|
||||
this.message = fabricators.message({ bookmark: fabricators.bookmark() });
|
||||
this.message = new ChatFabricators(getOwner(this)).message({
|
||||
bookmark: new CoreFabricators(getOwner(this)).bookmark(),
|
||||
});
|
||||
|
||||
await render(template);
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue