/*
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 { useState, useRef, useEffect } from 'react';
import { Heading, View } from '@aws-amplify/ui-react';
import {
AlertPrimitive,
BadgePrimitive,
ButtonPrimitive,
ButtonGroupPrimitive,
CardPrimitive,
CheckboxFieldPrimitive,
CollectionPrimitive,
DividerPrimitive,
ExpanderPrimitive,
FlexPrimitive,
GridPrimitive,
HeadingPrimitive,
IconPrimitive,
ImagePrimitive,
LinkPrimitive,
LoaderPrimitive,
MenuButtonPrimitive,
MenuPrimitive,
PaginationPrimitive,
PasswordFieldPrimitive,
PhoneNumberFieldPrimitive,
PlaceholderPrimitive,
RadioPrimitive,
RadioGroupFieldPrimitive,
RatingPrimitive,
ScrollViewPrimitive,
SearchFieldPrimitive,
SelectFieldPrimitive,
SliderFieldPrimitive,
StepperFieldPrimitive,
SwitchFieldPrimitive,
TabsPrimitive,
TablePrimitive,
TextPrimitive,
TextAreaFieldPrimitive,
TextFieldPrimitive,
ToggleButtonPrimitive,
ToggleButtonGroupPrimitive,
ViewPrimitive,
VisuallyHiddenPrimitive,
// eslint-disable-next-line import/extensions
} from './ui-components';
import { initializeListingTestData } from './mock-utils';
export default function PrimitivesTests() {
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.
const ddbRequest = indexedDB.deleteDatabase('amplify-datastore');
await new Promise((res, rej) => {
ddbRequest.onsuccess = () => {
res(true);
};
ddbRequest.onerror = () => {
rej(ddbRequest.error);
};
});
await Promise.all([initializeListingTestData()]);
setInitialized(true);
};
initializeTestUserData();
initializeStarted.current = true;
}, []);
if (!isInitialized) {
return null;
}
return (
<>
Alert
Badge
Button
Button Group
Card
Checkbox Field
Collection
Divider
Expander
Flex
Grid
Heading
Icon
Image
Link
Loader
Password Field
Phone Number Field
Placeholder
Radio
Radio Group Field
Rating
Scroll View
Search Field
Select Field
Slider Field
Stepper Field
Switch Field
Tabs
Table
Text
Text Area Field
Text Field
Toggle Button
Toggle Button Group
View
Visually Hidden
>
);
}