-
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.
chore: adding mutation binding tests
- Loading branch information
1 parent
b11929a
commit 510880f
Showing
7 changed files
with
664 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
...ages/test-generator/integration-test-templates/cypress/integration/action-binding-spec.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,99 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
describe('Workflow', () => { | ||
before(() => { | ||
cy.visit('http://localhost:3000/action-binding-tests'); | ||
}); | ||
|
||
describe('Mutation Bindings', () => { | ||
it('supports value bindings', () => { | ||
cy.get('#mutated-value').contains('Fixed Value').should('not.exist'); | ||
cy.contains('Apply Fixed Property Mutation').click(); | ||
cy.get('#mutated-value').contains('Fixed Value'); | ||
}); | ||
|
||
it('supports bound prop bindings', () => { | ||
cy.get('#mutated-value').contains('Bound Value').should('not.exist'); | ||
cy.contains('Apply Bound Property Mutation').click(); | ||
cy.get('#mutated-value').contains('Bound Value'); | ||
}); | ||
|
||
it('supports concat bindings', () => { | ||
cy.get('#mutated-value').contains('Concatenated Value').should('not.exist'); | ||
cy.contains('Apply Concatenated Property Mutation').click(); | ||
cy.get('#mutated-value').contains('Concatenated Value'); | ||
}); | ||
|
||
it('supports conditional bindings', () => { | ||
cy.get('#mutated-value').contains('Conditional Value').should('not.exist'); | ||
cy.contains('Apply Conditional Property Mutation').click(); | ||
cy.get('#mutated-value').contains('Conditional Value'); | ||
}); | ||
|
||
// Auth Bindings not yet supported in functional tests | ||
it.skip('supports auth bindings', () => { | ||
cy.get('#mutated-value').contains('Auth Value').should('not.exist'); | ||
cy.contains('Apply Auth Property Mutation').click(); | ||
cy.get('#mutated-value').contains('Auth Value'); | ||
}); | ||
|
||
it('supports state bindings', () => { | ||
cy.get('#mutated-value').contains('State Value').should('not.exist'); | ||
cy.contains('Apply State Property Mutation').click(); | ||
cy.get('#mutated-value').contains('State Value'); | ||
}); | ||
}); | ||
|
||
describe('DataStore Bindings', () => { | ||
it('supports value bindings', () => { | ||
cy.get('#data-store-value').contains('Fixed Value').should('not.exist'); | ||
cy.contains('Apply Fixed Property DataStoreUpdateItemAction').click(); | ||
cy.get('#data-store-value').contains('Fixed Value'); | ||
}); | ||
|
||
it('supports bound prop bindings', () => { | ||
cy.get('#data-store-value').contains('Bound Value').should('not.exist'); | ||
cy.contains('Apply Bound Property DataStoreUpdateItemAction').click(); | ||
cy.get('#data-store-value').contains('Bound Value'); | ||
}); | ||
|
||
it('supports concat bindings', () => { | ||
cy.get('#data-store-value').contains('Concatenated Value').should('not.exist'); | ||
cy.contains('Apply Concatenated Property DataStoreUpdateItemAction').click(); | ||
cy.get('#data-store-value').contains('Concatenated Value'); | ||
}); | ||
|
||
it('supports conditional bindings', () => { | ||
cy.get('#data-store-value').contains('Conditional Value').should('not.exist'); | ||
cy.contains('Apply Conditional Property DataStoreUpdateItemAction').click(); | ||
cy.get('#data-store-value').contains('Conditional Value'); | ||
}); | ||
|
||
// Auth Bindings not yet supported in functional tests | ||
it.skip('supports auth bindings', () => { | ||
cy.get('#data-store-value').contains('Auth Value').should('not.exist'); | ||
cy.contains('Apply Auth Property DataStoreUpdateItemAction').click(); | ||
cy.get('#data-store-value').contains('Auth Value'); | ||
}); | ||
|
||
it('supports state bindings', () => { | ||
cy.get('#data-store-value').contains('State Value').should('not.exist'); | ||
cy.contains('Apply State Property DataStoreUpdateItemAction').click(); | ||
cy.get('#data-store-value').contains('State Value'); | ||
}); | ||
}); | ||
}); |
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
67 changes: 67 additions & 0 deletions
67
packages/test-generator/integration-test-templates/src/ActionBindingTests.tsx
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,67 @@ | ||
/* | ||
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, useEffect } from 'react'; | ||
import '@aws-amplify/ui-react/styles.css'; | ||
import { AmplifyProvider } from '@aws-amplify/ui-react'; | ||
import { DataStore } from '@aws-amplify/datastore'; | ||
import { useDataStoreBinding } from '@aws-amplify/ui-react/internal'; | ||
import { User, Listing } from './models'; | ||
// eslint-disable-next-line import/extensions | ||
import { MutationActionBindings, DataStoreActionBindings } from './ui-components'; | ||
|
||
export default function ActionBindingTests() { | ||
const [isInitialized, setInitialized] = useState(false); | ||
|
||
useEffect(() => { | ||
const initializeTestState = async () => { | ||
// DataStore.clear() doesn't appear to reliably work in this scenario. | ||
indexedDB.deleteDatabase('amplify-datastore'); | ||
await DataStore.save(new Listing({ title: 'Default Value' })); | ||
await DataStore.save(new User({ firstName: 'Johnny', lastName: 'Bound Value', age: 45 })); | ||
setInitialized(true); | ||
}; | ||
|
||
initializeTestState(); | ||
}, []); | ||
|
||
// Pulling this binding out here, since currently there's a bug in observeQuery, that doesn't let | ||
// us define a component which gets observable updates if a criteria is defined | ||
// https://github.com/aws-amplify/amplify-js/issues/9573 | ||
const listing = useDataStoreBinding({ | ||
type: 'collection', | ||
model: Listing, | ||
}).items[0]; | ||
|
||
if (!isInitialized) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<AmplifyProvider> | ||
<MutationActionBindings | ||
overrides={{ | ||
MutatedValue: { id: 'mutated-value' }, | ||
}} | ||
/> | ||
<DataStoreActionBindings | ||
listing={listing} | ||
overrides={{ | ||
DataStoreValue: { id: 'data-store-value' }, | ||
}} | ||
/> | ||
</AmplifyProvider> | ||
); | ||
} |
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
Oops, something went wrong.