mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 01:57:15 +08:00
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:
@ -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";
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user