"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * @jest-environment jsdom
 */
require("../../__tests__/test-helpers/dom-polyfill");
const index_1 = require("../../currencies/index");
(0, index_1.setSupportedCurrencies)(["tron"]);
const react_1 = require("@testing-library/react");
const react_2 = require("./react");
const data_mock_1 = require("./data.mock");
const superRepresentativesData_mock_1 = __importDefault(require("@ledgerhq/coin-tron/network/superRepresentativesData.mock"));
jest.mock("@ledgerhq/coin-tron/network", () => {
    return {
        getTronSuperRepresentatives: jest.fn().mockImplementation(() => {
            return Promise.resolve(superRepresentativesData_mock_1.default);
        }),
    };
});
jest.mock("@ledgerhq/coin-tron/logic/utils", () => {
    return {
        extractBandwidthInfo: jest.fn().mockImplementation(() => {
            return {
                freeUsed: 0,
                freeLimit: 0,
                gainedUsed: 0,
                gainedLimit: 0,
            };
        }),
    };
});
test("Tron SuperRepresentatives hook - useTronSuperRepresentatives - Expect super representatives list", async () => {
    const { result } = (0, react_1.renderHook)(() => (0, react_2.useTronSuperRepresentatives)());
    await (0, react_1.act)(async () => {
        expect(result.current).toStrictEqual([]);
    });
    process.nextTick(() => expect(result.current).toStrictEqual(superRepresentativesData_mock_1.default));
});
test("Tron get last voting date - getLastVotedDate - Expect to get last voted date", () => {
    expect((0, react_2.getLastVotedDate)(data_mock_1.mockAccount)).toStrictEqual(data_mock_1.__LAST_VOTING_DATE__);
    expect((0, react_2.getLastVotedDate)(data_mock_1.mockAccountNoVote)).toStrictEqual(null);
});
test("Tron get next reward date - getNextRewardDate - Expect to get next reward date", () => {
    expect((0, react_2.getNextRewardDate)(data_mock_1.mockAccount)).toStrictEqual(data_mock_1.__NEXT_REWARD_DATE__.valueOf() + 24 * 60 * 60 * 1000);
    expect((0, react_2.getNextRewardDate)(data_mock_1.mockAccountNoReward)).toStrictEqual(null);
});
const __VOTES__ = superRepresentativesData_mock_1.default.slice(0, 2).map(({ address }) => ({
    address,
    voteCount: 100,
}));
const __FORMATTED_VOTES__ = superRepresentativesData_mock_1.default.slice(0, 2).map((validator, i) => ({
    address: validator.address,
    voteCount: 100,
    validator,
    rank: i + 1,
    isSR: true,
}));
test("Tron format votes - formatVotes - Expect to get formatted votes", () => {
    expect((0, react_2.formatVotes)(undefined, superRepresentativesData_mock_1.default)).toStrictEqual([]);
    expect((0, react_2.formatVotes)(__VOTES__, superRepresentativesData_mock_1.default)).toStrictEqual(__FORMATTED_VOTES__);
});
const SR_INDEX_1 = 9;
const SR_INDEX_2 = 2;
const VOTE_AMOUNT_1 = 10;
const VOTE_AMOUNT_2 = 50;
const votes = [
    {
        address: superRepresentativesData_mock_1.default[SR_INDEX_1].address,
        voteCount: VOTE_AMOUNT_1,
    },
    {
        address: superRepresentativesData_mock_1.default[SR_INDEX_2].address,
        voteCount: VOTE_AMOUNT_2,
    },
];
test("Tron search SR - search SR in the list - Expect to retrieve a specific list SR", () => {
    const { result } = (0, react_1.renderHook)(() => (0, react_2.useSortedSr)(superRepresentativesData_mock_1.default[SR_INDEX_1].name, 
    // @ts-expect-error wat
    superRepresentativesData_mock_1.default, votes));
    (0, react_1.act)(() => {
        expect(Array.isArray(result.current)).toBe(true);
        expect(result.current[0].address).toBe(superRepresentativesData_mock_1.default[SR_INDEX_1].address);
    });
});
test("Tron search SR - search SR in the list - Expect to retrieve all the list if no search provided and sorted by votes", () => {
    const { result } = (0, react_1.renderHook)(() => (0, react_2.useSortedSr)("", superRepresentativesData_mock_1.default, votes));
    (0, react_1.act)(() => {
        expect(Array.isArray(result.current)).toBe(true);
        expect(result.current.length).toBe(superRepresentativesData_mock_1.default.length);
        expect(result.current[0].address).toBe(votes[1].address);
        expect(result.current[1].address).toBe(votes[0].address);
    });
});
test("Tron unfreeze - get unfreeze data - Expect to retrieve unfreeze data from account", () => {
    const { unfreezeBandwidth, unfreezeEnergy, canUnfreezeBandwidth, canUnfreezeEnergy } = (0, react_2.getUnfreezeData)(data_mock_1.mockAccountV2);
    expect(unfreezeBandwidth.toString()).toBe("539000000");
    expect(unfreezeEnergy.toString()).toBe("28877000");
    expect(canUnfreezeBandwidth).toBe(true);
    expect(canUnfreezeEnergy).toBe(true);
});
//# sourceMappingURL=react.test.js.map