DEV: allows fabricators to use faker (#26555)

The complexity of the situation is that we don't want to load faker into production by default but fabricators and styleguide are available on production.

This is made possible through app/assets/javascripts/discourse/app/lib/load-faker.js which contains a function to ensure faker is loaded asynchronously (loadFaker) and another function to access the loaded faker (getLoadedFaker).

Note 1: this commit also refactors fabricators to have access to context and use faker where possible
Note 2: this commit moves automation to admin bundle

---------

Co-authored-by: David Taylor <david@taylorhq.com>
This commit is contained in:
Joffrey JAFFEUX
2024-04-08 21:00:09 +02:00
committed by GitHub
parent 1801e3d64c
commit 1060e4573a
121 changed files with 732 additions and 515 deletions

View File

@ -1,8 +1,9 @@
import { getOwner } from "@ember/application";
import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module(
"Discourse Chat | Component | chat-composer-message-details",
@ -10,7 +11,7 @@ module(
setupRenderingTest(hooks);
test("data-id attribute", async function (assert) {
this.message = fabricators.message();
this.message = new ChatFabricators(getOwner(this)).message();
await render(
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
@ -22,7 +23,9 @@ module(
});
test("editing a message has the pencil icon", async function (assert) {
this.message = fabricators.message({ editing: true });
this.message = new ChatFabricators(getOwner(this)).message({
editing: true,
});
await render(
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
@ -32,8 +35,10 @@ module(
});
test("replying to a message has the reply icon", async function (assert) {
const firstMessage = fabricators.message();
this.message = fabricators.message({ inReplyTo: firstMessage });
const firstMessage = new ChatFabricators(getOwner(this)).message();
this.message = new ChatFabricators(getOwner(this)).message({
inReplyTo: firstMessage,
});
await render(
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
@ -43,7 +48,7 @@ module(
});
test("displays user avatar", async function (assert) {
this.message = fabricators.message();
this.message = new ChatFabricators(getOwner(this)).message();
await render(
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
@ -55,7 +60,7 @@ module(
});
test("displays message excerpt", async function (assert) {
this.message = fabricators.message();
this.message = new ChatFabricators(getOwner(this)).message();
await render(
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
@ -65,7 +70,7 @@ module(
});
test("displays user’s username", async function (assert) {
this.message = fabricators.message();
this.message = new ChatFabricators(getOwner(this)).message();
await render(
hbs`<ChatComposerMessageDetails @message={{this.message}} />`