-
Notifications
You must be signed in to change notification settings - Fork 0
Checkbox + Dropdown Question Tests #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
surbhi-gulati
wants to merge
18
commits into
main
Choose a base branch
from
sg-questiontests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3d83710
figure out exampleForm
surbhi-gulati 16302e4
Fix FormatQuestion.tsx imports error
surbhi-gulati a8ec383
Checkbox test errors bc hook call outside FC
surbhi-gulati 38adc93
Invalid hook call outside FC
surbhi-gulati 6b09919
Flopping w mocks
surbhi-gulati 0080a71
Fix DropdownQuestion test ID
surbhi-gulati 16e3ebe
Fix checkbox tests
surbhi-gulati 4fdb97c
Fix dropdown tests
surbhi-gulati ef06768
Fix dropdown failure
surbhi-gulati d25387a
merge main
surbhi-gulati 28ec518
merge main
surbhi-gulati b03b6eb
checkbox text change
surbhi-gulati a35ecdc
idk
surbhi-gulati 746dc52
finish dropdown question testing
surbhi-gulati ae7aa99
dropdown working now?
surbhi-gulati 8c77c06
does dropdown work wo correct vals test
surbhi-gulati 37178f4
does dropdown work wo disabled test
surbhi-gulati 2077a0a
fec disabled test
surbhi-gulati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
components/questions/checkboxes-question/CheckboxesQuestion.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { describe, expect, it } from '@jest/globals'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import CheckboxesQuestion from './CheckboxesQuestion'; | ||
| import { Checkboxes, QuestionResponse, QuestionType } from '../../../common/types'; | ||
| import { Form } from 'antd'; | ||
|
|
||
| Object.defineProperty(window, 'matchMedia', { | ||
| writable: true, | ||
| value: jest.fn().mockImplementation(query => ({ | ||
| matches: false, | ||
| media: query, | ||
| onchange: null, | ||
| addListener: jest.fn(), // Deprecated | ||
| removeListener: jest.fn(), // Deprecated | ||
| addEventListener: jest.fn(), | ||
| removeEventListener: jest.fn(), | ||
| dispatchEvent: jest.fn(), | ||
| })), | ||
| }); | ||
|
|
||
| describe('CheckboxesQuestion component', () => { | ||
| const n = (name: string) => ({ name }); | ||
| const exampleContent = 'Your top two most proficient languages. Select at least 1, but no more than 2.'; | ||
| const exampleQuestion: Checkboxes = { | ||
| field: 'education', | ||
| type: QuestionType.Checkboxes, | ||
| id: '1', | ||
| content: exampleContent, | ||
| minNumber: 1, | ||
| maxNumber: 2, | ||
| options: ['English', 'Java', 'Typescript', 'Japanese'].map(n), | ||
| required: true, | ||
| }; | ||
|
|
||
| const CheckboxesQuestionWrapper = () => { | ||
| const form = Form.useForm<Record<string, QuestionResponse>>()[0]; | ||
|
|
||
| return <CheckboxesQuestion question={exampleQuestion} form={form} disabled={false} />; | ||
| }; | ||
|
|
||
| it('renders', () => { | ||
| render(<CheckboxesQuestionWrapper />); | ||
| const confirmedDialogText = screen.getByTestId('checkboxes-question'); | ||
|
|
||
| expect(confirmedDialogText.textContent).toContain(exampleContent); | ||
| expect(confirmedDialogText.textContent).toContain("English"); | ||
| expect(confirmedDialogText.textContent).toContain("Java"); | ||
| expect(confirmedDialogText.textContent).toContain("Typescript"); | ||
| expect(confirmedDialogText.textContent).toContain("Japanese"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
components/questions/dropdown-question/DropdownQuestion.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { describe, expect, it } from '@jest/globals'; | ||
| import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
| import DropdownQuestion from './DropdownQuestion'; | ||
| import { Dropdown, QuestionResponse, QuestionType } from '../../../common/types'; | ||
| import { Form } from 'antd'; | ||
|
|
||
| Object.defineProperty(window, 'matchMedia', { | ||
| writable: true, | ||
| value: jest.fn().mockImplementation(query => ({ | ||
| matches: false, | ||
| media: query, | ||
| onchange: null, | ||
| addListener: jest.fn(), // Deprecated | ||
| removeListener: jest.fn(), // Deprecated | ||
| addEventListener: jest.fn(), | ||
| removeEventListener: jest.fn(), | ||
| dispatchEvent: jest.fn(), | ||
| })), | ||
| }); | ||
|
|
||
| describe('CheckboxesQuestion component', () => { | ||
| const n = (name: string) => ({ name }); | ||
| const exampleContent = 'How old are you?'; | ||
| const exampleQuestion: Dropdown = { | ||
| field: 'adult', | ||
| type: QuestionType.Dropdown, | ||
| id: '1', | ||
| content: exampleContent, | ||
| options: ['1', '2', '3', '4+'].map(n), | ||
| required: true, | ||
| }; | ||
|
|
||
| const DropdownQuestionWrapper = () => { | ||
| const form = Form.useForm<Record<string, QuestionResponse>>()[0]; | ||
|
|
||
| return <DropdownQuestion question={exampleQuestion} form={form} disabled={false} />; | ||
| }; | ||
|
|
||
| const DisabledDropdownQuestionWrapper = () => { | ||
| const form = Form.useForm<Record<string, QuestionResponse>>()[0]; | ||
|
|
||
| return <DropdownQuestion question={exampleQuestion} form={form} disabled={true} />; | ||
| }; | ||
|
|
||
| it('renders', () => { | ||
| render(<DropdownQuestionWrapper />); | ||
| const confirmedDialogText = screen.getByTestId('dropdown-question'); | ||
|
|
||
| expect(confirmedDialogText.textContent).toContain(exampleContent); | ||
| expect(confirmedDialogText.textContent).toContain("Select"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also be checking that the correct dropdown options render when it is clicked? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^^ this is a rlly good point! |
||
| }); | ||
|
|
||
| // it('renders the correct dropdown values', async () => { | ||
| // render(<DropdownQuestionWrapper />); | ||
| // const confirmedDialogText = screen.getByTestId('dropdown-question'); | ||
|
|
||
| // if (confirmedDialogText instanceof Element) { | ||
| // fireEvent.mouseDown(confirmedDialogText); | ||
| // } | ||
| // await waitFor(() => expect(screen.getAllByText('1')).toHaveLength(2)); | ||
|
|
||
| // if (confirmedDialogText instanceof Element) { | ||
| // fireEvent.mouseDown(confirmedDialogText); | ||
| // } | ||
| // await waitFor(() => expect(screen.getAllByText('2')).toHaveLength(2)); | ||
| // }); | ||
|
|
||
| it('does not render options when clicked, if it is disabled', async () => { | ||
| render(<DisabledDropdownQuestionWrapper />); | ||
| const confirmedDialogText = screen.getByTestId('dropdown-question').firstElementChild; | ||
|
|
||
| if (confirmedDialogText instanceof Element) { | ||
| fireEvent.mouseDown(confirmedDialogText); | ||
| } | ||
| await waitFor(() => expect(screen.getAllByText('1')).toHaveLength(0)); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.