@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
168 lines • 8.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @jest-environment jsdom
*/
const rxjs_1 = require("rxjs");
const react_1 = require("@testing-library/react");
const _1 = require(".");
const mock_1 = require("./mock");
const react_2 = require("./react");
const react_3 = require("./react");
const polyfill_1 = require("./polyfill");
(0, polyfill_1.calculateDependencies)();
const mockedState = (0, _1.initState)((0, mock_1.mockListAppsResult)("Bitcoin, Bitcoin Legacy, Ethereum, Litecoin, Dogecoin, Ethereum Classic, XRP, Bitcoin Cash, Decred, Aave, Polygon, Binance Smart Chain", "Litecoin (outdated), Ethereum, Ethereum Classic, Aave, Polygon, Binance Smart Chain", mock_1.deviceInfo155));
test("Apps hooks - useAppInstallNeedsDeps - Expect Bitcoin cash to depend on bitcoin legacy", () => {
const { result = {} } = (0, react_1.renderHook)(() => (0, react_2.useAppInstallNeedsDeps)(mockedState, mockedState.appByName["Bitcoin Cash"]));
expect(result?.current.dependencies.length).toBe(1);
expect(result?.current.dependencies[0].name).toBe("Bitcoin");
//TODO: Reactivate the following code after new bitcoin nano app 2.1.0
/*
expect(result?.current.dependencies.length).toBe(1);
expect(result?.current.dependencies[0].name).toBe("Bitcoin Legacy");
*/
});
test("Apps hooks - useAppInstallNeedsDeps - Expect Decred to not depend on bitcoin", () => {
const { result = {} } = (0, react_1.renderHook)(() => (0, react_2.useAppInstallNeedsDeps)(mockedState, mockedState.appByName["Decred"]));
expect(result.current).toBe(null);
});
test("Apps hooks - useAppInstallNeedsDeps - Expect no dep apps", () => {
const { result } = (0, react_1.renderHook)(() => (0, react_2.useAppInstallNeedsDeps)(mockedState, mockedState.appByName["Bitcoin"]));
expect(result.current).toBe(null);
});
test("Apps hooks - useAppUninstallNeedsDeps - Expect dep apps", () => {
const { result = {} } = (0, react_1.renderHook)(() => (0, react_2.useAppUninstallNeedsDeps)(mockedState, mockedState.appByName["Ethereum"]));
expect(result.current.dependents.map(({ name }) => name)).toEqual([
"Ethereum Classic",
"Aave",
"Polygon",
"Binance Smart Chain",
]);
});
test("Apps hooks - useAppUninstallNeedsDeps - Expect no dep apps", () => {
const { result } = (0, react_1.renderHook)(() => (0, react_2.useAppUninstallNeedsDeps)(mockedState, mockedState.appByName["Ethereum Classic"]));
expect(result.current).toBe(null);
});
test("Apps hooks - useAppInstallProgress - Queued or unknown app", () => {
const { result } = (0, react_1.renderHook)(() => (0, react_2.useAppInstallProgress)(mockedState, "not_in_queue"));
expect(result.current).toBe(0);
});
test("Apps hooks - useAppInstallProgress - Current app", () => {
const currentProgressSubject = new rxjs_1.Subject();
const { result = {} } = (0, react_1.renderHook)(() => (0, react_2.useAppInstallProgress)({
...mockedState,
currentProgressSubject,
currentAppOp: {
type: "install",
name: "XRP",
},
}, "XRP"));
(0, react_1.act)(() => {
currentProgressSubject.next(0.71);
});
expect(result.current).toBe(0.71);
});
const mockedWithFreeBlocksStateNanoS = (0, _1.initState)((0, mock_1.mockListAppsResult)("Bitcoin, Ethereum, Litecoin, Dogecoin, Ethereum Classic, XRP, Bitcoin Cash, Stellar, Monero, Tezos", "Bitcoin, Ethereum, Litecoin, Dogecoin, Ethereum Classic, XRP, Bitcoin Cash", mock_1.deviceInfo155));
const mockedNoFreeBlocksStateNanoS = (0, _1.initState)((0, mock_1.mockListAppsResult)("Bitcoin, Ethereum, Litecoin, Dogecoin, Ethereum Classic, XRP, Bitcoin Cash, Stellar, Monero, Tezos", "Bitcoin_4090blocks, Ethereum, Litecoin, Dogecoin, Ethereum Classic, XRP, Bitcoin Cash", mock_1.deviceInfo155));
test("Apps hooks - useNotEnoughMemoryToInstall - Will fit new install", () => {
const { result } = (0, react_1.renderHook)(() => (0, react_3.useNotEnoughMemoryToInstall)(mockedWithFreeBlocksStateNanoS, "Tezos"));
expect(result.current).toBe(false);
});
test("Apps hooks - useNotEnoughMemoryToInstall - Will not fit install", () => {
const { result } = (0, react_1.renderHook)(() => (0, react_3.useNotEnoughMemoryToInstall)(mockedNoFreeBlocksStateNanoS, "Tezos"));
expect(result.current).toBe(true);
});
test("Apps hooks - useAppsSections - Correct number of updatable apps", () => {
const { result } = (0, react_1.renderHook)(() => (0, react_2.useAppsSections)(mockedState, {
query: "",
appFilter: "all",
sort: {
type: "name",
order: "desc",
},
}));
expect(result.current.update.length).toBe(1);
});
test("Apps hooks - useAppsSections - Correct number of installed apps", () => {
const { result } = (0, react_1.renderHook)(() => (0, react_2.useAppsSections)(mockedState, {
query: "",
appFilter: "all",
sort: {
type: "name",
order: "desc",
},
}));
expect(result.current.device.length).toBe(6);
});
test("Apps hooks - useAppsSections - Correct number of catalog apps", () => {
const { result } = (0, react_1.renderHook)(() => (0, react_2.useAppsSections)(mockedState, {
query: "",
appFilter: "all",
sort: {
type: "name",
order: "desc",
},
}));
expect(result.current.catalog.length).toBe(12);
});
test("Apps hooks - useAppsSections - Correct number of catalog apps with query", () => {
const { result } = (0, react_1.renderHook)(() => (0, react_2.useAppsSections)(mockedState, {
query: "coin",
appFilter: "all",
sort: {
type: "name",
order: "desc",
},
}));
expect(result.current.catalog.length).toBe(5);
});
test("Apps hooks - useAppsSections - Correct number of installed apps with query", () => {
const { result } = (0, react_1.renderHook)(() => (0, react_2.useAppsSections)(mockedState, {
query: "coin",
appFilter: "all",
sort: {
type: "name",
order: "desc",
},
}));
expect(result.current.device.length).toBe(1);
});
const mockedStateWithInstallQueue = {
...(0, _1.initState)((0, mock_1.mockListAppsResult)("Bitcoin, Bitcoin Legacy, Ethereum, Litecoin, Dogecoin, Ethereum Classic, XRP, Bitcoin Cash, Decred, Aave, Polygon, Binance Smart Chain", "Litecoin (outdated), Ethereum, Ethereum Classic, Aave, Polygon, Binance Smart Chain", mock_1.deviceInfo155)),
installQueue: ["Bitcoin", "Dogecoin"],
};
test('Apps hooks - useAppsSections - Sort "device" category apps with installing apps first', () => {
const options = {
query: "",
appFilter: "all",
sort: { type: "name", order: "desc" },
};
const { result: vanillaResult } = (0, react_1.renderHook)(() => (0, react_2.useAppsSections)(mockedState, options));
const { result: installQueueResult } = (0, react_1.renderHook)(() => (0, react_2.useAppsSections)(mockedStateWithInstallQueue, options));
// "catalog" and "update" categories should be similar with/without install queue
expect(vanillaResult.current.catalog).toMatchObject(installQueueResult.current.catalog);
expect(vanillaResult.current.update).toMatchObject(installQueueResult.current.update);
// "device" category should be sorted differently
expect(vanillaResult.current.device.map(elt => elt.name)).toMatchObject([
// Installed apps
"Ethereum",
"Litecoin",
"Ethereum Classic",
"Aave",
"Polygon",
"Binance Smart Chain",
]);
expect(installQueueResult.current.device.map(elt => elt.name)).toMatchObject([
// Apps being installed
"Bitcoin",
"Dogecoin",
// Installed apps
"Ethereum",
"Litecoin",
"Ethereum Classic",
"Aave",
"Polygon",
"Binance Smart Chain",
]);
});
//# sourceMappingURL=react.test.js.map