DEV: Introduce faker.js for use in tests & styleguide (#26533)

Available as a normal synchronous module in tests
Available as an async import in core, or via the `loadFaker` helper in themes/plugins (which cannot use async import directly)
This commit is contained in:
David Taylor
2024-04-05 16:57:17 +01:00
committed by GitHub
parent 9c38ff7b38
commit 1df97e86c1
7 changed files with 33 additions and 2 deletions

View File

@ -1,15 +1,18 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { service } from "@ember/service";
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.args.dummy.shortLorem;
@tracked body = this.styleguide.faker.lorem.lines(5);
@tracked subtitle = "";
@tracked flash = "";
@tracked flashType = "success";

View File

@ -1,8 +1,12 @@
import Route from "@ember/routing/route";
import { service } from "@ember/service";
import { allCategories } from "discourse/plugins/styleguide/discourse/lib/styleguide";
export default class Styleguide extends Route {
model() {
@service styleguide;
async model() {
await this.styleguide.ensureFakerLoaded(); // So that it can be used synchronously in styleguide components
return allCategories();
}

View File

@ -0,0 +1,10 @@
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;
}
}