Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteflower committed Dec 2, 2024
1 parent 78c60a9 commit 13ef761
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
50 changes: 50 additions & 0 deletions ui/pages/bridge/transaction-details/transaction-details.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
BridgeHistoryItem,
StatusTypes,
} from '../../../../shared/types/bridge-status';
import { getIsDelayed } from './transaction-details';

describe('transaction-details', () => {
describe('getIsDelayed', () => {
it('returns false when status is not PENDING', () => {
const result = getIsDelayed(StatusTypes.COMPLETE, {
startTime: Date.now(),
estimatedProcessingTimeInSeconds: 60,
} as BridgeHistoryItem);
expect(result).toBe(false);
});

it('returns false when bridgeHistoryItem is undefined', () => {
const result = getIsDelayed(StatusTypes.PENDING, undefined);
expect(result).toBe(false);
});

it('returns false when startTime is undefined', () => {
const result = getIsDelayed(StatusTypes.PENDING, {
startTime: undefined,
estimatedProcessingTimeInSeconds: 60,
} as BridgeHistoryItem);
expect(result).toBe(false);
});

it('returns false when current time is less than estimated completion time', () => {
const result = getIsDelayed(StatusTypes.PENDING, {
startTime: Date.now() - 1000,
estimatedProcessingTimeInSeconds: 60,
} as BridgeHistoryItem);

expect(result).toBe(false);
});

it('returns true when current time exceeds estimated completion time', () => {
const startTime = Date.now() - 61 * 1000;

const result = getIsDelayed(StatusTypes.PENDING, {
startTime,
estimatedProcessingTimeInSeconds: 60,
} as BridgeHistoryItem);

expect(result).toBe(true);
});
});
});
12 changes: 6 additions & 6 deletions ui/pages/bridge/transaction-details/transaction-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ const getBridgeAmount = ({
return undefined;
};

const getIsDelayed = (
export const getIsDelayed = (
status: StatusTypes,
bridgeHistoryItem?: BridgeHistoryItem,
) => {
return (
return Boolean(
status === StatusTypes.PENDING &&
bridgeHistoryItem?.startTime &&
Date.now() >
bridgeHistoryItem.startTime +
bridgeHistoryItem.estimatedProcessingTimeInSeconds * 1000
bridgeHistoryItem?.startTime &&
Date.now() >
bridgeHistoryItem.startTime +
bridgeHistoryItem.estimatedProcessingTimeInSeconds * 1000,
);
};

Expand Down

0 comments on commit 13ef761

Please sign in to comment.