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

FIX Don't split ID into separate digits #335

Merged
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
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions client/src/components/LinkField/LinkField.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,10 @@ const LinkField = ({
})
);

// The value for a has_one LinkField will start off as a numeric 0
// If a parent object containing a child LinkField without a value is submitted,
// using FormSchema, then the FormSchema response may contain a string '0' instead
// Ensure that a numeric 0 is used
if (value === '0') {
value = 0;
// Sometimes, the value will be given as a numeric string.
// Ensure that an actual number is used
if (typeof value === 'string') {
value = Number(value);
}

// Ensure we have a valid array
Expand Down
16 changes: 16 additions & 0 deletions client/src/components/LinkField/tests/LinkField-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ test('LinkField can handle a string "0" value', async () => {
expect(container.querySelectorAll('.link-picker')).toHaveLength(1);
});

test('LinkField can handle a multi-digit string value', async () => {
const { container } = render(<LinkField {...makeProps({
value: '123'
})}
/>);

await doResolve({ json: () => ({
123: {
title: 'Page title',
typeKey: 'sitetree',
},
}) });
await screen.findByText('Page title');
expect(container.querySelectorAll('.link-picker__button')).toHaveLength(1);
});

test('LinkField will render disabled state if disabled is true', async () => {
const { container } = render(<LinkField {...makeProps({
ownerID: 1,
Expand Down
Loading