2023-04-25 11:47:49 +02:00
|
|
|
import { ApprovalType } from '@metamask/controller-utils';
|
2023-06-29 17:51:56 +02:00
|
|
|
import { getApprovalFlows, hasPendingApprovals } from './approvals';
|
2023-04-25 11:47:49 +02:00
|
|
|
|
|
|
|
describe('approval selectors', () => {
|
|
|
|
const mockedState = {
|
|
|
|
metamask: {
|
2023-05-11 07:56:17 +02:00
|
|
|
pendingApprovalCount: 3,
|
2023-04-25 11:47:49 +02:00
|
|
|
pendingApprovals: {
|
|
|
|
'1': {
|
|
|
|
id: '1',
|
|
|
|
origin: 'origin',
|
|
|
|
time: Date.now(),
|
|
|
|
type: ApprovalType.WatchAsset,
|
|
|
|
requestData: {},
|
|
|
|
requestState: null,
|
2023-06-29 17:51:56 +02:00
|
|
|
expectsResult: false,
|
2023-04-25 11:47:49 +02:00
|
|
|
},
|
|
|
|
'2': {
|
|
|
|
id: '2',
|
|
|
|
origin: 'origin',
|
|
|
|
time: Date.now(),
|
2023-05-11 07:56:17 +02:00
|
|
|
type: ApprovalType.Transaction,
|
2023-04-25 11:47:49 +02:00
|
|
|
requestData: {},
|
|
|
|
requestState: null,
|
2023-06-29 17:51:56 +02:00
|
|
|
expectsResult: false,
|
2023-04-25 11:47:49 +02:00
|
|
|
},
|
|
|
|
},
|
2023-06-29 17:51:56 +02:00
|
|
|
approvalFlows: [
|
|
|
|
{
|
|
|
|
id: '1',
|
|
|
|
loadingText: 'loadingText1',
|
|
|
|
},
|
|
|
|
{
|
2023-05-11 07:56:17 +02:00
|
|
|
id: '2',
|
2023-06-29 17:51:56 +02:00
|
|
|
loadingText: 'loadingText2',
|
2023-05-11 07:56:17 +02:00
|
|
|
},
|
2023-06-29 17:51:56 +02:00
|
|
|
],
|
2023-04-25 11:47:49 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-05-11 07:56:17 +02:00
|
|
|
describe('hasPendingApprovals', () => {
|
2023-04-25 11:47:49 +02:00
|
|
|
it('should return true if there is a pending approval request', () => {
|
2023-05-11 07:56:17 +02:00
|
|
|
const result = hasPendingApprovals(mockedState, ApprovalType.WatchAsset);
|
2023-04-25 11:47:49 +02:00
|
|
|
|
|
|
|
expect(result).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if there is no pending approval request', () => {
|
2023-05-11 07:56:17 +02:00
|
|
|
const result = hasPendingApprovals(
|
2023-04-25 11:47:49 +02:00
|
|
|
mockedState,
|
2023-05-11 07:56:17 +02:00
|
|
|
ApprovalType.SnapDialogPrompt,
|
2023-04-25 11:47:49 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(result).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2023-06-29 17:51:56 +02:00
|
|
|
|
|
|
|
describe('getApprovalFlows', () => {
|
|
|
|
it('should return existing approval flows', () => {
|
|
|
|
const result = getApprovalFlows(mockedState);
|
|
|
|
|
|
|
|
expect(result).toStrictEqual(mockedState.metamask.approvalFlows);
|
|
|
|
});
|
|
|
|
});
|
2023-04-25 11:47:49 +02:00
|
|
|
});
|