Skip to content

Commit c23e323

Browse files
authored
fix(generator): change order of cleanup of the overrides (#82)
* fix(generator): change order of cleanup of the overrides to avoid to remove overrides. fix ariaSelected attribute on DataGridCell not compliant to specs * fix(generator): add tests * fix(generator): cleanup tests
1 parent 9f01308 commit c23e323

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

scripts/generateWrappers/consts.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,12 @@ const Vivid3ComponentsExtraPropertiesMap = {
370370
type: { text: 'string' }
371371
}
372372
],
373+
DataGridCell: [
374+
{
375+
name: 'ariaSelected',
376+
type: { text: 'boolean | undefined' }
377+
}
378+
],
373379
Select: [
374380
{
375381
name: 'disabled',

scripts/generateWrappers/generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ const renderComponentV3 = prefix => classDeclaration => language => componentCla
160160
const componentName = getClassName(classDeclaration)
161161
const componentTagName = `${componentPrefix}-${camel2kebab(componentName)}`
162162
const events = [...(classDeclaration.events?.map(({ name }) => name) || []), ...(ComponentsEventsMapV3[componentClassName] || [])]
163-
const properties = (classDeclaration.members?.filter(({ privacy = 'public', kind, readonly }) => kind === 'field' && privacy === 'public' && readonly !== true) || [])
164-
.concat(Vivid3ComponentsExtraPropertiesMap[componentName] || [])
163+
const properties = (Vivid3ComponentsExtraPropertiesMap[componentName] || [])
164+
.concat(classDeclaration.members?.filter(({ privacy = 'public', kind, readonly }) => kind === 'field' && privacy === 'public' && readonly !== true) || [])
165165
const attributes = classDeclaration.attributes?.filter(({ fieldName }) => properties.find(({ name }) => fieldName === name)) || []
166166
const propertyNames = properties.map(({ name }) => `'${name}'`)
167167
const props = [

scripts/generateWrappers/generator.spec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,49 @@ describe("generator", () => {
328328
`);
329329
});
330330

331+
it("should add extra props from Vivid3ComponentsExtraPropertiesMap", async () => {
332+
function replaceComponentWithOverridable() {
333+
const newData = JSON.parse(JSON.stringify(MOCK_DATA));
334+
newData.modules[0].declarations[1].name = 'DataGridCell'
335+
return newData;
336+
}
337+
setTokenTemplateMock(TemplateToken.PROPS);
338+
const newData = replaceComponentWithOverridable();
339+
340+
await generateWrappersV3InstanceTS({ elements: newData });
341+
342+
const content = fs.outputFile.mock.calls[0][1];
343+
expect(content).toMatchInlineSnapshot(`
344+
" onChange?: (event: SyntheticEvent) => void,
345+
\\"ariaSelected\\"?: any /* boolean | undefined */,
346+
\\"field1\\"?: any /* AccordionExpandMode */,
347+
\\"field2\\"?: string | null,
348+
\\"activeItemIndex\\"?: number"
349+
`);
350+
});
351+
352+
it("should override default props with extra props from Vivid3ComponentsExtraPropertiesMap", async () => {
353+
function replaceComponentWithOverridable() {
354+
const newData = JSON.parse(JSON.stringify(MOCK_DATA));
355+
newData.modules[0].declarations[1].name = 'DataGridCell'
356+
newData.modules[0].declarations[1].members[0].name = 'ariaSelected'
357+
newData.modules[0].declarations[1].attributes[0].name = 'ariaSelected'
358+
return newData;
359+
}
360+
setTokenTemplateMock(TemplateToken.PROPS);
361+
const newData = replaceComponentWithOverridable();
362+
363+
await generateWrappersV3InstanceTS({ elements: newData });
364+
365+
const content = fs.outputFile.mock.calls[0][1];
366+
expect(content).toMatchInlineSnapshot(`
367+
" onChange?: (event: SyntheticEvent) => void,
368+
\\"ariaSelected\\"?: any /* boolean | undefined */,
369+
\\"field2\\"?: string | null,
370+
\\"activeItemIndex\\"?: number"
371+
`);
372+
});
373+
331374
it("should replace component registration for DataGridRow with empty string", async () => {
332375
setTokenTemplateMock(`
333376
import { register<% component-name %> } from '@vonage/vivid'

0 commit comments

Comments
 (0)