Skip to content

Commit

Permalink
Align tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryczko committed Nov 9, 2024
1 parent 233de58 commit fcba034
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 6 deletions.
7 changes: 7 additions & 0 deletions cypress/e2e/answerSurvey.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]')
Expand Down
7 changes: 7 additions & 0 deletions cypress/e2e/createSurvey.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const AddQuestionButton = ({ onClick }: AddQuestionButtonProps) => {
onClick={openModal}
sizeType={ButtonSize.FULL}
className="h-[50px]"
data-test-id="add-question-button"
icon={<PlusCircleIcon className="h-5 w-5" />}
>
Add new block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,25 @@ export default function NewQuestionModal({
onClick={addEmojiQuestion}
icon={<EmojiIcon />}
text="Emoji"
testSelector="emoji-question-button"
/>
<NewQuestionModalButton
onClick={addInputQuestion}
icon={<InputIcon />}
text="Text"
testSelector="input-question-button"
/>
<NewQuestionModalButton
onClick={addChoiceQuestion}
icon={<ChoiceIcon />}
text="Choice"
test-selector="choice-question-button"
/>
<NewQuestionModalButton
onClick={addRateQuestion}
icon={<RateIcon />}
text="Rate"
test-selector="rate-question-button"
/>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Button
onClick={onClick}
className="flex flex-col p-4 text-center sm:w-[160px]"
data-test-id={testSelector}
>
<div className="mb-[2px] w-[18px]">{icon}</div>
{text}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface TemplateItemProps {
onTemplatePick: (event: React.MouseEvent<HTMLButtonElement>) => void;
isInPreview: boolean;
buttonContent?: string;
fieldTestSelector?: string;
buttonTestSelector?: string;
}

export default function TemplateItem({
Expand All @@ -19,10 +21,13 @@ export default function TemplateItem({
onTemplatePick,
isInPreview,
buttonContent,
fieldTestSelector,
buttonTestSelector,
}: TemplateItemProps) {
return (
<div
onClick={(e) => onTemplatePreview?.(e)}
data-test-id={fieldTestSelector}
className={clsx(
'flex h-[140px] flex-grow cursor-pointer flex-col items-center rounded border border-zinc-600/50 px-4 pb-4 shadow',
template ? 'border-solid bg-zinc-50' : 'bg-white',
Expand All @@ -35,6 +40,7 @@ export default function TemplateItem({
className="w-full"
variant={ButtonVariant.PRIMARY}
onClick={(e) => onTemplatePick(e)}
data-test-id={buttonTestSelector}
>
{buttonContent || 'Use Template'}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
});

Expand All @@ -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);
});
});

Expand Down

0 comments on commit fcba034

Please sign in to comment.