Skip to content

Commit

Permalink
[FEQ] P2P-V2 Close header test (#13656)
Browse files Browse the repository at this point in the history
* chore: removed responsive root

* chore: reverted old changes

* chore: added test cases for close header

* chore: added test cases for close header
  • Loading branch information
adrienne-deriv authored Feb 22, 2024
1 parent 57d7c7e commit 0505cce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/p2p-v2/src/components/CloseHeader/CloseHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ const CloseHeader = () => {
<Text size={isMobile ? 'md' : 'xl'} weight='bold'>
{isMobile ? 'Deriv P2P' : 'Cashier'}
</Text>
<LabelPairedXmarkLgBoldIcon className='p2p-v2-close-header--icon' onClick={() => window.history.back()} />
<LabelPairedXmarkLgBoldIcon
className='p2p-v2-close-header--icon'
data-testid='dt_p2p_v2_close_header_close_icon'
onClick={() => window.history.back()}
/>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import CloseHeader from '../CloseHeader';

const mockUseDevice = {
isMobile: false,
};

jest.mock('@/hooks/useDevice', () => ({
__esModule: true,
default: jest.fn(() => mockUseDevice),
}));
let windowHistoryBackSpy: jest.SpyInstance<void, []>;

describe('CloseHeader', () => {
it('should navigate back when cross icon is clicked', () => {
windowHistoryBackSpy = jest.spyOn(window.history, 'back');
render(<CloseHeader />);
const crossIcon = screen.getByTestId('dt_p2p_v2_close_header_close_icon');
userEvent.click(crossIcon);
expect(windowHistoryBackSpy).toBeCalled();
});
it('should render the correct header title on desktop', () => {
render(<CloseHeader />);
expect(screen.queryByText('Cashier')).toBeInTheDocument();
});
it('should render the correct header title on mobile', () => {
mockUseDevice.isMobile = true;
render(<CloseHeader />);
expect(screen.queryByText('Deriv P2P')).toBeInTheDocument();
});
});

0 comments on commit 0505cce

Please sign in to comment.