---
# System prepended metadata

title: OpportunityList test

---

import React from 'react';
import { shallow } from 'enzyme';
import { Constants, LocalStorageHelper } from '@wealthlabs/midgard-components';
import OpportunityList from '../OpportunityList.jsx';
import OpportunityListFormatter from '../OpportunityListFormatter';

jest.mock('@wealthlabs/midgard-components', () => jest.requireActual('@wealthlabs/midgard-components'));
jest.mock('../../../../../resources/OpportunityResourceReworked.js', () => ({
    listOpportunity: jest.fn().mockResolvedValue({
        data: {
            "items": [
                {
                    "id": "ac1e345a-85c3-49b4-aea9-90d1e412a0aa",
                    "status": "PROGRESS",
                    "code": 6,
                    "description": "oportunidade de testes",
                    "opportunityType": {
                        "id": "b5848795-75df-48a1-820a-fc3c6c163785",
                        "description": "Oportunidade de venda"
                    },
                    "pipeline": {
                        "id": "46b0f7c0-01de-473b-b767-591a67eec35c",
                        "description": "Pipeline padrão",
                        "allowReopenWon": true,
                        "allowReopenLost": true,
                        "enableProbabilityByStage": false,
                        "enableDiscardedStep": true,
                        "enableWonStep": true,
                        "enableLostStep": true
                    },
                    "stage": {
                        "id": "b4f5218d-3114-4168-8199-d63d902d7122",
                        "description": "Apresentação"
                    },
                    "user": {
                        "id": "7636f630-2358-4cf4-a290-2ec0b13ea47c",
                        "name": "Admin TotvsCRM"
                    },
                    "account": {
                        "type": "CUSTOMER",
                        "id": "d923f893-dc15-4645-8a4a-97f791b6dc24",
                        "name": "Cliente teste da silva"
                    },
                    "exchange": {
                        "currency": {
                            "id": "5ebcc87b-af5d-42ad-85ad-df620844055f",
                            "description": "Real Brasileiro",
                            "symbol": "R$",
                            "code": "BRL",
                            "standard": true
                        }
                    },
                    "startedAt": "2023-05-13T14:06:20.849Z",
                    "expectedAt": "2023-05-20",
                    "totalSingleValue": 9.020000,
                    "totalRecurrentValue": 0.000000,
                    "totalValue": 9.020000,
                    "customer": {
                        "id": "d923f893-dc15-4645-8a4a-97f791b6dc24",
                        "name": "Cliente teste da silva"
                    },
                    "updatedAt": "2023-06-13T19:01:02.732Z",
                    "itemCount": 1,
                    "stageUpdatedAt": "2023-05-16T18:45:19.333Z",
                    "currency": {
                        "id": "5ebcc87b-af5d-42ad-85ad-df620844055f",
                        "description": "Real Brasileiro",
                        "symbol": "R$",
                        "code": "BRL",
                        "standard": true
                    }
                }        
            ],
            "count": 1,
            "firstRow": 0,
            "page": 0,
            "pageSize": 25
        }
    }),
    getDefaultCurrency: jest.fn().mockResolvedValue({
        "id": "5ebcc87b-af5d-42ad-85ad-df620844055f",
        "description": "Real Brasileiro",
        "code": "BRL",
        "symbol": "R$"
    }),
}));
jest.mock('../../../../../resources/OpportunityResources.js', () => ({
    opportunityConfigurations: {
        getConfigurations: jest.fn().mockResolvedValue({
            "allowUpdateExpectedAt": true,
            "allowRetroactiveExpectedAt": false,
            "allowManuallyInsertCompletedAt": false,
            "allowRecoverOpportunities": false,
            "allowEditClosedOpportunities": false,
            "allowExchangeInformation": false,
            "companyRequired": false
        }),
    }
}));
jest.mock('../OpportunityListFormatter.jsx', () => {
    const original = jest. requireActual('../OpportunityListFormatter.jsx')
    return {
        _esModule: true,
        ...original,
        default: jest.fn(),
        formatAccountType: jest.fn(),
        formatTotalValue: jest.fn(),
    }
});
jest.mock('@wealthlabs/user', () => ({
    ManualSharing: jest.fn(),
    GdaObjects: jest.fn(),
}));

function setContractedServices(item) {
    LocalStorageHelper.setItem(Constants.GLOBAL_STORAGE_KEYS.CONTRACTED_SERVICES, [item]);
}

describe('OpportunityList', () => {
    it('should render correctly', async (done) => {
        setContractedServices({ name: 'Opportunity', uri: '/opportunities' });      

        const wrapper = await shallow(<OpportunityList />);
        wrapper.instance().renderAdvancedFilter = jest.fn();
        wrapper.instance().renderDataTableHeadFilter = jest.fn();

        setTimeout(() => {
            jestExpect(wrapper.find('ListRender').props().gridColumns[2].formatter).toEqual(OpportunityListFormatter.formatAccountType);
            done();
        });       
    });
});