From a527462ce2583a80d5d1e178b03e375b6bf8f74e Mon Sep 17 00:00:00 2001 From: Alan Date: Mon, 13 Sep 2021 22:01:02 +0200 Subject: [PATCH] fix flaky cypress test --- cypress/integration/smoke.ts | 29 +++++++------------ .../comments/components/DeleteComment.tsx | 2 +- .../components/DeleteDiscussion.tsx | 4 +-- src/features/users/components/DeleteUser.tsx | 2 +- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/cypress/integration/smoke.ts b/cypress/integration/smoke.ts index 9de396fb..c7cd2cf0 100644 --- a/cypress/integration/smoke.ts +++ b/cypress/integration/smoke.ts @@ -91,13 +91,9 @@ describe('smoke', () => { cy.wait(200); // visit discussion page: - cy.findByRole('row', { - name: `${discussion.title} ${formatDate(discussion.createdAt)} View Delete`, - }).within(() => { - cy.findByRole('link', { - name: /view/i, - }).click(); - }); + cy.findByRole('link', { + name: /view/i, + }).click(); cy.findByRole('heading', { name: discussion.title, @@ -174,7 +170,7 @@ describe('smoke', () => { cy.findByRole('dialog').within(() => { cy.findByRole('button', { - name: /delete/i, + name: /delete comment/i, }).click(); }); @@ -196,25 +192,22 @@ describe('smoke', () => { cy.wait(200); // delete discussion: - cy.findByRole('row', { - name: `${updatedDiscussion.title} ${formatDate(discussion.createdAt)} View Delete`, - }).within(() => { - cy.findByRole('button', { - name: 'Delete', - }).click(); - }); + cy.findByRole('button', { + name: /delete discussion/i, + }).click(); cy.findByRole('dialog').within(() => { cy.findByRole('button', { - name: /delete/i, + name: /delete discussion/i, }).click(); }); cy.checkAndDismissNotification(/discussion deleted/i); cy.wait(200); - cy.findByRole('row', { - name: `${updatedDiscussion.title} ${formatDate(discussion.createdAt)} View Delete`, + + cy.findByRole('cell', { + name: updatedDiscussion.title, }).should('not.exist'); }); }); diff --git a/src/features/comments/components/DeleteComment.tsx b/src/features/comments/components/DeleteComment.tsx index 8e9c21dd..9f5f0010 100644 --- a/src/features/comments/components/DeleteComment.tsx +++ b/src/features/comments/components/DeleteComment.tsx @@ -30,7 +30,7 @@ export const DeleteComment = ({ id, discussionId }: DeleteCommentProps) => { className="bg-red-600" onClick={async () => await deleteCommentMutation.mutateAsync({ commentId: id })} > - Delete + Delete Comment } /> diff --git a/src/features/discussions/components/DeleteDiscussion.tsx b/src/features/discussions/components/DeleteDiscussion.tsx index 6f146194..f0fc2288 100644 --- a/src/features/discussions/components/DeleteDiscussion.tsx +++ b/src/features/discussions/components/DeleteDiscussion.tsx @@ -20,7 +20,7 @@ export const DeleteDiscussion = ({ id }: DeleteDiscussionProps) => { body="Are you sure you want to delete this discussion?" triggerButton={ } confirmButton={ @@ -30,7 +30,7 @@ export const DeleteDiscussion = ({ id }: DeleteDiscussionProps) => { className="bg-red-600" onClick={async () => await deleteDiscussionMutation.mutateAsync({ discussionId: id })} > - Delete + Delete Discussion } /> diff --git a/src/features/users/components/DeleteUser.tsx b/src/features/users/components/DeleteUser.tsx index c0e63866..0799a244 100644 --- a/src/features/users/components/DeleteUser.tsx +++ b/src/features/users/components/DeleteUser.tsx @@ -26,7 +26,7 @@ export const DeleteUser = ({ id }: DeleteUserProps) => { className="bg-red-600" onClick={() => deleteUserMutation.mutate({ userId: id })} > - Delete + Delete User } />