From 8089e1553ed58111fdbf082da08699d08c2a3e30 Mon Sep 17 00:00:00 2001 From: ssandupatla <58558770+ssandupatla@users.noreply.github.com> Date: Wed, 29 Mar 2023 11:06:16 +0530 Subject: [PATCH 1/2] UIIN-1671 create JEST/RTL for ItemsListRow.js --- src/Instance/ItemsList/ItemsListRow.test.js | 79 +++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/Instance/ItemsList/ItemsListRow.test.js diff --git a/src/Instance/ItemsList/ItemsListRow.test.js b/src/Instance/ItemsList/ItemsListRow.test.js new file mode 100644 index 000000000..8bcb1ef68 --- /dev/null +++ b/src/Instance/ItemsList/ItemsListRow.test.js @@ -0,0 +1,79 @@ +import React from 'react'; +import { screen } from '@testing-library/react'; + +import '../../../test/jest/__mock__/currencyData.mock'; +import '../../../test/jest/__mock__/stripesConfig.mock'; +import '../../../test/jest/__mock__/stripesCore.mock'; +import { renderWithIntl } from '../../../test/jest/helpers'; + +import ItemsListRow from './ItemsListRow'; + +jest.mock('react-beautiful-dnd', () => ({ + Draggable: jest.fn().mockImplementation(({ children }) => children({ + draggableProps: { + style: {}, + }, + innerRef: jest.fn(), + }, + { + isDragging: false + })) + .mockImplementationOnce(({ children }) => children({ + draggableProps: { + style: {}, + }, + innerRef: jest.fn(), + }, + { + isDragging: true + })), +})); + +const mockisItemsDragSelected = jest.fn(); +const defaultProps = { + rowClass: [ + 'RowClass 1', + 'RowClass 2', + 'RowClass 3' + ], + cells: [ + 'cell 1', + 'cell 2', + 'cell 3' + ], + rowIndex: 1, + rowData: { + id: 'testID' + }, + rowProps: { + draggable: false, + isItemsDragSelected: mockisItemsDragSelected, + getDraggingItems: jest.fn().mockReturnValue({ + items: { + length: 5 + } + }) + }, +}; + +const renderItemsListRow = (props) => { + let container = document.getElementById('ModuleContainer'); + if (!container) { + container = document.createElement('div'); + container.setAttribute('id', 'ModuleContainer'); + document.body.appendChild(container); + } + renderWithIntl(); +}; + + +describe('ItemsListRow', () => { + it('new mo should render isDragging of snapshot is true', () => { + renderItemsListRow(defaultProps); + expect(screen.queryByText('ui-inventory.moveItems.move.items.count')).toBeInTheDocument(); + }); + it('child should render isDragging of snapshot is false', () => { + renderItemsListRow(defaultProps); + expect(screen.getByRole('row', { name: 'cell 1cell 2cell 3' })).toBeInTheDocument(); + }); +}); From abd568917ee7305e9f2865f7e1cd805de887cd18 Mon Sep 17 00:00:00 2001 From: ssandupatla <58558770+ssandupatla@users.noreply.github.com> Date: Fri, 14 Apr 2023 16:35:25 +0530 Subject: [PATCH 2/2] Update ItemsListRow.test.js Update js file --- src/Instance/ItemsList/ItemsListRow.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Instance/ItemsList/ItemsListRow.test.js b/src/Instance/ItemsList/ItemsListRow.test.js index 8bcb1ef68..5e5313ec1 100644 --- a/src/Instance/ItemsList/ItemsListRow.test.js +++ b/src/Instance/ItemsList/ItemsListRow.test.js @@ -68,12 +68,14 @@ const renderItemsListRow = (props) => { describe('ItemsListRow', () => { - it('new mo should render isDragging of snapshot is true', () => { + it('Message should render when isDragging of snapshot is true', () => { renderItemsListRow(defaultProps); expect(screen.queryByText('ui-inventory.moveItems.move.items.count')).toBeInTheDocument(); + expect(screen.queryByRole('row', { name: 'cell 1cell 2cell 3' })).not.toBeInTheDocument(); }); - it('child should render isDragging of snapshot is false', () => { + it('Row Data should render when isDragging of snapshot is false', () => { renderItemsListRow(defaultProps); + expect(screen.queryByText('ui-inventory.moveItems.move.items.count')).not.toBeInTheDocument(); expect(screen.getByRole('row', { name: 'cell 1cell 2cell 3' })).toBeInTheDocument(); }); });