Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIIN-1671 create JEST/RTL for ItemsListRow.js #2090

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/Instance/ItemsList/ItemsListRow.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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(<ItemsListRow {...props} />);
};


describe('ItemsListRow', () => {
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('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();
});
});