From eef990108086c17d837863563585a6b06981b063 Mon Sep 17 00:00:00 2001 From: Leung Cheng Date: Fri, 26 Jul 2024 17:44:48 +0800 Subject: [PATCH] Interactor add delete related methods --- src/app/components/editor.test.tsx | 37 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/app/components/editor.test.tsx b/src/app/components/editor.test.tsx index 280525f..071160b 100644 --- a/src/app/components/editor.test.tsx +++ b/src/app/components/editor.test.tsx @@ -132,6 +132,29 @@ class UIServiceInteractor { fireEvent.click(screen.getByText('Save')) return this } + + clickDelete() { + fireEvent.click(screen.getByText('Delete')) + return this + } + + clickConfirmDelete() { + fireEvent.click( + screen.getByRole('button', { + name: 'Confirm', + }), + ) + return this + } + + clickCancelDelete() { + fireEvent.click( + screen.getByRole('button', { + name: 'Cancel', + }), + ) + return this + } } class QuestionComponentQueryHelper { @@ -832,12 +855,7 @@ describe('QuestionSetEditor', () => { }) interactor.renderModifyingPage(questionSet.id) - fireEvent.click(screen.getByText('Delete')) - fireEvent.click( - screen.getByRole('button', { - name: 'Confirm', - }), - ) + interactor.clickDelete().clickConfirmDelete() expect(questionSetRepo.getQuestionSets()).toEqual([]) }) @@ -850,12 +868,7 @@ describe('QuestionSetEditor', () => { const interactor = new UIServiceInteractor({ questionSetRepo }) interactor.renderModifyingPage(questionSet.id) - fireEvent.click(screen.getByText('Delete')) - fireEvent.click( - screen.getByRole('button', { - name: 'Cancel', - }), - ) + interactor.clickDelete().clickCancelDelete() expect(screen.queryByRole('button', { name: 'Confirm' })).toBeNull() })