-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): support blocks field type (#47)
* feat(*): support blocks field type * docs(reamdme): update
- Loading branch information
1 parent
b681bef
commit 6a8d4a9
Showing
7 changed files
with
415 additions
and
178 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
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
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
165 changes: 165 additions & 0 deletions
165
src/utilities/tests/buildJsonCrowdinObject/array-field-type.spec.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,165 @@ | ||
import { CollectionConfig, Field } from "payload/types" | ||
import { buildCrowdinJsonObject, getLocalizedFields } from "../.." | ||
import { FieldWithName } from "../../../types" | ||
|
||
describe("fn: buildCrowdinJsonObject: array field type", () => { | ||
it ("includes localized fields nested in an array", () => { | ||
const doc = { | ||
id: '638641358b1a140462752076', | ||
title: 'Test Policy created with title', | ||
arrayField: [ | ||
{ | ||
title: "Array field title content one", | ||
text: "Array field text content one", | ||
select: "two", | ||
id: "64735620230d57bce946d370" | ||
}, | ||
{ | ||
title: "Array field title content two", | ||
text: "Array field text content two", | ||
select: "two", | ||
id: "64735621230d57bce946d371" | ||
} | ||
], | ||
status: 'draft', | ||
createdAt: '2022-11-29T17:28:21.644Z', | ||
updatedAt: '2022-11-29T17:28:21.644Z' | ||
} | ||
const fields: FieldWithName[] = [ | ||
{ | ||
name: 'title', | ||
type: 'text', | ||
localized: true, | ||
}, | ||
// select not supported yet | ||
{ | ||
name: 'select', | ||
type: 'select', | ||
localized: true, | ||
options: [ | ||
'one', | ||
'two' | ||
] | ||
}, | ||
{ | ||
name: 'arrayField', | ||
type: 'array', | ||
fields: [ | ||
{ | ||
name: 'title', | ||
type: 'text', | ||
localized: true, | ||
}, | ||
{ | ||
name: 'text', | ||
type: 'text', | ||
localized: true, | ||
}, | ||
{ | ||
name: 'select', | ||
type: 'select', | ||
localized: true, | ||
options: [ | ||
'one', | ||
'two' | ||
] | ||
}, | ||
] | ||
}, | ||
] | ||
const localizedFields = getLocalizedFields({ fields }) | ||
const expected = { | ||
title: 'Test Policy created with title', | ||
arrayField: [ | ||
{ | ||
title: "Array field title content one", | ||
text: "Array field text content one", | ||
}, | ||
{ | ||
title: "Array field title content two", | ||
text: "Array field text content two", | ||
} | ||
], | ||
} | ||
expect(buildCrowdinJsonObject({doc, fields: localizedFields})).toEqual(expected) | ||
}) | ||
|
||
it ("includes localized fields nested in an array with a localization setting on the array field", () => { | ||
const doc = { | ||
id: '638641358b1a140462752076', | ||
title: 'Test Policy created with title', | ||
arrayField: [ | ||
{ | ||
title: "Array field title content one", | ||
text: "Array field text content one", | ||
select: "two", | ||
id: "64735620230d57bce946d370" | ||
}, | ||
{ | ||
title: "Array field title content two", | ||
text: "Array field text content two", | ||
select: "two", | ||
id: "64735621230d57bce946d371" | ||
} | ||
], | ||
status: 'draft', | ||
createdAt: '2022-11-29T17:28:21.644Z', | ||
updatedAt: '2022-11-29T17:28:21.644Z' | ||
} | ||
const fields: FieldWithName[] = [ | ||
{ | ||
name: 'title', | ||
type: 'text', | ||
localized: true, | ||
}, | ||
// select not supported yet | ||
{ | ||
name: 'select', | ||
type: 'select', | ||
localized: true, | ||
options: [ | ||
'one', | ||
'two' | ||
] | ||
}, | ||
{ | ||
name: 'arrayField', | ||
type: 'array', | ||
localized: true, | ||
fields: [ | ||
{ | ||
name: 'title', | ||
type: 'text', | ||
}, | ||
{ | ||
name: 'text', | ||
type: 'text', | ||
}, | ||
{ | ||
name: 'select', | ||
type: 'select', | ||
options: [ | ||
'one', | ||
'two' | ||
] | ||
}, | ||
] | ||
}, | ||
] | ||
const localizedFields = getLocalizedFields({ fields }) | ||
const expected = { | ||
title: 'Test Policy created with title', | ||
arrayField: [ | ||
{ | ||
title: "Array field title content one", | ||
text: "Array field text content one", | ||
}, | ||
{ | ||
title: "Array field title content two", | ||
text: "Array field text content two", | ||
} | ||
], | ||
} | ||
expect(buildCrowdinJsonObject({doc, fields: localizedFields})).toEqual(expected) | ||
}) | ||
}) |
Oops, something went wrong.