-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create fixtures for blocks as services
- Loading branch information
1 parent
9d6a8ec
commit dc5d9ad
Showing
32 changed files
with
779 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+840 KB
demo/api/src/db/fixtures/assets/videos/meer-vogelperspektive-natur-ozean-480p.mp4
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,56 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { ConfigModule } from "@src/config/config.module"; | ||
import { FixturesConsole } from "@src/db/fixtures/fixtures.console"; | ||
import { ImageGeneratorService } from "@src/db/fixtures/generators/image-generator.service"; | ||
import { FileGeneratorService } from "@src/db/fixtures/generators/file-generator.service"; | ||
import { LinksModule } from "@src/links/links.module"; | ||
import { PagesModule } from "@src/pages/pages.module"; | ||
import { ConsoleModule } from "nestjs-console"; | ||
|
||
import { AnchorBlockGeneratorService } from "./generators/blocks/anchor.generator"; | ||
import { ColumnsBlockGeneratorService } from "./generators/blocks/columns.generator"; | ||
import { DamImageBlockGeneratorService } from "./generators/blocks/dam-image.generator"; | ||
import { DamVideoBlockGeneratorService } from "./generators/blocks/dam-video.generator"; | ||
import { FullWidthImageBlockGeneratorService } from "./generators/blocks/full-width-image.generator"; | ||
import { HeadlineBlockGeneratorService } from "./generators/blocks/headline.generator"; | ||
import { LinkBlockGeneratorService } from "./generators/blocks/link.generator"; | ||
import { LinkListBlockGeneratorService } from "./generators/blocks/link-list.generator"; | ||
import { PageContentBlockGeneratorService } from "./generators/blocks/page-content-block.generator"; | ||
import { PixelImageBlockGeneratorService } from "./generators/blocks/pixel-image.generator"; | ||
import { RichTextBlockGeneratorService } from "./generators/blocks/richtext.generator"; | ||
import { SeoBlockGeneratorService } from "./generators/blocks/seo.generator"; | ||
import { SpaceBlockGeneratorService } from "./generators/blocks/space.generator"; | ||
import { SvgImageBlockGeneratorService } from "./generators/blocks/svg-image.generator"; | ||
import { TextImageBlockGeneratorService } from "./generators/blocks/text-image.generator"; | ||
import { TextLinkBlockGeneratorService } from "./generators/blocks/text-link.generator"; | ||
import { YouTubeVideoBlockGeneratorService } from "./generators/blocks/you-tube-video.generator"; | ||
import { LinkGeneratorService } from "./generators/link-generator.service"; | ||
import { PageGeneratorService } from "./generators/page-generator.service"; | ||
|
||
@Module({ | ||
imports: [ConfigModule, ConsoleModule, PagesModule, LinksModule], | ||
providers: [FixturesConsole, PageGeneratorService, LinkGeneratorService, ImageGeneratorService], | ||
providers: [ | ||
FixturesConsole, | ||
PageGeneratorService, | ||
LinkGeneratorService, | ||
FileGeneratorService, | ||
PageContentBlockGeneratorService, | ||
RichTextBlockGeneratorService, | ||
DamImageBlockGeneratorService, | ||
SeoBlockGeneratorService, | ||
TextImageBlockGeneratorService, | ||
SpaceBlockGeneratorService, | ||
HeadlineBlockGeneratorService, | ||
AnchorBlockGeneratorService, | ||
FullWidthImageBlockGeneratorService, | ||
LinkBlockGeneratorService, | ||
LinkListBlockGeneratorService, | ||
YouTubeVideoBlockGeneratorService, | ||
DamVideoBlockGeneratorService, | ||
ColumnsBlockGeneratorService, | ||
LinkBlockGeneratorService, | ||
TextLinkBlockGeneratorService, | ||
SvgImageBlockGeneratorService, | ||
PixelImageBlockGeneratorService, | ||
], | ||
}) | ||
export class FixturesModule {} |
13 changes: 13 additions & 0 deletions
13
demo/api/src/db/fixtures/generators/blocks/anchor.generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ExtractBlockInputFactoryProps } from "@comet/blocks-api"; | ||
import { AnchorBlock } from "@comet/cms-api"; | ||
import { Injectable } from "@nestjs/common"; | ||
import { random } from "faker"; | ||
|
||
@Injectable() | ||
export class AnchorBlockGeneratorService { | ||
async generateBlock(): Promise<ExtractBlockInputFactoryProps<typeof AnchorBlock>> { | ||
return { | ||
name: random.word(), | ||
}; | ||
} | ||
} |
37 changes: 0 additions & 37 deletions
37
demo/api/src/db/fixtures/generators/blocks/blocks.generator.ts
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
demo/api/src/db/fixtures/generators/blocks/columns.generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { ExtractBlockInputFactoryProps } from "@comet/blocks-api"; | ||
import { Injectable } from "@nestjs/common"; | ||
import { ColumnsBlock, supportedBlocks } from "@src/pages/blocks/columns.block"; | ||
import { datatype, random } from "faker"; | ||
|
||
import { ColumnsContentBlock } from "../../../../pages/blocks/columns.block"; | ||
import { DamImageBlockGeneratorService } from "./dam-image.generator"; | ||
import { HeadlineBlockGeneratorService } from "./headline.generator"; | ||
import { BlockGenerator } from "./page-content-block.generator"; | ||
import { RichTextBlockGeneratorService } from "./richtext.generator"; | ||
import { SpaceBlockGeneratorService } from "./space.generator"; | ||
|
||
@Injectable() | ||
export class ColumnsBlockGeneratorService { | ||
constructor( | ||
private readonly richtextGeneratorService: RichTextBlockGeneratorService, | ||
private readonly damImageBlockGenerator: DamImageBlockGeneratorService, | ||
private readonly spaceBlockGenerator: SpaceBlockGeneratorService, | ||
private readonly headlineBlockGenerator: HeadlineBlockGeneratorService, | ||
) {} | ||
|
||
async generateBlock(): Promise<ExtractBlockInputFactoryProps<typeof ColumnsBlock>> { | ||
const layoutTypes = ["one-column", "two-columns"]; | ||
const columnCount = datatype.number({ min: 1, max: 2 }); | ||
const layout = layoutTypes[columnCount - 1]; | ||
const columns = []; | ||
|
||
for (let i = 0; i < columnCount; i++) { | ||
const blocks: ExtractBlockInputFactoryProps<typeof ColumnsContentBlock>["blocks"] = []; | ||
|
||
const blockCfg: Record<keyof typeof supportedBlocks, BlockGenerator> = { | ||
space: this.spaceBlockGenerator, | ||
richtext: this.richtextGeneratorService, | ||
headline: this.headlineBlockGenerator, | ||
image: this.damImageBlockGenerator, | ||
}; | ||
|
||
for (let i = 0; i < datatype.number(20); i++) { | ||
const [type, generator] = random.arrayElement(Object.entries(blockCfg)); | ||
if (generator) { | ||
const props = await generator.generateBlock(); | ||
|
||
blocks.push({ | ||
key: String(i), | ||
visible: datatype.boolean(), | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
type: type as any, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
props: props as any, | ||
}); | ||
} | ||
} | ||
columns.push({ key: datatype.uuid(), visible: datatype.boolean(), props: { blocks } }); | ||
} | ||
|
||
return { | ||
columns, | ||
layout, | ||
}; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
demo/api/src/db/fixtures/generators/blocks/dam-image.generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { ExtractBlockInputFactoryProps } from "@comet/blocks-api"; | ||
import { DamImageBlock, FocalPoint, ImageCropAreaInput } from "@comet/cms-api"; | ||
import { Injectable } from "@nestjs/common"; | ||
import { datatype, random } from "faker"; | ||
|
||
import { PixelImageBlockGeneratorService } from "./pixel-image.generator"; | ||
import { SvgImageBlockGeneratorService } from "./svg-image.generator"; | ||
|
||
@Injectable() | ||
export class DamImageBlockGeneratorService { | ||
constructor( | ||
private readonly svgImageBlockGenerator: SvgImageBlockGeneratorService, | ||
private readonly pixelImageBlockGenerator: PixelImageBlockGeneratorService, | ||
) {} | ||
|
||
async generateBlock(): Promise<ExtractBlockInputFactoryProps<typeof DamImageBlock>> { | ||
let type: "svgImage" | "pixelImage" = "pixelImage"; | ||
let props = await this.pixelImageBlockGenerator.generateBlock(); | ||
|
||
if (datatype.boolean()) { | ||
type = "svgImage"; | ||
props = await this.svgImageBlockGenerator.generateBlock(); | ||
} | ||
|
||
return { | ||
attachedBlocks: [ | ||
{ | ||
type, | ||
props, | ||
}, | ||
], | ||
activeType: type, | ||
}; | ||
} | ||
} | ||
|
||
export const calculateDefaultCropInput = (): ImageCropAreaInput => { | ||
const focalPoint = random.arrayElement([ | ||
FocalPoint.SMART, | ||
FocalPoint.CENTER, | ||
FocalPoint.NORTHEAST, | ||
FocalPoint.NORTHWEST, | ||
FocalPoint.SOUTHEAST, | ||
FocalPoint.SOUTHWEST, | ||
]); | ||
|
||
return { | ||
focalPoint, | ||
x: focalPoint !== FocalPoint.SMART ? 0 : undefined, | ||
y: focalPoint !== FocalPoint.SMART ? 0 : undefined, | ||
height: focalPoint !== FocalPoint.SMART ? datatype.number({ min: 20, max: 100 }) : undefined, | ||
width: focalPoint !== FocalPoint.SMART ? datatype.number({ min: 20, max: 100 }) : undefined, | ||
}; | ||
}; |
Oops, something went wrong.