Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support repeatable links #27

Merged
merged 7 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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.5.0-alpha.1](https://github.com/prismicio/prismic-mock/compare/v0.5.0-alpha.0...v0.5.0-alpha.1) (2024-11-28)

## [0.5.0-alpha.0](https://github.com/prismicio/prismic-mock/compare/v0.4.0...v0.5.0-alpha.0) (2024-11-11)

## [0.4.0](https://github.com/prismicio/prismic-mock/compare/v0.3.9...v0.4.0) (2024-09-26)

### [0.3.8-alpha.1](https://github.com/prismicio/prismic-mock/compare/v0.3.7...v0.3.8-alpha.1) (2024-08-29)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismicio/mock",
"version": "0.4.0",
"version": "0.5.0-alpha.1",
"description": "Generate mock Prismic documents, fields, Slices, and models for development and testing environments",
"keywords": [
"typescript",
Expand Down Expand Up @@ -49,8 +49,8 @@
"lint": "eslint --ext .js,.ts .",
"prepare": "npm run build",
"release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
"release:alpha": "npm run test && standard-version --release-as patch --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
"release:alpha:dry": "standard-version --release-as patch --prerelease alpha --dry-run",
"release:alpha": "npm run test && standard-version --release-as minor --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
"release:alpha:dry": "npm run test && standard-version --release-as minor --prerelease alpha --dry-run",
"release:dry": "standard-version --dry-run",
"size": "size-limit",
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size",
Expand Down
14 changes: 11 additions & 3 deletions src/model/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MockModelConfig } from "../types";
type MockLinkModel<
AllowTargetBlank extends boolean = boolean,
AllowText extends boolean = boolean,
Repeat extends boolean = boolean,
> = prismic.CustomTypeModelLinkField & {
config: AllowTargetBlank extends true
? { allowTargetBlank: true }
Expand All @@ -16,22 +17,27 @@ type MockLinkModel<
config: AllowText extends true
? { allowText: true }
: { allowText?: undefined };
} & {
config: Repeat extends true ? { repeat: true } : { repeat?: undefined };
};

export type MockLinkModelConfig<
AllowTargetBlank extends boolean = boolean,
AllowText extends boolean = boolean,
Repeat extends boolean = boolean,
> = {
allowTargetBlank?: AllowTargetBlank;
allowText?: AllowText;
repeat?: Repeat;
} & MockModelConfig;

export const link = <
AllowTargetBlank extends boolean = boolean,
AllowText extends boolean = boolean,
Repeat extends boolean = boolean,
>(
config: MockLinkModelConfig<AllowTargetBlank, AllowText>,
): MockLinkModel<AllowTargetBlank, AllowText> => {
config: MockLinkModelConfig<AllowTargetBlank, AllowText, Repeat>,
): MockLinkModel<AllowTargetBlank, AllowText, Repeat> => {
const faker = config.faker || createFaker(config.seed);

return {
Expand All @@ -47,6 +53,8 @@ export const link = <
allowText:
("allowText" in config ? config.allowText : faker.boolean()) ||
undefined,
repeat:
("repeat" in config ? config.repeat : faker.boolean()) || undefined,
},
} as MockLinkModel<AllowTargetBlank, AllowText>;
} as MockLinkModel<AllowTargetBlank, AllowText, Repeat>;
};
5 changes: 2 additions & 3 deletions src/model/linkToMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ type MockLinkToMediaModel<AllowText extends boolean = boolean> =
: { allowText?: undefined };
};

export type MockLinkToMediaModelConfig<AllowText extends boolean = boolean> = {
allowText?: AllowText;
} & MockModelConfig;
export type MockLinkToMediaModelConfig<AllowText extends boolean = boolean> =
MockModelConfig & { allowText?: AllowText };

export const linkToMedia = <AllowText extends boolean = boolean>(
config: MockLinkToMediaModelConfig<AllowText>,
Expand Down
14 changes: 14 additions & 0 deletions test/model-link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@ test("can be configured to explicitly support the text property", (t) => {
});
t.is(actualFalse.config.allowText, undefined);
});

