-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: adding additional test cases, and documenting failures as they c…
…ome up
- Loading branch information
1 parent
d1b782f
commit 8340f98
Showing
13 changed files
with
429 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,6 @@ | ||
import { StudioComponent } from '@amzn/amplify-ui-codegen-schema'; | ||
import { StudioTemplateRendererManager, StudioTemplateRendererFactory } from '@amzn/studio-ui-codegen'; | ||
import { | ||
AmplifyRenderer, | ||
ReactOutputConfig, | ||
ReactRenderConfig, | ||
ModuleKind, | ||
ScriptTarget, | ||
ScriptKind, | ||
} from '@amzn/studio-ui-codegen-react'; | ||
import path from 'path'; | ||
import log from 'loglevel'; | ||
import { ComponentSchemas } from './lib'; | ||
import { TestGenerator } from './lib/generators/TestGenerator'; | ||
|
||
Error.stackTraceLimit = Infinity; | ||
|
||
log.setLevel('info'); | ||
|
||
const renderConfig: ReactRenderConfig = { | ||
module: ModuleKind.CommonJS, | ||
target: ScriptTarget.ES2015, | ||
script: ScriptKind.TSX, | ||
}; | ||
|
||
const componentRendererFactory = new StudioTemplateRendererFactory( | ||
(component: StudioComponent) => new AmplifyRenderer(component, renderConfig), | ||
); | ||
|
||
// const themeRendererFactory = new StudioTemplateRendererFactory( | ||
// (theme: StudioTheme) => new ReactThemeStudioTemplateRenderer(theme, renderConfig), | ||
// ); | ||
|
||
const outputPathDir = path.resolve(path.join(__dirname, '..', 'test-app-templates', 'src', 'ui-components')); | ||
const outputConfig: ReactOutputConfig = { | ||
outputPathDir, | ||
}; | ||
|
||
const rendererManager = new StudioTemplateRendererManager(componentRendererFactory, outputConfig); | ||
// const themeRendererManager = new StudioTemplateRendererManager(themeRendererFactory, outputConfig); | ||
|
||
const decorateTypescriptWithMarkdown = (typescriptSource: string): string => { | ||
return `\`\`\`typescript jsx\n${typescriptSource}\n\`\`\``; | ||
}; | ||
|
||
Object.entries(ComponentSchemas).forEach(([name, schema]) => { | ||
log.info(`# ${name}`); | ||
try { | ||
rendererManager.renderSchemaToTemplate(schema as any); | ||
const buildRenderer = componentRendererFactory.buildRenderer(schema as any); | ||
|
||
const compOnly = buildRenderer.renderComponentOnly(); | ||
log.info('## Component Only Output'); | ||
log.info('### componentImports'); | ||
log.info(decorateTypescriptWithMarkdown(compOnly.importsText)); | ||
log.info('### componentText'); | ||
log.info(decorateTypescriptWithMarkdown(compOnly.compText)); | ||
|
||
const compOnlyAppSample = buildRenderer.renderSampleCodeSnippet(); | ||
log.info('## Code Snippet Output'); | ||
log.info('### componentImports'); | ||
log.info(decorateTypescriptWithMarkdown(compOnlyAppSample.importsText)); | ||
log.info('### componentText'); | ||
log.info(decorateTypescriptWithMarkdown(compOnlyAppSample.compText)); | ||
} catch (err) { | ||
log.error(`${name} failed with error:`); | ||
log.error(err); | ||
} | ||
}); | ||
// | ||
// Object.entries(ThemeSchemas).forEach(([name, schema]) => { | ||
// log.info(`# ${name}`); | ||
// try { | ||
// themeRendererManager.renderSchemaToTemplate(schema as any); | ||
// const buildRenderer = themeRendererFactory.buildRenderer(schema as any); | ||
// | ||
// const component = buildRenderer.renderComponent(); | ||
// log.info('## Theme Output'); | ||
// log.info(decorateTypescriptWithMarkdown(component.componentText)); | ||
// } catch (err) { | ||
// log.error(`${name} failed with error:`); | ||
// log.error(err); | ||
// } | ||
// }); | ||
new TestGenerator({ | ||
writeToLogger: true, | ||
writeToDisk: false, | ||
}).generate(); |
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
47 changes: 47 additions & 0 deletions
47
packages/test-generator/lib/components/buttonWithConcatenatedText.json
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,47 @@ | ||
{ | ||
"id": "1234-5678-9010", | ||
"componentType": "Button", | ||
"name": "ButtonWithConcatenatedText", | ||
"bindingProperties": { | ||
"width": { | ||
"type": "Number" | ||
}, | ||
"buttonUser": { | ||
"type": "Data", | ||
"bindingProperties": { | ||
"model": "User" | ||
} | ||
}, | ||
"buttonColor": { | ||
"type": "String" | ||
} | ||
}, | ||
"properties": { | ||
"label": { | ||
"concat": [ | ||
{ | ||
"bindingProperties": { | ||
"property": "buttonUser", | ||
"field": "firstname" | ||
}, | ||
"defaultValue": "Harry" | ||
}, | ||
{ | ||
"value": " " | ||
}, | ||
{ | ||
"bindingProperties": { | ||
"property": "buttonUser", | ||
"field": "lastname" | ||
}, | ||
"defaultValue": "Callahan" | ||
} | ||
] | ||
}, | ||
"labelWidth": { | ||
"bindingProperties": { | ||
"property": "width" | ||
} | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
packages/test-generator/lib/components/buttonWithConditionalState.json
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,105 @@ | ||
{ | ||
"id": "1234-5678-9010", | ||
"componentType": "Button", | ||
"name": "ButtonWithConditionalState", | ||
"bindingProperties": { | ||
"width": { | ||
"type": "Number" | ||
}, | ||
"buttonUser": { | ||
"type": "Data", | ||
"bindingProperties": { | ||
"model": "User" | ||
} | ||
}, | ||
"buttonColor": { | ||
"type": "String" | ||
} | ||
}, | ||
"properties": { | ||
"label": { | ||
"concat": [ | ||
{ | ||
"bindingProperties": { | ||
"property": "buttonUser", | ||
"field": "firstname" | ||
}, | ||
"defaultValue": "Harry" | ||
}, | ||
{ | ||
"value": " " | ||
}, | ||
{ | ||
"bindingProperties": { | ||
"property": "buttonUser", | ||
"field": "lastname" | ||
}, | ||
"defaultValue": "Callahan" | ||
} | ||
] | ||
}, | ||
"labelWidth": { | ||
"bindingProperties": { | ||
"property": "width" | ||
} | ||
}, | ||
"disabled": { | ||
"condition": { | ||
"property": "buttonUser", | ||
"field": "isLoggedIn", | ||
"operator": "eq", | ||
"operand": true, | ||
"then": { | ||
"value": true | ||
}, | ||
"else": { | ||
"value": false | ||
} | ||
} | ||
}, | ||
"prompt": { | ||
"condition": { | ||
"property": "buttonUser", | ||
"field": "age", | ||
"operator": "gt", | ||
"operand": 18, | ||
"then": { | ||
"concat": [ | ||
{ | ||
"bindingProperties": { | ||
"property": "buttonUser", | ||
"field": "firstname" | ||
} | ||
}, | ||
{ | ||
"value": ", cast your vote." | ||
} | ||
] | ||
}, | ||
"else": { | ||
"value": "Sorry you cannot vote" | ||
} | ||
} | ||
}, | ||
"backgroundColor": { | ||
"condition": { | ||
"property": "buttonUser", | ||
"field": "isLoggedIn", | ||
"operator": "eq", | ||
"operand": true, | ||
"then": { | ||
"bindingProperties": { | ||
"property": "buttonUser", | ||
"field": "loggedInColor" | ||
} | ||
}, | ||
"else": { | ||
"bindingProperties": { | ||
"property": "buttonUser", | ||
"field": "loggedOutColor" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
"value": "20px" | ||
}, | ||
"value": { | ||
"value": "Text Value" | ||
"value": "Custom Text Value" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { TestGenerator } from './TestGenerator'; | ||
|
||
new TestGenerator({ | ||
writeToLogger: false, | ||
writeToDisk: true, | ||
disabledSchemas: [ | ||
'ButtonWithConditionalState', // TODO: Fix Conditional | ||
'ButtonWithConcatenatedText', // TODO: Fix Concatenation | ||
'ExampleTheme', // TODO: Fix Themes | ||
], | ||
}).generate(); |
Oops, something went wrong.