diff --git a/app/assets/javascripts/discourse/app/lib/fabricators.js b/app/assets/javascripts/discourse/app/lib/fabricators.js new file mode 100644 index 00000000000..f9c077291b7 --- /dev/null +++ b/app/assets/javascripts/discourse/app/lib/fabricators.js @@ -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, + }; + } +} diff --git a/app/assets/javascripts/discourse/app/lib/load-faker.js b/app/assets/javascripts/discourse/app/lib/load-faker.js index beb128de591..8c42c39d7f4 100644 --- a/app/assets/javascripts/discourse/app/lib/load-faker.js +++ b/app/assets/javascripts/discourse/app/lib/load-faker.js @@ -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; } diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index 6cf3fd99d20..63e87609e2b 100644 --- a/app/assets/javascripts/discourse/tests/setup-tests.js +++ b/app/assets/javascripts/discourse/tests/setup-tests.js @@ -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(); } diff --git a/plugins/automation/assets/javascripts/discourse/admin/adapters/discourse-automation-adapter.js b/plugins/automation/admin/assets/javascripts/admin/adapters/discourse-automation-adapter.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/admin/adapters/discourse-automation-adapter.js rename to plugins/automation/admin/assets/javascripts/admin/adapters/discourse-automation-adapter.js diff --git a/plugins/automation/assets/javascripts/discourse/admin/adapters/discourse-automation-automation.js b/plugins/automation/admin/assets/javascripts/admin/adapters/discourse-automation-automation.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/admin/adapters/discourse-automation-automation.js rename to plugins/automation/admin/assets/javascripts/admin/adapters/discourse-automation-automation.js diff --git a/plugins/automation/assets/javascripts/discourse/admin/adapters/discourse-automation-scriptable.js b/plugins/automation/admin/assets/javascripts/admin/adapters/discourse-automation-scriptable.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/admin/adapters/discourse-automation-scriptable.js rename to plugins/automation/admin/assets/javascripts/admin/adapters/discourse-automation-scriptable.js diff --git a/plugins/automation/assets/javascripts/discourse/admin/adapters/discourse-automation-triggerable.js b/plugins/automation/admin/assets/javascripts/admin/adapters/discourse-automation-triggerable.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/admin/adapters/discourse-automation-triggerable.js rename to plugins/automation/admin/assets/javascripts/admin/adapters/discourse-automation-triggerable.js diff --git a/plugins/automation/assets/javascripts/discourse/components/automation-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/automation-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/automation-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/automation-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-base-field.js b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-base-field.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-base-field.js rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-base-field.js diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-boolean-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-boolean-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-boolean-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-boolean-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-categories-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-categories-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-categories-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-categories-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-category-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-category-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-category-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-category-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-category-notification-level-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-category-notification-level-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-category-notification-level-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-category-notification-level-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-choices-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-choices-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-choices-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-choices-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-custom-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-custom-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-custom-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-custom-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-custom-fields.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-custom-fields.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-custom-fields.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-custom-fields.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-date-time-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-date-time-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-date-time-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-date-time-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-email-group-user-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-email-group-user-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-email-group-user-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-email-group-user-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-field-description.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-field-description.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-field-description.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-field-description.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-field-label.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-field-label.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-field-label.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-field-label.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-group-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-group-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-group-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-group-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-key-value-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-key-value-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-key-value-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-key-value-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-message-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-message-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-message-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-message-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-period-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-period-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-period-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-period-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-pms-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-pms-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-pms-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-pms-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-post-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-post-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-post-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-post-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-tags-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-tags-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-tags-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-tags-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-text-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-text-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-text-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-text-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-text-list-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-text-list-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-text-list-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-text-list-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-trust-levels-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-trust-levels-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-trust-levels-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-trust-levels-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-user-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-user-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-user-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-user-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-user-profile-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-user-profile-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-user-profile-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-user-profile-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/fields/da-users-field.gjs b/plugins/automation/admin/assets/javascripts/admin/components/fields/da-users-field.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/fields/da-users-field.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/fields/da-users-field.gjs diff --git a/plugins/automation/assets/javascripts/discourse/components/placeholders-list.gjs b/plugins/automation/admin/assets/javascripts/admin/components/placeholders-list.gjs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/components/placeholders-list.gjs rename to plugins/automation/admin/assets/javascripts/admin/components/placeholders-list.gjs diff --git a/plugins/automation/assets/javascripts/discourse/controllers/admin-plugins-discourse-automation-edit.js b/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-edit.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/controllers/admin-plugins-discourse-automation-edit.js rename to plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-edit.js diff --git a/plugins/automation/assets/javascripts/discourse/controllers/admin-plugins-discourse-automation-index.js b/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-index.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/controllers/admin-plugins-discourse-automation-index.js rename to plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-index.js diff --git a/plugins/automation/assets/javascripts/discourse/controllers/admin-plugins-discourse-automation-new.js b/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-new.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/controllers/admin-plugins-discourse-automation-new.js rename to plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation-new.js diff --git a/plugins/automation/assets/javascripts/discourse/controllers/admin-plugins-discourse-automation.js b/plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/controllers/admin-plugins-discourse-automation.js rename to plugins/automation/admin/assets/javascripts/admin/controllers/admin-plugins-discourse-automation.js diff --git a/plugins/automation/assets/javascripts/discourse/discourse-automation-route-map.js b/plugins/automation/admin/assets/javascripts/admin/discourse-automation-route-map.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/discourse-automation-route-map.js rename to plugins/automation/admin/assets/javascripts/admin/discourse-automation-route-map.js diff --git a/plugins/automation/assets/javascripts/discourse/helpers/format-enabled-automation.js b/plugins/automation/admin/assets/javascripts/admin/helpers/format-enabled-automation.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/helpers/format-enabled-automation.js rename to plugins/automation/admin/assets/javascripts/admin/helpers/format-enabled-automation.js diff --git a/plugins/automation/assets/javascripts/discourse/initializers/discourse-automation.js b/plugins/automation/admin/assets/javascripts/admin/initializers/discourse-automation.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/initializers/discourse-automation.js rename to plugins/automation/admin/assets/javascripts/admin/initializers/discourse-automation.js diff --git a/plugins/automation/admin/assets/javascripts/admin/lib/fabricators.js b/plugins/automation/admin/assets/javascripts/admin/lib/fabricators.js new file mode 100644 index 00000000000..9a2392ed5dc --- /dev/null +++ b/plugins/automation/admin/assets/javascripts/admin/lib/fabricators.js @@ -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; + } +} diff --git a/plugins/automation/assets/javascripts/discourse/admin/models/discourse-automation-automation.js b/plugins/automation/admin/assets/javascripts/admin/models/discourse-automation-automation.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/admin/models/discourse-automation-automation.js rename to plugins/automation/admin/assets/javascripts/admin/models/discourse-automation-automation.js diff --git a/plugins/automation/assets/javascripts/discourse/admin/models/discourse-automation-field.js b/plugins/automation/admin/assets/javascripts/admin/models/discourse-automation-field.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/admin/models/discourse-automation-field.js rename to plugins/automation/admin/assets/javascripts/admin/models/discourse-automation-field.js diff --git a/plugins/automation/assets/javascripts/discourse/admin/models/discourse-automation-script.js b/plugins/automation/admin/assets/javascripts/admin/models/discourse-automation-script.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/admin/models/discourse-automation-script.js rename to plugins/automation/admin/assets/javascripts/admin/models/discourse-automation-script.js diff --git a/plugins/automation/assets/javascripts/discourse/routes/admin-plugins-discourse-automation-edit.js b/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-edit.js similarity index 96% rename from plugins/automation/assets/javascripts/discourse/routes/admin-plugins-discourse-automation-edit.js rename to plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-edit.js index e8746126f90..9016555935d 100644 --- a/plugins/automation/assets/javascripts/discourse/routes/admin-plugins-discourse-automation-edit.js +++ b/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-edit.js @@ -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"; diff --git a/plugins/automation/assets/javascripts/discourse/routes/admin-plugins-discourse-automation-index.js b/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-index.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/routes/admin-plugins-discourse-automation-index.js rename to plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-index.js diff --git a/plugins/automation/assets/javascripts/discourse/routes/admin-plugins-discourse-automation-new.js b/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-new.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/routes/admin-plugins-discourse-automation-new.js rename to plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation-new.js diff --git a/plugins/automation/assets/javascripts/discourse/routes/admin-plugins-discourse-automation.js b/plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation.js similarity index 100% rename from plugins/automation/assets/javascripts/discourse/routes/admin-plugins-discourse-automation.js rename to plugins/automation/admin/assets/javascripts/admin/routes/admin-plugins-discourse-automation.js diff --git a/plugins/automation/assets/javascripts/discourse/templates/admin-plugins-discourse-automation-edit.hbs b/plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation-edit.hbs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/templates/admin-plugins-discourse-automation-edit.hbs rename to plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation-edit.hbs diff --git a/plugins/automation/assets/javascripts/discourse/templates/admin-plugins-discourse-automation-index.hbs b/plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation-index.hbs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/templates/admin-plugins-discourse-automation-index.hbs rename to plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation-index.hbs diff --git a/plugins/automation/assets/javascripts/discourse/templates/admin-plugins-discourse-automation-new.hbs b/plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation-new.hbs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/templates/admin-plugins-discourse-automation-new.hbs rename to plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation-new.hbs diff --git a/plugins/automation/assets/javascripts/discourse/templates/admin-plugins-discourse-automation.hbs b/plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation.hbs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/templates/admin-plugins-discourse-automation.hbs rename to plugins/automation/admin/assets/javascripts/admin/templates/admin-plugins-discourse-automation.hbs diff --git a/plugins/automation/assets/javascripts/discourse/templates/components/form-error.hbs b/plugins/automation/admin/assets/javascripts/admin/templates/components/form-error.hbs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/templates/components/form-error.hbs rename to plugins/automation/admin/assets/javascripts/admin/templates/components/form-error.hbs diff --git a/plugins/automation/assets/javascripts/discourse/templates/components/topic-trigger.hbs b/plugins/automation/admin/assets/javascripts/admin/templates/components/topic-trigger.hbs similarity index 100% rename from plugins/automation/assets/javascripts/discourse/templates/components/topic-trigger.hbs rename to plugins/automation/admin/assets/javascripts/admin/templates/components/topic-trigger.hbs diff --git a/plugins/automation/assets/javascripts/discourse/lib/fabricators.js b/plugins/automation/assets/javascripts/discourse/lib/fabricators.js deleted file mode 100644 index fd894b548d8..00000000000 --- a/plugins/automation/assets/javascripts/discourse/lib/fabricators.js +++ /dev/null @@ -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, -}; diff --git a/plugins/automation/test/javascripts/integration/components/da-boolean-field-test.js b/plugins/automation/test/javascripts/integration/components/da-boolean-field-test.js index fe68f57a7fa..558c94b0541 100644 --- a/plugins/automation/test/javascripts/integration/components/da-boolean-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-boolean-field-test.js @@ -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`` diff --git a/plugins/automation/test/javascripts/integration/components/da-categories-field-test.js b/plugins/automation/test/javascripts/integration/components/da-categories-field-test.js index 2589d2c44f5..23c47d7b032 100644 --- a/plugins/automation/test/javascripts/integration/components/da-categories-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-categories-field-test.js @@ -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`` diff --git a/plugins/automation/test/javascripts/integration/components/da-category-field-test.js b/plugins/automation/test/javascripts/integration/components/da-category-field-test.js index e306ed57bff..4de32b682e5 100644 --- a/plugins/automation/test/javascripts/integration/components/da-category-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-category-field-test.js @@ -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`` diff --git a/plugins/automation/test/javascripts/integration/components/da-category-notification-level-field-test.js b/plugins/automation/test/javascripts/integration/components/da-category-notification-level-field-test.js index d62be347fa6..61bff2b83e9 100644 --- a/plugins/automation/test/javascripts/integration/components/da-category-notification-level-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-category-notification-level-field-test.js @@ -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", }); diff --git a/plugins/automation/test/javascripts/integration/components/da-choices-field-test.js b/plugins/automation/test/javascripts/integration/components/da-choices-field-test.js index a01208ffeba..b2561c56665 100644 --- a/plugins/automation/test/javascripts/integration/components/da-choices-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-choices-field-test.js @@ -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 }] }, }); diff --git a/plugins/automation/test/javascripts/integration/components/da-custom-field-test.js b/plugins/automation/test/javascripts/integration/components/da-custom-field-test.js index 46e9d89964d..3cd64487b1a 100644 --- a/plugins/automation/test/javascripts/integration/components/da-custom-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-custom-field-test.js @@ -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`` diff --git a/plugins/automation/test/javascripts/integration/components/da-date-time-field-test.js b/plugins/automation/test/javascripts/integration/components/da-date-time-field-test.js index e3f791667ed..047233e4004 100644 --- a/plugins/automation/test/javascripts/integration/components/da-date-time-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-date-time-field-test.js @@ -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`` diff --git a/plugins/automation/test/javascripts/integration/components/da-group-field-test.js b/plugins/automation/test/javascripts/integration/components/da-group-field-test.js index afd461b5dd6..8002dc09318 100644 --- a/plugins/automation/test/javascripts/integration/components/da-group-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-group-field-test.js @@ -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`` diff --git a/plugins/automation/test/javascripts/integration/components/da-message-field-test.js b/plugins/automation/test/javascripts/integration/components/da-message-field-test.js index 054ce03e765..ab953eaef38 100644 --- a/plugins/automation/test/javascripts/integration/components/da-message-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-message-field-test.js @@ -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`` diff --git a/plugins/automation/test/javascripts/integration/components/da-pms-field-test.js b/plugins/automation/test/javascripts/integration/components/da-pms-field-test.js index 476badaa207..75df028186d 100644 --- a/plugins/automation/test/javascripts/integration/components/da-pms-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-pms-field-test.js @@ -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", }); diff --git a/plugins/automation/test/javascripts/integration/components/da-post-field-test.js b/plugins/automation/test/javascripts/integration/components/da-post-field-test.js index 3121d59f027..51de3bff6a5 100644 --- a/plugins/automation/test/javascripts/integration/components/da-post-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-post-field-test.js @@ -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`` diff --git a/plugins/automation/test/javascripts/integration/components/da-tags-field-test.js b/plugins/automation/test/javascripts/integration/components/da-tags-field-test.js index e8bf5ac6b84..bd8eced4c4c 100644 --- a/plugins/automation/test/javascripts/integration/components/da-tags-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-tags-field-test.js @@ -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", }); diff --git a/plugins/automation/test/javascripts/integration/components/da-text-field-test.js b/plugins/automation/test/javascripts/integration/components/da-text-field-test.js index 16b51200dc2..42261f2e08a 100644 --- a/plugins/automation/test/javascripts/integration/components/da-text-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-text-field-test.js @@ -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`` diff --git a/plugins/automation/test/javascripts/integration/components/da-text-list-field-test.js b/plugins/automation/test/javascripts/integration/components/da-text-list-field-test.js index 9e76ea9a089..e8d1819fa8e 100644 --- a/plugins/automation/test/javascripts/integration/components/da-text-list-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-text-list-field-test.js @@ -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", }); diff --git a/plugins/automation/test/javascripts/integration/components/da-trust-levels-field-test.js b/plugins/automation/test/javascripts/integration/components/da-trust-levels-field-test.js index 49a89796b17..401dbe94d02 100644 --- a/plugins/automation/test/javascripts/integration/components/da-trust-levels-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-trust-levels-field-test.js @@ -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", }); diff --git a/plugins/automation/test/javascripts/integration/components/da-user-field-test.js b/plugins/automation/test/javascripts/integration/components/da-user-field-test.js index 09154935e2e..1d57e24398e 100644 --- a/plugins/automation/test/javascripts/integration/components/da-user-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-user-field-test.js @@ -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", }); diff --git a/plugins/automation/test/javascripts/integration/components/da-users-field-test.js b/plugins/automation/test/javascripts/integration/components/da-users-field-test.js index 1a9b5cc1a72..2cd8bedab0a 100644 --- a/plugins/automation/test/javascripts/integration/components/da-users-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-users-field-test.js @@ -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", }); diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-composer-message-details.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-composer-message-details.js index 3b70cc84536..ba89ec206f3 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-composer-message-details.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-composer-message-details.js @@ -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; diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-composer.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-composer.js index 2c40d72e1b4..f24a99a15f5 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-composer.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-composer.js @@ -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() { diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-message.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-message.js index fea3465a2bf..18605fa7b62 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-message.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-message.js @@ -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(), + ]; } } } diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-archive-channel.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-archive-channel.js index fcb31a8764c..2870ba46c85 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-archive-channel.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-archive-channel.js @@ -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() { diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-channel-summary.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-channel-summary.js index 65f2c6e0c04..af2007f5af2 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-channel-summary.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-channel-summary.js @@ -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 }, }); } } diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-delete-channel.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-delete-channel.js index 05f3770f9c2..60f1966646c 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-delete-channel.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-delete-channel.js @@ -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() { diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-description.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-description.js index 852090a201e..3700697342c 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-description.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-description.js @@ -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() { diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-name.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-name.js index 0d6f65edcdf..75390e030b3 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-name.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-edit-channel-name.js @@ -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() { diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-move-message-to-channel.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-move-message-to-channel.js index c53fb0a72c2..d2596799a38 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-move-message-to-channel.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-move-message-to-channel.js @@ -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"), }, }); diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-thread-settings.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-thread-settings.js index 4a758ffae69..7cb42f686d9 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-thread-settings.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-thread-settings.js @@ -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(), }); } } diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-toggle-channel-status.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-toggle-channel-status.js index 65a9079bd20..8e4e5fcbdbe 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-toggle-channel-status.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-modal-toggle-channel-status.js @@ -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(), }); } } diff --git a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-thread-list-item.js b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-thread-list-item.js index dd197e0b03c..53332749faa 100644 --- a/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-thread-list-item.js +++ b/plugins/chat/assets/javascripts/discourse/components/styleguide/chat-thread-list-item.js @@ -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(); } diff --git a/plugins/chat/assets/javascripts/discourse/lib/fabricators.js b/plugins/chat/assets/javascripts/discourse/lib/fabricators.js index a7189ce0dcb..2d02a06207c 100644 --- a/plugins/chat/assets/javascripts/discourse/lib/fabricators.js +++ b/plugins/chat/assets/javascripts/discourse/lib/fabricators.js @@ -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, + }); + } +} diff --git a/plugins/chat/test/javascripts/components/channel-icon-test.gjs b/plugins/chat/test/javascripts/components/channel-icon-test.gjs index 1f1afdc33ce..a750d786ac3 100644 --- a/plugins/chat/test/javascripts/components/channel-icon-test.gjs +++ b/plugins/chat/test/javascripts/components/channel-icon-test.gjs @@ -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 | ", function (hooks) { setupRenderingTest(hooks); test("category channel - badge", async function (assert) { - const channel = fabricators.channel(); + const channel = new ChatFabricators(getOwner(this)).channel(); await render(); @@ -21,7 +23,7 @@ module("Discourse Chat | Component | ", 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: "
evil
", }); @@ -32,8 +34,10 @@ module("Discourse Chat | Component | ", 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(); @@ -42,8 +46,10 @@ module("Discourse Chat | Component | ", 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(); @@ -52,9 +58,9 @@ module("Discourse Chat | Component | ", 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 | ", 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; diff --git a/plugins/chat/test/javascripts/components/channel-name-test.gjs b/plugins/chat/test/javascripts/components/channel-name-test.gjs index 6f47ba46a0b..6ce8284af8c 100644 --- a/plugins/chat/test/javascripts/components/channel-name-test.gjs +++ b/plugins/chat/test/javascripts/components/channel-name-test.gjs @@ -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 | ", function (hooks) { setupRenderingTest(hooks); test("category channel - label", async function (assert) { - const channel = fabricators.channel(); + const channel = new ChatFabricators(getOwner(this)).channel(); await render(); @@ -20,7 +22,7 @@ module("Discourse Chat | Component | ", 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: "
evil
", }); @@ -31,9 +33,9 @@ module("Discourse Chat | Component | ", 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 | ", 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; diff --git a/plugins/chat/test/javascripts/components/channel-title-test.gjs b/plugins/chat/test/javascripts/components/channel-title-test.gjs index d9e6dca9f71..21d1257b7a4 100644 --- a/plugins/chat/test/javascripts/components/channel-title-test.gjs +++ b/plugins/chat/test/javascripts/components/channel-title-test.gjs @@ -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 | ", function (hooks) { setupRenderingTest(hooks); test("icon", async function (assert) { - const channel = fabricators.channel(); + const channel = new ChatFabricators(getOwner(this)).channel(); await render(); @@ -16,7 +17,7 @@ module("Discourse Chat | Component | ", function (hooks) { }); test("label", async function (assert) { - const channel = fabricators.channel(); + const channel = new ChatFabricators(getOwner(this)).channel(); await render(); diff --git a/plugins/chat/test/javascripts/components/chat-channel-card-test.js b/plugins/chat/test/javascripts/components/chat-channel-card-test.js index 153757bdcab..167c4f281df 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-card-test.js +++ b/plugins/chat/test/javascripts/components/chat-channel-card-test.js @@ -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``); - assert.true(exists(".d-icon-lock")); - assert.strictEqual( - query(".chat-channel-card").style.borderLeftColor, - "rgb(213, 99, 83)" - ); }); }); diff --git a/plugins/chat/test/javascripts/components/chat-channel-leave-btn-test.js b/plugins/chat/test/javascripts/components/chat-channel-leave-btn-test.js index 2c54258ec14..c26ad2a1534 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-leave-btn-test.js +++ b/plugins/chat/test/javascripts/components/chat-channel-leave-btn-test.js @@ -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`` @@ -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``); @@ -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``); @@ -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``); diff --git a/plugins/chat/test/javascripts/components/chat-channel-metadata-test.js b/plugins/chat/test/javascripts/components/chat-channel-metadata-test.js index 53f64e92725..51ab4a81fc6 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-metadata-test.js +++ b/plugins/chat/test/javascripts/components/chat-channel-metadata-test.js @@ -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; diff --git a/plugins/chat/test/javascripts/components/chat-channel-preview-card-test.js b/plugins/chat/test/javascripts/components/chat-channel-preview-card-test.js index 3e8f395defa..915bf551a20 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-preview-card-test.js +++ b/plugins/chat/test/javascripts/components/chat-channel-preview-card-test.js @@ -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"; diff --git a/plugins/chat/test/javascripts/components/chat-channel-row-test.js b/plugins/chat/test/javascripts/components/chat-channel-row-test.js index 0cd7d4dde5d..4acdbcb467e 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-row-test.js +++ b/plugins/chat/test/javascripts/components/chat-channel-row-test.js @@ -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``); @@ -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; diff --git a/plugins/chat/test/javascripts/components/chat-channel-status-test.js b/plugins/chat/test/javascripts/components/chat-channel-status-test.js index d3b489c7a0e..77253727527 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-status-test.js +++ b/plugins/chat/test/javascripts/components/chat-channel-status-test.js @@ -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``); @@ -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``); @@ -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, }); diff --git a/plugins/chat/test/javascripts/components/chat-channel-test.js b/plugins/chat/test/javascripts/components/chat-channel-test.js index 69c9bd08992..69db4e461f9 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-test.js +++ b/plugins/chat/test/javascripts/components/chat-channel-test.js @@ -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 }, diff --git a/plugins/chat/test/javascripts/components/chat-composer-message-details-test.js b/plugins/chat/test/javascripts/components/chat-composer-message-details-test.js index 61705a470f4..efe9ae6c4b4 100644 --- a/plugins/chat/test/javascripts/components/chat-composer-message-details-test.js +++ b/plugins/chat/test/javascripts/components/chat-composer-message-details-test.js @@ -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`` @@ -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`` @@ -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`` @@ -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`` @@ -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`` @@ -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`` diff --git a/plugins/chat/test/javascripts/components/chat-message-avatar-test.js b/plugins/chat/test/javascripts/components/chat-message-avatar-test.js index f51460bd4a8..b0272be8c60 100644 --- a/plugins/chat/test/javascripts/components/chat-message-avatar-test.js +++ b/plugins/chat/test/javascripts/components/chat-message-avatar-test.js @@ -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``); @@ -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``); diff --git a/plugins/chat/test/javascripts/components/chat-message-info-test.js b/plugins/chat/test/javascripts/components/chat-message-info-test.js index ecd4b8cf139..293d70c96e9 100644 --- a/plugins/chat/test/javascripts/components/chat-message-info-test.js +++ b/plugins/chat/test/javascripts/components/chat-message-info-test.js @@ -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" }, }); diff --git a/plugins/chat/test/javascripts/components/chat-message-left-gutter-test.js b/plugins/chat/test/javascripts/components/chat-message-left-gutter-test.js index 58d3866daf5..80577b377ea 100644 --- a/plugins/chat/test/javascripts/components/chat-message-left-gutter-test.js +++ b/plugins/chat/test/javascripts/components/chat-message-left-gutter-test.js @@ -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); diff --git a/plugins/chat/test/javascripts/components/chat-message-test.js b/plugins/chat/test/javascripts/components/chat-message-test.js index deef63f5960..14dc787e756 100644 --- a/plugins/chat/test/javascripts/components/chat-message-test.js +++ b/plugins/chat/test/javascripts/components/chat-message-test.js @@ -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 } 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-message", function (hooks) { setupRenderingTest(hooks); @@ -13,14 +14,16 @@ module("Discourse Chat | Component | chat-message", function (hooks) { `; test("Message with edits", async function (assert) { - this.message = fabricators.message({ edited: true }); + this.message = new ChatFabricators(getOwner(this)).message({ + edited: true, + }); await render(template); assert.true(exists(".chat-message-edited"), "has the correct css class"); }); test("Deleted message", async function (assert) { - this.message = fabricators.message({ + this.message = new ChatFabricators(getOwner(this)).message({ user: this.currentUser, deleted_at: moment(), }); @@ -33,7 +36,9 @@ module("Discourse Chat | Component | chat-message", function (hooks) { }); test("Hidden message", async function (assert) { - this.message = fabricators.message({ hidden: true }); + this.message = new ChatFabricators(getOwner(this)).message({ + hidden: true, + }); await render(template); assert.true( @@ -43,7 +48,9 @@ module("Discourse Chat | Component | chat-message", function (hooks) { }); test("Message with reply", async function (assert) { - this.message = fabricators.message({ inReplyTo: fabricators.message() }); + this.message = new ChatFabricators(getOwner(this)).message({ + inReplyTo: new ChatFabricators(getOwner(this)).message(), + }); await render(template); assert.true( diff --git a/plugins/chat/test/javascripts/components/chat-modal-archive-channel-test.js b/plugins/chat/test/javascripts/components/chat-modal-archive-channel-test.js index be645a37a5b..75f048e76d1 100644 --- a/plugins/chat/test/javascripts/components/chat-modal-archive-channel-test.js +++ b/plugins/chat/test/javascripts/components/chat-modal-archive-channel-test.js @@ -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 { 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 | ", @@ -11,7 +12,7 @@ module( setupRenderingTest(hooks); test("channel title is escaped in instructions correctly", async function (assert) { - this.channel = fabricators.channel({ + this.channel = new ChatFabricators(getOwner(this)).channel({ title: ``, }); diff --git a/plugins/chat/test/javascripts/components/chat-modal-delete-channel-test.js b/plugins/chat/test/javascripts/components/chat-modal-delete-channel-test.js index 9d3d58d49bc..bf7a5bcc9c0 100644 --- a/plugins/chat/test/javascripts/components/chat-modal-delete-channel-test.js +++ b/plugins/chat/test/javascripts/components/chat-modal-delete-channel-test.js @@ -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 { 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 | ", @@ -11,7 +12,7 @@ module( setupRenderingTest(hooks); test("channel title is escaped in instructions correctly", async function (assert) { - this.channel = fabricators.channel({ + this.channel = new ChatFabricators(getOwner(this)).channel({ title: ``, }); diff --git a/plugins/chat/test/javascripts/components/chat-modal-move-message-to-channel-test.js b/plugins/chat/test/javascripts/components/chat-modal-move-message-to-channel-test.js index 20511df4bf6..f627cc1337b 100644 --- a/plugins/chat/test/javascripts/components/chat-modal-move-message-to-channel-test.js +++ b/plugins/chat/test/javascripts/components/chat-modal-move-message-to-channel-test.js @@ -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 { 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 | ", @@ -11,7 +12,7 @@ module( setupRenderingTest(hooks); test("channel title is escaped in instructions correctly", async function (assert) { - this.channel = fabricators.channel({ + this.channel = new ChatFabricators(getOwner(this)).channel({ title: "", }); this.selectedMessageIds = [this.channel.id]; diff --git a/plugins/chat/test/javascripts/components/chat-notices-test.js b/plugins/chat/test/javascripts/components/chat-notices-test.js index 0a6782029e2..5257dd37c0a 100644 --- a/plugins/chat/test/javascripts/components/chat-notices-test.js +++ b/plugins/chat/test/javascripts/components/chat-notices-test.js @@ -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,13 +6,13 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import pretender from "discourse/tests/helpers/create-pretender"; import { query, queryAll } 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-notice", function (hooks) { setupRenderingTest(hooks); test("displays all notices for a channel", async function (assert) { - this.channel = fabricators.channel(); + this.channel = new ChatFabricators(getOwner(this)).channel(); this.manager = this.container.lookup( "service:chat-channel-notices-manager" ); @@ -39,7 +40,7 @@ module("Discourse Chat | Component | chat-notice", function (hooks) { }); test("Notices can be cleared", async function (assert) { - this.channel = fabricators.channel(); + this.channel = new ChatFabricators(getOwner(this)).channel(); this.manager = this.container.lookup( "service:chat-channel-notices-manager" ); @@ -65,7 +66,7 @@ module("Discourse Chat | Component | chat-notice", function (hooks) { ); }); test("MentionWithoutMembership notice renders", async function (assert) { - this.channel = fabricators.channel(); + this.channel = new ChatFabricators(getOwner(this)).channel(); this.manager = this.container.lookup( "service:chat-channel-notices-manager" ); diff --git a/plugins/chat/test/javascripts/components/chat-replying-indicator-test.js b/plugins/chat/test/javascripts/components/chat-replying-indicator-test.js index e087be17b6c..5e2900d0d41 100644 --- a/plugins/chat/test/javascripts/components/chat-replying-indicator-test.js +++ b/plugins/chat/test/javascripts/components/chat-replying-indicator-test.js @@ -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"; @@ -7,7 +8,7 @@ import { leaveChannel, } from "discourse/tests/helpers/presence-pretender"; 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"; async function addUser(id, username, channelName = "/chat-reply/1") { await joinChannel(channelName, { @@ -87,7 +88,7 @@ module( }); test("displays indicator when 2 or 3 users are replying", async function (assert) { - this.channel = fabricators.channel(); + this.channel = new ChatFabricators(getOwner(this)).channel(); await render( hbs`` @@ -102,7 +103,7 @@ module( }); test("displays indicator when 3 users are replying", async function (assert) { - this.channel = fabricators.channel(); + this.channel = new ChatFabricators(getOwner(this)).channel(); await render( hbs`` @@ -118,7 +119,7 @@ module( }); test("displays indicator when more than 3 users are replying", async function (assert) { - this.channel = fabricators.channel(); + this.channel = new ChatFabricators(getOwner(this)).channel(); await render( hbs`` @@ -135,7 +136,7 @@ module( }); test("filters current user from list of repliers", async function (assert) { - this.channel = fabricators.channel(); + this.channel = new ChatFabricators(getOwner(this)).channel(); await render( hbs`` diff --git a/plugins/chat/test/javascripts/components/chat-retention-reminder-text-test.js b/plugins/chat/test/javascripts/components/chat-retention-reminder-text-test.js index 4f6f5b75f10..cfd98d9adcb 100644 --- a/plugins/chat/test/javascripts/components/chat-retention-reminder-text-test.js +++ b/plugins/chat/test/javascripts/components/chat-retention-reminder-text-test.js @@ -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"; module( "Discourse Chat | Component | chat-retention-reminder-text", @@ -11,7 +12,7 @@ module( setupRenderingTest(hooks); test("when setting is set on 0", async function (assert) { - this.channel = fabricators.channel(); + this.channel = new ChatFabricators(getOwner(this)).channel(); this.siteSettings.chat_channel_retention_days = 0; await render( @@ -33,7 +34,7 @@ module( test("when channel is a public channel", async function (assert) { const count = 10; - this.channel = fabricators.channel(); + this.channel = new ChatFabricators(getOwner(this)).channel(); this.siteSettings.chat_channel_retention_days = count; await render( @@ -55,7 +56,7 @@ module( test("when channel is a DM channel", async function (assert) { const count = 10; - this.channel = fabricators.directMessageChannel(); + this.channel = new ChatFabricators(getOwner(this)).directMessageChannel(); this.siteSettings.chat_dm_retention_days = count; await render( diff --git a/plugins/chat/test/javascripts/components/chat-thread-header-test.js b/plugins/chat/test/javascripts/components/chat-thread-header-test.js index 56ab3c7bda7..883d838f390 100644 --- a/plugins/chat/test/javascripts/components/chat-thread-header-test.js +++ b/plugins/chat/test/javascripts/components/chat-thread-header-test.js @@ -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 | Component | chat-thread-header", function (hooks) { setupRenderingTest(hooks); test("it safely renders title", async function (assert) { const title = ""; - this.thread = fabricators.thread({ title }); + this.thread = new ChatFabricators(getOwner(this)).thread({ title }); await render(hbs` diff --git a/plugins/chat/test/javascripts/components/chat-thread-list-item-test.js b/plugins/chat/test/javascripts/components/chat-thread-list-item-test.js index 18b7bdae4f7..04dcf375904 100644 --- a/plugins/chat/test/javascripts/components/chat-thread-list-item-test.js +++ b/plugins/chat/test/javascripts/components/chat-thread-list-item-test.js @@ -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 | Component | chat-thread-list-item", function (hooks) { setupRenderingTest(hooks); test("it safely renders title", async function (assert) { const title = ""; - this.thread = fabricators.thread({ title }); + this.thread = new ChatFabricators(getOwner(this)).thread({ title }); await render(hbs` diff --git a/plugins/chat/test/javascripts/components/chat-thread-participants-test.js b/plugins/chat/test/javascripts/components/chat-thread-participants-test.js index 4310c7866b5..f399d54d125 100644 --- a/plugins/chat/test/javascripts/components/chat-thread-participants-test.js +++ b/plugins/chat/test/javascripts/components/chat-thread-participants-test.js @@ -1,8 +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 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 | ", @@ -10,21 +12,25 @@ module( setupRenderingTest(hooks); test("no participants", async function (assert) { - this.thread = fabricators.thread(); + this.thread = new ChatFabricators(getOwner(this)).thread(); await render(hbs``); assert.dom(".chat-thread-participants").doesNotExist(); }); test("@includeOriginalMessageUser=true", async function (assert) { - const originalMessageUser = fabricators.user({ username: "bob" }); - this.thread = fabricators.thread({ - original_message: fabricators.message({ user: originalMessageUser }), - preview: fabricators.threadPreview({ + const originalMessageUser = new CoreFabricators(getOwner(this)).user({ + username: "bob", + }); + this.thread = new ChatFabricators(getOwner(this)).thread({ + original_message: new ChatFabricators(getOwner(this)).message({ + user: originalMessageUser, + }), + preview: new ChatFabricators(getOwner(this)).threadPreview({ channel: this.channel, participant_users: [ originalMessageUser, - fabricators.user({ username: "alice" }), + new CoreFabricators(getOwner(this)).user({ username: "alice" }), ], }), }); @@ -35,14 +41,18 @@ module( }); test("@includeOriginalMessageUser=false", async function (assert) { - const originalMessageUser = fabricators.user({ username: "bob" }); - this.thread = fabricators.thread({ - original_message: fabricators.message({ user: originalMessageUser }), - preview: fabricators.threadPreview({ + const originalMessageUser = new CoreFabricators(getOwner(this)).user({ + username: "bob", + }); + this.thread = new ChatFabricators(getOwner(this)).thread({ + original_message: new ChatFabricators(getOwner(this)).message({ + user: originalMessageUser, + }), + preview: new ChatFabricators(getOwner(this)).threadPreview({ channel: this.channel, participant_users: [ originalMessageUser, - fabricators.user({ username: "alice" }), + new CoreFabricators(getOwner(this)).user({ username: "alice" }), ], }), }); diff --git a/plugins/chat/test/javascripts/components/chat-user-avatar-test.js b/plugins/chat/test/javascripts/components/chat-user-avatar-test.js index d2d2996b754..50f100ae758 100644 --- a/plugins/chat/test/javascripts/components/chat-user-avatar-test.js +++ b/plugins/chat/test/javascripts/components/chat-user-avatar-test.js @@ -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 CoreFabricators from "discourse/lib/fabricators"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; -import fabricators from "discourse/plugins/chat/discourse/lib/fabricators"; function containerSelector(user, options = {}) { let onlineSelector = ":not(.is-online)"; @@ -17,7 +18,7 @@ module("Discourse Chat | Component | ", function (hooks) { setupRenderingTest(hooks); test("when user is not online", async function (assert) { - this.user = fabricators.user(); + this.user = new CoreFabricators(getOwner(this)).user(); this.chat = { presenceChannel: { users: [] } }; await render( @@ -28,7 +29,7 @@ module("Discourse Chat | Component | ", function (hooks) { }); test("user is online", async function (assert) { - this.user = fabricators.user(); + this.user = new CoreFabricators(getOwner(this)).user(); this.chat = { presenceChannel: { users: [{ id: this.user.id }] }, }; @@ -41,7 +42,7 @@ module("Discourse Chat | Component | ", function (hooks) { }); test("@showPresence=false", async function (assert) { - this.user = fabricators.user(); + this.user = new CoreFabricators(getOwner(this)).user(); this.chat = { presenceChannel: { users: [{ id: this.user.id }] }, }; @@ -54,7 +55,7 @@ module("Discourse Chat | Component | ", function (hooks) { }); test("@interactive=true", async function (assert) { - this.user = fabricators.user(); + this.user = new CoreFabricators(getOwner(this)).user(); await render( hbs`` diff --git a/plugins/chat/test/javascripts/components/chat-user-card-button-test.js b/plugins/chat/test/javascripts/components/chat-user-card-button-test.js index 27645408ca4..a0f200a695d 100644 --- a/plugins/chat/test/javascripts/components/chat-user-card-button-test.js +++ b/plugins/chat/test/javascripts/components/chat-user-card-button-test.js @@ -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 sinon from "sinon"; +import CoreFabricators from "discourse/lib/fabricators"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; -import fabricators from "discourse/plugins/chat/discourse/lib/fabricators"; module( "Discourse Chat | Component | ", @@ -14,7 +15,7 @@ module( sinon .stub(this.owner.lookup("service:chat"), "userCanDirectMessage") .value(true); - this.user = fabricators.user(); + this.user = new CoreFabricators(getOwner(this)).user(); await render( hbs`` @@ -27,7 +28,7 @@ module( sinon .stub(this.owner.lookup("service:chat"), "userCanDirectMessage") .value(false); - this.user = fabricators.user(); + this.user = new CoreFabricators(getOwner(this)).user(); await render( hbs`` @@ -43,7 +44,7 @@ module( .stub(this.owner.lookup("service:chat"), "userCanDirectMessage") .value(true); - this.user = fabricators.user({ + this.user = new CoreFabricators(getOwner(this)).user({ suspended_till: moment().add(1, "year").toDate(), }); diff --git a/plugins/chat/test/javascripts/unit/helpers/format-chat-date-test.js b/plugins/chat/test/javascripts/unit/helpers/format-chat-date-test.js index fcc463ffc0b..0474992b312 100644 --- a/plugins/chat/test/javascripts/unit/helpers/format-chat-date-test.js +++ b/plugins/chat/test/javascripts/unit/helpers/format-chat-date-test.js @@ -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)}}` diff --git a/plugins/chat/test/javascripts/unit/lib/get-reaction-text-test.js b/plugins/chat/test/javascripts/unit/lib/get-reaction-text-test.js index d8ff01ac7d6..38a97ec7739 100644 --- a/plugins/chat/test/javascripts/unit/lib/get-reaction-text-test.js +++ b/plugins/chat/test/javascripts/unit/lib/get-reaction-text-test.js @@ -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()), "martin reacted with :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()), "claude and martin reacted with :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()), "user0, user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, user11, user12, user13, user14 and 1 other reacted with :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()), "user0, user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, user11, user12 and user13 reacted with :heart:" ); }); diff --git a/plugins/chat/test/javascripts/unit/models/chat-message-test.js b/plugins/chat/test/javascripts/unit/models/chat-message-test.js index 091d5bfd4e4..751cd7298fe 100644 --- a/plugins/chat/test/javascripts/unit/models/chat-message-test.js +++ b/plugins/chat/test/javascripts/unit/models/chat-message-test.js @@ -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); diff --git a/plugins/chat/test/javascripts/unit/services/chat-drafts-manager-test.js b/plugins/chat/test/javascripts/unit/services/chat-drafts-manager-test.js index 1c5a4bad213..1d634b1a9c9 100644 --- a/plugins/chat/test/javascripts/unit/services/chat-drafts-manager-test.js +++ b/plugins/chat/test/javascripts/unit/services/chat-drafts-manager-test.js @@ -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); diff --git a/plugins/chat/test/javascripts/unit/services/chat-guardian-test.js b/plugins/chat/test/javascripts/unit/services/chat-guardian-test.js index 106ff523fa6..32c1340f55b 100644 --- a/plugins/chat/test/javascripts/unit/services/chat-guardian-test.js +++ b/plugins/chat/test/javascripts/unit/services/chat-guardian-test.js @@ -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); diff --git a/plugins/chat/test/javascripts/unit/utility/plugin-api-test.js b/plugins/chat/test/javascripts/unit/utility/plugin-api-test.js index 9c48c47c38e..6c6d024b91d 100644 --- a/plugins/chat/test/javascripts/unit/utility/plugin-api-test.js +++ b/plugins/chat/test/javascripts/unit/utility/plugin-api-test.js @@ -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"; diff --git a/plugins/styleguide/assets/javascripts/discourse/components/sections/organisms/modal.js b/plugins/styleguide/assets/javascripts/discourse/components/sections/organisms/modal.js index b0ebcea4496..3e4e0aa6b4b 100644 --- a/plugins/styleguide/assets/javascripts/discourse/components/sections/organisms/modal.js +++ b/plugins/styleguide/assets/javascripts/discourse/components/sections/organisms/modal.js @@ -1,18 +1,16 @@ import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { action } from "@ember/object"; -import { service } from "@ember/service"; +import { getLoadedFaker } from "discourse/lib/load-faker"; import I18n from "discourse-i18n"; export default class extends Component { - @service styleguide; - @tracked inline = true; @tracked hideHeader = false; @tracked dismissable = true; @tracked modalTagName = "div"; @tracked title = I18n.t("styleguide.sections.modal.header"); - @tracked body = this.styleguide.faker.lorem.lines(5); + @tracked body = getLoadedFaker().faker.lorem.lines(5); @tracked subtitle = ""; @tracked flash = ""; @tracked flashType = "success"; diff --git a/plugins/styleguide/assets/javascripts/discourse/routes/styleguide.js b/plugins/styleguide/assets/javascripts/discourse/routes/styleguide.js index abb5a486b0a..5977bfe1fb9 100644 --- a/plugins/styleguide/assets/javascripts/discourse/routes/styleguide.js +++ b/plugins/styleguide/assets/javascripts/discourse/routes/styleguide.js @@ -1,12 +1,10 @@ import Route from "@ember/routing/route"; -import { service } from "@ember/service"; +import loadFaker from "discourse/lib/load-faker"; import { allCategories } from "discourse/plugins/styleguide/discourse/lib/styleguide"; export default class Styleguide extends Route { - @service styleguide; - async model() { - await this.styleguide.ensureFakerLoaded(); // So that it can be used synchronously in styleguide components + await loadFaker(); // So that it can be used synchronously in styleguide components return allCategories(); } diff --git a/plugins/styleguide/assets/javascripts/discourse/services/styleguide.js b/plugins/styleguide/assets/javascripts/discourse/services/styleguide.js deleted file mode 100644 index c4688eb6149..00000000000 --- a/plugins/styleguide/assets/javascripts/discourse/services/styleguide.js +++ /dev/null @@ -1,10 +0,0 @@ -import Service from "@ember/service"; -import loadFaker from "discourse/lib/load-faker"; - -export default class StyleguideService extends Service { - faker; - - async ensureFakerLoaded() { - this.faker ||= (await loadFaker()).faker; - } -}