test("can be configured to be repeatable", (t) => {
const actualTrue = model.link({
seed: t.title,
repeat: true,
});
t.is(actualTrue.config.repeat, true);

const actualFalse = model.link({
seed: t.title,
repeat: false,
});
t.is(actualFalse.config.repeat, undefined);
});
124 changes: 64 additions & 60 deletions test/snapshots/lib-buildMockGroupFieldMap.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Generated by [AVA](https://avajs.dev).

[
{
diam: {
config: {
allowText: true,
label: 'Odio',
placeholder: 'Adipiscing elit duis',
select: 'media',
},
type: 'Link',
},
egestas: {
config: {
label: 'Pharetra',
Expand Down Expand Up @@ -38,28 +47,26 @@ Generated by [AVA](https://avajs.dev).
},
type: 'Image',
},
faucibus_vitae: {
config: {
label: 'Viverra',
placeholder: 'Pulvinar neque laoreet',
},
type: 'Number',
},
in_hac: {
config: {
label: 'Aliquam',
placeholder: 'Elit at imperdiet',
},
type: 'Color',
},
in_metus: {
config: {
allowText: true,
label: 'Diam',
placeholder: 'Odio pellentesque diam',
select: 'media',
},
type: 'Link',
},
porttitor: {
lacus: {
config: {
allowTargetBlank: undefined,
label: 'Risus',
placeholder: 'Ultricies leo integer',
single: 'heading1,heading3,heading4,heading5',
label: 'Ultricies',
placeholder: 'In metus vulputate',
single: 'heading2,heading3,heading5,heading6',
},
type: 'StructuredText',
},
Expand All @@ -76,25 +83,28 @@ Generated by [AVA](https://avajs.dev).
},
type: 'IntegrationFields',
},
vel_risus: {
config: {
label: 'Faucibus',
placeholder: 'Viverra vitae congue',
},
type: 'Number',
},
vulputate_mi: {
config: {
allowTargetBlank: true,
allowText: true,
label: 'Et',
placeholder: 'Magna fringilla urna',
repeat: true,
select: null,
},
type: 'Link',
},
},
{
diam: {
config: {
allowText: true,
label: 'Odio',
placeholder: 'Adipiscing elit duis',
select: 'media',
},
type: 'Link',
},
egestas: {
config: {
label: 'Pharetra',
Expand Down Expand Up @@ -123,28 +133,26 @@ Generated by [AVA](https://avajs.dev).
},
type: 'Image',
},
faucibus_vitae: {
config: {
label: 'Viverra',
placeholder: 'Pulvinar neque laoreet',
},
type: 'Number',
},
in_hac: {
config: {
label: 'Aliquam',
placeholder: 'Elit at imperdiet',
},
type: 'Color',
},
in_metus: {
config: {
allowText: true,
label: 'Diam',
placeholder: 'Odio pellentesque diam',
select: 'media',
},
type: 'Link',
},
porttitor: {
lacus: {
config: {
allowTargetBlank: undefined,
label: 'Risus',
placeholder: 'Ultricies leo integer',
single: 'heading1,heading3,heading4,heading5',
label: 'Ultricies',
placeholder: 'In metus vulputate',
single: 'heading2,heading3,heading5,heading6',
},
type: 'StructuredText',
},
Expand All @@ -161,19 +169,13 @@ Generated by [AVA](https://avajs.dev).
},
type: 'IntegrationFields',
},
vel_risus: {
config: {
label: 'Faucibus',
placeholder: 'Viverra vitae congue',
},
type: 'Number',
},
vulputate_mi: {
config: {
allowTargetBlank: true,
allowText: true,
label: 'Et',
placeholder: 'Magna fringilla urna',
repeat: true,
select: null,
},
type: 'Link',
Expand All @@ -187,12 +189,12 @@ Generated by [AVA](https://avajs.dev).

[
{
donec: {
elementum: {
config: {
default_value: undefined,
label: 'Elementum',
label: 'Rhoncus',
options: [],
placeholder: 'Rhoncus urna neque',
placeholder: 'Pretium nibh ipsum',
},
type: 'Select',
},
Expand All @@ -208,6 +210,7 @@ Generated by [AVA](https://avajs.dev).
allowText: true,
label: 'Imperdiet',
placeholder: 'Massa tempor nec',
repeat: undefined,
select: null,
},
type: 'Link',
Expand All @@ -219,10 +222,10 @@ Generated by [AVA](https://avajs.dev).
},
type: 'Date',
},
nisl_nunc: {
morbi: {
config: {
label: 'Morbi',
placeholder: 'Rutrum quisque non',
label: 'Rutrum',
placeholder: 'Lacus laoreet non',
},
type: 'Timestamp',
},
Expand All @@ -233,11 +236,11 @@ Generated by [AVA](https://avajs.dev).
},
type: 'Color',
},
quis: {
potenti: {
config: {
allowText: true,
label: 'Potenti',
placeholder: 'Ut sem viverra',
allowText: undefined,
label: 'Ut',
placeholder: 'Et ultrices neque',
select: 'media',
},
type: 'Link',
Expand Down Expand Up @@ -268,12 +271,12 @@ Generated by [AVA](https://avajs.dev).
},
},
{
donec: {
elementum: {
config: {
default_value: undefined,
label: 'Elementum',
label: 'Rhoncus',
options: [],
placeholder: 'Rhoncus urna neque',
placeholder: 'Pretium nibh ipsum',
},
type: 'Select',
},
Expand All @@ -289,6 +292,7 @@ Generated by [AVA](https://avajs.dev).
allowText: true,
label: 'Imperdiet',
placeholder: 'Massa tempor nec',
repeat: undefined,
select: null,
},
type: 'Link',
Expand All @@ -300,10 +304,10 @@ Generated by [AVA](https://avajs.dev).
},
type: 'Date',
},
nisl_nunc: {
morbi: {
config: {
label: 'Morbi',
placeholder: 'Rutrum quisque non',
label: 'Rutrum',
placeholder: 'Lacus laoreet non',
},
type: 'Timestamp',
},
Expand All @@ -314,11 +318,11 @@ Generated by [AVA](https://avajs.dev).
},
type: 'Color',
},
quis: {
potenti: {
config: {
allowText: true,
label: 'Potenti',
placeholder: 'Ut sem viverra',
allowText: undefined,
label: 'Ut',
placeholder: 'Et ultrices neque',
select: 'media',
},
type: 'Link',
Expand Down
Binary file modified test/snapshots/lib-buildMockGroupFieldMap.test.ts.snap
Binary file not shown.
Loading
Loading