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 element label in vue array renderer #2191

Merged
merged 1 commit into from
Oct 24, 2023
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
6 changes: 5 additions & 1 deletion packages/vue-vanilla/src/util/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ export const useVanillaArrayControl = <I extends { control: any }>(
input.control.value.data,
composePaths(`${index}`, childLabelProp)
);
if (labelValue === undefined || labelValue === null || isNaN(labelValue)) {
if (
labelValue === undefined ||
labelValue === null ||
Number.isNaN(labelValue)
) {
return '';
}
return `${labelValue}`;
Expand Down
76 changes: 76 additions & 0 deletions packages/vue-vanilla/tests/unit/array/ArrayListRenderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,42 @@ const uischema = {
},
};

const schemaWithNameAndRate = {
type: 'array',
title: 'My Array',
maxItems: 3,
minItems: 1,
items: {
type: 'object',
properties: {
name: {
type: 'string',
},
rate: {
type: 'number',
},
},
},
};

const schemaWithCountAndName = {
type: 'array',
title: 'My Array',
maxItems: 3,
minItems: 1,
items: {
type: 'object',
properties: {
count: {
type: 'number',
},
name: {
type: 'string',
},
},
},
};

describe('ArrayListRenderer.vue', () => {
it('renders a fieldset', () => {
const wrapper = mountJsonForms(['a'], schema, uischema);
Expand Down Expand Up @@ -88,4 +124,44 @@ describe('ArrayListRenderer.vue', () => {
expect(type).to.equal('button');
}
});

it('compute default label', async () => {
const wrapper = mountJsonForms(
[{ name: 'name1', rate: 5 }],
schemaWithNameAndRate,
uischema
);
const labels = wrapper.findAll('.array-list-item-label');
const labelText = labels[0].text();
expect(labelText).to.equal('name1');
});

it('compute default label with undefined', async () => {
const wrapper = mountJsonForms([{}], schemaWithNameAndRate, uischema);
const labels = wrapper.findAll('.array-list-item-label');
const labelText = labels[0].text();
expect(labelText).to.equal('');
});

it('compute default label with number', async () => {
const wrapper = mountJsonForms(
[{ count: 1, name: 'name1' }],
schemaWithCountAndName,
uischema
);
const labels = wrapper.findAll('.array-list-item-label');
const labelText = labels[0].text();
expect(labelText).to.equal('1');
});

it('compute default label with NaN', async () => {
const wrapper = mountJsonForms(
[{ count: Number(undefined), name: 'name1' }],
schemaWithCountAndName,
uischema
);
const labels = wrapper.findAll('.array-list-item-label');
const labelText = labels[0].text();
expect(labelText).to.equal('');
});
});