From 97e0328838b76768567bfd90e711f72649df72c0 Mon Sep 17 00:00:00 2001 From: acnormun Date: Wed, 4 Dec 2024 18:27:52 -0300 Subject: [PATCH 1/7] chore: add currency element test --- .../airtime/currency/CurrencyElement.test.tsx | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx diff --git a/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx b/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx new file mode 100644 index 000000000..844d91d74 --- /dev/null +++ b/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx @@ -0,0 +1,108 @@ +import React from 'react'; +import { render, fireEvent } from '@testing-library/react'; +import { Provider } from 'react-redux'; +import configureStore from 'redux-mock-store'; +import CurrencyElement from './CurrencyElement'; +import { CurrencyElementProps } from './CurrencyElement'; +import { AssetType } from 'store/flowContext'; +import styles from './CurrencyElement.module.scss'; + +const mockStore = configureStore([]); + +describe('CurrencyElement Component', () => { + let store: any; + + const mockOnChange = vi.fn(); + const mockOnRemove = vi.fn(); + + const defaultProps: CurrencyElementProps = { + currencies: { + items: { + ['id1']: { + id: 'default currency', + name: 'default currency', + type: AssetType.Currency, + }, + }, + type: AssetType.Currency, + }, + transfer: { + value: { amount: '100', code: 'USD' }, + validationFailures: [], + }, + index: 0, + exclude: [], + onChange: mockOnChange, + onRemove: mockOnRemove, + }; + + beforeEach(() => { + store = mockStore({ + flowContext: { + assetStore: { + completion: { + items: [], + }, + }, + }, + }); + }); + + it('renders correctly with default props', () => { + const { getByText } = render( + + + , + ); + expect(getByText(/default currency/i)).toBeInTheDocument(); + }); + + it('renders amount input when index is greater than -1', () => { + const props = { + ...defaultProps, + index: 1, + }; + + const { getByPlaceholderText } = render( + + + , + ); + + expect(getByPlaceholderText(/Transfer Amount/i)).toBeInTheDocument(); + }); + + it('renders remove icon when index is greater than -1', () => { + const props = { + ...defaultProps, + index: 1, + }; + + const { container } = render( + + + , + ); + + const removeIcon = container.querySelector(`div.${styles.remove}`); + expect(removeIcon).toBeInTheDocument(); + }); + + it('calls onRemove when remove icon is clicked', () => { + const props = { + ...defaultProps, + index: 1, + }; + + const { container } = render( + + + , + ); + + const removeIcon = container.querySelector(`div.${styles.remove}`); + fireEvent.click(removeIcon); + + expect(mockOnRemove).toHaveBeenCalledWith(1); + }); +}); From 02101430adfb028bf6bc32c6d08a86cfb7294491 Mon Sep 17 00:00:00 2001 From: acnormun Date: Thu, 5 Dec 2024 11:18:48 -0300 Subject: [PATCH 2/7] fix: remove currency elements test --- .../actions/openticket/OpenTicket.test.tsx | 98 ------------------- 1 file changed, 98 deletions(-) delete mode 100644 src/components/flow/actions/openticket/OpenTicket.test.tsx diff --git a/src/components/flow/actions/openticket/OpenTicket.test.tsx b/src/components/flow/actions/openticket/OpenTicket.test.tsx deleted file mode 100644 index 8832ce824..000000000 --- a/src/components/flow/actions/openticket/OpenTicket.test.tsx +++ /dev/null @@ -1,98 +0,0 @@ -import * as React from 'react'; -import { render, screen } from '@testing-library/react'; -import OpenTicketComp from './OpenTicket'; -import { Types } from 'config/interfaces'; - -const mockContext = { - config: { - brand: 'MyBrand', - }, -}; - -const ConfigContext = React.createContext(mockContext); - -describe('OpenTicketComp', () => { - it('should render subject if provided', () => { - const props = { - ticketer: { name: 'John Doe', uuid: '1234' }, - subject: 'Test Subject', - body: 'This is the body', - result_name: 'Result Name', - type: Types.open_ticket, - uuid: '5678', - }; - - render( - - - , - ); - - expect(screen.getByText('Test Subject')).toBeInTheDocument(); - }); - - it('should render topic name if subject is not provided', () => { - const props = { - ticketer: { name: 'John Doe', uuid: '1234' }, - topic: { name: 'Test Topic', uuid: '5678' }, - body: 'This is the body', - result_name: 'Result Name', - type: Types.open_ticket, - uuid: '5678', - }; - - render( - - - , - ); - - expect(screen.getByText('Test Topic')).toBeInTheDocument(); - }); - - it('should display ticketer name if brand is not present in ticketer name', () => { - const props = { - context: { - config: { - brand: 'MyBrand', - }, - }, - ticketer: { name: 'Another Brand Support', uuid: '1234' }, - body: 'This is the body', - result_name: 'Result Name', - type: Types.open_ticket, - uuid: '5678', - }; - - render( - - - , - ); - - expect(screen.getByText(/Another Brand Support/)).toBeInTheDocument(); - }); - - // it('should not display ticketer name if brand is in ticketer name', () => { - // const props = { - // context: { - // config: { - // brand: 'MyBrand', - // }, - // }, - // ticketer: { name: 'MyBrand Support', uuid: '1234' }, - // body: 'This is the body', - // result_name: 'Result Name', - // type: Types.open_ticket, - // uuid: '5678', - // }; - - // render( - // - // - // , - // ); - - // expect(screen.queryByText(/Using/)).not.toBeInTheDocument(); - // }); -}); From 6fd8a6637041c79e5de9d54cb24058716282eddb Mon Sep 17 00:00:00 2001 From: acnormun Date: Thu, 5 Dec 2024 11:28:04 -0300 Subject: [PATCH 3/7] fix: openticket --- src/components/flow/actions/openticket/OpenTicket.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/components/flow/actions/openticket/OpenTicket.tsx b/src/components/flow/actions/openticket/OpenTicket.tsx index 66594ecaa..ef6c419e0 100644 --- a/src/components/flow/actions/openticket/OpenTicket.tsx +++ b/src/components/flow/actions/openticket/OpenTicket.tsx @@ -6,18 +6,13 @@ const OpenTicketComp: React.SFC = ( { ticketer, subject, topic }: OpenTicket, context: any, ): JSX.Element => { - const brand = - context && context.config && 'brand' in context.config - ? context.config.brand - : null; - const showTicketer = brand ? ticketer.name.indexOf(brand) === -1 : true; + const showTicketer = ticketer.name.indexOf(context.config.brand) === -1; return (
{subject ? subject : topic ? topic.name : null}
{showTicketer ? (
- Using aaaa {JSON.stringify(context)}{' '} - {ticketer.name} + Using {ticketer.name}
) : null}
From f9fed27b1d7f13105bc09f3f791c097dafcb24d4 Mon Sep 17 00:00:00 2001 From: acnormun Date: Thu, 5 Dec 2024 11:35:55 -0300 Subject: [PATCH 4/7] fix: clear test --- .../airtime/currency/CurrencyElement.test.tsx | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx b/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx index 844d91d74..64c4e8ede 100644 --- a/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx +++ b/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx @@ -36,6 +36,11 @@ describe('CurrencyElement Component', () => { onRemove: mockOnRemove, }; + const props = { + ...defaultProps, + index: 1, + }; + beforeEach(() => { store = mockStore({ flowContext: { @@ -58,11 +63,6 @@ describe('CurrencyElement Component', () => { }); it('renders amount input when index is greater than -1', () => { - const props = { - ...defaultProps, - index: 1, - }; - const { getByPlaceholderText } = render( @@ -73,11 +73,6 @@ describe('CurrencyElement Component', () => { }); it('renders remove icon when index is greater than -1', () => { - const props = { - ...defaultProps, - index: 1, - }; - const { container } = render( @@ -89,11 +84,6 @@ describe('CurrencyElement Component', () => { }); it('calls onRemove when remove icon is clicked', () => { - const props = { - ...defaultProps, - index: 1, - }; - const { container } = render( From 7519e6c446e27ed7896edc6d49c931a28f58fe50 Mon Sep 17 00:00:00 2001 From: acnormun Date: Fri, 6 Dec 2024 12:45:20 -0300 Subject: [PATCH 5/7] fix: add remove icon test --- .../airtime/currency/CurrencyElement.test.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx b/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx index 64c4e8ede..ccbd2d323 100644 --- a/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx +++ b/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx @@ -83,6 +83,21 @@ describe('CurrencyElement Component', () => { expect(removeIcon).toBeInTheDocument(); }); + it('doesn`t render remove icon when index is less than 0', () => { + const props = { + ...defaultProps, + index: -1, + }; + const { container } = render( + + + , + ); + + const removeIcon = container.querySelector(`div.${styles.remove}`); + expect(removeIcon).not.toBeInTheDocument(); + }); + it('calls onRemove when remove icon is clicked', () => { const { container } = render( From d0fffc6711ba6404523a9a587ab4f93c74e5c3a0 Mon Sep 17 00:00:00 2001 From: acnormun Date: Fri, 6 Dec 2024 15:41:51 -0300 Subject: [PATCH 6/7] fix: check amount input qhen index is less than 0 --- .../airtime/currency/CurrencyElement.test.tsx | 14 ++++++++++++++ .../routers/airtime/currency/CurrencyElement.tsx | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx b/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx index ccbd2d323..24acf0888 100644 --- a/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx +++ b/src/components/flow/routers/airtime/currency/CurrencyElement.test.tsx @@ -72,6 +72,20 @@ describe('CurrencyElement Component', () => { expect(getByPlaceholderText(/Transfer Amount/i)).toBeInTheDocument(); }); + it('doesn`t render amount input when index is less than 0', () => { + const props = { + ...defaultProps, + index: -1, + }; + const { queryByPlaceholderText } = render( + + + , + ); + + expect(queryByPlaceholderText('Transfer Amount')).not.toBeInTheDocument(); + }); + it('renders remove icon when index is greater than -1', () => { const { container } = render( diff --git a/src/components/flow/routers/airtime/currency/CurrencyElement.tsx b/src/components/flow/routers/airtime/currency/CurrencyElement.tsx index 53ef4c009..ea4c97551 100644 --- a/src/components/flow/routers/airtime/currency/CurrencyElement.tsx +++ b/src/components/flow/routers/airtime/currency/CurrencyElement.tsx @@ -93,7 +93,7 @@ export default class CurrencyElement extends React.Component< const amountInput = this.props.index > -1 ? ( -
+
Date: Fri, 6 Dec 2024 15:43:22 -0300 Subject: [PATCH 7/7] fix: remove unused test id --- .../flow/routers/airtime/currency/CurrencyElement.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/flow/routers/airtime/currency/CurrencyElement.tsx b/src/components/flow/routers/airtime/currency/CurrencyElement.tsx index ea4c97551..53ef4c009 100644 --- a/src/components/flow/routers/airtime/currency/CurrencyElement.tsx +++ b/src/components/flow/routers/airtime/currency/CurrencyElement.tsx @@ -93,7 +93,7 @@ export default class CurrencyElement extends React.Component< const amountInput = this.props.index > -1 ? ( -
+