Skip to content

Commit

Permalink
feat: support table field (#30)
Browse files Browse the repository at this point in the history
* chore: update prismic-client dep

* chore(release): 0.7.0-alpha.0

* Bump prismic client

* Add table model

* Add table value

* chore(release): 0.7.0-alpha.1

* Add table to value mock factory

* chore(release): 0.7.0-alpha.2

* Remove text from links when it's undefined

* chore(release): 0.7.0-alpha.3

* Sort alphabetically

* Add table to model mock factory

* chore(release): 0.7.0-alpha.4

* Make faker avoid reserved words

# Conflicts:
#	test/snapshots/value-link.test.ts.md
#	test/snapshots/value-link.test.ts.snap
#	test/snapshots/value-linkToMedia.test.ts.md
#	test/snapshots/value-linkToMedia.test.ts.snap

* Update snapshots

* chore(release): 0.7.0-alpha.5

* Make faker avoid reserved words

# Conflicts:
#	test/snapshots/api-repository.test.ts.snap
#	test/snapshots/lib-buildMockGroupFieldMap.test.ts.md
#	test/snapshots/lib-buildMockGroupFieldMap.test.ts.snap
#	test/snapshots/value-contentRelationship.test.ts.md
#	test/snapshots/value-contentRelationship.test.ts.snap
#	test/snapshots/value-customType.test.ts.md
#	test/snapshots/value-customType.test.ts.snap
#	test/snapshots/value-link.test.ts.md
#	test/snapshots/value-link.test.ts.snap
#	test/snapshots/value-linkToMedia.test.ts.md
#	test/snapshots/value-linkToMedia.test.ts.snap

* Update snapshots

* chore(release): 0.7.0-alpha.6

* Fixes after merge

* Fix package.json

* Revert "Make faker avoid reserved words"

This reverts commit 783df10.

# Conflicts:
#	test/snapshots/api-repository.test.ts.snap
#	test/snapshots/lib-buildMockGroupFieldMap.test.ts.md
#	test/snapshots/lib-buildMockGroupFieldMap.test.ts.snap
#	test/snapshots/model-color.test.ts.md
#	test/snapshots/model-color.test.ts.snap
#	test/snapshots/model-contentRelationship.test.ts.md
#	test/snapshots/model-contentRelationship.test.ts.snap
#	test/snapshots/model-date.test.ts.md
#	test/snapshots/model-date.test.ts.snap
#	test/snapshots/model-embed.test.ts.md
#	test/snapshots/model-embed.test.ts.snap
#	test/snapshots/model-integration.test.ts.md
#	test/snapshots/model-integration.test.ts.snap
#	test/snapshots/model-keyText.test.ts.md
#	test/snapshots/model-keyText.test.ts.snap
#	test/snapshots/model-link.test.ts.md
#	test/snapshots/model-link.test.ts.snap
#	test/snapshots/model-linkToMedia.test.ts.md
#	test/snapshots/model-linkToMedia.test.ts.snap
#	test/snapshots/model-number.test.ts.md
#	test/snapshots/model-number.test.ts.snap
#	test/snapshots/model-richText.test.ts.md
#	test/snapshots/model-richText.test.ts.snap
#	test/snapshots/model-select.test.ts.snap
#	test/snapshots/model-slice.test.ts.md
#	test/snapshots/model-slice.test.ts.snap
#	test/snapshots/model-timestamp.test.ts.md
#	test/snapshots/model-timestamp.test.ts.snap
#	test/snapshots/model-title.test.ts.md
#	test/snapshots/model-title.test.ts.snap
#	test/snapshots/model-uid.test.ts.md
#	test/snapshots/model-uid.test.ts.snap
#	test/snapshots/value-contentRelationship.test.ts.md
#	test/snapshots/value-contentRelationship.test.ts.snap
#	test/snapshots/value-customType.test.ts.md
#	test/snapshots/value-customType.test.ts.snap
#	test/snapshots/value-link.test.ts.md
#	test/snapshots/value-link.test.ts.snap
#	test/snapshots/value-linkToMedia.test.ts.md
#	test/snapshots/value-linkToMedia.test.ts.snap

* Revert "Make faker avoid reserved words"

This reverts commit fa99f64.

# Conflicts:
#	test/snapshots/api-ref.test.ts.snap
#	test/snapshots/api-repository.test.ts.md
#	test/snapshots/api-repository.test.ts.snap
#	test/snapshots/api-tags.test.ts.md
#	test/snapshots/api-tags.test.ts.snap
#	test/snapshots/lib-buildMockGroupFieldMap.test.ts.md
#	test/snapshots/lib-buildMockGroupFieldMap.test.ts.snap
#	test/snapshots/model-sharedSlice.test.ts.md
#	test/snapshots/model-sharedSlice.test.ts.snap
#	test/snapshots/model-sharedSliceVariation.test.ts.md
#	test/snapshots/model-sharedSliceVariation.test.ts.snap
#	test/snapshots/value-contentRelationship.test.ts.md
#	test/snapshots/value-contentRelationship.test.ts.snap
#	test/snapshots/value-customType.test.ts.md
#	test/snapshots/value-customType.test.ts.snap
#	test/snapshots/value-link.test.ts.md
#	test/snapshots/value-link.test.ts.snap
#	test/snapshots/value-linkToMedia.test.ts.md
#	test/snapshots/value-linkToMedia.test.ts.snap
#	test/snapshots/value-sharedSliceVariation.test.ts.md
#	test/snapshots/value-sharedSliceVariation.test.ts.snap
#	test/snapshots/value-slice.test.ts.md
#	test/snapshots/value-slice.test.ts.snap
#	test/snapshots/value-uid.test.ts.snap

* chore(release): 0.7.0-alpha.7

* Use stable version of prismic client

* Add test for table cell model sync

* Use a random number of body rows and cells

---------

Co-authored-by: Daniel Martín <[email protected]>
  • Loading branch information
levimykel and dani-mp authored Feb 6, 2025
1 parent 8cac367 commit 83b4320
Show file tree
Hide file tree
Showing 21 changed files with 1,093 additions and 31 deletions.
52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,58 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [0.7.0-alpha.7](https://github.com/prismicio/prismic-mock/compare/v0.6.1...v0.7.0-alpha.7) (2025-02-04)

## [0.7.0-alpha.6](https://github.com/prismicio/prismic-mock/compare/v0.7.0-alpha.5...v0.7.0-alpha.6) (2025-01-31)


### Chore

* **release:** 0.7.0-alpha.6 ([74ed61b](https://github.com/prismicio/prismic-mock/commit/74ed61b20dbb48db1a069d87b68faeae3558feba))

## [0.7.0-alpha.5](https://github.com/prismicio/prismic-mock/compare/v0.7.0-alpha.4...v0.7.0-alpha.5) (2025-01-31)


### Chore

* **release:** 0.7.0-alpha.5 ([5044cad](https://github.com/prismicio/prismic-mock/commit/5044cad67f95c09e29f67390eddacf430196837e))

## [0.7.0-alpha.4](https://github.com/prismicio/prismic-mock/compare/v0.7.0-alpha.3...v0.7.0-alpha.4) (2025-01-30)


### Chore

* **release:** 0.7.0-alpha.4 ([b6118f8](https://github.com/prismicio/prismic-mock/commit/b6118f8462bad165232f873d9c3719904572f6db))

## [0.7.0-alpha.3](https://github.com/prismicio/prismic-mock/compare/v0.7.0-alpha.2...v0.7.0-alpha.3) (2025-01-29)


### Chore

* **release:** 0.7.0-alpha.3 ([c5d23e8](https://github.com/prismicio/prismic-mock/commit/c5d23e8ad016d61e18f9a38a81161f2627be0755))

## [0.7.0-alpha.2](https://github.com/prismicio/prismic-mock/compare/v0.7.0-alpha.1...v0.7.0-alpha.2) (2025-01-28)


### Chore

* **release:** 0.7.0-alpha.2 ([e42485f](https://github.com/prismicio/prismic-mock/commit/e42485ff006ca6cb6d80903bc5a71e147a27eb5d))

## [0.7.0-alpha.1](https://github.com/prismicio/prismic-mock/compare/v0.7.0-alpha.0...v0.7.0-alpha.1) (2025-01-28)


### Chore

* **release:** 0.7.0-alpha.1 ([1d9964d](https://github.com/prismicio/prismic-mock/commit/1d9964dd4716e866e16431b1f4deb54b77b962a7))

## [0.7.0-alpha.0](https://github.com/prismicio/prismic-mock/compare/v0.6.0...v0.7.0-alpha.0) (2025-01-21)


### Chore

* **release:** 0.7.0-alpha.0 ([11663e8](https://github.com/prismicio/prismic-mock/commit/11663e844ec6d700f2cbae4ce8801a3eee027e75))
* update prismic-client dep ([58aa2ba](https://github.com/prismicio/prismic-mock/commit/58aa2baa329f0f13d8a7f83fe97dcf1bf627e89a))

### [0.6.1](https://github.com/prismicio/prismic-mock/compare/v0.6.0...v0.6.1) (2025-02-04)


Expand Down
102 changes: 96 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismicio/mock",
"version": "0.6.1",
"version": "0.7.0-alpha.7",
"description": "Generate mock Prismic documents, fields, Slices, and models for development and testing environments",
"keywords": [
"typescript",
Expand Down Expand Up @@ -60,7 +60,8 @@
"unit:watch": "npm run unit -- --watch"
},
"devDependencies": {
"@prismicio/client": "7.11.0",
"@prismicio/client": "^7.16.0",
"@prismicio/types-internal": "^3.5.0",
"@size-limit/preset-small-lib": "^11.1.2",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.6.0",
Expand Down
5 changes: 5 additions & 0 deletions src/model/createModelMockFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { sliceZone, MockSliceZoneModelConfig } from "./sliceZone";
import { timestamp, MockTimestampModelConfig } from "./timestamp";
import { title, MockTitleModelConfig } from "./title";
import { uid, MockUIDModelConfig } from "./uid";
import { MockTableModelConfig, table } from "./table";

export const createModelMockFactory = (
...args: ConstructorParameters<typeof ModelMockFactory>
Expand Down Expand Up @@ -200,6 +201,10 @@ export class ModelMockFactory {
return sliceZone({ ...config, faker: this.faker });
}

table(config?: WithoutFakerConfig<MockTableModelConfig>) {
return table({ ...config, faker: this.faker });
}

timestamp(config?: WithoutFakerConfig<MockTimestampModelConfig>) {
return timestamp({ ...config, faker: this.faker });
}
Expand Down
1 change: 1 addition & 0 deletions src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { sliceZone } from "./sliceZone";
export { timestamp } from "./timestamp";
export { title } from "./title";
export { uid } from "./uid";
export { table } from "./table";

export { buildMockGroupFieldMap } from "./buildMockGroupFieldMap";

Expand Down
21 changes: 21 additions & 0 deletions src/model/table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as prismic from "@prismicio/client";

import { capitalCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";

import { MockModelConfig } from "../types";

export type MockTableModelConfig = MockModelConfig;

export const table = (
config: MockTableModelConfig,
): prismic.CustomTypeModelTableField => {
const faker = config.faker || createFaker(config.seed);

return {
type: prismic.CustomTypeModelFieldType.Table,
config: {
label: capitalCase(faker.word()),
},
};
};
22 changes: 15 additions & 7 deletions src/value/createValueMockFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { sliceZone, MockSliceZoneValueConfig } from "./sliceZone";
import { timestamp, MockTimestampValueConfig } from "./timestamp";
import { title, MockTitleValueConfig } from "./title";
import { uid, MockUIDValueConfig } from "./uid";
import { MockTableValueConfig, table } from "./table";

export const createValueMockFactory = (
...args: ConstructorParameters<typeof ValueMockFactory>
Expand Down Expand Up @@ -188,6 +189,13 @@ export class ValueMockFactory {
return number({ ...config, faker: this.faker });
}

richText<
Model extends
prismic.CustomTypeModelRichTextField = prismic.CustomTypeModelRichTextField,
>(config?: WithoutFakerConfig<MockRichTextValueConfig<Model>>) {
return richText({ ...config, faker: this.faker });
}

select<
Model extends
prismic.CustomTypeModelSelectField = prismic.CustomTypeModelSelectField,
Expand Down Expand Up @@ -223,6 +231,13 @@ export class ValueMockFactory {
return sliceZone({ ...config, faker: this.faker });
}

table<
Model extends
prismic.CustomTypeModelTableField = prismic.CustomTypeModelTableField,
>(config?: WithoutFakerConfig<MockTableValueConfig<Model>>) {
return table({ ...config, faker: this.faker });
}

timestamp<
Model extends
prismic.CustomTypeModelTimestampField = prismic.CustomTypeModelTimestampField,
Expand All @@ -245,11 +260,4 @@ export class ValueMockFactory {
>(config?: WithoutFakerConfig<MockUIDValueConfig<Model>>) {
return uid({ ...config, faker: this.faker });
}

richText<
Model extends
prismic.CustomTypeModelRichTextField = prismic.CustomTypeModelRichTextField,
>(config?: WithoutFakerConfig<MockRichTextValueConfig<Model>>) {
return richText({ ...config, faker: this.faker });
}
}
3 changes: 3 additions & 0 deletions src/value/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ export type { MockTitleValueConfig } from "./title";

export { uid } from "./uid";
export type { MockUIDValueConfig } from "./uid";

export { table } from "./table";
export type { MockTableValueConfig } from "./table";
7 changes: 3 additions & 4 deletions src/value/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ export const link = <
(model.config?.allowTargetBlank && faker.boolean())
? "_blank"
: undefined,
text:
config.withText ?? (model.config?.allowText && faker.boolean())
? sentenceCase(faker.words(2))
: undefined,
...(config.withText ?? (model.config?.allowText && faker.boolean())
? { text: sentenceCase(faker.words(2)) }
: {}),
} as MockLinkValue<LinkType, State>;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/value/linkToMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ export const linkToMedia = <
size: faker.range(500, 3000).toString(),
height: faker.range(500, 3000).toString(),
width: faker.range(500, 3000).toString(),
text:
config.withText ?? (model.config?.allowText && faker.boolean())
? sentenceCase(faker.words(2))
: undefined,
...(config.withText ?? (model.config?.allowText && faker.boolean())
? { text: sentenceCase(faker.words(2)) }
: {}),
} as MockLinkToMediaValue<State>;
}
};
Loading

0 comments on commit 83b4320

Please sign in to comment.