/* 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 { useEffect, useState, useRef } from 'react'; import { AmplifyProvider } from '@aws-amplify/ui-react'; import '@aws-amplify/ui-react/styles.css'; import { DataStore } from 'aws-amplify'; import { User, Listing, Class, CompositeBowl, CompositeToy, CompositeOwner, CompositeDog } from './models'; import { ViewTest, ViewWithButton, CustomButton, BasicComponentBadge, BasicComponentView, BasicComponentButton, BasicComponentCard, BasicComponentCollection, BasicComponentText, ComponentWithConcatenation, ComponentWithConditional, BasicComponentDivider, BasicComponentFlex, BasicComponentImage, BasicComponentCustomRating, ComponentWithVariant, ComponentWithVariantAndOverrides, ComponentWithVariantsAndNotOverrideChildProp, SimplePropertyBindingDefaultValue, BoundDefaultValue, SimpleAndBoundDefaultValue, CollectionDefaultValue, MyTheme, ComponentWithSimplePropertyBinding, ComponentWithSlotBinding, ComponentWithDataBindingWithoutPredicate, ComponentWithDataBindingWithPredicate, ComponentWithMultipleDataBindingsWithPredicate, CollectionWithBinding, CollectionWithSort, ParsedFixedValues, CustomChildren, CustomParent, CustomParentAndChildren, CollectionWithBindingItemsName, ComponentWithBoundPropertyConditional, ComponentWithNestedOverrides, PaginatedCollection, SearchableCollection, ComponentWithAuthBinding, DataBindingNamedClass, CollectionWithCompositeKeysAndRelationships, CollectionWithBetweenPredicate, } from './ui-components'; // eslint-disable-line import/extensions import { initializeAuthMockData } from './mock-utils'; const initializeUserTestData = async (): Promise => { await DataStore.save(new User({ firstName: 'Real', lastName: 'LUser3', age: 29 })); await DataStore.save(new User({ firstName: 'Another', lastName: 'LUser2', age: 72 })); await DataStore.save(new User({ firstName: 'Last', lastName: 'LUser1', age: 50 })); await DataStore.save(new User({ firstName: 'Too Young', lastName: 'LUser0', age: 5 })); }; const initializeListingTestData = async (): Promise => { await DataStore.save( new Listing({ title: 'Cozy Bungalow', priceUSD: 1500, description: 'Lorem ipsum dolor sit amet' }), ); await DataStore.save( new Listing({ title: 'Mountain Retreat', priceUSD: 1800, description: 'consectetur adipiscing elit, sed do eiusmod tempor incididunt', }), ); await DataStore.save( new Listing({ title: 'Quiet Cottage', priceUSD: 1100, description: 'ut labore et dolore magna aliqua. Ut enim ad minim veniam', }), ); await DataStore.save( new Listing({ title: 'Creekside Hideaway', priceUSD: 950, description: 'quis nostrud exercitation ullamco laboris nisi ut aliquip', }), ); await DataStore.save( new Listing({ title: 'Cabin in the Woods', priceUSD: 600, description: 'ex ea commodo consequat. Duis aute irure dolor in reprehenderit', }), ); await DataStore.save( new Listing({ title: 'Cabin at the Lake (unit 1)', priceUSD: 700, description: 'in voluptate velit esse cillum dolore eu fugiat nulla pariatur', }), ); await DataStore.save( new Listing({ title: 'Cabin at the Lake (unit 2)', priceUSD: 800, description: 'Excepteur sint occaecat cupidatat non proident', }), ); await DataStore.save( new Listing({ title: 'Beachside Cottage', priceUSD: 1000, description: 'sunt in culpa qui officia deserunt mollit anim id est laborum', }), ); await DataStore.save(new Listing({ title: 'Lush Resort', priceUSD: 3500, description: 'Its real nice' })); await DataStore.save(new Listing({ title: 'Chalet away from home', priceUSD: 5000, description: 'youll like it' })); }; const initializeCompositeDogTestData = async (): Promise => { const connectedBowl = await DataStore.save(new CompositeBowl({ shape: 'round', size: 'xl' })); const connectedOwner = await DataStore.save(new CompositeOwner({ lastName: 'Erica', firstName: 'Raunak' })); const connectedToys = await Promise.all([ DataStore.save(new CompositeToy({ kind: 'stick', color: 'oak' })), DataStore.save(new CompositeToy({ kind: 'ball', color: 'green' })), ]); const createdRecord = await DataStore.save( new CompositeDog({ name: 'Ruca', description: 'fetch maniac', CompositeBowl: connectedBowl, CompositeOwner: connectedOwner, }), ); await Promise.all( connectedToys.map((toy) => { return DataStore.save( CompositeToy.copyOf(toy, (updated) => { Object.assign(updated, { compositeDogCompositeToysName: createdRecord.name, compositeDogCompositeToysDescription: createdRecord.description, }); }), ); }), ); }; export default function ComponentTests() { const [isInitialized, setInitialized] = useState(false); const initializeStarted = useRef(false); useEffect(() => { const initializeTestUserData = async () => { if (initializeStarted.current) { return; } // DataStore.clear() doesn't appear to reliably work in this scenario. indexedDB.deleteDatabase('amplify-datastore'); await Promise.all([initializeUserTestData(), initializeListingTestData(), initializeCompositeDogTestData()]); initializeAuthMockData({ picture: 'http://media.corporate-ir.net/media_files/IROL/17/176060/Oct18/AWS.png', username: 'TestUser', 'custom:favorite_icecream': 'Mint Chip', }); setInitialized(true); }; initializeTestUserData(); initializeStarted.current = true; }, []); if (!isInitialized) { return null; } return (

Generated Component Tests

Basic Components

Concatenation and Conditional Tests

Variants

Data Binding

Customer component
} />

Collections

{ return { children: `${index} - ${item.lastName}, ${item.firstName}`, }; }} /> { return { children: ( <>
{item.lastName}
{item.firstName}
), }; }} /> { return { mySlot: (
{`Owner: ${item.CompositeOwner?.lastName}`} {`Bowl: ${item.CompositeBowl?.shape}`} {`Toys: ${item.CompositeToys?.map((toy: CompositeToy) => toy.kind).join(', ')}`}
), }; }} />

Default Value

Overrides

); }