Skip to content

Commit

Permalink
Fix number as string for count
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorin95670 committed Jul 10, 2024
1 parent eecf1b3 commit 0f350ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/drawer/render/TerraformComponentRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ class TerraformComponentRenderer extends ComponentRenderer {
*/
getTemplateData(component) {
const countAttribute = component.getAttributeByName('count');
const hasCount = !!countAttribute && countAttribute.value !== 1;
const countValue = parseInt(countAttribute?.value, 10);
const hasCount = !!countAttribute && countValue !== 1;
let count = '?';

if (hasCount && countAttribute.type === 'Number') {
count = countAttribute.value;
if (hasCount && Number.isInteger(countValue)) {
count = countValue;
}

return {
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/drawer/render/TerraformComponentRenderer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ describe('Test class: TerraformComponentRenderer', () => {
definition: new TerraformComponentDefinition(),
attributes: [new TerraformComponentAttribute({
name: 'count',
type: 'Number',
value: 2,
type: 'String',
value: '2',
})],
});
const result = renderer.getTemplateData(component);

expect(result.hasCount).toEqual(true);
expect(result.count).toBe(2);
});

Expand Down

0 comments on commit 0f350ca

Please sign in to comment.