From fcba034c066882ad6527e8a8785bbd6d36426764 Mon Sep 17 00:00:00 2001 From: Ryczko Date: Sat, 9 Nov 2024 14:17:49 +0100 Subject: [PATCH] Align tests --- cypress/e2e/answerSurvey.cy.ts | 7 +++++++ cypress/e2e/createSurvey.cy.ts | 7 +++++++ .../components/AddQuestionButton/AddQuestionButton.tsx | 1 + .../components/NewQuestionModal/NewQuestionModal.tsx | 4 ++++ .../components/NewQuestionModalButton.tsx | 3 +++ .../SurveyCreator/components/Templates/TemplateItem.tsx | 6 ++++++ .../SurveyCreator/components/Templates/Templates.tsx | 2 ++ .../createSurveyManager/createSurveyManager.test.tsx | 8 ++------ 8 files changed, 32 insertions(+), 6 deletions(-) diff --git a/cypress/e2e/answerSurvey.cy.ts b/cypress/e2e/answerSurvey.cy.ts index af3f3246..04d29d18 100644 --- a/cypress/e2e/answerSurvey.cy.ts +++ b/cypress/e2e/answerSurvey.cy.ts @@ -11,6 +11,13 @@ describe('Answering survey tests', () => { cy.get('[data-test-id="create-survey"]').click(); cy.url().should('include', '/survey/create'); + cy.get('[data-test-id="start-from-scratch-field"]').click(); + cy.get('[data-test-id="start-from-scratch-button"]').click(); + cy.get('[data-test-id="add-question-button"]').click(); + cy.get('[data-test-id="emoji-question-button"]').click(); + cy.get('[data-test-id="add-question-button"]').click(); + cy.get('[data-test-id="input-question-button"]').click(); + cy.get('input[name="survey-title"]').clear().type(surveyTitle); cy.get('input[data-test-id="question-input-0"]') diff --git a/cypress/e2e/createSurvey.cy.ts b/cypress/e2e/createSurvey.cy.ts index bd6fb0c9..8e9789e3 100644 --- a/cypress/e2e/createSurvey.cy.ts +++ b/cypress/e2e/createSurvey.cy.ts @@ -9,6 +9,13 @@ describe('Creating survey tests', () => { cy.get('[data-test-id="create-survey"]').click(); cy.url().should('include', '/survey/create'); + cy.get('[data-test-id="start-from-scratch-field"]').click(); + cy.get('[data-test-id="start-from-scratch-button"]').click(); + cy.get('[data-test-id="add-question-button"]').click(); + cy.get('[data-test-id="emoji-question-button"]').click(); + cy.get('[data-test-id="add-question-button"]').click(); + cy.get('[data-test-id="input-question-button"]').click(); + cy.get('input[name="survey-title"]').clear().type(surveyTitle); cy.get('input[data-test-id="question-input-0"]') diff --git a/src/features/surveys/features/SurveyCreator/components/AddQuestionButton/AddQuestionButton.tsx b/src/features/surveys/features/SurveyCreator/components/AddQuestionButton/AddQuestionButton.tsx index 9a2cd902..ca1355b3 100644 --- a/src/features/surveys/features/SurveyCreator/components/AddQuestionButton/AddQuestionButton.tsx +++ b/src/features/surveys/features/SurveyCreator/components/AddQuestionButton/AddQuestionButton.tsx @@ -16,6 +16,7 @@ export const AddQuestionButton = ({ onClick }: AddQuestionButtonProps) => { onClick={openModal} sizeType={ButtonSize.FULL} className="h-[50px]" + data-test-id="add-question-button" icon={} > Add new block diff --git a/src/features/surveys/features/SurveyCreator/components/NewQuestionModal/NewQuestionModal.tsx b/src/features/surveys/features/SurveyCreator/components/NewQuestionModal/NewQuestionModal.tsx index becf29ea..c3cd7812 100644 --- a/src/features/surveys/features/SurveyCreator/components/NewQuestionModal/NewQuestionModal.tsx +++ b/src/features/surveys/features/SurveyCreator/components/NewQuestionModal/NewQuestionModal.tsx @@ -86,21 +86,25 @@ export default function NewQuestionModal({ onClick={addEmojiQuestion} icon={} text="Emoji" + testSelector="emoji-question-button" /> } text="Text" + testSelector="input-question-button" /> } text="Choice" + test-selector="choice-question-button" /> } text="Rate" + test-selector="rate-question-button" /> } diff --git a/src/features/surveys/features/SurveyCreator/components/NewQuestionModal/components/NewQuestionModalButton.tsx b/src/features/surveys/features/SurveyCreator/components/NewQuestionModal/components/NewQuestionModalButton.tsx index 379b7373..be11d464 100644 --- a/src/features/surveys/features/SurveyCreator/components/NewQuestionModal/components/NewQuestionModalButton.tsx +++ b/src/features/surveys/features/SurveyCreator/components/NewQuestionModal/components/NewQuestionModalButton.tsx @@ -5,17 +5,20 @@ interface NewQuestionModalButtonProps { onClick: () => void; icon: React.ReactNode; text: string; + testSelector?: string; } export default function NewQuestionModalButton({ onClick, icon, text, + testSelector, }: NewQuestionModalButtonProps) { return ( diff --git a/src/features/surveys/features/SurveyCreator/components/Templates/Templates.tsx b/src/features/surveys/features/SurveyCreator/components/Templates/Templates.tsx index b1ffc3f5..2511c476 100644 --- a/src/features/surveys/features/SurveyCreator/components/Templates/Templates.tsx +++ b/src/features/surveys/features/SurveyCreator/components/Templates/Templates.tsx @@ -85,6 +85,8 @@ function Templates() { } isInPreview={previewIndex === 1} buttonContent="Start from scratch" + fieldTestSelector="start-from-scratch-field" + buttonTestSelector="start-from-scratch-button" /> {TEMPLATES.map((template, index) => ( diff --git a/src/features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager.test.tsx b/src/features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager.test.tsx index ab0e4411..546cd656 100644 --- a/src/features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager.test.tsx +++ b/src/features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager.test.tsx @@ -1,7 +1,6 @@ import { useCreateSurveyManager } from 'features/surveys/features/SurveyCreator/managers/createSurveyManager/createSurveyManager'; import { v4 } from 'uuid'; import { act, renderHook, waitFor } from '@testing-library/react'; -import { defaultQuestions } from 'shared/constants/surveysConfig'; import { useApplicationManager } from 'features/application/manager'; import { ApplicationContext } from 'features/application/context'; import { PropsWithChildren } from 'react'; @@ -58,7 +57,7 @@ describe('useCreateSurveyManager tests', () => { }); await waitFor(() => { - expect(result.current.questions.length).toBe(defaultQuestions.length + 2); + expect(result.current.questions.length).toBe(2); }); }); @@ -70,10 +69,7 @@ describe('useCreateSurveyManager tests', () => { }); await waitFor(() => { - expect(result.current.questions.length).toBe(defaultQuestions.length); - }); - await waitFor(() => { - expect(result.current.questions[1].title).toBe(NEW_QUESTION_TITLE); + expect(result.current.questions.length).toBe(0); }); });