Skip to content

Commit

Permalink
test: fix bidirectional 1:m test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hein Jeong authored and hein-j committed Mar 16, 2023
1 parent d81a50e commit 3eef853
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ describe('FormTests - DSBidirectionalToy', () => {
});

specify('Create Dog - should update toy connection to new dog', () => {
const connectedPhrase1 = 'Toy BiDirectionalDogId is connected to new dog';
const connectedPhrase2 = 'Toy biDirectionalDogBiDirectionalToysId is connected to new dog';

cy.get('#DataStoreFormCreateBidirectionalDog').within(() => {
cy.contains(connectedPhrase1).should('not.exist');
cy.contains(connectedPhrase2).should('not.exist');

getInputByLabel('Name').type('Spot');

getArrayFieldButtonByLabel('Bi directional toys').click();
typeInAutocomplete('F{downArrow}{enter}');
typeInAutocomplete('B{downArrow}{enter}');
clickAddToArray();

cy.contains('Submit').click();

cy.contains('Toy BiDirectionalDogId is connected to new dog');
cy.contains('Toy biDirectionalDogBiDirectionalToysId is connected to new dog');
cy.contains(connectedPhrase1);
cy.contains(connectedPhrase2);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ export default function DSBidirectionalToy() {
}
// DataStore.clear() doesn't appear to reliably work in this scenario.
indexedDB.deleteDatabase('amplify-datastore');
const { connectedDog, connectedToy } = await initializeTestData();
setCreatedDogId(connectedDog.id);
const { connectedToy } = await initializeTestData();
setDogBiDirectionalToyId({
toyBiDirectionalDogIdUpdated: (await connectedToy.BiDirectionalDog).id,
biDirectionalDogBiDirectionalToysIdUpdated: connectedToy.biDirectionalDogBiDirectionalToysId,
Expand All @@ -82,6 +81,13 @@ export default function DSBidirectionalToy() {
const results = await DataStore.query(BiDirectionalDog, (dog) => dog.name.eq('Spot'));
const createdDogId = results.pop()?.id ?? '';
setCreatedDogId(createdDogId);
const stolenToy = (await DataStore.query(BiDirectionalToy, (toy) => toy.name.eq(toyName))).pop();
if (stolenToy) {
setDogBiDirectionalToyId({
toyBiDirectionalDogIdUpdated: (await stolenToy.BiDirectionalDog).id,
biDirectionalDogBiDirectionalToysIdUpdated: stolenToy.biDirectionalDogBiDirectionalToysId,
});
}
}}
/>
<Text>
Expand Down

0 comments on commit 3eef853

Please sign in to comment.