-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xstream-452/506 adapter le design d'un attribut liaison mono-valuée (#…
…445) * feat(@leav/ui): design system Select to mono value link field
- Loading branch information
Showing
21 changed files
with
1,088 additions
and
518 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
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
142 changes: 142 additions & 0 deletions
142
libs/ui/src/components/RecordEdition/EditRecordContent/antdUtils.test.tsx
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,142 @@ | ||
import {getAntdFormInitialValues} from '_ui/components/RecordEdition/EditRecordContent/antdUtils'; | ||
import {AttributeFormat, AttributeType} from '_ui/_gqlTypes'; | ||
|
||
jest.mock('dayjs', () => ({ | ||
unix: jest.fn(t => t) | ||
})); | ||
|
||
describe('getAntdFormInitialValues', () => { | ||
test('Should return empty object on empty elements', async () => { | ||
const recordForm = {elements: []}; | ||
|
||
const antdFormInitialValues = getAntdFormInitialValues(recordForm as any); | ||
|
||
expect(antdFormInitialValues).toEqual({}); | ||
}); | ||
|
||
test('Should skip if attribute is undefined', async () => { | ||
const elementWithoutAttribute = {values: []}; | ||
const recordForm = {elements: [elementWithoutAttribute]}; | ||
|
||
const antdFormInitialValues = getAntdFormInitialValues(recordForm as any); | ||
|
||
expect(antdFormInitialValues).toEqual({}); | ||
}); | ||
|
||
describe.each([{type: AttributeType.simple_link}, {type: AttributeType.advanced_link, multiple_values: false}])( | ||
'links', | ||
attributeProperties => { | ||
test('Should initialize antd form with given value for links (advanced and simple)', async () => { | ||
const elementFormId = 'elementFormId'; | ||
const linkAttributeId = 'linkAttributeId'; | ||
const linkElement = { | ||
attribute: {...attributeProperties, id: linkAttributeId}, | ||
values: [{linkValue: {id: elementFormId}}] | ||
}; | ||
const recordForm = {elements: [linkElement]}; | ||
|
||
const antdFormInitialValues = getAntdFormInitialValues(recordForm as any); | ||
|
||
expect(antdFormInitialValues).toEqual({ | ||
[linkAttributeId]: 'elementFormId' | ||
}); | ||
}); | ||
|
||
test('Should initialize antd form with undefined for links (advanced and simple) when linkValue is not set', async () => { | ||
const linkAttributeId = 'linkAttributeId'; | ||
const linkElement = { | ||
attribute: {...attributeProperties, id: linkAttributeId}, | ||
values: [{}] | ||
}; | ||
const recordForm = {elements: [linkElement]}; | ||
|
||
const antdFormInitialValues = getAntdFormInitialValues(recordForm as any); | ||
|
||
expect(antdFormInitialValues).toEqual({ | ||
[linkAttributeId]: undefined | ||
}); | ||
}); | ||
} | ||
); | ||
|
||
describe('AttributeFormat.text', () => { | ||
test('Should initialize antd form with given value for text attribute', async () => { | ||
const rawValue = 'rawValue'; | ||
const textAttributeId = 'textAttributeId'; | ||
const textElement = { | ||
attribute: {format: AttributeFormat.text, id: textAttributeId}, | ||
values: [{raw_value: rawValue}] | ||
}; | ||
const recordForm = {elements: [textElement]}; | ||
|
||
const antdFormInitialValues = getAntdFormInitialValues(recordForm as any); | ||
|
||
expect(antdFormInitialValues).toEqual({ | ||
[textAttributeId]: rawValue | ||
}); | ||
}); | ||
|
||
test('Should initialize antd form with given empty string for text when raw_value is not set', async () => { | ||
const textAttributeId = 'textAttributeId'; | ||
const textElement = { | ||
attribute: {format: AttributeFormat.text, id: textAttributeId}, | ||
values: [{}] | ||
}; | ||
const recordForm = {elements: [textElement]}; | ||
|
||
const antdFormInitialValues = getAntdFormInitialValues(recordForm as any); | ||
|
||
expect(antdFormInitialValues).toEqual({ | ||
[textAttributeId]: '' | ||
}); | ||
}); | ||
}); | ||
|
||
describe('AttributeFormat.date_range', () => { | ||
test('Should skip when raw_value is not set', async () => { | ||
const dateRangeElementWithoutRawValue = { | ||
attribute: {format: AttributeFormat.date_range}, | ||
values: [{}] | ||
}; | ||
const recordForm = {elements: [dateRangeElementWithoutRawValue]}; | ||
|
||
const antdFormInitialValues = getAntdFormInitialValues(recordForm as any); | ||
|
||
expect(antdFormInitialValues).toEqual({}); | ||
}); | ||
|
||
test('Should initialize antd form with dayjs formatted value for date_range attribute', async () => { | ||
const from = '1000'; | ||
const to = '2000'; | ||
const dateRangeAttributeId = 'dateRangeAttributeId'; | ||
const strcturedDateRangeElement = { | ||
attribute: {format: AttributeFormat.date_range, id: dateRangeAttributeId}, | ||
values: [{raw_value: {from, to}}] | ||
}; | ||
const recordForm = {elements: [strcturedDateRangeElement]}; | ||
|
||
const antdFormInitialValues = getAntdFormInitialValues(recordForm as any); | ||
|
||
expect(antdFormInitialValues).toEqual({ | ||
[dateRangeAttributeId]: [Number(from), Number(to)] | ||
}); | ||
}); | ||
|
||
test('Should initialize antd form with dayjs formatted value for stringified date_range attribute', async () => { | ||
const from = '1000'; | ||
const to = '2000'; | ||
const dateRangeAttributeId = 'dateRangeAttributeId'; | ||
const strcturedDateRangeElement = { | ||
attribute: {format: AttributeFormat.date_range, id: dateRangeAttributeId}, | ||
values: [{raw_value: JSON.stringify({from, to})}] | ||
}; | ||
const recordForm = {elements: [strcturedDateRangeElement]}; | ||
|
||
const antdFormInitialValues = getAntdFormInitialValues(recordForm as any); | ||
|
||
expect(antdFormInitialValues).toEqual({ | ||
[dateRangeAttributeId]: [Number(from), Number(to)] | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.