-
Notifications
You must be signed in to change notification settings - Fork 0
Task_9.Tests: add tests #7
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
{ | ||
"presets": [ | ||
["@babel/preset-env", {"corejs": 3, "useBuiltIns": "usage"}], | ||
"@babel/react" | ||
"@babel/react", | ||
"@babel/preset-typescript" | ||
], | ||
"plugins": ["@babel/plugin-transform-runtime"] | ||
"plugins": [ | ||
[ | ||
"@babel/plugin-proposal-decorators", | ||
{ | ||
"legacy": true | ||
} | ||
], | ||
"@babel/plugin-proposal-class-properties", | ||
"@babel/plugin-transform-runtime" | ||
] | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,10 +60,10 @@ export const ModalFooter: React.FC<{ | |
return ( | ||
<ModalFooterContainer> | ||
<Button type={'reset'} onClick={onDecline} classNames={declineBtnCn}> | ||
<span className={declineBtnContentCn}>{declineContent}</span> | ||
<span data-testid={'decline-btn'} className={declineBtnContentCn}>{declineContent}</span> | ||
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. it's better: data-testid="decline-btn" |
||
</Button> | ||
<Button type={'submit'} onClick={onConfirm} classNames={confirmBtnCn}> | ||
<span className={confirmBtnContentCn}>{confirmContent}</span> | ||
<span data-testid={'confirm-btn'} className={confirmBtnContentCn}>{confirmContent}</span> | ||
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. data-testid="confirm-btn" |
||
</Button> | ||
</ModalFooterContainer> | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ export const Close: React.FC<{ | |
); | ||
|
||
return ( | ||
<div onClick={onClick} className={defaultClassNames} > | ||
<div data-testid={'close'} onClick={onClick} className={defaultClassNames} > | ||
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. data-testid="close" |
||
X | ||
</div> | ||
) | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import '@testing-library/jest-dom' | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { renderHook } from '@testing-library/react-hooks' | ||
import { ConfirmationDialog } from '@components'; | ||
import { useModal } from './useModal'; | ||
import * as context from '../context'; | ||
|
||
jest.mock('../context', () => ({ | ||
useDialogContext: jest.fn(), | ||
useDialogDispatch: jest.fn(), | ||
DialogContainer: jest.fn(() => (<></>)) | ||
})); | ||
|
||
describe('show modal hook test', () => { | ||
it('is service mock called', () => { | ||
|
||
const { result } = renderHook(() => useModal('test_confirmation_dialog', ConfirmationDialog)); | ||
|
||
const [ openFn, RenderFn, closeFn, state ] = result.current; | ||
|
||
const dialogSettings = { | ||
DialogContent: () => (<>Test dialog content</>), | ||
dialogTitle: 'Test dialog title', | ||
onConfirm: jest.fn(), | ||
}; | ||
|
||
render( | ||
<context.DialogContainer> | ||
<div id="dialog-root"></div> | ||
<RenderFn {...dialogSettings}/> | ||
</context.DialogContainer> | ||
); | ||
|
||
expect(state).toBeFalsy(); | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`render counter component 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="counter" | ||
> | ||
<span | ||
class="text text_lg text_white text_bold padding-h_right_10px" | ||
> | ||
2 | ||
</span> | ||
<span | ||
class="text text_normal text_md text_white" | ||
> | ||
movies found | ||
</span> | ||
</div> | ||
</DocumentFragment> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import '@testing-library/jest-dom' | ||
import * as React from 'react'; | ||
|
||
import { render } from '@testing-library/react'; | ||
import { Counter } from './Counter'; | ||
|
||
it('render counter component', () => { | ||
const { asFragment } = render(<Counter count={2}/>); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import '@testing-library/jest-dom' | ||
import * as React from 'react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
import { SearchMovie } from './SearchMovie'; | ||
|
||
it('render search movie component', () => { | ||
render(<SearchMovie />); | ||
const text = screen.getByText("find your movie"); | ||
expect(text).toBeInTheDocument(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need
key
on this element?