-
Notifications
You must be signed in to change notification settings - Fork 30
chore: add integ tests for storage field #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bombguy
wants to merge
6
commits into
main
Choose a base branch
from
cshin/storage-field-integ-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0c3d3e1
chore: add integ tests for storage field
e731c32
chore: fix lint
a996118
chore: fix lint
095561e
fix: update cypress selectors
f6caaeb
Merge branch 'main' into cshin/storage-field-integ-test
2339668
Merge branch 'main' into cshin/storage-field-integ-test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
packages/test-generator/integration-test-templates/cypress/e2e/form/DSUserProfile-spec.cy.ts
This file contains hidden or 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,130 @@ | ||
| /* | ||
| 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 { getStorageManagerByLabel, getInputByLabel } from '../../utils/form'; | ||
|
|
||
| describe.only('FormTests - DSUserProfile', () => { | ||
| const firstFile = 'amplify-logo.jpg'; | ||
| const secondFile = 'amplify-logo.svg'; | ||
|
|
||
| beforeEach(() => { | ||
| cy.visit('http://localhost:3000/form-tests/DSUserProfile'); | ||
| }); | ||
|
|
||
| specify('Should be able to add and remove files on storage field', () => { | ||
| cy.get('#CreateUserProfile > form').within(() => { | ||
| getInputByLabel('Name').type('John Doe'); | ||
| getInputByLabel('Headline').type('Hello World'); | ||
|
|
||
| getStorageManagerByLabel('Image').within(() => { | ||
| cy.get('input[type=file]').selectFile(`cypress/fixtures/${firstFile}`, { action: 'select', force: true }); | ||
| // File is found in the selected list | ||
| cy.get('div.amplify-storagemanager__file__list > div.amplify-storagemanager__file').within(() => { | ||
| // Remove file from selected list | ||
| cy.contains(`Remove file ${firstFile}`).click(); | ||
| }); | ||
| // Removed file should not exist | ||
| cy.get('div.amplify-storagemanager__file__list > div.amplify-storagemanager__file').should('not.exist'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| specify('Should render error when uploading number of files that exceed maxFileCount limit', () => { | ||
| cy.get('#CreateUserProfile > form').within(() => { | ||
| getStorageManagerByLabel('Image').within(() => { | ||
| // `image` field configured with maxFileCount = 1 | ||
| cy.get('input[type=file]').selectFile([`cypress/fixtures/${firstFile}`, `cypress/fixtures/${secondFile}`], { | ||
| action: 'select', | ||
| force: true, | ||
| }); | ||
|
|
||
| cy.contains(/Cannot choose more than/).should('exist'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| specify('Should be able to select multiple files on supported storage fields', () => { | ||
| cy.get('#CreateUserProfile > form').within(() => { | ||
| getStorageManagerByLabel('Additional images').within(() => { | ||
| // `additionalImages` field configured with maxFileCount = 2 | ||
| cy.get('input[type=file]').selectFile([`cypress/fixtures/${firstFile}`, `cypress/fixtures/${secondFile}`], { | ||
| action: 'select', | ||
| force: true, | ||
| }); | ||
|
|
||
| cy.contains(/Cannot choose more than/).should('not.exist'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| specify('Should load with existing user profile and be able to unlink existing files from record', () => { | ||
| // Check initial data | ||
| cy.get('#UpdateUserProfile > #data-preview').within(() => { | ||
| cy.get('p') | ||
| .contains('name') | ||
| .contains(/Jane Doe/); | ||
| cy.get('p') | ||
| .contains('headline') | ||
| .contains(/Hello World/); | ||
| cy.get('p') | ||
| .contains('image') | ||
| .contains(/"file1.jpg"/); | ||
| cy.get('p') | ||
| .contains('additionalImages') | ||
| .contains(/["file2.jpg","file3.png"]/); | ||
|
|
||
| }); | ||
|
|
||
| cy.get('#UpdateUserProfile > form').within(() => { | ||
| getInputByLabel('Name').should('have.value', 'Jane Doe'); | ||
| getInputByLabel('Headline').should('have.value', 'Hello World'); | ||
|
|
||
| getStorageManagerByLabel('Image').within(() => { | ||
| // There should be a file associated with the user on load | ||
| cy.get('div.amplify-storagemanager__file__list > div.amplify-storagemanager__file').contains(/file1.jpg/); | ||
| }); | ||
|
|
||
| getStorageManagerByLabel('Additional images').within(() => { | ||
| // There should be multiple file associated with the user on load | ||
| cy.get('div.amplify-storagemanager__file__list > div.amplify-storagemanager__file') | ||
| .should('have.length', 2) | ||
| .first() | ||
| .within(() => { | ||
| // remove the first file (file2.jpg) | ||
| cy.contains(/file2.jpg/); | ||
| cy.contains(/Remove file/).click(); | ||
| }); | ||
| }); | ||
|
|
||
| cy.contains(/Submit/).click(); | ||
| }); | ||
|
|
||
| // Check data send onSubmit | ||
| cy.get('#UpdateUserProfile > #data-preview').within(() => { | ||
| cy.get('p') | ||
| .contains('name') | ||
| .contains(/Jane Doe/); | ||
| cy.get('p') | ||
| .contains('headline') | ||
| .contains(/Hello World/); | ||
| cy.get('p') | ||
| .contains('image') | ||
| .contains(/"file1.jpg"/); | ||
| cy.get('p') | ||
| .contains('additionalImages') | ||
| .contains(/["file3.png"]/); | ||
|
|
||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
Binary file added
BIN
+1.47 KB
...ges/test-generator/integration-test-templates/cypress/fixtures/amplify-logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
...ges/test-generator/integration-test-templates/cypress/fixtures/amplify-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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
83 changes: 83 additions & 0 deletions
83
packages/test-generator/integration-test-templates/src/FormTests/DSUserProfile.tsx
This file contains hidden or 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,83 @@ | ||
| /* | ||
| 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 '@aws-amplify/ui-react/styles.css'; | ||
| import { AmplifyProvider, View, Heading, Text } from '@aws-amplify/ui-react'; | ||
| import React, { useState, useEffect, useRef } from 'react'; | ||
| import { DataStore } from '@aws-amplify/datastore'; | ||
| import { DataStoreFormCreateUserProfile, DataStoreFormUpdateUserProfile } from '../ui-components'; // eslint-disable-line import/extensions, max-len | ||
| import { UserProfile } from '../models'; | ||
|
|
||
| const initializeTestData = async () => { | ||
| const existingProfile = await DataStore.save( | ||
| new UserProfile({ | ||
| name: 'Jane Doe', | ||
| image: 'file1.jpg', | ||
| additionalImages: ['file2.jpg', 'file3.png'], | ||
| headline: 'Hello World', | ||
| }), | ||
| ); | ||
| return { existingProfile }; | ||
| }; | ||
|
|
||
| export default function () { | ||
| const [DataStoreCreateUserProfileRecord, setDataStoreCreateUserProfileRecord] = useState<Partial<UserProfile>>({}); | ||
| const [isInitialized, setInitialized] = useState(false); | ||
| const initializeStarted = useRef(false); | ||
|
|
||
| useEffect(() => { | ||
| const initializeTestState = async () => { | ||
| if (initializeStarted.current) { | ||
| return; | ||
| } | ||
| // DataStore.clear() doesn't appear to reliably work in this scenario. | ||
| indexedDB.deleteDatabase('amplify-datastore'); | ||
| const { existingProfile } = await initializeTestData(); | ||
| setDataStoreCreateUserProfileRecord(existingProfile); | ||
| setInitialized(true); | ||
| }; | ||
|
|
||
| initializeTestState(); | ||
| initializeStarted.current = true; | ||
| }, []); | ||
|
|
||
| if (!isInitialized) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <AmplifyProvider> | ||
| <Heading>UserProfile</Heading> | ||
| <View id="CreateUserProfile"> | ||
| <DataStoreFormCreateUserProfile /> | ||
| </View> | ||
| <View id="UpdateUserProfile"> | ||
| <View id="data-preview"> | ||
| {DataStoreCreateUserProfileRecord && | ||
| Object.entries(DataStoreCreateUserProfileRecord).map(([prop, value]) => { | ||
| return <Text>{`${prop}: ${JSON.stringify(value)}`}</Text>; | ||
| })} | ||
| </View> | ||
| <DataStoreFormUpdateUserProfile | ||
| id={DataStoreCreateUserProfileRecord?.id} | ||
| onSubmit={(r) => { | ||
| setDataStoreCreateUserProfileRecord(r); | ||
| return r; | ||
| }} | ||
| /> | ||
| </View> | ||
| </AmplifyProvider> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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
39 changes: 39 additions & 0 deletions
39
packages/test-generator/integration-test-templates/src/models/index.d.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.