diff --git a/packages/components/src/components/popover/popover.tsx b/packages/components/src/components/popover/popover.tsx index 9661d670aab6..b175ec643413 100644 --- a/packages/components/src/components/popover/popover.tsx +++ b/packages/components/src/components/popover/popover.tsx @@ -57,6 +57,7 @@ const Popover = ({ return (
} className={classNames({ 'dc-popover__wrapper': relative_render })} onClick={onClick} diff --git a/packages/core/src/App/Components/Layout/Header/__tests__/account-info.spec.tsx b/packages/core/src/App/Components/Layout/Header/__tests__/account-info.spec.tsx index 61c7399fc01a..106d5f706b96 100644 --- a/packages/core/src/App/Components/Layout/Header/__tests__/account-info.spec.tsx +++ b/packages/core/src/App/Components/Layout/Header/__tests__/account-info.spec.tsx @@ -1,77 +1,102 @@ -// TODO refactor old tests in this component import React from 'react'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import AccountInfo from '../account-info.jsx'; -import { Icon } from '@deriv/components'; -import { AccountSwitcher } from '../../../../Containers/AccountSwitcher'; -import { CSSTransition } from 'react-transition-group'; -import { render } from '@testing-library/react'; -describe('AccountInfo', () => { - it('should render one component', () => { +describe('AccountInfo component', () => { + it('should show "disabled_message" when "is_disabled" property is "true"', () => { + render(); + const popover = screen.getByTestId('dt_popover_container'); + userEvent.hover(popover); + const disabled_message = screen.getByText(/test disabled message/i); + expect(disabled_message).toBeInTheDocument(); + }); + + it('should have "acc-info--is-disabled" class when "is_disabled" property is "true"', () => { + render(); + const div_element = screen.getByTestId('dt_acc_info'); + expect(div_element).toHaveClass('acc-info--is-disabled'); + }); + + it('should have "acc-info--is-virtual" class when "is_virtual" property is "true"', () => { + render(); + const div_element = screen.getByTestId('dt_acc_info'); + expect(div_element).toHaveClass('acc-info--is-virtual'); + }); + + it('should not have "acc-info--show" class when "is_dialog_on" property is "false"', () => { + render(); + const div_element = screen.getByTestId('dt_acc_info'); + expect(div_element).not.toHaveClass('acc-info--show'); + }); + + it('can not "toggleDialog" when "is_disabled" property is "true"', () => { + const toggleDialog = jest.fn(); + render(); + const div_element = screen.getByTestId('dt_acc_info'); + userEvent.click(div_element); + expect(toggleDialog).toHaveBeenCalledTimes(0); + }); + + it('should render "AccountInfoIcon" with the proper className', () => { + const { rerender } = render(); + expect(screen.getByTestId('dt_icon')).toHaveClass('acc-info__id-icon--usd'); + + rerender(); + expect(screen.getByTestId('dt_icon')).toHaveClass('acc-info__id-icon--virtual'); + }); + + it('should render "IcLock" icon when "is_disabled" property is "true"', () => { + render(); + const icon = screen.getByTestId('dt_lock_icon'); + expect(icon).toBeInTheDocument(); + }); + + it('should render "IcChevronDownBold" icon when "is_disabled" property is "false"', () => { + render(); + const icon = screen.getByTestId('dt_select_arrow'); + expect(icon).toBeInTheDocument(); + }); + + it('should not render balance section when "currency" property passed', () => { render(); - // const wrapper = shallow(); - // expect(wrapper).toHaveLength(1); + const balance_wrapper = screen.queryByTestId('dt_balance'); + expect(balance_wrapper).not.toBeInTheDocument(); + }); + + it('should have "acc-info__balance--no-currency" class when "is_virtual" property is "false" and we don\'t have "currency" property', () => { + render(); + const balance_wrapper = screen.getByTestId('dt_balance'); + expect(balance_wrapper).toHaveClass('acc-info__balance--no-currency'); + }); + + it('should have "No currency assigned" text when we don\'t have "currency" property', () => { + render(); + const text = screen.getByText(/no currency assigned/i); + expect(text).toBeInTheDocument(); + }); + + it('should have "123456789 USD" text when we have "currency" and "balance" properties', () => { + render(); + const text = screen.getByText(/123456789 usd/i); + expect(text).toBeInTheDocument(); + expect(screen.queryByText(/no currency assigned/i)).not.toBeInTheDocument(); + }); + + it('should render proper "AccountType" base on the passed properties', () => { + const { rerender } = render(); + expect(screen.getByText(/multipliers/i)).toBeInTheDocument(); + + rerender(); + expect(screen.getByText(/gaming/i)).toBeInTheDocument(); + + rerender(); + expect(screen.getByText(/options/i)).toBeInTheDocument(); + + rerender(); + expect(screen.getByText(/options/i)).toBeInTheDocument(); + + rerender(); + expect(screen.getByText(/derived/i)).toBeInTheDocument(); }); - // it('should have .acc-info--show if is_dialog_on is true', () => { - // const wrapper = shallow(); - // expect(wrapper.find('.acc-info--show').exists()).toBe(true); - // }); - // it('should not have .acc-info--show if is_dialog_on is false', () => { - // const wrapper = shallow(); - // expect(wrapper.find('.acc-info--show').exists()).toBe(false); - // }); - // it('should have .acc-info--is-virtual if is_virtual is true', () => { - // const wrapper = shallow(); - // expect(wrapper.find('.acc-info--is-virtual').exists()).toBe(true); - // }); - // it('should not have .acc-info--is-virtual if is_virtual is false', () => { - // const wrapper = shallow(); - // expect(wrapper.find('.acc-info--is-virtual').exists()).toBe(false); - // }); - // it('should contain and children', () => { - // const wrapper = shallow( - // true} is_upgrade_enabled={true} /> - // ); - // expect( - // wrapper.contains( - // - //
- // true} is_upgrade_enabled={true} /> - //
- //
- // ) - // ); - // }); - // it("should have CSSTransition's prop 'in' equal to false when is_dialog_on is false", () => { - // const wrapper = shallow( - // true} is_upgrade_enabled={true} /> - // ); - // expect(wrapper.find(CSSTransition).prop('in')).toBe(false); - // }); - // it("should have CSSTransition's prop 'in' equal to true when is_dialog_on is true", () => { - // const wrapper = shallow( - // true} is_upgrade_enabled={true} /> - // ); - // expect(wrapper.find(CSSTransition).prop('in')).toBe(true); - // }); - // it("should have AccountSwitcher's prop 'is_visible' equal to true when is_dialog_on is true", () => { - // const wrapper = shallow( - // true} is_upgrade_enabled={true} /> - // ); - // expect(wrapper.find(AccountSwitcher).prop('is_visible')).toBe(true); - // }); - // it("should have AccountSwitcher's prop 'is_visible' equal to false when is_dialog_on is false", () => { - // const wrapper = shallow( - // true} is_upgrade_enabled={true} /> - // ); - // expect(wrapper.find(AccountSwitcher).prop('is_visible')).toBe(false); - // }); - // it('should not have .acc-balance-amount when balance is undefined', () => { - // const wrapper = shallow(); - // expect(wrapper.find('.acc-balance-amount').exists()).toBe(false); - // }); - // it('should render balance when balance is passed in props', () => { - // const wrapper = shallow(); - // expect(wrapper.contains(

123456789 USD

)).toBe(true); - // }); }); diff --git a/packages/core/src/App/Components/Layout/Header/account-info.jsx b/packages/core/src/App/Components/Layout/Header/account-info.jsx index 69b5f254fbf4..ad02d60a8813 100644 --- a/packages/core/src/App/Components/Layout/Header/account-info.jsx +++ b/packages/core/src/App/Components/Layout/Header/account-info.jsx @@ -19,6 +19,7 @@ const AccountInfoWrapper = ({ is_disabled, disabled_message, children }) => const AccountInfoIcon = ({ is_virtual, currency }) => ( { - const currency_lower = currency.toLowerCase(); + const currency_lower = currency?.toLowerCase(); return (

)} {is_disabled ? ( - + ) : ( - + )}