import React from 'react';
import { act } from 'react-dom/test-utils';
import { mount, shallow } from 'enzyme';
import { UserContext } from '@wealthlabs/user';
import { Loader, QuickEditResource } from '@wealthlabs/midgard-components';
import OpportunityItemsTab from '../OpportunityItemsTab.jsx';
import OpportunityResourceReworked from '../../../../../../resources/OpportunityResourceReworked.js';
import MaximumDiscountPercentageResource from '../../../../../../resources/pipeline/MaximumDiscountPercentageResource.js';
import OpportunityItemQuickEditResource from '../../../../../../resources/quickedit/OpportunityItemQuickEditResource.js';
import spy from 'sinon/lib/sinon/spy.js';
const spyMaximumDiscountPercentageResource = jest
.spyOn(MaximumDiscountPercentageResource, 'get')
.mockImplementation(() =>
Promise.resolve({
data: [
{
userId: '0734f031-00d1-452c-a0ba-d3c43f2c3d9d',
maximumDiscountPercentage: 10.5,
},
],
}),
);
const spyOpportunityItemQuickEditResource = jest
.spyOn(OpportunityItemQuickEditResource, 'get')
.mockImplementation(() => Promise.resolve(null));
const spyQuickEditResource = jest
.spyOn(QuickEditResource, 'getMetaData')
.mockImplementation(() => Promise.resolve({}));
const mockedResponse = {
data: {
items: [
{
discount: {
percentage: 0,
value: 0,
},
id: 'd5a4dc1d-57d1-473a-b54c-f9c3d1577572',
product: {
id: '9acf9f7c-f27c-48df-9338-a74bd41dfbc3',
description: 'Desinfetante Pinho Sol Perfumado Lavanda 3,8L',
active: true,
allowRecurrence: false,
},
quantity: 1,
sellingPrice: 0,
totalValue: 0,
basePrice: 0,
itemType: 'PRODUCT',
},
],
count: 1,
firstRow: 0,
page: 0,
pageSize: 25,
},
status: 200,
};
jest.mock('@wealthlabs/midgard-components', () =>
jest.requireActual('@wealthlabs/midgard-components'),
);
jest.mock('@wealthlabs/user', () => ({
ManualSharing: jest.fn(),
GdaObjects: jest.fn(),
UserContext: {
get: () => ({
user: {
id: '0734f031-00d1-452c-a0ba-d3c43f2c3d9d',
},
tenantId: null,
}),
getAccessRule: jest.fn(),
hasPermission: jest.fn(),
hasGdaPermission: jest.fn(),
validateGdaAllowedActions: jest.fn(),
validateAccessRule: jest.fn(),
},
}));
jest.mock('../../../../../../resources/OpportunityResourceReworked.js', () => ({
getOpportunityItems: jest.fn().mockResolvedValue({
data: {
items: [
{
discount: {
percentage: 0,
value: 0,
},
id: 'd5a4dc1d-57d1-473a-b54c-f9c3d1577572',
product: {
id: '9acf9f7c-f27c-48df-9338-a74bd41dfbc3',
description: 'Desinfetante Pinho Sol Perfumado Lavanda 3,8L',
active: true,
allowRecurrence: false,
},
quantity: 1,
sellingPrice: 0,
totalValue: 0,
basePrice: 0,
itemType: 'PRODUCT',
},
],
count: 1,
firstRow: 0,
page: 0,
pageSize: 25,
},
status: 200,
}),
}));
const defaultProps = {
opportunity: {
id: 'b6762383-b05e-4e88-8a2f-3a347b68f77c',
status: 'PROGRESS',
code: '251',
description: 'Teste do Vinicius',
opportunityType: { id: '0234f031-00d1-452c-a0ba-d3c43f2c3d9d' },
pipeline: { id: '0434f031-00d1-452c-a0ba-d3c43f2c3d9d' },
stage: { id: '0534f031-00d1-452c-a0ba-d3c43f2c3d9d' },
user: { id: '0734f031-00d1-452c-a0ba-d3c43f2c3d9d' },
account: { id: 'aa9b5af3-ddfd-46db-a9fc-d3c43f2c3d9d' },
totalSingleValue: 22,
totalRecurrentValue: 0,
totalValue: 22,
expectedAt: '2023-01-31',
startedAt: '2023-01-25T13:13:21.977Z',
createdAt: '2023-01-25T13:13:22.140Z',
},
allowedActions: {
READ: true,
UPDATE: true,
DELETE: true,
TRANSFER: true,
SHARE: true,
CREATE: true,
},
opportunityConfigurations: {
allowUpdateExpectedAt: true,
allowRetroactiveExpectedAt: false,
allowManuallyInsertCompletedAt: false,
allowRecoverOpportunities: true,
allowEditClosedOpportunities: false,
allowExchangeInformation: true,
companyRequired: false,
},
location: {
pathname: '/opportunity/opportunities/da43d829-6ade-4b78-9974-ec5a3bbd186d',
search: '',
hash: '#items',
state: {
submitForm: false,
},
key: 'm0y6s6',
},
onChange: jest.fn(),
};
const mockedSelectedItems = ['test-id', 'test-id0', 'test-id1'];
describe('OpportunityItemsTab', () => {
const wrapper = mount(<OpportunityItemsTab {...defaultProps} />);
const instance = wrapper.instance();
// const spyFormatCurrency = jest.spyOn(instance, 'formatCurrency');
const spyGridColumns = jest.spyOn(instance, 'getGridColumns');
it('should be defined', () => {
instance.renderAdvancedFilter = jest.fn();
instance.renderDataTableHeadFilter = jest.fn();
// console.log(wrapper.debug())
const component = wrapper
.find('#opportunity-items-grid')
.first();
jestExpect(spyGridColumns).toHaveBeenCalled();
// comparar outras props
jestExpect(component.prop('data')).toEqual(defaultProps.opportunity.items);
jestExpect(JSON.stringify(component.prop('columns')))
.toEqual(JSON.stringify(spyGridColumns.mock.results[0].value));
});
// it('should be able to call handleBulkEditionPrice and set selectedItems on state', () => {
// const bulkEditionStateOld = instance.state.bulkEditionPrice;
// instance.handleBulkEditionPrice(mockedSelectedItems);
// jestExpect(bulkEditionStateOld).not.toBe(instance.state.bulkEditionPrice);
// jestExpect(instance.state.bulkEditionPrice.items).toBe(mockedSelectedItems);
// });
// it('should be able to call handleOnCloseBulkPrice and set null items on state', () => {
// const bulkEditionStateOld = instance.state.bulkEditionPrice;
// instance.handleOnCloseBulkPrice();
// jestExpect(bulkEditionStateOld).not.toBe(instance.state.bulkEditionPrice);
// jestExpect(instance.state.bulkEditionPrice.items).toBe(null);
// });
// it('should be able to call handleOnUpdatedBulkPrice and call functions', () => {
// const spyHandleOnCloseBulkPrice = jest.spyOn(instance, 'handleOnCloseBulkPrice');
// const spyRefreshScreenData = jest
// .spyOn(instance, 'refreshScreenData')
// .mockReturnValue(true);
// instance.handleOnUpdatedBulkPrice();
// jestExpect(spyHandleOnCloseBulkPrice).toBeCalled();
// jestExpect(spyRefreshScreenData).toBeCalled();
// });
// it('should be able to call handleBulkEditionPrice and open BulkEditionPriceModal', () => {
// instance.handleBulkEditionPrice(mockedSelectedItems);
// jestExpect(wrapper.find({ id: 'bulk-edition-price-modal' })).toBeDefined();
// });
// it('should be able to call handleOnCloseBulkPrice and close BulkEditionPriceModal', () => {
// instance.handleOnCloseBulkPrice();
// jestExpect(wrapper.find({ id: 'bulk-edition-price-modal' })).toMatchInlineSnapshot(
// `ReactWrapper {}`,
// );
// });
// describe('function handleSearch', () => {
// const mockedResponse = {
// data: {
// items: [
// {
// discount: {
// percentage: 0,
// value: 0,
// },
// id: 'd5a4dc1d-57d1-473a-b54c-f9c3d1577572',
// product: {
// id: '9acf9f7c-f27c-48df-9338-a74bd41dfbc3',
// description: 'Desinfetante Pinho Sol Perfumado Lavanda 3,8L',
// active: true,
// allowRecurrence: false,
// },
// quantity: 1,
// sellingPrice: 0,
// totalValue: 0,
// basePrice: 0,
// itemType: 'PRODUCT',
// },
// {
// discount: {
// percentage: 0,
// value: 0,
// },
// id: '86d02dda-44ea-4977-a319-a47aa5ef44ce',
// product: {
// id: '5fd6069f-ebbf-4c56-b438-4c6b92fb30b6',
// description: 'Limpador Multiuso Veja Gold Original 500ml',
// active: true,
// allowRecurrence: false,
// },
// quantity: 1,
// sellingPrice: 22,
// totalValue: 22,
// basePrice: 22,
// itemType: 'PRODUCT',
// },
// {
// discount: {
// percentage: 0,
// value: 0,
// },
// id: '89aad90c-c810-4ccf-b3d8-b4058c073730',
// product: {
// id: '6baa41cb-4fc9-47f9-a184-59ee76eac4f8',
// description:
// 'Limpador Perfumado para pisos Casa & Perfume Mistero Di Amore, 2 l (Pacote de 1)',
// active: true,
// allowRecurrence: false,
// },
// quantity: 1,
// sellingPrice: 0,
// totalValue: 0,
// basePrice: 0,
// itemType: 'PRODUCT',
// },
// {
// discount: {
// percentage: 0,
// value: 0,
// },
// id: '4c836e42-748d-45fc-b70c-4289665234dc',
// product: {
// id: 'e67c75d3-2dae-43c5-8272-3dde4d4e933f',
// description: 'Limpador Perfumado Veja Lavanda da França - 2L',
// active: true,
// allowRecurrence: false,
// },
// quantity: 1,
// sellingPrice: 0,
// totalValue: 0,
// basePrice: 0,
// itemType: 'PRODUCT',
// },
// {
// discount: {
// percentage: 0,
// value: 0,
// },
// id: '631708d5-2dbf-479b-81c1-f46628f89bc5',
// product: {
// id: 'e5340201-6264-43ff-abff-ecbbd8c868c1',
// description:
// 'Limpador Sanitário Marine promocional, Pato, 500Ml+250Ml Gratis',
// active: true,
// allowRecurrence: false,
// },
// quantity: 1,
// sellingPrice: 0,
// totalValue: 0,
// basePrice: 0,
// itemType: 'PRODUCT',
// },
// ],
// count: 5,
// firstRow: 0,
// page: 0,
// pageSize: 25,
// },
// status: 200,
// };
// OpportunityResourceReworked.getOpportunityItems = jest
// .fn()
// .mockResolvedValue(mockedResponse);
// it('should be able to call getOpportunityItems resource ', () => {
// instance.handleSearch();
// jestExpect(OpportunityResourceReworked.getOpportunityItems).toBeCalled();
// });
// it('should be able to call getOpportunityItems resource with orderBy params', () => {
// instance.handleSearch();
// jestExpect(OpportunityResourceReworked.getOpportunityItems).toBeCalledWith(
// defaultProps.opportunity.id,
// { orderBy: 'createdAt asc, description asc', page: 0, pageSize: 25 },
// );
// });
// it('should be able to call getOpportunityItems resource and update state of items', async () => {
// instance.setState({ items: [] });
// jestExpect(instance.state.items).toMatchInlineSnapshot(`Array []`);
// await instance.handleSearch();
// jestExpect(instance.state.items).toMatchInlineSnapshot(`
// Array [
// Object {
// "active": true,
// "basePrice": 0,
// "discount": Object {
// "percentage": 0,
// "value": 0,
// },
// "id": "d5a4dc1d-57d1-473a-b54c-f9c3d1577572",
// "itemType": "PRODUCT",
// "product": Object {
// "active": true,
// "allowRecurrence": false,
// "description": "Desinfetante Pinho Sol Perfumado Lavanda 3,8L",
// "id": "9acf9f7c-f27c-48df-9338-a74bd41dfbc3",
// },
// "quantity": 1,
// "sellingPrice": 0,
// "totalValue": 0,
// },
// Object {
// "active": true,
// "basePrice": 22,
// "discount": Object {
// "percentage": 0,
// "value": 0,
// },
// "id": "86d02dda-44ea-4977-a319-a47aa5ef44ce",
// "itemType": "PRODUCT",
// "product": Object {
// "active": true,
// "allowRecurrence": false,
// "description": "Limpador Multiuso Veja Gold Original 500ml",
// "id": "5fd6069f-ebbf-4c56-b438-4c6b92fb30b6",
// },
// "quantity": 1,
// "sellingPrice": 22,
// "totalValue": 22,
// },
// Object {
// "active": true,
// "basePrice": 0,
// "discount": Object {
// "percentage": 0,
// "value": 0,
// },
// "id": "89aad90c-c810-4ccf-b3d8-b4058c073730",
// "itemType": "PRODUCT",
// "product": Object {
// "active": true,
// "allowRecurrence": false,
// "description": "Limpador Perfumado para pisos Casa & Perfume Mistero Di Amore, 2 l (Pacote de 1)",
// "id": "6baa41cb-4fc9-47f9-a184-59ee76eac4f8",
// },
// "quantity": 1,
// "sellingPrice": 0,
// "totalValue": 0,
// },
// Object {
// "active": true,
// "basePrice": 0,
// "discount": Object {
// "percentage": 0,
// "value": 0,
// },
// "id": "4c836e42-748d-45fc-b70c-4289665234dc",
// "itemType": "PRODUCT",
// "product": Object {
// "active": true,
// "allowRecurrence": false,
// "description": "Limpador Perfumado Veja Lavanda da França - 2L",
// "id": "e67c75d3-2dae-43c5-8272-3dde4d4e933f",
// },
// "quantity": 1,
// "sellingPrice": 0,
// "totalValue": 0,
// },
// Object {
// "active": true,
// "basePrice": 0,
// "discount": Object {
// "percentage": 0,
// "value": 0,
// },
// "id": "631708d5-2dbf-479b-81c1-f46628f89bc5",
// "itemType": "PRODUCT",
// "product": Object {
// "active": true,
// "allowRecurrence": false,
// "description": "Limpador Sanitário Marine promocional, Pato, 500Ml+250Ml Gratis",
// "id": "e5340201-6264-43ff-abff-ecbbd8c868c1",
// },
// "quantity": 1,
// "sellingPrice": 0,
// "totalValue": 0,
// },
// ]
// `);
// });
// it('should be able to call getOpportunityItems resource and call handleSearchInconsistencyItem', async () => {
// const spy = jest.spyOn(instance, 'handleSearchInconsistencyItem');
// const response = await instance.handleSearch();
// jestExpect(spy).toBeCalled();
// jestExpect(spy).toHaveBeenCalledWith(response.data.items);
// });
// it('should be able to call getOpportunityItems resource and return formmatted item', async () => {
// const response = await instance.handleSearch();
// response.data.items.forEach((item) => {
// jestExpect(item.active).toBeDefined();
// });
// });
// });
// describe('function loadMaximumDiscountPercentage', () => {
// it('should state setted to 10.5 when there are items configured', async () => {
// const spyMaximumDiscountPercentageResource = jest
// .spyOn(MaximumDiscountPercentageResource, 'get')
// .mockImplementation(() =>
// Promise.resolve({
// data: [
// {
// userId: '0734f031-00d1-452c-a0ba-d3c43f2c3d9d',
// maximumDiscountPercentage: 10.5,
// },
// ],
// }),
// );
// const pipelineId = '0434f031-00d1-452c-a0ba-d3c43f2c3d9d';
// const component = await shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const userIds = ['0734f031-00d1-452c-a0ba-d3c43f2c3d9d'];
// jestExpect(spyMaximumDiscountPercentageResource).toHaveBeenCalledWith(
// pipelineId,
// userIds,
// );
// jestExpect(componentInstance.state.maximumDiscountPercentageLoggedUser).toEqual(10.5);
// jestExpect(componentInstance.state.maximumDiscountPercentageResponsibleUser).toEqual(
// 10.5,
// );
// });
// it('should not set state when there are no items configured', async () => {
// const spyMaximumDiscountPercentageResource = jest
// .spyOn(MaximumDiscountPercentageResource, 'get')
// .mockImplementation(() => Promise.resolve({ data: [] }));
// const pipelineId = '0434f031-00d1-452c-a0ba-d3c43f2c3d9d';
// const component = await shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const userIds = ['0734f031-00d1-452c-a0ba-d3c43f2c3d9d'];
// jestExpect(spyMaximumDiscountPercentageResource).toHaveBeenCalledWith(
// pipelineId,
// userIds,
// );
// jestExpect(componentInstance.state.maximumDiscountPercentageLoggedUser).toEqual(100);
// jestExpect(componentInstance.state.maximumDiscountPercentageResponsibleUser).toEqual(
// 100,
// );
// });
// it('should set maximumDiscountPercentageLoggedUser to custom quantity and maximumDiscountPercentageResponsibleUser to default', async () => {
// const spyMaximumDiscountPercentageResource = jest
// .spyOn(MaximumDiscountPercentageResource, 'get')
// .mockImplementation(() =>
// Promise.resolve({
// data: [
// {
// userId: '0734f031-00d1-452c-a0ba-d3c43f2c3d9d',
// maximumDiscountPercentage: 10.5,
// },
// ],
// }),
// );
// UserContext.get = jest.fn(() => ({
// user: {
// id: '5',
// },
// }));
// const pipelineId = '0434f031-00d1-452c-a0ba-d3c43f2c3d9d';
// const component = await shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const userIds = ['0734f031-00d1-452c-a0ba-d3c43f2c3d9d', '5'];
// jestExpect(spyMaximumDiscountPercentageResource).toHaveBeenCalledWith(
// pipelineId,
// userIds,
// );
// jestExpect(componentInstance.state.maximumDiscountPercentageLoggedUser).toEqual(100);
// jestExpect(componentInstance.state.maximumDiscountPercentageResponsibleUser).toEqual(
// 10.5,
// );
// });
// it('should set maximumDiscountPercentageLoggedUser to default and maximumDiscountPercentageResponsibleUser to custom quantity', async () => {
// const spyMaximumDiscountPercentageResource = jest
// .spyOn(MaximumDiscountPercentageResource, 'get')
// .mockImplementation(() =>
// Promise.resolve({
// data: [
// {
// userId: '5',
// maximumDiscountPercentage: 10.5,
// },
// ],
// }),
// );
// UserContext.get = jest.fn(() => ({
// user: {
// id: '5',
// },
// }));
// const pipelineId = '0434f031-00d1-452c-a0ba-d3c43f2c3d9d';
// const component = await shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const userIds = ['0734f031-00d1-452c-a0ba-d3c43f2c3d9d', '5'];
// jestExpect(spyMaximumDiscountPercentageResource).toHaveBeenCalledWith(
// pipelineId,
// userIds,
// );
// jestExpect(componentInstance.state.maximumDiscountPercentageLoggedUser).toEqual(10.5);
// jestExpect(componentInstance.state.maximumDiscountPercentageResponsibleUser).toEqual(
// 100,
// );
// });
// it('should set maximumDiscountPercentageLoggedUser and maximumDiscountPercentageResponsibleUser to custom quantity when one of the results is zero', async () => {
// const spyMaximumDiscountPercentageResource = jest
// .spyOn(MaximumDiscountPercentageResource, 'get')
// .mockImplementation(() =>
// Promise.resolve({
// data: [
// {
// userId: '0734f031-00d1-452c-a0ba-d3c43f2c3d9d',
// maximumDiscountPercentage: 0,
// },
// {
// userId: '5',
// maximumDiscountPercentage: 10.5,
// },
// ],
// }),
// );
// UserContext.get = jest.fn(() => ({
// user: {
// id: '5',
// },
// }));
// const pipelineId = '0434f031-00d1-452c-a0ba-d3c43f2c3d9d';
// const component = await shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const userIds = ['0734f031-00d1-452c-a0ba-d3c43f2c3d9d', '5'];
// jestExpect(spyMaximumDiscountPercentageResource).toHaveBeenCalledWith(
// pipelineId,
// userIds,
// );
// jestExpect(componentInstance.state.maximumDiscountPercentageLoggedUser).toEqual(10.5);
// jestExpect(componentInstance.state.maximumDiscountPercentageResponsibleUser).toEqual(0);
// });
// });
// describe('renderBanner function', () => {
// it('should render banner when there are items configured', async () => {
// const component = await shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const spyRenderBanner = jest.spyOn(instance, 'renderBanner');
// const locationProps = {
// ...defaultProps.location,
// state: {
// discount: {
// errors: [
// {
// id: '1',
// message: 'Erro',
// },
// ],
// },
// },
// };
// component.setProps({ location: locationProps });
// setTimeout(() => {
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// jestExpect(spyRenderBanner).toHaveBeenCalled();
// }, 100);
// });
// it('should not render banner when there are no items configured', async () => {
// const component = await shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const spyRenderBanner = jest.spyOn(instance, 'renderBanner');
// jestExpect(componentInstance.state.bannerOpen).toBe(false);
// jestExpect(spyRenderBanner).not.toHaveBeenCalled();
// });
// });
// describe('handleCloseBanner function', () => {
// it('should set state to false', async () => {
// const component = await shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// componentInstance.handleCloseBanner();
// jestExpect(componentInstance.state.bannerOpen).toBe(false);
// });
// });
// describe('handleSearchInconsistencyItem function', () => {
// it('should set openEditItemModal in state to true when items are informed', async () => {
// const locationMock = {
// ...defaultProps.location,
// state: {
// itemWithInconsistency: {
// editProductId: '1',
// },
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyLoadItem = jest.spyOn(componentInstance, 'loadItem').mockResolvedValue({
// product: {
// id: '1',
// },
// });
// const itemsMock = [
// {
// product: {
// id: '1',
// },
// },
// ];
// await componentInstance.handleSearchInconsistencyItem(itemsMock);
// jestExpect(spyLoadItem).not.toHaveBeenCalled();
// jestExpect(componentInstance.state.openEditItemModal).toBe(true);
// });
// describe('when items are not empty', () => {
// it('should set bannerOpen to true when discount errors is true and loadItem returns a product', async () => {
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '1',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyLoadItem = jest.spyOn(componentInstance, 'loadItem').mockResolvedValue({
// id: '2',
// product: {
// id: '1',
// },
// });
// const itemsMock = [
// {
// id: '2',
// product: {
// id: '1',
// },
// },
// ];
// await componentInstance.handleSearchInconsistencyItem(itemsMock);
// jestExpect(spyLoadItem).toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// });
// it('should set bannerOpen to true when discount errors is true and loadItem returns a service', async () => {
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '1',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyLoadItem = jest.spyOn(componentInstance, 'loadItem').mockResolvedValue({
// id: '1',
// service: {
// id: '1',
// },
// });
// const itemsMock = [
// {
// id: '2',
// service: {
// id: '1',
// },
// },
// ];
// await componentInstance.handleSearchInconsistencyItem(itemsMock);
// jestExpect(spyLoadItem).toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// });
// it('should set bannerOpen to true when discount errors is true and the request to loadItems fails', async () => {
// OpportunityResourceReworked.getOpportunityItems = jest
// .fn()
// .mockRejectedValueOnce({ response: { status: 404 } });
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '1',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyHandleErrorForLoadItem = jest.spyOn(
// componentInstance,
// 'handleErrorForLoadItem',
// );
// const spyHasMaximumDiscountErrors = jest.spyOn(
// componentInstance,
// 'hasMaximumDiscountErrors',
// );
// const itemsMock = [
// {
// id: '2',
// service: {
// id: '1',
// },
// },
// ];
// await componentInstance.handleSearchInconsistencyItem(itemsMock);
// jestExpect(spyHandleErrorForLoadItem).toHaveBeenCalledWith(
// { response: { status: 404 } },
// 'opportunity::opportunity.item',
// );
// jestExpect(spyHasMaximumDiscountErrors).toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// jestExpect(componentInstance.state.openEditItemModal).toBe(false);
// jestExpect(componentInstance.state.editItem).toBeNull();
// });
// });
// describe('when items are empty', () => {
// it('should set bannerOpen to true when discount errors is true and loadItem returns a product', async () => {
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '1',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyLoadItem = jest.spyOn(componentInstance, 'loadItem').mockResolvedValue({
// id: '2',
// product: {
// id: '1',
// },
// });
// await componentInstance.handleSearchInconsistencyItem([]);
// jestExpect(spyLoadItem).toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// });
// it('should set bannerOpen to true when discount errors is true and loadItem returns a service', async () => {
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '1',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyLoadItem = jest.spyOn(componentInstance, 'loadItem').mockResolvedValue({
// id: '1',
// service: {
// id: '1',
// },
// });
// await componentInstance.handleSearchInconsistencyItem([]);
// jestExpect(spyLoadItem).toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// });
// it('should set bannerOpen to true when discount errors is true and the request to loadItems fails', async () => {
// OpportunityResourceReworked.getOpportunityItems = jest
// .fn()
// .mockRejectedValueOnce({ response: { status: 404 } });
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '1',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyHandleErrorForLoadItem = jest.spyOn(
// componentInstance,
// 'handleErrorForLoadItem',
// );
// const spyHasMaximumDiscountErrors = jest.spyOn(
// componentInstance,
// 'hasMaximumDiscountErrors',
// );
// await componentInstance.handleSearchInconsistencyItem([]);
// jestExpect(spyHandleErrorForLoadItem).toHaveBeenCalledWith(
// { response: { status: 404 } },
// 'opportunity::opportunity.item',
// );
// jestExpect(spyHasMaximumDiscountErrors).toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// jestExpect(componentInstance.state.openEditItemModal).toBe(false);
// jestExpect(componentInstance.state.editItem).toBeNull();
// });
// });
// describe('when items in state contains errors', () => {
// it('should set bannerOpen to true when discount errors is true and loadItem returns a product', async () => {
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '2',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyLoadItem = jest.spyOn(componentInstance, 'loadItem').mockResolvedValue({
// id: '50',
// product: {
// id: '50',
// },
// });
// const itemsMock = [
// {
// id: '2',
// product: {
// id: '1',
// },
// },
// ];
// await componentInstance.handleSearchInconsistencyItem(itemsMock);
// jestExpect(spyLoadItem).not.toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// });
// it('should set bannerOpen to true when discount errors is true and loadItem returns a service', async () => {
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '2',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyLoadItem = jest.spyOn(componentInstance, 'loadItem').mockResolvedValue({
// id: '50',
// service: {
// id: '50',
// },
// });
// const itemsMock = [
// {
// id: '2',
// service: {
// id: '1',
// },
// },
// ];
// await componentInstance.handleSearchInconsistencyItem(itemsMock);
// jestExpect(spyLoadItem).not.toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// });
// it('should set bannerOpen to true when discount errors is true and the request to loadItems fails', async () => {
// OpportunityResourceReworked.getOpportunityItems = jest
// .fn()
// .mockRejectedValueOnce({ response: { status: 404 } });
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '1',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyHandleErrorForLoadItem = jest.spyOn(
// componentInstance,
// 'handleErrorForLoadItem',
// );
// const spyHasMaximumDiscountErrors = jest.spyOn(
// componentInstance,
// 'hasMaximumDiscountErrors',
// );
// const itemsMock = [
// {
// id: '2',
// service: {
// id: '1',
// },
// },
// ];
// await componentInstance.handleSearchInconsistencyItem(itemsMock);
// jestExpect(spyHandleErrorForLoadItem).toHaveBeenCalledWith(
// { response: { status: 404 } },
// 'opportunity::opportunity.item',
// );
// jestExpect(spyHasMaximumDiscountErrors).toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// jestExpect(componentInstance.state.openEditItemModal).toBe(false);
// jestExpect(componentInstance.state.editItem).toBeNull();
// });
// });
// describe('when items is undefined', () => {
// it('should set bannerOpen to true when discount errors is true and loadItem returns a product', async () => {
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '1',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyLoadItem = jest.spyOn(componentInstance, 'loadItem').mockResolvedValue({
// id: '2',
// product: {
// id: '1',
// },
// });
// await componentInstance.handleSearchInconsistencyItem();
// jestExpect(spyLoadItem).toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// });
// it('should set bannerOpen to true when discount errors is true and loadItem returns a service', async () => {
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '1',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyLoadItem = jest.spyOn(componentInstance, 'loadItem').mockResolvedValue({
// id: '1',
// service: {
// id: '1',
// },
// });
// await componentInstance.handleSearchInconsistencyItem();
// jestExpect(spyLoadItem).toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// });
// it('should set bannerOpen to true when discount errors is true and the request to loadItems fails', async () => {
// OpportunityResourceReworked.getOpportunityItems = jest
// .fn()
// .mockRejectedValueOnce({ response: { status: 404 } });
// const locationMock = {
// ...defaultProps.location,
// state: {
// inconsistencyItemArray: [
// {
// editItemId: '1',
// errors: {
// discount: ['The maximum discount for your user is 2.00%'],
// },
// },
// ],
// },
// };
// const component = await shallow(
// <OpportunityItemsTab {...defaultProps} location={locationMock} />,
// );
// const componentInstance = component.instance();
// const spyHandleErrorForLoadItem = jest.spyOn(
// componentInstance,
// 'handleErrorForLoadItem',
// );
// const spyHasMaximumDiscountErrors = jest.spyOn(
// componentInstance,
// 'hasMaximumDiscountErrors',
// );
// await componentInstance.handleSearchInconsistencyItem();
// jestExpect(spyHandleErrorForLoadItem).toHaveBeenCalledWith(
// { response: { status: 404 } },
// 'opportunity::opportunity.item',
// );
// jestExpect(spyHasMaximumDiscountErrors).toHaveBeenCalled();
// jestExpect(componentInstance.state.bannerOpen).toBe(true);
// jestExpect(componentInstance.state.openEditItemModal).toBe(false);
// jestExpect(componentInstance.state.editItem).toBeNull();
// });
// });
// });
// describe('getFirstItemWithInconsistency function', () => {
// it('should return the first item with inconsistency', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const itemsMock = [
// {
// product: {
// id: '1',
// },
// id: '1',
// },
// {
// product: {
// id: '2',
// },
// id: '2',
// },
// ];
// const inconsistencyItemArrayMock = [
// {
// editItemId: '1',
// errors: {
// discount: {
// errors: [
// {
// message: 'Erro',
// },
// ],
// },
// },
// },
// {
// editItemId: '2',
// errors: {
// discount: {
// errors: [
// {
// message: 'Erro',
// },
// ],
// },
// },
// },
// ];
// const result = componentInstance.getFirstItemWithInconsistency(
// itemsMock,
// inconsistencyItemArrayMock,
// );
// jestExpect(result).toMatchInlineSnapshot(`
// Object {
// "id": "1",
// "product": Object {
// "id": "1",
// },
// }
// `);
// });
// it('should not return the first item when inconsistencyItemsArray is empty', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const itemsMock = [
// {
// product: {
// id: '1',
// },
// id: '1',
// },
// {
// product: {
// id: '2',
// },
// id: '2',
// },
// ];
// const inconsistencyItemArrayMock = [];
// const result = componentInstance.getFirstItemWithInconsistency(
// itemsMock,
// inconsistencyItemArrayMock,
// );
// jestExpect(result).toBe(null);
// });
// it('should not return the first item when inconsistencyItemsArray is undefined', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const itemsMock = [
// {
// product: {
// id: '1',
// },
// id: '1',
// },
// {
// product: {
// id: '2',
// },
// id: '2',
// },
// ];
// const inconsistencyItemArrayMock = undefined;
// const result = componentInstance.getFirstItemWithInconsistency(
// itemsMock,
// inconsistencyItemArrayMock,
// );
// jestExpect(result).toBe(null);
// });
// it('should not return the first item when items is an empty array', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const itemsMock = [];
// const inconsistencyItemArrayMock = [
// {
// editItemId: '1',
// errors: {
// discount: {
// errors: [
// {
// message: 'Erro',
// },
// ],
// },
// },
// },
// {
// editItemId: '2',
// errors: {
// discount: {
// errors: [
// {
// message: 'Erro',
// },
// ],
// },
// },
// },
// ];
// const result = componentInstance.getFirstItemWithInconsistency(
// itemsMock,
// inconsistencyItemArrayMock,
// );
// jestExpect(result).toBe(null);
// });
// it('should not return the first item when items is undefined', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const itemsMock = undefined;
// const inconsistencyItemArrayMock = [
// {
// editItemId: '1',
// errors: {
// discount: {
// errors: [
// {
// message: 'Erro',
// },
// ],
// },
// },
// },
// {
// editItemId: '2',
// errors: {
// discount: {
// errors: [
// {
// message: 'Erro',
// },
// ],
// },
// },
// },
// ];
// const result = componentInstance.getFirstItemWithInconsistency(
// itemsMock,
// inconsistencyItemArrayMock,
// );
// jestExpect(result).toBe(null);
// });
// it('should not return the first item when items and inconsistencyItemsArray are empty', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const itemsMock = [];
// const inconsistencyItemArrayMock = [];
// const result = componentInstance.getFirstItemWithInconsistency(
// itemsMock,
// inconsistencyItemArrayMock,
// );
// jestExpect(result).toBe(null);
// });
// it('should not return the first item when items and inconsistencyItemsArray are undefined', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const itemsMock = undefined;
// const inconsistencyItemArrayMock = undefined;
// const result = componentInstance.getFirstItemWithInconsistency(
// itemsMock,
// inconsistencyItemArrayMock,
// );
// jestExpect(result).toBe(null);
// });
// });
// describe('hasMaximumDiscountErrors function', () => {
// it('should return true when has maximum discount errors', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const errorsMock = [
// {
// errors: [
// {
// id: '1',
// message: 'Erro',
// },
// ],
// },
// ];
// const result = componentInstance.hasMaximumDiscountErrors(errorsMock);
// jestExpect(result).toBe(true);
// });
// it('should return false when the parameter is an empty array', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const errorsMock = [];
// const result = componentInstance.hasMaximumDiscountErrors(errorsMock);
// jestExpect(result).toBe(false);
// });
// it('should return false when the parameter is undefined', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const errorsMock = undefined;
// const result = componentInstance.hasMaximumDiscountErrors(errorsMock);
// jestExpect(result).toBe(false);
// });
// it('should return false when the parameter is not an array', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const errorsMock = {};
// const result = componentInstance.hasMaximumDiscountErrors(errorsMock);
// jestExpect(result).toBe(false);
// });
// it('should return false when the parameter is an array with no errors', () => {
// const component = shallow(<OpportunityItemsTab {...defaultProps} />);
// const componentInstance = component.instance();
// const errorsMock = [
// {
// otherAttribute: true,
// },
// ];
// const result = componentInstance.hasMaximumDiscountErrors(errorsMock);
// jestExpect(result).toBe(false);
// });
// });
});