-
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: set correct import location for code sample (#203)
- Loading branch information
Showing
6 changed files
with
86 additions
and
5 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
21 changes: 21 additions & 0 deletions
21
...-ui-codegen-react/lib/__tests__/__snapshots__/react-studio-template-renderer.test.ts.snap
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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ReactStudioTemplateRenderer renderSampleCodeSnippet component with name 1`] = ` | ||
Object { | ||
"compText": "export const App = () => { | ||
return (<MyText></MyText>); | ||
};", | ||
"importsText": "import { MyText } from \\"./ui-components\\"; | ||
", | ||
} | ||
`; | ||
|
||
exports[`ReactStudioTemplateRenderer renderSampleCodeSnippet component without name 1`] = ` | ||
Object { | ||
"compText": "export const App = () => { | ||
return (<unknown_component_name></unknown_component_name>); | ||
};", | ||
"importsText": "import { unknown_component_name } from \\"./ui-components\\"; | ||
", | ||
} | ||
`; |
23 changes: 23 additions & 0 deletions
23
packages/studio-ui-codegen-react/lib/__tests__/__utils__/mock-classes.ts
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,23 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
import { JsxFragment, factory } from 'typescript'; | ||
import { ReactStudioTemplateRenderer } from '../../react-studio-template-renderer'; | ||
|
||
export class MockTemplateRenderer extends ReactStudioTemplateRenderer { | ||
renderJsx(): JsxFragment { | ||
return factory.createJsxFragment(factory.createJsxOpeningFragment(), [], factory.createJsxJsxClosingFragment()); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
packages/studio-ui-codegen-react/lib/__tests__/react-studio-template-renderer.test.ts
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,40 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"). | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
import { MockTemplateRenderer } from './__utils__/mock-classes'; | ||
|
||
describe('ReactStudioTemplateRenderer', () => { | ||
describe('renderSampleCodeSnippet', () => { | ||
const component = { | ||
componentType: 'Text', | ||
bindingProperties: {}, | ||
properties: { | ||
children: { | ||
value: 'value', | ||
}, | ||
}, | ||
}; | ||
|
||
test('component with name', () => { | ||
const renderer = new MockTemplateRenderer({ ...component, name: 'MyText' }, {}); | ||
expect(renderer.renderSampleCodeSnippet()).toMatchSnapshot(); | ||
}); | ||
|
||
test('component without name', () => { | ||
const renderer = new MockTemplateRenderer(component, {}); | ||
expect(renderer.renderSampleCodeSnippet()).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
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