-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5e0814
commit f6d64b1
Showing
10 changed files
with
320 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,72 @@ | ||
// import { ReactNode } from 'react'; | ||
import { mockAdvertiserAdvertValues, mockCountryList } from '@/__mocks__/mock-data'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import CopyAdForm from '../CopyAdForm'; | ||
|
||
const mockProps = { | ||
...mockAdvertiserAdvertValues, | ||
formValues: { | ||
amount: 22, | ||
maxOrder: '22', | ||
minOrder: '22', | ||
rateValue: '22', | ||
}, | ||
isModalOpen: true, | ||
isValid: true, | ||
onClickCancel: jest.fn(), | ||
onFormSubmit: jest.fn(), | ||
onRequestClose: jest.fn(), | ||
}; | ||
|
||
jest.mock('@deriv-com/ui', () => ({ | ||
...jest.requireActual('@deriv-com/ui'), | ||
useDevice: () => ({ isMobile: false }), | ||
})); | ||
|
||
jest.mock('@/pages/my-ads/components/AdFormInput', () => ({ | ||
AdFormInput: () => <div>AdFormInput</div>, | ||
})); | ||
|
||
jest.mock('@/pages/my-ads/components/AdFormTextArea', () => ({ | ||
AdFormTextArea: () => <div>AdFormTextArea</div>, | ||
})); | ||
|
||
jest.mock('@/hooks/custom-hooks', () => { | ||
return { | ||
...jest.requireActual('@/hooks'), | ||
useFloatingRate: () => ({ floatRateOffsetLimitString: '22', rateType: 'fixed' }), | ||
}; | ||
}); | ||
|
||
jest.mock('@/hooks', () => ({ | ||
...jest.requireActual('@/hooks'), | ||
api: { | ||
countryList: { | ||
useGet: jest.fn(() => ({ data: mockCountryList })), | ||
}, | ||
}, | ||
})); | ||
|
||
describe('CopyAdForm', () => { | ||
it('should render the form', () => { | ||
render(<CopyAdForm {...mockProps} />); | ||
expect(screen.getByText('Ad type')).toBeInTheDocument(); | ||
expect(screen.getByText('Instructions')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText('Review your settings and create a new ad. Every ad must have unique limits and rates.') | ||
).toBeInTheDocument(); | ||
}); | ||
it('should handle cancel', async () => { | ||
render(<CopyAdForm {...mockProps} />); | ||
const button = screen.getByRole('button', { name: 'Cancel' }); | ||
await userEvent.click(button); | ||
expect(mockProps.onClickCancel).toHaveBeenCalled(); | ||
}); | ||
it('should handle submit', async () => { | ||
render(<CopyAdForm {...mockProps} />); | ||
const button = screen.getByRole('button', { name: 'Create ad' }); | ||
await userEvent.click(button); | ||
expect(mockProps.onFormSubmit).toHaveBeenCalled(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/components/CopyAdForm/__tests__/CopyAdFormDisplayWrapper.spec.tsx
This file contains 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,29 @@ | ||
import { useDevice } from '@deriv-com/ui'; | ||
import { render, screen } from '@testing-library/react'; | ||
import CopyAdFormDisplayWrapper from '../CopyAdFormDisplayWrapper'; | ||
|
||
const mockProps = { | ||
isModalOpen: true, | ||
isValid: true, | ||
onClickCancel: jest.fn(), | ||
onRequestClose: jest.fn(), | ||
onSubmit: jest.fn(), | ||
}; | ||
|
||
jest.mock('@deriv-com/ui', () => ({ | ||
...jest.requireActual('@deriv-com/ui'), | ||
useDevice: jest.fn(() => ({ isMobile: false })), | ||
})); | ||
|
||
describe('CopyAdFormDisplayWrapper', () => { | ||
it('should render the modal with header for desktop view', () => { | ||
render(<CopyAdFormDisplayWrapper {...mockProps} />); | ||
expect(screen.getByText('Create a similar ad')).toBeInTheDocument(); | ||
}); | ||
it('should render the full page mobile wrapper for mobile view', () => { | ||
(useDevice as jest.Mock).mockReturnValue({ isMobile: true }); | ||
render(<CopyAdFormDisplayWrapper {...mockProps} />); | ||
expect(screen.getByTestId('dt_full_page_mobile_wrapper')).toBeInTheDocument(); | ||
expect(screen.queryByText('Create a similar ad')).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains 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 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
41 changes: 41 additions & 0 deletions
41
src/components/Modals/CopyAdFormModal/__tests__/CopyAdFormModal.spec.tsx
This file contains 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,41 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import CopyAdFormModal from '../CopyAdFormModal'; | ||
|
||
const mockProps = { | ||
isModalOpen: true, | ||
isValid: true, | ||
onClickCancel: jest.fn(), | ||
onSubmit: jest.fn(), | ||
}; | ||
|
||
jest.mock('@deriv-com/ui', () => ({ | ||
...jest.requireActual('@deriv-com/ui'), | ||
useDevice: () => ({ isMobile: false }), | ||
})); | ||
describe('CopyAdFormModal', () => { | ||
it('should render the component as expected', () => { | ||
render(<CopyAdFormModal {...mockProps} />); | ||
expect(screen.getByText('Create a similar ad')).toBeInTheDocument(); | ||
}); | ||
it('should call onClickCancel function on clicking cancel button', async () => { | ||
render(<CopyAdFormModal {...mockProps} />); | ||
const button = screen.getByRole('button', { name: 'Cancel' }); | ||
await userEvent.click(button); | ||
expect(mockProps.onClickCancel).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should call onSubmit function on clicking submit button', async () => { | ||
render(<CopyAdFormModal {...mockProps} />); | ||
const button = screen.getByRole('button', { name: 'Create ad' }); | ||
await userEvent.click(button); | ||
expect(mockProps.onSubmit).toHaveBeenCalledTimes(1); | ||
}); | ||
it('should render the children as expected', () => { | ||
render( | ||
<CopyAdFormModal {...mockProps}> | ||
<div>Children</div> | ||
</CopyAdFormModal> | ||
); | ||
expect(screen.getByText('Children')).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.