Skip to content

Commit

Permalink
test: add integ and unit test for collection default value (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilch committed Oct 29, 2021
1 parent 49f8190 commit 7849ae0
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,56 @@ export default function BoundDefaultValue(
}
`;
exports[`amplify render tests default value should render collection default value 1`] = `
Object {
"componentText": "/* eslint-disable */
import React from \\"react\\";
import {
Collection,
CollectionProps,
EscapeHatchProps,
Text,
TextProps,
getOverrideProps,
useDataStoreBinding,
} from \\"@aws-amplify/ui-react\\";
import { User } from \\"../models\\";
export type CollectionDefaultValueProps = Partial<CollectionProps<any>> & {
overrides?: EscapeHatchProps | undefined | null;
};
export default function CollectionDefaultValue(
props: CollectionDefaultValueProps
): React.ReactElement {
const { items, overrides: overridesProp, ...rest } = props;
const overrides = { ...overridesProp };
const user =
items !== undefined
? items
: useDataStoreBinding({
type: \\"collection\\",
model: User,
}).items;
return (
<Collection
items={user || []}
{...rest}
{...getOverrideProps(overrides, \\"Collection\\")}
>
{(item, index) => (
<Text {...getOverrideProps(overrides, \\"Collection.Text\\")}>
{item.username || \\"Collection Default Value\\"}
</Text>
)}
</Collection>
);
}
",
"declaration": undefined,
"renderComponentToFilesystem": [Function],
}
`;
exports[`amplify render tests default value should render simple and bound default value 1`] = `
Object {
"componentText": "/* eslint-disable */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,9 @@ describe('amplify render tests', () => {
generateWithAmplifyRenderer('default-value-components/simplePropertyBindingDefaultValue'),
).toMatchSnapshot();
});

it('should render collection default value', () => {
expect(generateWithAmplifyRenderer('default-value-components/collectionDefaultValue')).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"id": "1234-5678-9010",
"componentType": "Collection",
"name": "CollectionDefaultValue",
"properties": {},
"collectionProperties": {
"user": {
"model": "User"
}
},
"children": [
{
"componentType": "Text",
"properties": {
"value": {
"collectionBindingProperties": {
"property": "user",
"field": "username"
},
"defaultValue": "Collection Default Value"
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,26 @@ describe('Generated Components', () => {
expect(text.trim()).equal('Override Simple And Bound');
});
});

it('Renders collection default value', () => {
cy.get('#default-value')
.get('#collection-default')
.find('.amplify-text')
.invoke('text')
.then((text) => {
expect(text.trim()).equal('Collection Default');
});
});

it('Overrides collection default value', () => {
cy.get('#default-value')
.get('#collection-override')
.find('.amplify-text')
.invoke('text')
.then((text) => {
expect(text.trim()).equal('Override Collection');
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import ComponentWithVariant from './ui-components/ComponentWithVariant';
import SimplePropertyBindingDefaultValue from './ui-components/SimplePropertyBindingDefaultValue';
import BoundDefaultValue from './ui-components/BoundDefaultValue';
import SimpleAndBoundDefaultValue from './ui-components/SimpleAndBoundDefaultValue';
import CollectionDefaultValue from './ui-components/CollectionDefaultValue';
import theme from './ui-components/MyTheme';
import ComponentWithSimplePropertyBinding from './ui-components/ComponentWithSimplePropertyBinding';
import ComponentWithDataBindingWithoutPredicate from './ui-components/ComponentWithDataBindingWithoutPredicate';
Expand Down Expand Up @@ -173,6 +174,8 @@ export default function ComponentTests() {
<BoundDefaultValue id="bound-override" label="Override Bound" />
<SimpleAndBoundDefaultValue id="simple-and-bound-default" />
<SimpleAndBoundDefaultValue id="simple-and-bound-override" label="Override Simple And Bound" />
<CollectionDefaultValue id="collection-default" items={[{}]} />
<CollectionDefaultValue id="collection-override" items={[{ username: 'Override Collection' }]} />
</div>
</AmplifyProvider>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"id": "1234-5678-9010",
"componentType": "Collection",
"name": "CollectionDefaultValue",
"properties": {
"type": {
"value": "list"
}
},
"collectionProperties": {
"user": {
"model": "User"
}
},
"children": [
{
"componentType": "Text",
"properties": {
"value": {
"collectionBindingProperties": {
"property": "user",
"field": "username"
},
"defaultValue": "Collection Default"
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
export { default as BoundDefaultValue } from './boundDefaultValue.json';
export { default as SimplePropertyBindingDefaultValue } from './simplePropertyBindingDefaultValue.json';
export { default as SimpleAndBouldDefaultValue } from './simpleAndBoundDefaultValue.json';
export { default as CollectionDefaultValue } from './collectionDefaultValue.json';

0 comments on commit 7849ae0

Please sign in to comment.